ParseMessageIn Module

This module implement a simple analyser for input messages (read from clients or server). It respect the semantics about the communications (this document is available here specification_slides).

Basically, it is a collection of mini parsers.

It also provides the function try_unpickling, to load datas from binary files (saved with ParseMessageOut.try_pickling).

ParseMessageIn.PRINT_ALL_PARSEIN = False

This can be erased by the module Constants to modify the global verbosity of this module

ParseMessageIn.try_unpickling(info='(no info about the unpickling was given)', verb=True, verb2=False, fn='savegame.ess')[source]

Load datas from the file fn.

This file have to be present, and have to be created by ParseMessageOut.try_pickling.

The goal of info is to say what variables will be set equal to the unpicked datas (see the examples below).

If verb is here, this function print a log saying from which file datas are being read.

If verb2 is here, this function will also print all unpicked datas (using the pprint.pprint pretty-printer).
Caution ! If the datas are quite huge (and you are allow to do so), the will print a huge message.

This function doesn’t handle exception, so be prudent with it (in particular, the file fn have to be there).

Example:
>>> from ParseMessageOut import try_pickling
>>> a, b, c = 0, 2.0, u"ok !" # Make a tuple.
>>> try_pickling((a,b,c)) # Save the tuple, in the default file (.datas_saved_by_picked_python.pkl).
>>> aa, bb, cc = try_unpickling(info="aa, bb, cc") # Load the tuple from the default file, and save it to (aa, bb, cc).

Warning:

Warning

All datas cannot be picked and upicked. Fore more details, see directly the documentation of the pickle module.

ParseMessageIn.try_parse(message, pattern, verb=False)[source]

A simple wrapping around scanf.sscanf.

This will try to parse the message, according to the scanf pattern. If verb, print useful and colored log information.

ParseMessageIn.number_of_kill(s)[source]

Sent message to manually kill a connected player.

For BombermanServer.py.

ParseMessageIn.newplayer_of_str(s)[source]

Sent message by a new player when he wants to change his pseudo. Contains the pseudo of the player.

ParseMessageIn.newcolor_of_str(s)[source]
Sent message by a new player when he wants to change his color.
Contains the color of the player.

Warning

The color is checked to be correct, i.e. one of the simple color from ANSIColors.simpleColorList. This list is [‘green’, ‘red’, ‘blue’, ‘black’, ‘cyan’, ‘magenta’, ‘yellow’, ‘white’].

ParseMessageIn.update_players(board, list_players, player, message, verb=True)[source]

Move the players in the list list_players according to the order in message.

This is for the first communication (message GAME_START), and only for this. The order was packed with ParseMessageOut.str_of_players.

ParseMessageIn.board_and_player_of_str(board, pl, player, message, verb=True) → board, pl, player[source]

Update the board and the list of players with the map sent in the string message.

The order was packed with ParseMessageOut.str_of_board_and_player.

exception ParseMessageIn.GameOver(player, msg='This is the default message. The winner is ')[source]

Bases: exceptions.Exception

Exception Class for handling the end of the game (win or lose).

Warning

Even if his name seems to says otherwise, this exception give the winner of the game. In fact, the name was choose to fit with the message GAME_OVER, already fixer in the formal semantics. This message, sent by the server, imply the end of the game, and give the id of the player who is winning the game.

Attributes:
  • player – the player which is which has wan.
  • msg – the message in case of victory.
__init__(player, msg='This is the default message. The winner is ')[source]

Construction of a GameOver exception.

player = None

the player which has wan.

msg = None

the message annoucing the death, which have to be printed to the player.

__str__(self) → str[source]

A pretty string for the exception. (with colors if self.player supports color).

__weakref__

list of weak references to the object (if defined)

ParseMessageIn.gameover_of_str(s) → s2, id[source]

Received message from the server to announce the winner of the game, by refering to his [id]. For the player who have the same id : he is the winner, and for the other : they have lost.

[s2] refers to the end of the message [s] (untouched by the data’s extraction).

The order was packed with ParseMessageOut.str_of_gameover.

ParseMessageIn.posplantbomb_of_str(s) → s2, i, j[source]

Received message from the server to announce that a bomb have been planted in the spot ([i], [j]).

[s2] refers to the end of the message [s] (untouched by the data’s extraction).

The order was packed with ParseMessageOut.str_of_posplantbomb.

ParseMessageIn.blowbomb_of_str(s) → s2, i, j, radius[source]
Received message from the server to announce that a bomb have blowed up
in the spot (i,j), with the radius [radius].

[s2] refers to the end of the message [s] (untouched by the data’s extraction).

The order was packed with ParseMessageOut.str_of_blowbomb.

ParseMessageIn.moveplayer_of_str(s) → s2, id, i, j[source]

Received message from the server to announce that a player [id] have moved to [i], [j].

[s2] refers to the end of the message [s] (untouched by the data’s extraction).

The order was packed with ParseMessageOut.str_of_moveplayer.

Previous topic

KeyBinding Module

Next topic

ParseMessageOut Module

This Page