From 9030013c68c029f5e618344b9745cd5e2753d8c7 Mon Sep 17 00:00:00 2001 From: sidya82 Date: Thu, 2 Apr 2015 13:47:02 +0200 Subject: [PATCH] Poulet --- .gitignore | 1 + log/activity.log | 27 --------------------------- log/error.log | 0 log/warning.log | 0 serveur/Server.py | 20 ++++++++++++++------ 5 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 log/activity.log delete mode 100644 log/error.log delete mode 100644 log/warning.log diff --git a/.gitignore b/.gitignore index 2483976..dd34015 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ __pycache__/ +log diff --git a/log/activity.log b/log/activity.log deleted file mode 100644 index 70d5bf3..0000000 --- a/log/activity.log +++ /dev/null @@ -1,27 +0,0 @@ -2015-04-01 08:42:26,046 :: INFO ::  Configuration load Namespace(port=8000, usermax=None)  -2015-04-01 08:42:26,046 :: INFO ::  Server start  -2015-04-01 08:42:26,088 :: INFO ::  Server Listen on port 8000  -2015-04-01 08:43:10,939 :: INFO ::  Wait for threads ending  -2015-04-01 08:43:10,940 :: INFO ::  Server shutdown  -2015-04-01 08:43:21,055 :: INFO ::  Configuration load Namespace(port=2222, usermax=None)  -2015-04-01 08:43:21,055 :: INFO ::  Server start  -2015-04-01 08:43:21,058 :: INFO ::  Server Listen on port 2222  -2015-04-01 08:43:32,103 :: INFO ::  Connection from IP -> ('127.0.0.1', 53851)  -2015-04-01 08:43:39,933 :: INFO ::  Request from IP -> ('127.0.0.1', 53851) bob  -2015-04-01 08:43:45,900 :: INFO ::  Request from IP -> ('127.0.0.1', 53851) super !  -2015-04-01 08:43:52,170 :: INFO ::  Request from IP -> ('127.0.0.1', 53851) /name bob  -2015-04-01 08:44:08,771 :: INFO ::  Connection from IP -> ('127.0.0.1', 53852)  -2015-04-01 08:44:12,601 :: INFO ::  Request from IP -> ('127.0.0.1', 53852) /quit  -2015-04-01 08:44:45,278 :: INFO ::  Wait for threads ending  -2015-04-01 08:44:45,278 :: INFO ::  Disconnection from IP -> ('127.0.0.1', 53851)  -2015-04-01 14:01:21,465 :: INFO ::  Configuration load Namespace(port=8000, usermax=None)  -2015-04-01 14:01:21,476 :: INFO ::  Server start  -2015-04-01 14:01:21,508 :: INFO ::  Server Listen on port 8000  -2015-04-01 14:01:59,767 :: INFO ::  Connection from IP -> ('127.0.0.1', 60151)  -2015-04-01 14:02:04,760 :: INFO ::  Request from IP -> ('127.0.0.1', 60151) coucou  -2015-04-01 14:02:20,518 :: INFO ::  Request from IP -> ('127.0.0.1', 60151) /name bob  -2015-04-01 14:03:35,380 :: INFO ::  Request from IP -> ('127.0.0.1', 60151) /newname bob  -2015-04-01 14:03:38,491 :: INFO ::  Request from IP -> ('127.0.0.1', 60151) coucou  -2015-04-01 14:03:48,807 :: INFO ::  Request from IP -> ('127.0.0.1', 60151) /newname  -2015-04-01 14:03:56,293 :: INFO ::  Request from IP -> ('127.0.0.1', 60151) /newname renan  -2015-04-01 14:04:53,177 :: INFO ::  Connection from IP -> ('127.0.0.1', 60182)  diff --git a/log/error.log b/log/error.log deleted file mode 100644 index e69de29..0000000 diff --git a/log/warning.log b/log/warning.log deleted file mode 100644 index e69de29..0000000 diff --git a/serveur/Server.py b/serveur/Server.py index 6fb16fd..e04397c 100644 --- a/serveur/Server.py +++ b/serveur/Server.py @@ -23,8 +23,6 @@ def handleConnection(connection, client_address) : def handleRequest(connection, data): #try: arrayData = data.split(" ") - if arrayData[0] == "/newname" : - pass if usersConnected[connection][1] is not None : if(not arrayData[0][0] == "/"): broadcastMsg( "NEW_MSG {} {} ".format(usersConnected[connection][1], data)) @@ -33,9 +31,6 @@ def handleRequest(connection, data): if arrayData[0] == "/name" : changeName(connection, arrayData[1]) return - if arrayData[0] == "/quit" : - quit(connection) - return if arrayData[0] == "/askpm" : askPrivateMsg(connection,arrayData[1]) return @@ -56,6 +51,12 @@ def handleRequest(connection, data): return connection.send("ERR_COMMAND_NOT_FOUND".encode()) else: + if arrayData[0] == "/newname" : + newName(connection) + return + if arrayData[0] == "/quit" : + quit(connection) + return connection.send("CMD_NOT_ALLOWED".encode()) """except Exception as e : log.printL(str(e), Log.lvl.FAIL)""" @@ -63,7 +64,8 @@ def handleRequest(connection, data): def broadcastMsg(message): for con, value in usersConnected.items() : - con.send(message.encode()) + if usersConnected[con][1] is not None : + con.send(message.encode()) def userListActive(connection): @@ -87,6 +89,12 @@ def changeName(connection, pseudo): usersConnected[connection][1] = pseudo +def newName(connection, pseudo): + broadcastMsg("HAS_JOIN {} ".format(pseudo)) + connection.send("SUCC_VALID_NICKNAME") + usersConnected[connection][1] = pseudo + + def askPrivateMsg(connection,pseudo): c = getConnectionByPseudo(pseudo) if c is None :