This show how the textual mode looks like during the game :
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 ?”).
- 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
- 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)
- 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.
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
The server follows an algorithm in 3 main parts.
- 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.
- 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.
- And when only one player is on the game, he is declared as the winner.
- 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 :
- explained in the specification_slides.pdf,
- or in the module ParseMessageIn,
- or in the module ParseMessageOut;
The specification of the game protocole is also detailed in the slides (and mainly it explains why we use TCP).
The server can save and restore his state.
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.
- That mean, with the option –load -f savegame.ess you can try to load a previous map save in savegame.ess
- 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.
The server (left up corner) picked up the last map and will start the game with it and not a randomly generated one.
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...
- ? implement and describe the bonus system.
- ? conclude the parser (add –bonus to activate bonus (not implemented yet)).
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.
Create a server socket and bind it to the port and the addresse host. Make also this socket listening (with socket.listen).
Create a client (data) socket from the server socket listen_socket. Update the integer [NB_CLIENT] by one.
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.
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).
Save all variables content the list variables_to_save, in a .pkl file.