|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.cuni.pogamut.server.UTServer
public class UTServer
Representation of the UTServer, runs it own thread and manages CONNECTION / RECONNECTION / KEEP ALIVE / COMMUNICATION Work of the thread is based on requests that are stored in the queue and executed accordinaly. This way whole communication with the server is synchronized.
Field Summary | |
---|---|
private java.util.Set<BotEnteredWorldListener> |
botEnteredWorldListeners
|
private java.util.Set<BotLeftWorldListener> |
botLeftWorldListeners
|
private UTServerConnection |
connection
ServerConnection object that manage the connection to GB and process the requests. |
protected GameBotConnection |
gbConn
|
protected java.net.Socket |
gbSocket
|
protected UTServerInfoSnapshot |
info
This contains all the informations about the server. |
private java.util.logging.Logger |
log
Logger for the class, used also by UTServerConnection. |
private java.util.logging.Logger |
rawGBLog
Logger for the GB raw data. |
protected java.util.concurrent.CountDownLatch |
waitInventory
|
protected java.util.concurrent.CountDownLatch |
waitItems
|
protected java.util.concurrent.CountDownLatch |
waitMaps
|
protected java.util.concurrent.CountDownLatch |
waitNavPoints
|
protected java.util.concurrent.CountDownLatch |
waitRefreshInfo
|
protected java.io.PrintWriter |
writer
|
Constructor Summary | |
---|---|
UTServer()
Used for loading the agent classes from projects directories. |
Method Summary | |
---|---|
void |
addBotEnteredWorldListener(BotEnteredWorldListener listener)
Add listener to the bot-enetered-the-world event. |
void |
addBotLeftWorldListener(BotLeftWorldListener listener)
Add listener to the bot-left-the-world event. |
void |
addInventory(java.lang.String botUnrealId,
java.lang.String inventoryClass)
Adds the item to the bot's inventory. |
void |
addRcvMsgListener(RcvMsgListener listener)
Add listener that will be notified when a new message from Server Control will arrive. |
void |
botAutoTrace(java.lang.String botUnrealId,
boolean autoTrace)
TODO: comment |
void |
botDrawTraceLines(java.lang.String botUnrealId,
boolean drawTraceLines)
|
void |
botInvulnerable(java.lang.String botUnrealId,
boolean invulnerable)
According to param 'invulnerable' sets (or retract) the invulnerability of the specified bot. |
void |
botManualSpawn(java.lang.String botUnrealId,
boolean manualSpawn)
TODO: comment |
void |
botShowDebug(java.lang.String botUnrealId,
boolean showDebug)
|
void |
botShowFocalPoint(java.lang.String botUnrealId,
boolean showFocalPoint)
|
void |
botSynchronousOff(java.lang.String botUnrealId,
boolean synchronousOff)
|
void |
connect()
Connects the server if communication is down with URI specified through setServerURI(). |
java.lang.String |
connectBot(Agent newBot)
Connects bot to the server. |
java.lang.String |
connectBot(Agent newBot,
ParserType parserType)
|
java.lang.String |
connectBot(Agent bot,
java.lang.String botName)
Connects bot to the server. |
void |
connectBot(Agent bot,
java.lang.String botName,
ParserType parserType)
Connects bot to the server with given type of parser. |
void |
connectOriginalBot(java.lang.String name,
Triple location,
int difficultyLevel,
int team)
Connects a native UT bot. |
static UTServer |
createLocalhostServer()
|
void |
disconnect()
Disconnect the server connection + stops the communication thread. |
void |
disconnectAllBots()
Disconnect all bots from server. |
void |
disconnectBot(Agent bot)
Disconnect bot from UT server |
void |
disconnectBot(java.lang.String botUnrealId)
Disconnects bot from this server. |
void |
finalize()
|
void |
flagChanged(java.lang.Object changedValue,
int listenerParam)
When registering the flag you may additionally specify listener parameter, if you do so - your listener will be called with that parameter. |
java.util.Collection<Player> |
getAllBots()
Returns list of players inside the world. |
boolean |
getAutomaticallyReconnect()
|
int |
getAutoReconnectMillis()
|
java.util.Collection<UTMap> |
getAvailableMaps()
Can return NULL -> means communication with GB is DOWN ... |
java.util.Collection<Agent> |
getConnectedBots()
List of bots connected to server through this UTServer instance. |
UTServerConnection |
getConnection()
|
java.util.Collection<Agent> |
getDisconnectedBots()
Returns collection of all TERMINATED or FAILed bots. |
MessageType |
getExpectedWelcomeMessage()
Which message we should expect as the greeting from GameBots? |
java.net.URI |
getGamebotsBotsURI()
|
java.net.URI |
getGamebotsControlConnectionURI()
|
GameInfo |
getGameInfo()
|
protected GameBotConnection |
getGBConnection()
|
UTServerInfoSnapshot |
getInfo()
Must NOT return null !!! |
java.util.Map<java.lang.String,Item> |
getInventory()
|
java.util.Collection<Item> |
getItems()
May return NULL -> means communication with GB is DOWN ... |
java.util.logging.Logger |
getLog()
|
java.lang.String |
getMap()
Returns name of the map which is loaded into UT2004. |
java.lang.String |
getName()
Returns human readable name of the server. |
java.util.Collection<NavPoint> |
getNavPoints()
May return NULL -> means communication with GB is DOWN ... |
boolean |
getPingPong()
|
java.util.Set<Player> |
getPlayers()
|
int |
getPongTimeoutMillis()
|
private ParserType |
getPreferredParserType()
Returns preferred parser type for bots connecting <-> server communication. |
java.util.logging.Logger |
getRawGBLog()
Which log should be used to dump raw GB data. |
java.net.URI |
getServerRemoteParserURI()
|
UTServerState |
getServerState()
Tells the server state ... e.g. running / initializing, etc. |
Flag<UTServerState> |
getServerStateFlag()
Flag of the server state, you may hook up the listener on it... |
UTServerInfoSnapshot |
getSnapshot()
|
java.util.concurrent.CountDownLatch |
getWaitInventoryLatch()
|
java.util.concurrent.CountDownLatch |
getWaitItemsLatch()
|
java.util.concurrent.CountDownLatch |
getWaitMapsLatch()
|
java.util.concurrent.CountDownLatch |
getWaitNavPointsLatch()
|
java.util.concurrent.CountDownLatch |
getWaitRefreshInfoLatch()
|
void |
changeAttribute(java.lang.String botUnrealId,
java.lang.String attribute,
java.lang.String value)
Changes the bot's attribute value to a specified value. |
protected void |
init()
Called from constructor or from readObject(). |
boolean |
isAutomaticallyReconnect()
Whether we should automaticly try to reconnect. |
boolean |
isConnectionAlive()
HERE BEGINS IMPLEMENTATION OF UTWORLD INTERFACE ****** |
boolean |
isPingPong()
Whether we should check whether the connection is active. |
boolean |
isServerOpened()
Does this server allow connection of new bots? |
void |
kickBot(java.lang.String botUnrealId)
Kick bot from the game. |
Agent |
loadAgent(java.lang.String fullyClassifiedClassName)
TODO redundant? |
java.lang.Class |
loadAgentClass(java.lang.String fullyClassifiedClassName)
TODO redundant? |
static void |
main(java.lang.String[] args)
|
void |
pause(boolean completely)
Pause the world. |
private void |
readObject(java.io.ObjectInputStream in)
Deserialization... |
void |
reconnect()
Issue reconnect request. |
boolean |
refreshInformations()
Requests and waits for refreshing the informations about the server. |
void |
removeAllBots()
Remove all bots from list of bots. |
void |
removeBot(Agent bot)
Remove bot from list of bots. |
void |
removeBotEnteredWorldListener(BotEnteredWorldListener listener)
Remove listener to the bot-enetered-the-world event. |
protected void |
removeBotInner(Agent bot)
|
void |
removeBotLeftWorldListener(BotLeftWorldListener listener)
Remove listener to the bot-left-the-world event. |
java.util.Collection<Agent> |
removeDisconnectedBots()
Remove all disconnected bots from list of bots. |
void |
removeRcvMsgListener(RcvMsgListener listener)
Remove listener that listens for messages from server control. |
boolean |
request(UTServerRequest request)
This method is synchronized (later on in the body)! |
void |
respawnBot(java.lang.String botUnrealId)
Respawns specified bot at random place. |
void |
respawnBot(java.lang.String botUnrealId,
Triple location)
Respawns specified bot at specified location. |
void |
resume()
Resume the world; |
void |
sendToGB(java.lang.String msg)
|
void |
setAutomaticallyReconnect(boolean automaticallyReconnect)
|
void |
setAutoReconnectMillis(int autoReconnectMillis)
|
void |
setBotName(java.lang.String botUnrealId,
java.lang.String name)
TODO: comment |
void |
setConnection(UTServerConnection connection)
|
void |
setGamebotsBotURI(java.net.URI serverURI)
|
void |
setGamebotsControlConnectionURI(java.net.URI serverURI)
|
void |
setGameInfo(GameInfo info)
DO NOT USED OUTSIDE THE UTServerConnection !!! |
void |
setGameSpeed(double speed)
Speed is from 0.1 to 40. 1 is normal game speed. |
boolean |
setMap(java.lang.String name)
Sets the map of the UT2004, NO BLOCK |
boolean |
setMapAndWait(java.lang.String name)
Will send command to change the map IFF it's not the one that is currently running. |
void |
setName(java.lang.String name)
Sets the name of the server. |
void |
setPingPong(boolean pingPong)
|
void |
setPongTimeoutMillis(int pongTimeoutMillis)
|
void |
setServerOpened(boolean opened)
Open or close server for new bots. |
void |
setServerRemoteParserURI(java.net.URI serverURI)
|
void |
setVisionTime(double visionTime)
Set vision time... whatever it is. |
void |
startRecording(java.lang.String fileName)
Starts recording of the "replay" to a specified file at server. |
void |
stopRecording()
Stops recording of the "replay". |
void |
terminate()
Requests termination of the server. |
java.lang.String |
toString()
Returns name of the server in format "name (uri)". |
boolean |
waitForCommunication()
Checks whether communication is OK, if not, issue reconnect() and waits for communication |
boolean |
waitForNFOMessageInHandshake()
Whether we should wait for NFO message after READY is sent. |
private void |
writeObject(java.io.ObjectOutputStream out)
Serialization... |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private transient java.util.logging.Logger log
private transient java.util.logging.Logger rawGBLog
private transient UTServerConnection connection
private transient java.util.Set<BotEnteredWorldListener> botEnteredWorldListeners
private transient java.util.Set<BotLeftWorldListener> botLeftWorldListeners
protected UTServerInfoSnapshot info
protected transient java.util.concurrent.CountDownLatch waitNavPoints
protected transient java.util.concurrent.CountDownLatch waitItems
protected transient java.util.concurrent.CountDownLatch waitMaps
protected transient java.util.concurrent.CountDownLatch waitRefreshInfo
protected transient java.util.concurrent.CountDownLatch waitInventory
protected GameBotConnection gbConn
protected java.net.Socket gbSocket
protected java.io.PrintWriter writer
Constructor Detail |
---|
public UTServer()
Method Detail |
---|
public static UTServer createLocalhostServer()
protected void init()
public void connect()
public void disconnect()
public java.lang.String toString()
toString
in class java.lang.Object
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
in
-
java.io.IOException
java.lang.ClassNotFoundException
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
out
-
java.io.IOException
public boolean request(UTServerRequest request)
request
-
public Flag<UTServerState> getServerStateFlag()
getServerStateFlag
in interface UTServerConnectionInterface
getServerStateFlag
in interface UTWorld
public UTServerState getServerState()
getServerState
in interface UTServerConnectionInterface
public boolean isAutomaticallyReconnect()
UTServerConnectionInterface
isAutomaticallyReconnect
in interface UTServerConnectionInterface
public void setAutomaticallyReconnect(boolean automaticallyReconnect)
public boolean getAutomaticallyReconnect()
public UTServerConnection getConnection()
public void setConnection(UTServerConnection connection)
public boolean isPingPong()
UTServerConnectionInterface
isPingPong
in interface UTServerConnectionInterface
public void setPingPong(boolean pingPong)
public boolean getPingPong()
public int getPongTimeoutMillis()
getPongTimeoutMillis
in interface UTServerConnectionInterface
public void setPongTimeoutMillis(int pongTimeoutMillis)
public java.util.logging.Logger getLog()
getLog
in interface UTServerConnectionInterface
public java.net.URI getGamebotsControlConnectionURI()
getGamebotsControlConnectionURI
in interface UTServerConnectionInterface
public java.net.URI getGamebotsBotsURI()
public void setGamebotsControlConnectionURI(java.net.URI serverURI)
public void setGamebotsBotURI(java.net.URI serverURI)
public void setServerRemoteParserURI(java.net.URI serverURI)
public java.net.URI getServerRemoteParserURI()
public int getAutoReconnectMillis()
getAutoReconnectMillis
in interface UTServerConnectionInterface
public void setAutoReconnectMillis(int autoReconnectMillis)
public java.util.logging.Logger getRawGBLog()
UTServerConnectionInterface
getRawGBLog
in interface UTServerConnectionInterface
public GameInfo getGameInfo()
getGameInfo
in interface UTServerConnectionInterface
public void setGameInfo(GameInfo info)
setGameInfo
in interface UTServerConnectionInterface
public void flagChanged(java.lang.Object changedValue, int listenerParam)
FlagListener
flagChanged
in interface FlagListener
public void terminate()
public void finalize()
finalize
in class java.lang.Object
public boolean refreshInformations()
public void reconnect()
public boolean waitForCommunication()
public java.util.Set<Player> getPlayers()
public void addRcvMsgListener(RcvMsgListener listener)
public void removeRcvMsgListener(RcvMsgListener listener)
public UTServerInfoSnapshot getSnapshot()
public boolean isServerOpened()
public void setServerOpened(boolean opened)
public void setName(java.lang.String name)
name
- New name.public boolean isConnectionAlive()
isConnectionAlive
in interface UTWorld
public java.lang.String getName()
getName
in interface UTWorld
public java.lang.String getMap()
getMap
in interface UTWorld
public boolean setMap(java.lang.String name) throws PogamutException
UTWorld
setMap
in interface UTWorld
PogamutException
public boolean setMapAndWait(java.lang.String name) throws PogamutException
UTWorld
setMapAndWait
in interface UTWorld
PogamutException
public java.util.Collection<UTMap> getAvailableMaps()
getAvailableMaps
in interface UTWorld
public java.util.Collection<NavPoint> getNavPoints() throws PogamutException
getNavPoints
in interface UTWorld
PogamutException
public java.util.Collection<Item> getItems()
getItems
in interface UTWorld
public java.util.Map<java.lang.String,Item> getInventory()
getInventory
in interface UTWorld
public java.util.Collection<Player> getAllBots() throws PogamutException
UTWorld
getAllBots
in interface UTWorld
PogamutException
public java.util.Collection<Agent> getConnectedBots()
getConnectedBots
in interface UTWorld
public java.lang.String connectBot(Agent newBot) throws PogamutException
connectBot
in interface UTWorld
bot
- Bot to be connected.
PogamutException
public java.lang.String connectBot(Agent newBot, ParserType parserType) throws PogamutException
newBot
- parserType
-
PogamutException
public java.lang.String connectBot(Agent bot, java.lang.String botName) throws PogamutException
connectBot
in interface UTWorld
bot
- Bot to be connected.
PogamutException
private ParserType getPreferredParserType()
public void connectBot(Agent bot, java.lang.String botName, ParserType parserType) throws PogamutException
bot
- Bot to be connected.
PogamutException
public void connectOriginalBot(java.lang.String name, Triple location, int difficultyLevel, int team) throws PogamutException
connectOriginalBot
in interface UTWorld
name
- identificator of the bot class inside UT
PogamutException
public void respawnBot(java.lang.String botUnrealId) throws PogamutException
UTWorld
respawnBot
in interface UTWorld
PogamutException
public void respawnBot(java.lang.String botUnrealId, Triple location) throws PogamutException
UTWorld
respawnBot
in interface UTWorld
PogamutException
public void kickBot(java.lang.String botUnrealId) throws PogamutException
kickBot
in interface UTWorld
botUnrealId
- Id of bot we want to kick from the game
PogamutException
public void disconnectBot(java.lang.String botUnrealId)
disconnectBot
in interface UTWorld
botUnrealId
- A bot to be disconnected.public void disconnectAllBots()
disconnectAllBots
in interface UTWorld
public void pause(boolean completely) throws PogamutException
UTWorld
pause
in interface UTWorld
PogamutException
public void resume() throws PogamutException
UTWorld
resume
in interface UTWorld
PogamutException
public void addInventory(java.lang.String botUnrealId, java.lang.String inventoryClass) throws PogamutException
UTWorld
addInventory
in interface UTWorld
PogamutException
public void changeAttribute(java.lang.String botUnrealId, java.lang.String attribute, java.lang.String value) throws PogamutException
UTWorld
changeAttribute
in interface UTWorld
PogamutException
public void botInvulnerable(java.lang.String botUnrealId, boolean invulnerable) throws PogamutException
UTWorld
botInvulnerable
in interface UTWorld
PogamutException
public void botAutoTrace(java.lang.String botUnrealId, boolean autoTrace) throws PogamutException
UTWorld
botAutoTrace
in interface UTWorld
PogamutException
public void botManualSpawn(java.lang.String botUnrealId, boolean manualSpawn) throws PogamutException
UTWorld
botManualSpawn
in interface UTWorld
PogamutException
public void botShowDebug(java.lang.String botUnrealId, boolean showDebug) throws PogamutException
PogamutException
public void botShowFocalPoint(java.lang.String botUnrealId, boolean showFocalPoint) throws PogamutException
PogamutException
public void botDrawTraceLines(java.lang.String botUnrealId, boolean drawTraceLines) throws PogamutException
PogamutException
public void botSynchronousOff(java.lang.String botUnrealId, boolean synchronousOff) throws PogamutException
PogamutException
public void setBotName(java.lang.String botUnrealId, java.lang.String name) throws PogamutException
UTWorld
setBotName
in interface UTWorld
PogamutException
public void setVisionTime(double visionTime) throws PogamutException
UTWorld
setVisionTime
in interface UTWorld
PogamutException
public void setGameSpeed(double speed) throws PogamutException
setGameSpeed
in interface UTWorld
PogamutException
public void startRecording(java.lang.String fileName) throws PogamutException
UTWorld
startRecording
in interface UTWorld
PogamutException
public void stopRecording() throws PogamutException
UTWorld
stopRecording
in interface UTWorld
PogamutException
public void addBotEnteredWorldListener(BotEnteredWorldListener listener)
UTWorld
addBotEnteredWorldListener
in interface UTWorld
public void removeBotEnteredWorldListener(BotEnteredWorldListener listener)
UTWorld
removeBotEnteredWorldListener
in interface UTWorld
public void addBotLeftWorldListener(BotLeftWorldListener listener)
UTWorld
addBotLeftWorldListener
in interface UTWorld
public void removeBotLeftWorldListener(BotLeftWorldListener listener)
UTWorld
removeBotLeftWorldListener
in interface UTWorld
public void disconnectBot(Agent bot)
disconnectBot
in interface UTWorld
public void removeBot(Agent bot)
protected void removeBotInner(Agent bot)
public void removeAllBots()
public java.util.Collection<Agent> removeDisconnectedBots()
public java.util.Collection<Agent> getDisconnectedBots()
public UTServerInfoSnapshot getInfo()
UTServerConnectionInterface
getInfo
in interface UTServerConnectionInterface
public java.util.concurrent.CountDownLatch getWaitNavPointsLatch()
getWaitNavPointsLatch
in interface UTServerConnectionInterface
public java.util.concurrent.CountDownLatch getWaitItemsLatch()
getWaitItemsLatch
in interface UTServerConnectionInterface
public java.util.concurrent.CountDownLatch getWaitMapsLatch()
getWaitMapsLatch
in interface UTServerConnectionInterface
public java.util.concurrent.CountDownLatch getWaitInventoryLatch()
getWaitInventoryLatch
in interface UTServerConnectionInterface
public java.util.concurrent.CountDownLatch getWaitRefreshInfoLatch()
getWaitRefreshInfoLatch
in interface UTServerConnectionInterface
public MessageType getExpectedWelcomeMessage()
UTServerConnectionInterface
getExpectedWelcomeMessage
in interface UTServerConnectionInterface
public boolean waitForNFOMessageInHandshake()
UTServerConnectionInterface
waitForNFOMessageInHandshake
in interface UTServerConnectionInterface
public java.lang.Class loadAgentClass(java.lang.String fullyClassifiedClassName) throws PogamutException
loadAgentClass
in interface UTWorld
fullyClassifiedName
- e.g. hunter.Main
PogamutException
- usualy class not found exceptionpublic Agent loadAgent(java.lang.String fullyClassifiedClassName) throws PogamutException
loadAgent
in interface UTWorld
fullyClassifiedName
- e.g. hunter.Main
PogamutException
- usualy class not found exceptionprotected GameBotConnection getGBConnection() throws java.net.UnknownHostException, ConnectException
java.net.UnknownHostException
ConnectException
public void sendToGB(java.lang.String msg) throws java.io.IOException, CantWriteException, ConnectException
java.io.IOException
CantWriteException
ConnectException
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |