|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
Server
Class Server implements the server-side of RMI.
This includes all the players, races and tracks. Their creation, deletion, joining, loading and changing.
Implements ServerInterface RMI interface. When the client
program is run and it joins to the server, ServerInterface is
the interface through which the client can communicate with the server. The
client receives an object that implements the ServerInterface
and can make direct method invocations to the server through the methods in
this interface.
ServerInterface,
Player,
Game,
ServerCommandHandler,
Serialized Form| Field Summary | |
private java.util.ArrayList |
games
List of the races on the server. |
private static int |
next_unique_id
Counter for the unique id. |
private java.util.ArrayList |
players
A list of the players that are on the server |
private static java.rmi.registry.Registry |
registry
Registry |
private java.lang.String[] |
track_list
A list of the names of the tracks that can be used. |
static java.lang.String |
version
|
| Fields inherited from class java.rmi.server.UnicastRemoteObject |
|
| Fields inherited from class java.rmi.server.RemoteServer |
|
| Fields inherited from class java.rmi.server.RemoteObject |
ref |
| Constructor Summary | |
Server()
The constructor for the server. |
|
| Method Summary | |
void |
addGame(Game g)
Adds a race to the list on the server. |
void |
addPlayer(Player p)
Adds a player to the list on the server. |
void |
changeTrack(int game_id,
java.lang.String track_name)
Loads a new track to a race (if it's not in a racing state). |
void |
cleanup()
Kicks the players from the server and ends all races. |
int |
createGame(int player_id,
java.lang.String game_name)
Creates a new race and places the player in it. |
void |
gameListChanged()
Sends an updated race list to all players. |
Game |
getGame(int game_id)
Returns the specified Game object. |
Game |
getGameById(int id)
Returns the race with the given id. |
GameInfo[] |
getGameList()
Collects a race list. |
java.util.Iterator |
getGamesIterator()
Returns an iterator for the races. |
int |
getNextUniqueId()
Returns the next unused unique_id. |
int |
getNumGames()
Returns the number of races. |
int |
getNumPlayers()
Returns the number of players on the server. |
Player |
getPlayer(int player_id)
Returns the specified Player object. |
Player |
getPlayerById(int player_id)
Returns the player with the given id. |
java.util.Iterator |
getPlayersIterator()
Returns an iterator for the players. |
boolean |
joinGame(int player_id,
int game_id)
Places the player in a race. |
void |
leaveGame(int player_id,
int game_id)
Exits a race. |
int |
loginPlayer(java.lang.String name,
ClientInterface cobj)
Logs the player in to the server. |
void |
logoutPlayer(int player_id)
Logs the player out from the server. |
static void |
main(java.lang.String[] args)
Main. |
void |
removeGame(Game g)
Removes a race from the list on the server. |
void |
removePlayer(Player p)
Removes a player from the list on the server. |
void |
sayToAll(java.lang.String message)
Sends a chat message to everybody. |
void |
sayToGame(int game_id,
java.lang.String message)
Sends a chat message to the specified race. |
void |
sayToLobby(java.lang.String message)
Sends a chat message to everybody in the lobby room. |
void |
setSail(int player_id,
int sail)
Adjusts a sail. |
void |
startGame(int game_id)
Starts racing in a race. |
void |
turnLeft(int player_id)
Turns a boat portboard. |
void |
turnRight(int player_id)
Turns a boat starboard. |
void |
updateTrackList()
Updates the track list by reading the names of all tracks from the tracklist file in the tracks directory. |
| Methods inherited from class java.rmi.server.UnicastRemoteObject |
clone, exportObject, exportObject, exportObject, unexportObject |
| Methods inherited from class java.rmi.server.RemoteServer |
getClientHost, getLog, setLog |
| Methods inherited from class java.rmi.server.RemoteObject |
equals, getRef, hashCode, toString, toStub |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.String version
private static java.rmi.registry.Registry registry
private java.util.ArrayList players
private java.util.ArrayList games
private static int next_unique_id
Each new player and race receives a new, unused
unique_id value.
private java.lang.String[] track_list
| Constructor Detail |
public Server()
throws java.rmi.RemoteException
| Method Detail |
public void addPlayer(Player p)
p - the handler object of the player to addpublic void removePlayer(Player p)
p - the handler object of the player to removepublic int getNumPlayers()
public java.util.Iterator getPlayersIterator()
public Player getPlayerById(int player_id)
player_id - the id of the player to return
public void addGame(Game g)
public void removeGame(Game g)
public int getNumGames()
public java.util.Iterator getGamesIterator()
public Game getGameById(int id)
id - the id of the race to return
public void gameListChanged()
This is executed when the race list has changed, i.e. a new race is created or an existing race is closed. Also executed when the state of a race is changed!
Game.javapublic GameInfo[] getGameList()
public int getNextUniqueId()
public void updateTrackList()
tracklist file in the tracks directory.
public static void main(java.lang.String[] args)
args - command line parameters givenpublic void cleanup()
public int loginPlayer(java.lang.String name,
ClientInterface cobj)
throws java.rmi.RemoteException
loginPlayer in interface ServerInterfacename - player namecobj - client's player object
java.rmi.RemoteException
public void logoutPlayer(int player_id)
throws java.rmi.RemoteException
logoutPlayer in interface ServerInterfaceplayer_id - player id
java.rmi.RemoteException
public boolean joinGame(int player_id,
int game_id)
throws java.rmi.RemoteException
joinGame in interface ServerInterfaceplayer_id - player idgame_id - race id
java.rmi.RemoteException
public int createGame(int player_id,
java.lang.String game_name)
throws java.rmi.RemoteException
createGame in interface ServerInterfaceplayer_id - player idgame_name - name of the race to create
java.rmi.RemoteException
public void leaveGame(int player_id,
int game_id)
throws java.rmi.RemoteException
leaveGame in interface ServerInterfaceplayer_id - player idgame_id - race id
java.rmi.RemoteException
public void startGame(int game_id)
throws java.rmi.RemoteException
Only race master calls this.
startGame in interface ServerInterfacegame_id - race id
java.rmi.RemoteException
public void turnLeft(int player_id)
throws java.rmi.RemoteException
turnLeft in interface ServerInterfaceplayer_id - player id
java.rmi.RemoteException
public void turnRight(int player_id)
throws java.rmi.RemoteException
turnRight in interface ServerInterfaceplayer_id - player id
java.rmi.RemoteException
public void setSail(int player_id,
int sail)
throws java.rmi.RemoteException
setSail in interface ServerInterfaceplayer_id - player idsail - new sail value
java.rmi.RemoteException
public Game getGame(int game_id)
throws java.rmi.RemoteException
Game object.
getGame in interface ServerInterfacegame_id - race id
Game object.
java.rmi.RemoteException
public Player getPlayer(int player_id)
throws java.rmi.RemoteException
Player object.
getPlayer in interface ServerInterfaceplayer_id - player id
Player object.
java.rmi.RemoteException
public void sayToAll(java.lang.String message)
throws java.rmi.RemoteException
sayToAll in interface ServerInterfacemessage - chat message
java.rmi.RemoteException
public void sayToLobby(java.lang.String message)
throws java.rmi.RemoteException
sayToLobby in interface ServerInterfacemessage - chat message
java.rmi.RemoteException
public void sayToGame(int game_id,
java.lang.String message)
throws java.rmi.RemoteException
sayToGame in interface ServerInterfacegame_id - the race to send the message tomessage - chat message
java.rmi.RemoteException
public void changeTrack(int game_id,
java.lang.String track_name)
throws java.rmi.RemoteException
changeTrack in interface ServerInterfacegame_id - race idtrack_name - the name of the track to load
java.rmi.RemoteException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||