@@ -46,16 +46,16 @@ class GameServerAPI:
4646 This class provides API functions to communicate with the game server.
4747 """
4848
49- def __init__ (self , server , port , game , token = 'auto' , players = None , name = '' ):
49+ def __init__ (self , server , port , game , session = 'auto' , players = None , name = '' ):
5050 """
5151 Parameters needed in order to connect to the server and to start or join
5252 a game session are passed to this constructor. Parameter game specifies
5353 the game to be started. It corresponds to the name of the game class on
5454 the server. To be able to join a specific game session, all participants
55- need to agree on a token and pass it to the constructor. The token is
56- used to identify the game session. Alternatively, you can have the
57- server automatically assign you to a session by passing 'auto' as the
58- token (this is the default). Refer to function join for more
55+ need to agree on a session token and pass it to the constructor. The
56+ token is used to identify the game session. Alternatively, you can have
57+ the server automatically assign you to a session by passing 'auto' as
58+ the token (this is the default). Refer to function join for more
5959 information.
6060
6161 The optional parameter players is required by function join in order to
@@ -73,7 +73,7 @@ def __init__(self, server, port, game, token='auto', players=None, name=''):
7373 server (str): server
7474 port (int): port number
7575 game (str): name of the game
76- token (str): name of the session (optional), 'auto' for auto-join (default)
76+ session (str): name of the game session (optional), 'auto' for auto-join (default)
7777 players (int): total number of players (optional)
7878 name (str): player name (optional)
7979
@@ -83,7 +83,7 @@ def __init__(self, server, port, game, token='auto', players=None, name=''):
8383 assert type (server ) == str and len (server ) > 0 , self ._error ('server' )
8484 assert type (port ) == int and 0 <= port <= 65535 , self ._error ('port' )
8585 assert type (game ) == str and len (game ) > 0 , self ._error ('game' )
86- assert type (token ) == str and len (token ) > 0 , self ._error ('token ' )
86+ assert type (session ) == str and len (session ) > 0 , self ._error ('session ' )
8787 assert players is None or type (players ) == int and players > 0 , self ._error ('players' )
8888 assert type (name ) == str , self ._error ('name' )
8989
@@ -93,7 +93,7 @@ def __init__(self, server, port, game, token='auto', players=None, name=''):
9393
9494 # game session:
9595 self ._game = game
96- self ._token = token
96+ self ._session = session
9797 self ._players = players
9898 self ._name = name
9999 self ._player_id = None
@@ -117,16 +117,16 @@ def join(self):
117117
118118 There are two ways to start or join a game session:
119119
120- - By providing a shared token to the constructor. All clients using the
121- same token will join this specific game session. If such a session
122- exists but is already fully occupied by players, it is terminated and
123- a new session is started.
124- - By passing the string 'auto' as the token. This causes the server to
125- automatically assign you to an open session. If no session exists that
126- can be joined, a new one is started. Existing sessions are never
127- terminated. This method of starting and joining sessions does not
128- interfere with the above method. To achieve this, the server creates
129- unique tokens internally.
120+ - By providing a shared session token to the constructor. All clients
121+ using the same token will join this specific game session. If such a
122+ session exists but is already fully occupied by players, it is
123+ terminated and a new session is started.
124+ - By passing the string 'auto' as the session token. This causes the
125+ server to automatically assign you to an open session. If no session
126+ exists that can be joined, a new one is started. Existing sessions are
127+ never terminated. This method of starting and joining sessions does
128+ not interfere with the above method. To achieve this, the server
129+ creates unique tokens internally.
130130
131131 The game starts as soon as the required number of clients has joined the
132132 game. The function then returns the player ID. The server assigns IDs in
@@ -141,15 +141,15 @@ def join(self):
141141 response , err , _ = self ._send ({
142142 'type' :'join' ,
143143 'game' :self ._game ,
144- 'token ' :self ._token ,
144+ 'session ' :self ._session ,
145145 'players' :self ._players ,
146146 'name' :self ._name })
147147
148148 if err : raise GameServerError (err )
149149
150150 self ._player_id = response ['player_id' ]
151151 self ._key = response ['key' ]
152- self ._token = response ['token ' ]
152+ self ._session = response ['session ' ]
153153 self ._request_size_max = response ['request_size_max' ]
154154
155155 return self ._player_id
@@ -180,7 +180,7 @@ def move(self, **kwargs):
180180 _ , err , status = self ._send ({
181181 'type' :'move' ,
182182 'game' :self ._game ,
183- 'token ' :self ._token ,
183+ 'session ' :self ._session ,
184184 'player_id' :self ._player_id ,
185185 'key' :self ._key ,
186186 'move' :kwargs })
@@ -204,17 +204,20 @@ def state(self):
204204
205205 Independent of the game, the dictionary always contains these two keys:
206206
207- 'current': a list of player IDs, indicating whose player's turn it is
208- 'gameover': a boolean value indicating whether the game is over or still active
207+ - 'current': a list of player IDs, indicating whose player's turn it is
208+ - 'gameover': a boolean value indicating whether the game is over or
209+ still active
209210
210211 This function will block until the game state changes. Only then does
211212 the server respond with the updated state. This is more efficient than
212213 polling. To avoid deadlocks, the function never blocks in these
213214 situations:
214215
215- - when the game has just started to allow clients to get the initial state
216+ - when the game has just started to allow clients to get the initial
217+ state
216218 - after a move was performed to allow clients to get the new state
217- - when the game was restarted and a client still has to get the old game's state
219+ - when the game was restarted and a client still has to get the old
220+ game's state
218221
219222 Returns:
220223 dict: game state
@@ -227,7 +230,7 @@ def state(self):
227230 state , err , _ = self ._send ({
228231 'type' :'state' ,
229232 'game' :self ._game ,
230- 'token ' :self ._token ,
233+ 'session ' :self ._session ,
231234 'player_id' :self ._player_id ,
232235 'key' :self ._key ,
233236 'observer' :self ._observer })
@@ -258,13 +261,13 @@ def observe(self):
258261 if type (self ._name ) != str or len (self ._name ) == 0 :
259262 raise GameServerError ('a valid name must be passed to the constructor' )
260263
261- if self ._token == 'auto' :
264+ if self ._session == 'auto' :
262265 raise GameServerError ('observer mode not available for auto-join sessions' )
263266
264267 response , err , _ = self ._send ({
265268 'type' :'observe' ,
266269 'game' :self ._game ,
267- 'token ' :self ._token ,
270+ 'session ' :self ._session ,
268271 'name' :self ._name })
269272
270273 if err : raise GameServerError (err )
@@ -291,7 +294,7 @@ def restart(self):
291294 _ , err , _ = self ._send ({
292295 'type' :'restart' ,
293296 'game' :self ._game ,
294- 'token ' :self ._token ,
297+ 'session ' :self ._session ,
295298 'player_id' :self ._player_id ,
296299 'key' :self ._key })
297300
0 commit comments