BombermanServer Module

Example

This show how the textual mode looks like during the game :
_images/exempletextual_server.png

How to ?

The program accept some command line options.

The simpliest way to use it is::
$ ./BombermanServer.py –server bomberman.crans.org –port 12885
This will launch the server on bomberman.crans.org (assuming that your machine is opened on the Internet with this domain name), on the port 12885 (it have to be an open port, maybe you will have to change something in your firewall).
On Windows, a window will surely pop to ask you confirmation for this (with a message like “Python is trying to use the port 12885, are you sure ?”).

PyRlwrap

The client have to be launched from the command line, and during the game the stdin (i.e. the keyboard) is listened.

So you can send messages yo your server, directly from the command line. The script PyRlwrap.py provide a readline wrapper for this command line interface. It brings:

  • shortcut, “a la Nano” (^A: begin line, ^E: end line etc);
  • history (Up & Down show previous message).
You can launch the client with PyRlwrap.py like this (-vv is to increase verbosity):
$ ./PyRlwrap.py ./BombermanServer.py –server 138.231.134.230 –port 9312 -vv

Options for textual mod

The following options can change how the textual mod looks like :
  • –noUTF : disabled UTF caracters for the board. And, warning for pseudos, if one begins with a non-ascii caracter, the id of the player is used (an integer, between 0 and the number of player -1).
  • –noANSI or –ANSI : force to disable or enable the colors. Normally, you don’t have to use them, because the ANSIColors module can detect cleverly if colors are supported. (Note: this have been tested with Linux, Cygwin, but not with Mac OS X)

Saving and restoring

This is an experimental functionnality, but it should work.
You can try to launch again the server on his last state, with the –load option. By default, the loaded file is savegame.ess, but you can specifify yourse with the –file option.
And the save file can also be changed with the –save option.
But this functionnality have to be enabled with changin USE_PICKLING to True in ConfigServer.py.

About

Getting some help

This program uses a high-level command line parser : ParseCommandArgs, based on argparse from the standard distribution.

Therefore, the help for this program can be obtained simply with ::
$ ./BombermanClient.py –help
The help embed some colors, and it can be read through a pipe :
$ ./BombermanClient.py -h | less -r

About:

Algorithm:

The server follows an algorithm in 3 main parts.

  1. First he waits for clients, and register them. Then, he create the game variables, send the map to the clients; and start his 2nb part.
  2. He listen for order from clients, check them, and if they are ok, apply them to his local version of the game. Then he make evolved his own game (blow the bomb etc). And he send back order to the clients, saying what have been modified. And the loop 2 begin again.
  3. And when only one player is on the game, he is declared as the winner.

Choices:

  • For handling many clients (i.e. listening for many incoming orders), select.select is used.

    Both for the step 1 and 2.

  • The syntax of messages is :
  • The specification of the game protocole is also detailed in the slides (and mainly it explains why we use TCP).

Saving and restoring:

The server can save and restore his state.

How ?

It still very experimental, and quite limited : socket connections cannot be save to a file and restore later ! But, by now, the board can be save during the game, and them restore after when launching a new server, to begin with this map.

  1. That mean, with the option –load -f savegame.ess you can try to load a previous map save in savegame.ess
  2. And with the option –save savegame2.ess, you can try to save the current map to savegame2.ess during the game.

Warning

This optionnal functionnality have to be enabled, by puting USE_PICKLING to 1 in ConfigServer.

Example:

The server (left up corner) picked up the last map and will start the game with it and not a randomly generated one.
_images/exemple_saverestore.png

Warning

Warning

This script is not yet fully concluded. So, it might end badly on some untests behaviour. I ran many tests, but I can’t ensure everything is all right...

TODOs ?:

  • ? implement and describe the bonus system.
  • ? conclude the parser (add –bonus to activate bonus (not implemented yet)).
BombermanServer.print_on_all(message='No message was gave', list_clients=[], origin='you (the server)', PRINT_ALL_MESSAGE=1)[source]

Print the message on stdout of each client (found in the list of client list_clients). origin permits to print some usefull informations for delivering the origin of the message the all connected clients.

FIXED: doesn’t fail any more.

BombermanServer.create_bind_socket(server = (SERVEUR_INIT, PORT_INIT)) → msocket[source]

Create a server socket and bind it to the port and the addresse host. Make also this socket listening (with socket.listen).

BombermanServer.create_data_socket(listen_socket, NB_CLIENT = 0) → data_socket, data_address, NB_CLIENT[source]

Create a client (data) socket from the server socket listen_socket. Update the integer [NB_CLIENT] by one.

Print useful and colorful informations about this connection, and then return a 3-tuple :
  • the created socket,
  • the origin address of the listen_socket (addr. of the server (so, not very useful)),
  • and the current number of clients.
BombermanServer.print_list(player_clients)[source]

To print the list of current players.

BombermanServer.print_help(commands=True)[source]

To print the help for the second phasis 2.

BombermanServer.action_on_readstr(readstr, list_clients, dict_clients, player_clients, server, lx, ly, nb) → <bool>[source]

Reaction to special message readed from the keyboard !

The goal is to allow the administrator of the server to act through the command line.

Return True is the key did something, False if the readstr wasn’t a command.

BombermanServer.run_phasis1(lx = LX_CST, ly = LY_CST, nb = NB_PLAYER, server = (SERVEUR_INIT, PORT_INIT)) -> (nbmax, lx, ly, pl, board, Mi, Mj)[source]

Creating all Game variables. The [server] variable refers to the address (and the port) of the server being builted.

This is the 1st step of the server algorithm : creating the game, wait for client, register them, and when there are the correct number, go to step 2 (i.e. this function returns and new connection are no longer accepted).

Returns (nbmax, lx, ly, pl, board, Mi, Mj) :
  • nbmax: the max number of player for the map,
  • lx, ly: the dimension of the map,
  • pl: the list of all the player connected with the server,
  • board: the map,
  • Mi, Mj: two integer lists, long as pl, of players’ initial positions.
BombermanServer.save_current_game(variables_to_save, info='variables_to_save', fn='savegame.ess')[source]

Save all variables content the list variables_to_save, in a .pkl file.

The game can be restored then, by setting all variables equals
to their previous values (of course this only work if the .pkl file is still there).
BombermanServer.run_phasis2(nb, lx, ly, player_clients, board, Mi, Mj, socket_server, server, list_clients, dict_clients) → Player.PlayerServer instance, for the winner.[source]

Mail Loop for the game.