Commit Graph

309 Commits

Author SHA1 Message Date
Fred Z 703380ded6 Refactors `listen()` about log, broadcast & send
Adds `server_log()` method in order to export the `print()` calls.
Centralize _log_, _broadcast_ & _send_ operations in the bottom of the
loop  (except when sockets needs to be close).
I think it is improves readability and will facilitate code evolution,
for example when writing the servers log in file(s).
2018-03-14 10:40:19 +01:00
Fred Z f90a1a38d5 Refuses client connection beyond a certain number
FIX TODO19: add max player number
2018-03-14 10:40:19 +01:00
Fred Z 44514971ef Ajusts messages to clients in waiing-room 2018-03-14 10:40:19 +01:00
Fred Z 7708781e29 Checks player name in `listen()`
Adds length limit
Fix TODO17: verify if user name is already used
2018-03-14 10:40:19 +01:00
Fred Z c075c17172 Improves `broadcast()`: linked to `list_sockets()`
Now sends messages only to named-client, and for that uses
`list_sockets()`

Takes sender name from `_user_name` attribute and delete the name
argument from the method
2018-03-14 10:40:19 +01:00
Fred Z 1c5366beb5 Refactors `count_clients()` & `list_sockets()`
`list_sockets()` uses only clients with a name already typed in
(filled in `_user_name` attribute), to avoid starting a game with not
named player

`count_clients()` was too messy and autonomous, now it uses
`list_sockets()` for counting only named players and not depend on
naming player mechanism or main socket.# Veuillez saisir le message de
validation pour vos modifications. Les lignes
2018-03-14 10:40:18 +01:00
Fred Z dfaee27cc4 Fixes 2 syntax errors caused by fatigue
Forget to:
- rename the import instruction after renaming the file
- instance the map object after exporting it from the function
2018-03-14 10:40:18 +01:00
Fred Z 7633dd0f1f Update TODO: add max player number TODO19 2018-03-14 10:40:18 +01:00
Fred Z 1446a49df6 Update README.md 2018-03-14 10:40:18 +01:00
Fred Z 2df0513d89 Rename Map instance according GAME_NETWORK style 2018-03-14 10:40:18 +01:00
Fred Z c7096ee757 Export Map instanciation in parent script
More readable and easier for adding multiplayer feature in the Map object
2018-03-14 10:40:18 +01:00
Fred Z 99ed30197c list_sockets(): return name in place of peername
Previous instructions do not work as expected, and finally I just need
user name to identify the clients connected, not connection parameters
2018-03-14 10:40:18 +01:00
Fred Z a501fd69bb Add the waiting-room-loop before game begining 2018-03-14 10:40:18 +01:00
Fred Z 5047c993a8 listen(): Use attribute, no more tuple return 2018-03-14 10:40:18 +01:00
Fred Z 7722ae368e broadcast(): Export string in a constant 2018-03-14 10:40:18 +01:00
Fred Z 2f024b5d0a count_client(): use client with a filled username 2018-03-14 10:40:18 +01:00
Fred Z ddf9d57d38 Syntax update in TODO 2018-03-14 10:40:18 +01:00
Fred Z b659d0ff7f Using the network to wait & connect client
Crash when MIN_CLIENT_NB is reached
2018-03-14 10:40:18 +01:00
Fred Z 1451c5ff36 Clean up and document __init__ method 2018-03-14 10:40:18 +01:00
Fred Z 91c5bdb761 Clean up the code a little bit 2018-03-14 10:40:18 +01:00
Fred Z ffe3023b4d Adding methods: listen connection & brobdcast msg 2018-03-14 10:40:18 +01:00
Fred Z 7b9128c3b2 Update TODO
- verify if user name is already used TODO17
- ordering a bit
2018-03-14 10:40:18 +01:00
Fred Z a0598d3599 Create client
DONE TODO03
2018-03-14 10:40:18 +01:00
Fred Z 03cbd5474d Add network/connection Class
Create a socket object for opening the server connection with some mehods:
-__init__()
- close()
- list_sockets()
- count_clients()
2018-03-14 10:40:18 +01:00
Fred Z 315e7f9537 Create server, and remove backup feature
DONE TODO01
DONE TODO02
2018-03-14 10:40:17 +01:00
Fred Z f903089686 Roadmap to next exercice: multiplayer & network 2018-03-14 10:40:17 +01:00
Fred Z 7b6953a948 Corrige la syntaxe: audit pyLint 2018-03-14 10:40:17 +01:00
Fred Z 0779b0b5c7 Transforme des TODO en issue 2018-03-14 10:40:17 +01:00
Fred Z 78be5f0877 Clean closing socket with <ctrl+c> 2018-03-05 23:14:40 +01:00
Fred Z 9106fdd490 Ajoute un script d'évaluation de plusieurs syntaxes 2018-03-05 23:14:40 +01:00
Fred Z d9dc6ce96a Edit TODO server crash if a client is killed
Traceback (most recent call last):
  File "server.py", line 78, in <module>
    peername = socket.getpeername()
