Poulet
This commit is contained in:
parent
bb72fdcc9a
commit
387ffab592
@ -23,29 +23,40 @@ def handleConnection(connection, client_address) :
|
|||||||
def handleRequest(connection, data):
|
def handleRequest(connection, data):
|
||||||
#try:
|
#try:
|
||||||
arrayData = data.split(" ")
|
arrayData = data.split(" ")
|
||||||
if(not arrayData[0][0] == "/"):
|
if arrayData[0] == "/newname" :
|
||||||
broadcastMsg( "NEW_MSG {} {} ".format(usersConnected[connection][1], data))
|
pass
|
||||||
return
|
if usersConnected[connection][1] is not None :
|
||||||
else :
|
if(not arrayData[0][0] == "/"):
|
||||||
if arrayData[0] == "/name" :
|
broadcastMsg( "NEW_MSG {} {} ".format(usersConnected[connection][1], data))
|
||||||
changeName(connection, arrayData[1])
|
|
||||||
return
|
return
|
||||||
if arrayData[0] == "/quit" :
|
else :
|
||||||
quit(connection)
|
if arrayData[0] == "/name" :
|
||||||
return
|
changeName(connection, arrayData[1])
|
||||||
if arrayData[0] == "/askpm" :
|
return
|
||||||
askPrivateMsg(connection,arrayData[1])
|
if arrayData[0] == "/quit" :
|
||||||
return
|
quit(connection)
|
||||||
if arrayData[0] == "/acceptpm" :
|
return
|
||||||
acceptPrivateMsg(connection,arrayData[1])
|
if arrayData[0] == "/askpm" :
|
||||||
return
|
askPrivateMsg(connection,arrayData[1])
|
||||||
if arrayData[0] == "/rejectpm" :
|
return
|
||||||
rejectPrivateMsg(connection,arrayData[1])
|
if arrayData[0] == "/acceptpm" :
|
||||||
return
|
acceptPrivateMsg(connection,arrayData[1])
|
||||||
if arrayData[0] == "/pm" :
|
return
|
||||||
privateMsg(connection,arrayData[1],arrayData[2:])
|
if arrayData[0] == "/rejectpm" :
|
||||||
return
|
rejectPrivateMsg(connection,arrayData[1])
|
||||||
connection.send("ERR_COMMAND_NOT_FOUND".encode())
|
return
|
||||||
|
if arrayData[0] == "/pm" :
|
||||||
|
privateMsg(connection,arrayData[1],arrayData[2:])
|
||||||
|
return
|
||||||
|
if arrayData[0] == "/enable":
|
||||||
|
enableUser(connection)
|
||||||
|
return
|
||||||
|
if arrayData[0] == "/disable":
|
||||||
|
disableUser(connection)
|
||||||
|
return
|
||||||
|
connection.send("ERR_COMMAND_NOT_FOUND".encode())
|
||||||
|
else:
|
||||||
|
connection.send("CMD_NOT_ALLOWED".encode())
|
||||||
"""except Exception as e :
|
"""except Exception as e :
|
||||||
log.printL(str(e), Log.lvl.FAIL)"""
|
log.printL(str(e), Log.lvl.FAIL)"""
|
||||||
|
|
||||||
@ -132,6 +143,22 @@ def privateMsg(connection, pseudo, msg):
|
|||||||
connection.send("SUCC_PM_SENDED".encode())
|
connection.send("SUCC_PM_SENDED".encode())
|
||||||
|
|
||||||
|
|
||||||
|
def enableUser(connection):
|
||||||
|
if usersConnected[connection][2] == False :
|
||||||
|
usersConnected[connection][2] = True
|
||||||
|
connection.send("SUCC_ENABLED".encode())
|
||||||
|
else:
|
||||||
|
connection.send("ERR_NOT_DISABLED".encode())
|
||||||
|
|
||||||
|
|
||||||
|
def disableUser(connection):
|
||||||
|
if usersConnected[connection][2] == True :
|
||||||
|
usersConnected[connection][2] = False
|
||||||
|
connection.send("SUCC_DISABLED".encode())
|
||||||
|
else:
|
||||||
|
connection.send("ERR_NOT_ENABLED".encode())
|
||||||
|
|
||||||
|
|
||||||
def quit(connection) :
|
def quit(connection) :
|
||||||
connection.send("SUCCESSFUL_LOGOUT".encode())
|
connection.send("SUCCESSFUL_LOGOUT".encode())
|
||||||
connection.close()
|
connection.close()
|
||||||
@ -178,7 +205,7 @@ def main():
|
|||||||
while True :
|
while True :
|
||||||
#Connection client
|
#Connection client
|
||||||
connection, client_address = sock.accept()
|
connection, client_address = sock.accept()
|
||||||
usersConnected[connection] = [client_address,"Anonymous",True] # ip pseudo status
|
usersConnected[connection] = [client_address,None,True] # ip pseudo status
|
||||||
threading.Thread(target=handleConnection,args=(connection,client_address)).start()
|
threading.Thread(target=handleConnection,args=(connection,client_address)).start()
|
||||||
except KeyboardInterrupt :
|
except KeyboardInterrupt :
|
||||||
# Disable to received more requests on socket
|
# Disable to received more requests on socket
|
||||||
|
5
startServer.py
Normal file
5
startServer.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
__author__ = 'sidya'
|
||||||
|
from serveur import Server
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
Server.main()
|
Reference in New Issue
Block a user