Interface ServerInterface

All Superinterfaces:
java.rmi.Remote
All Known Implementing Classes:
Server

public interface ServerInterface
extends java.rmi.Remote

Interface ServerInterface is an interface through which the client (Tracksail) executes remote calls to the server.

Inherits the Remote interface. Class Server implements the ServerInterface interface. Thus, ServerInterface provides the RMI functionality of making remote calls directly from the client to the server.

The client receives an object that implements ServerInterface from RMI (returned by the Naming.lookup(...) method). After this, the client can directly call the ServerInterface methods of the received object and the calls are transferred to the server which has implemented the methods in question.

First we call the loginPlayer method, which receives as it's parameter, among others, a client object that implements the ClientInterface interface. The object is stored on the server. The reason behind this is that the server can use it to call the services of the client directly.

Version:
1.0
Author:
Stefan Brockmann, Tero Kuusela
See Also:
Server, ClientInterface

Method Summary
 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).
 int createGame(int player_id, java.lang.String game_name)
          Creates a new race and places the player in it.
 Game getGame(int game_id)
          Returns the specified Game object.
 Player getPlayer(int player_id)
          Returns the specified Player object.
 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.
 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.
 

Method Detail

loginPlayer

public int loginPlayer(java.lang.String name,
                       ClientInterface cobj)
                throws java.rmi.RemoteException
Logs the player in to the server.

Parameters:
name - player name
cobj - client's player object
Returns:
The unique id for this player.
Throws:
java.rmi.RemoteException

logoutPlayer

public void logoutPlayer(int player_id)
                  throws java.rmi.RemoteException
Logs the player out from the server.

Parameters:
player_id - player id
Throws:
java.rmi.RemoteException

joinGame

public boolean joinGame(int player_id,
                        int game_id)
                 throws java.rmi.RemoteException
Places the player in a race.

Parameters:
player_id - player id
game_id - race id
Returns:
true if the player successfully joined the race, false otherwise
Throws:
java.rmi.RemoteException

createGame

public int createGame(int player_id,
                      java.lang.String game_name)
               throws java.rmi.RemoteException
Creates a new race and places the player in it.

Parameters:
player_id - player id
game_name - name of the race to create
Returns:
-1 if failed, game_id(<=0) if a new race was created and the player placed in it.
Throws:
java.rmi.RemoteException

leaveGame

public void leaveGame(int player_id,
                      int game_id)
               throws java.rmi.RemoteException
Exits a race.

Parameters:
player_id - player id
game_id - race id
Throws:
java.rmi.RemoteException

startGame

public void startGame(int game_id)
               throws java.rmi.RemoteException
Starts racing in a race.

Only race master calls this.

Parameters:
game_id - race id
Throws:
java.rmi.RemoteException

turnLeft

public void turnLeft(int player_id)
              throws java.rmi.RemoteException
Turns a boat portboard.

Parameters:
player_id - player id
Throws:
java.rmi.RemoteException

turnRight

public void turnRight(int player_id)
               throws java.rmi.RemoteException
Turns a boat starboard.

Parameters:
player_id - player id
Throws:
java.rmi.RemoteException

setSail

public void setSail(int player_id,
                    int sail)
             throws java.rmi.RemoteException
Adjusts a sail.

Parameters:
player_id - player id
sail - new sail value
Throws:
java.rmi.RemoteException

getGame

public Game getGame(int game_id)
             throws java.rmi.RemoteException
Returns the specified Game object.

Parameters:
game_id - race id
Returns:
Game object.
Throws:
java.rmi.RemoteException

getPlayer

public Player getPlayer(int player_id)
                 throws java.rmi.RemoteException
Returns the specified Player object.

Parameters:
player_id - player id
Returns:
Player object.
Throws:
java.rmi.RemoteException

sayToAll

public void sayToAll(java.lang.String message)
              throws java.rmi.RemoteException
Sends a chat message to everybody.

Parameters:
message - chat message
Throws:
java.rmi.RemoteException

sayToLobby

public void sayToLobby(java.lang.String message)
                throws java.rmi.RemoteException
Sends a chat message to everybody in the lobby room.

Parameters:
message - chat message
Throws:
java.rmi.RemoteException

sayToGame

public void sayToGame(int game_id,
                      java.lang.String message)
               throws java.rmi.RemoteException
Sends a chat message to the specified race.

Parameters:
game_id - the race to send the message to
message - chat message
Throws:
java.rmi.RemoteException

changeTrack

public void changeTrack(int game_id,
                        java.lang.String track_name)
                 throws java.rmi.RemoteException
Loads a new track to a race (if it's not in a racing state).

Parameters:
game_id - race id
track_name - the name of the track to load
Throws:
java.rmi.RemoteException