broadcast(): Export string in a constant

This commit is contained in:
Fred Z 2018-03-09 14:10:14 +01:00
parent 2f024b5d0a
commit 7722ae368e
2 changed files with 7 additions and 3 deletions

View File

@ -43,6 +43,7 @@ class ConnectSocket:
_BUFFER = 1024
# Template messages
_BROADCAST_MSG = "{}~ {}\n"
_MSG_DISCONNECTED = "<gone away to infinity, and beyond>"
_MSG_SALUTE = "Hi, {}, wait for other players\n"
_MSG_SERVER_STOP = "Server stop"
@ -79,11 +80,13 @@ class ConnectSocket:
def broadcast(self, sender, name, message):
"""
Send message to all clients, except the sender
Send a message to all clients but the sender
In progress
:param obj sender: socket_object of tne sender
:param str name: name of tne sender
:param str message: message to send
"""
message = "{}~ {}\n".format(name, message)
message = self._BROADCAST_MSG.format(name, message)
for sckt in self._inputs:
if sckt != self._CONNECTION and sckt != sender:
try:

View File

@ -19,6 +19,7 @@
- [ ] chat commands: listing players TODO15
- [ ] chat commands: chating with other players TODO16
- [ ] verify if user name is already used TODO17
- [ ] rename ConnectSocket._user_name to ConnectSocket._user_name TODO18
- [ ] … TODO
Ideas after correcting [exercice 3](https://openclassrooms.com/courses/apprenez-a-programmer-en-python/exercises/180):