OSError: [Errno 107] Transport endpoint is not connected
2018-03-05 23:12:50 +01:00
Fred Z 5df5f1ec75 Edit TODO : 3 enhancements & 1 bug
- convert logic to oreiented object
- server crash witn opened connection with <ctrl+Z>
- add some commands: help, list user, disconnect user, etc
- add time logging:
    - a timestamp in log's server
    - brodcast time to client at regular intervals
2018-03-05 23:12:50 +01:00
Fred Z 0074e57612 Improve UX with better prompt & message display
- UPDATE: last condition for messages passing the commands case and
the string.stripping()
 - FIX: clean the prompt and std.out a bit messy since broadcasting
2018-03-05 23:12:50 +01:00
Fred Z e43f19c2ae Revise messages: server's log & broadcasted 2018-03-05 23:12:50 +01:00
Fred Z 870953051d Ask for username and use it
First client's message is used as usernane in server loging and other
clients broadcasting
2018-03-05 23:12:50 +01:00
Fred Z 3c5c169045 Clean the main-loop from useless instructions
Remove:
 - try/catch for received case, seems to be useless
 - useless `continue`
 - **move closing connection at the script's end** from TODO, do not find how to exit while from handler()
2018-03-05 23:12:50 +01:00
Fred Z 86b0b983f7 Add a template message in broadcasting
Move the template outside the for-loop to avoid overide
Separate client and server client-disconnect-message
2018-03-05 23:12:50 +01:00
Fred Z a395444baf Update TODO: client freeze finally work
I do not know if the bug disappear or if the bug has never existed.
The messaqe is striped so, nothing is sent when it contains nothing
or only spaces.
2018-03-05 23:12:50 +01:00
Fred Z d0016e50cc Add socket SO_REUSEADDR
… to avoid been blocked at relaunching immediatly the server
2018-03-05 23:12:50 +01:00
Fred Z 07284076cd Edit TODO using wlist with select.select()
Under heavy charge the script might be weak with seocket.read() &
socket.send() using together rlist in select.select().
See https://pymotw.com/3/select/index.html
2018-03-05 23:12:50 +01:00
Fred Z 993b5bcfa8 Edit TODO move closing connect at the script's end
Use a boolean to escape while-loop and move the closing stuff outside
the handler()
2018-03-05 23:12:50 +01:00
Fred Z 594fa78141 Display welcome message when a client connects #20
FIX #20 sending welcome message only at 1st client connection
2018-03-05 23:12:50 +01:00
Fred Z c863a2c727 Improve <ctrl+c> interruption
Add clean server disconnection with «quit» keyword

Fix this 2 bugs:
- show message on server when client use <ctrl+c>
- crash after 2 <ctrl+c> in client
2018-03-05 23:12:50 +01:00
Fred Z 8951d7dcd5 Edit TODO crash after 2 <ctrl+c> in client
When 2 clients quit with <ctrl+c> consecutively, the 3 client trying
to connect will crash the server
2018-03-05 23:12:50 +01:00
Fred Z 19271c5995 Edit TODO show msg server when client use <ctrl+c>
When 1 client is interrupted with <ctrl+c>, the server do not print the
disconnect message.
2018-03-05 23:12:50 +01:00
Fred Z 29634fdec4 Edit TODO clean the prompt and std.out
Since broadcast implementation the screen is now a bit messy:
 - empty prompt line
 - message from other clients
 - empty liness
 - etc…
2018-03-05 23:12:50 +01:00
Fred Z b742bf42ad Add broadcasting feature
Now it's a chat-room, each message sending by a client is now
broadcasted to other clients.
Modifications on the client are:
 - rename connections list as in server.py
 - fix using the wrong list for checking events. It was not a problem
 before implementation of broadcasting
2018-03-05 23:12:50 +01:00
Fred Z 7ecefcf2ad Add bug when sending space or empty string
In client if a empty string is typed (or a _space only_) string,
server do not print it and client lose connection and prompt do not
appear.
2018-03-05 23:12:50 +01:00
Fred Z c6b16c2c87 Add signal interrupt for clean exit in server 2018-03-05 23:12:50 +01:00
Fred Z cd3a0e1782 Formate and update TODO.md 2018-03-05 23:12:50 +01:00