From f0f3dbcfede866515fa1fcef8c6dac4eadff29e1 Mon Sep 17 00:00:00 2001 From: sidya82 Date: Wed, 8 Apr 2015 21:35:52 +0200 Subject: [PATCH] ULTIMATE SERVER DE LA MUERTE V2.0 --- serveur/Server.py | 124 +++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/serveur/Server.py b/serveur/Server.py index dfb548c..4006a8f 100644 --- a/serveur/Server.py +++ b/serveur/Server.py @@ -20,77 +20,79 @@ def handleConnection(connection, client_address): def handleRequest(connection, data): - #try: - arrayData = data.split(" ") + try: + arrayData = data.split(" ") - ### Command for user with nickname ### - if usersConnected[connection][1] is not None: - if not arrayData[0][0] == "/" and usersConnected[connection][2]: - connection.sendall("SUCC_MESSAGE_SENDED".encode()) - broadcastMsg(connection, "NEW_MSG {} {} ".format(usersConnected[connection][1], data)) - return + ### Command for user with nickname ### + if usersConnected[connection][1] is not None: + ### No command -> new message ### + if not arrayData[0][0] == "/" and usersConnected[connection][2]: + connection.sendall("SUCC_MESSAGE_SENDED".encode()) + broadcastMsg(connection, "NEW_MSG {} {} ".format(usersConnected[connection][1], data)) + return + else: + ### Command for user enable & disable ### + if arrayData[0] == "/name": + changeName(connection, arrayData[1]) + return + if arrayData[0] == "/userlist": + userListActive(connection) + return + if arrayData[0] == "/userlistaway": + userListAway(connection) + return + if arrayData[0] == "/enable": + enableUser(connection) + return + if arrayData[0] == "/disable": + disableUser(connection) + return + if arrayData[0] == "/quit": + connection.shutdown(socket.SHUT_RD) + return + + ### Command available for enable only ### + if not usersConnected[connection][2] : + connection.sendall("ERR_U_ARE_DISABLE".encode()) + return + else : + if arrayData[0] == "/askpm": + askPrivateMsg(connection, arrayData[1]) + return + if arrayData[0] == "/acceptpm": + acceptPrivateMsg(connection, arrayData[1]) + return + if arrayData[0] == "/rejectpm": + rejectPrivateMsg(connection, arrayData[1]) + return + if arrayData[0] == "/pm": + privateMsg(connection, arrayData[1], " ".join(arrayData[2:])) + return + if arrayData[0] == "/pmfile": + askFile(connection,arrayData[1],arrayData[2]) + return + if arrayData[0] == "/acceptfile": + acceptFile(connection, arrayData[1], arrayData[2],arrayData[3]) + return + if arrayData[0] == "/rejectfile": + rejectFile(connection, arrayData[1], " ".join(arrayData[2:])) + return + connection.sendall("ERR_COMMAND_NOT_FOUND".encode()) else: - if arrayData[0] == "/name": - changeName(connection, arrayData[1]) - return - if arrayData[0] == "/userlist": - userListActive(connection) - return - if arrayData[0] == "/userlistaway": - userListAway(connection) - return - if arrayData[0] == "/enable": - enableUser(connection) - return - if arrayData[0] == "/disable": - disableUser(connection) + ### Command for user without nickname ### + if arrayData[0] == "/newname": + newName(connection, arrayData[1]) return if arrayData[0] == "/quit": connection.shutdown(socket.SHUT_RD) return - - ### Command available for enable only ### - if not usersConnected[connection][2] : - connection.sendall("ERR_U_ARE_DISABLE".encode()) - return - else : - if arrayData[0] == "/askpm": - askPrivateMsg(connection, arrayData[1]) - return - if arrayData[0] == "/acceptpm": - acceptPrivateMsg(connection, arrayData[1]) - return - if arrayData[0] == "/rejectpm": - rejectPrivateMsg(connection, arrayData[1]) - return - if arrayData[0] == "/pm": - privateMsg(connection, arrayData[1], " ".join(arrayData[2:])) - return - if arrayData[0] == "/pmfile": - askFile(connection,arrayData[1],arrayData[2]) - return - if arrayData[0] == "/acceptfile": - acceptFile(connection, arrayData[1], arrayData[2],arrayData[3]) - return - if arrayData[0] == "/rejectfile": - rejectFile(connection, arrayData[1], " ".join(arrayData[2:])) - return - connection.sendall("ERR_COMMAND_NOT_FOUND".encode()) - else: - ### Command for user without nickname - if arrayData[0] == "/newname": - newName(connection, arrayData[1]) - return - if arrayData[0] == "/quit": - connection.shutdown(socket.SHUT_RD) - return - connection.sendall("ERR_NO_NICKNAME".encode()) - """except IndexError: + connection.sendall("ERR_NO_NICKNAME".encode()) + except IndexError: log.printL("Parameter missing in the request", Log.lvl.WARNING) connection.sendall("ERR_PARAMETER_MISSING".encode()) except Exception as e : log.printL("Handle request fail : {}".format(str(e)), Log.lvl.FAIL) - connection.sendall("ERR_INTERNAL_SERVER_ERROR".encode())""" + connection.sendall("ERR_INTERNAL_SERVER_ERROR".encode()) def broadcastMsg(connection, message):