ggz.client.mod
Class ModGame

java.lang.Object
  extended by ggz.client.mod.ModGame

public class ModGame
extends java.lang.Object

How a game is launched (incomplete): 1. ggz client invokes ggzcore to execute the game. The game executable is started. If socketpair() is available then it is used to create a ggz<->game socket connection. 2. A game launch packet is sent from the GGZ client to the game client. 3. The game client sets its state to CONNECTED (from created).. 4. GGZ-client is informed of the game state change. 5a. set_server informs the game client about where to connect to. A "server" packet is sent GGZ -> game. 6ab.The GGZ core client (or the game client) creates a socket and connects to GGZ... 7b. ...GGZ_GAME_NEGOTIATED ggzcore event is triggered... 8b. ggzcore_set_server_fd is called by the GGZ core client... ...it calls set_server_fd 9. the game client sets its state to WAITING 10. GGZ-client is informed of the game state change 11. GGZ_GAME_PLAYING ggzcore event is triggered 12. table-join or table-launch packet is sent from ggz CLIENT->SERVER 13. ggz SERVER handles join/launch packets, sends response 14. ... and then what? ...


Method Summary
 void connect()
          Connect to ggz.
 void disconnect()
          Disconnect from ggz.
 java.lang.Object getGamedata()
          Return gamedata object.
 java.lang.String getMyName()
          Gets the name of the player that we represent.
 int getMySeatNum()
          Call this function to find out where at the table this player is sitting.
 int getNumSeats()
          Get the total number of seats at the table.
 int getNumSpectatorSeats()
          Get the maximum number of spectators.
 Seat getSeat(int seatNum)
          Get all data for the specified seat.
 java.net.Socket getServerSocket()
          Get the socket of the game server connection.
 SpectatorSeat getSpectatorSeat(int seatNum)
          Get a spectator's data.
 ModState getState()
          Get the current state of the table.
 void handlePlayer(java.lang.String name, boolean isSpectator, int seatNum)
           
 boolean isSpectator()
           
 void requestBoot(java.lang.String name)
          Boot a player.
 void requestBot(int seatNum)
          Change the requested seat from an open seat to a bot.
 void requestChat(ChatType type, java.lang.String target, java.lang.String chatMsg)
          Chat! This initiates a table chat.
 void requestOpen(int seatNum)
          Change the requested seat from a bot to an open seat.
 void requestPlayerInfo(int seatNum)
          Request extended player information for one or more players Depending on the seat parameter (-1 or valid number), this function asynchronously requests information about player(s), which trigget ModEventHandler.handleInfo().
 void requestSit(int seatNum)
          Sit down (move from a spectator seat into a player seat).
 void requestStand()
          Stand up (move from your seat into a spectator seat).
 void setHandler(ModEventHandler listener)
           
 void setState(ModState state)
          Change the table's state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getState

public ModState getState()
Get the current state of the table.

Returns:
The state of the table.

getServerSocket

public java.net.Socket getServerSocket()
Get the socket of the game server connection.

Returns:
The server connection fd

getGamedata

public java.lang.Object getGamedata()
Return gamedata object. Each GGZMod object can be given a "gamedata" object that is returned by this function. This is useful for when a single process serves multiple GGZmod's.

Returns:
A the gamedata object (or NULL if none).
See Also:
#setGameData(Object)

setHandler

public void setHandler(ModEventHandler listener)

setState

public void setState(ModState state)
              throws java.io.IOException
Change the table's state. This function should be called to change the state of a table. A game can use this function to change state between WAITING and PLAYING, or to set it to DONE.

Parameters:
state - The new state.
Throws:
java.io.IOException

handlePlayer

public void handlePlayer(java.lang.String name,
                         boolean isSpectator,
                         int seatNum)

getMyName

public java.lang.String getMyName()
Gets the name of the player that we represent.

Returns:
The name of the player.

isSpectator

public boolean isSpectator()
Returns:
true iff player is spectating.

getMySeatNum

public int getMySeatNum()
Call this function to find out where at the table this player is sitting.

Returns:
the number of our (spectator) seat.

getNumSeats

public int getNumSeats()
Get the total number of seats at the table. If no connection is present, 0 will be returned. While in GGZMOD_STATE_CREATED, we don't know the number of seats.

Returns:
The number of seats.

getNumSpectatorSeats

public int getNumSpectatorSeats()
Get the maximum number of spectators. This function returns the maximum number of spectator seats available. A game can use this to iterate over the spectator seats to look for spectators occupying them. Since spectators may come and go at any point and there is no limit on the number of spectators, you should consider this value to be dynamic and call this function again each time you're looking for spectators.

Returns:
The number of available spectator seats.

getSeat

public Seat getSeat(int seatNum)
Get all data for the specified seat.

Parameters:
seatNum - The seat number (0..(number of seats - 1)).
Returns:
A valid Seat structure, if seat is a valid seat.

getSpectatorSeat

public SpectatorSeat getSpectatorSeat(int seatNum)
Get a spectator's data.

Parameters:
seatNum - The number, between 0 and (number of spectators - 1).
Returns:
A valid SpectatorSeat object, if given a valid seat.

connect

public void connect()
             throws java.io.IOException
Connect to ggz. Call this function to make an initial GGZ core client <-> game client connection.

Throws:
java.io.IOException

disconnect

public void disconnect()
                throws java.io.IOException
Disconnect from ggz. This terminates the link between the game client and the GGZ core client.

Throws:
java.io.IOException

requestStand

public void requestStand()
                  throws java.io.IOException
Stand up (move from your seat into a spectator seat).

Throws:
java.io.IOException

requestSit

public void requestSit(int seatNum)
                throws java.io.IOException
Sit down (move from a spectator seat into a player seat).

Parameters:
seatNum - The seat to sit in.
Throws:
java.io.IOException

requestBoot

public void requestBoot(java.lang.String name)
                 throws java.io.IOException
Boot a player. Only the game host may do this.

Parameters:
name - The name of the player to boot.
Throws:
java.io.IOException

requestBot

public void requestBot(int seatNum)
                throws java.io.IOException
Change the requested seat from an open seat to a bot.

Parameters:
seatNum - The number of the seat to toggle.
Throws:
java.io.IOException

requestOpen

public void requestOpen(int seatNum)
                 throws java.io.IOException
Change the requested seat from a bot to an open seat.

Parameters:
seatNum - The number of the seat to toggle.
Throws:
java.io.IOException

requestChat

public void requestChat(ChatType type,
                        java.lang.String target,
                        java.lang.String chatMsg)
                 throws java.io.IOException
Chat! This initiates a table chat.

Parameters:
chatMsg - The chat message.
Throws:
java.io.IOException

requestPlayerInfo

public void requestPlayerInfo(int seatNum)
                       throws java.io.IOException
Request extended player information for one or more players Depending on the seat parameter (-1 or valid number), this function asynchronously requests information about player(s), which trigget ModEventHandler.handleInfo().

Parameters:
seatNum - The seat number to request info for, or -1 to select all.
Throws:
java.io.IOException