Poulet
This commit is contained in:
parent
fb9f95aa26
commit
bb72fdcc9a
@ -55,8 +55,8 @@ class start(QtGui.QDialog):
|
|||||||
exit(0)
|
exit(0)
|
||||||
try:
|
try:
|
||||||
self.s.send(cmd.encode())
|
self.s.send(cmd.encode())
|
||||||
# data , addr = s.recvfrom(4096)
|
data = self.s.recv(4096)
|
||||||
# print(data.decode())
|
print(data.decode())
|
||||||
except timeout:
|
except timeout:
|
||||||
print("Erreur : Timeout. Le serveur ne repond pas.")
|
print("Erreur : Timeout. Le serveur ne repond pas.")
|
||||||
|
|
||||||
|
@ -6,52 +6,53 @@ from serveur import Log
|
|||||||
|
|
||||||
|
|
||||||
def handleConnection(connection, client_address) :
|
def handleConnection(connection, client_address) :
|
||||||
try:
|
#try:
|
||||||
log.printL("Connection from IP -> {}".format(client_address), Log.lvl.INFO)
|
log.printL("Connection from IP -> {}".format(client_address), Log.lvl.INFO)
|
||||||
while True:
|
while True:
|
||||||
data = connection.recv(4096)
|
data = connection.recv(4096)
|
||||||
if data:
|
if data:
|
||||||
log.printL("Request from IP -> {}"
|
log.printL("Request from IP -> {}"
|
||||||
" {}".format(client_address,data.decode()), Log.lvl.INFO)
|
" {}".format(client_address,data.decode()), Log.lvl.INFO)
|
||||||
threading.Thread(target=handleRequest, args=(connection, data.decode())).start()
|
threading.Thread(target=handleRequest, args=(connection, data.decode())).start()
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Exception as e :
|
"""except Exception as e :
|
||||||
log.printL(str(e), Log.lvl.FAIL)
|
log.printL(str(e), Log.lvl.FAIL)"""
|
||||||
|
|
||||||
|
|
||||||
def handleRequest(connection, data):
|
def handleRequest(connection, data):
|
||||||
try:
|
#try:
|
||||||
arrayData = data.split(" ")
|
arrayData = data.split(" ")
|
||||||
if(not arrayData[0][0] == "/"):
|
if(not arrayData[0][0] == "/"):
|
||||||
broadcastMsg( "NEW_MSG {} {} ".format(usersConnected[connection][1], data))
|
broadcastMsg( "NEW_MSG {} {} ".format(usersConnected[connection][1], data))
|
||||||
|
return
|
||||||
|
else :
|
||||||
|
if arrayData[0] == "/name" :
|
||||||
|
changeName(connection, arrayData[1])
|
||||||
return
|
return
|
||||||
else :
|
if arrayData[0] == "/quit" :
|
||||||
if arrayData[0] == "/name" :
|
quit(connection)
|
||||||
changeName(connection, arrayData[1])
|
return
|
||||||
return
|
if arrayData[0] == "/askpm" :
|
||||||
if arrayData[0] == "/quit" :
|
askPrivateMsg(connection,arrayData[1])
|
||||||
quit(connection)
|
return
|
||||||
return
|
if arrayData[0] == "/acceptpm" :
|
||||||
if arrayData[0] == "/askpm" :
|
acceptPrivateMsg(connection,arrayData[1])
|
||||||
askPrivateMsg(connection,arrayData[1])
|
return
|
||||||
return
|
if arrayData[0] == "/rejectpm" :
|
||||||
if arrayData[0] == "/acceptpm" :
|
rejectPrivateMsg(connection,arrayData[1])
|
||||||
acceptPrivateMsg(connection,arrayData[1])
|
return
|
||||||
return
|
if arrayData[0] == "/pm" :
|
||||||
if arrayData[0] == "/rejectpm" :
|
privateMsg(connection,arrayData[1],arrayData[2:])
|
||||||
rejectPrivateMsg(connection,arrayData[1])
|
return
|
||||||
return
|
connection.send("ERR_COMMAND_NOT_FOUND".encode())
|
||||||
if arrayData[0] == "/pm" :
|
"""except Exception as e :
|
||||||
privateMsg(connection,arrayData[1],arrayData[2:])
|
log.printL(str(e), Log.lvl.FAIL)"""
|
||||||
return
|
|
||||||
connection.send("ERR_COMMAND_NOT_FOUND".encode())
|
|
||||||
except Exception as e :
|
|
||||||
log.printL(str(e), Log.lvl.FAIL)
|
|
||||||
|
|
||||||
|
|
||||||
def broadcastMsg(message):
|
def broadcastMsg(message):
|
||||||
sock.sendall(message.encode())
|
for con, value in usersConnected.items() :
|
||||||
|
con.send(message.encode())
|
||||||
|
|
||||||
|
|
||||||
def userListActive(connection):
|
def userListActive(connection):
|
||||||
@ -132,11 +133,11 @@ def privateMsg(connection, pseudo, msg):
|
|||||||
|
|
||||||
|
|
||||||
def quit(connection) :
|
def quit(connection) :
|
||||||
broadcastMsg("HAS_LEFT {}".format(usersConnected[connection][1]))
|
|
||||||
connection.send("SUCCESSFUL_LOGOUT".encode())
|
connection.send("SUCCESSFUL_LOGOUT".encode())
|
||||||
connection.close()
|
connection.close()
|
||||||
usersConnected.__delitem__(connection)
|
|
||||||
log.printL("Disconnection from IP -> {}".format(usersConnected[connection][0]), Log.lvl.INFO)
|
log.printL("Disconnection from IP -> {}".format(usersConnected[connection][0]), Log.lvl.INFO)
|
||||||
|
usersConnected.pop(connection)
|
||||||
|
broadcastMsg("HAS_LEFT {}".format(usersConnected[connection][1]))
|
||||||
|
|
||||||
|
|
||||||
def getConnectionByPseudo(pseudo):
|
def getConnectionByPseudo(pseudo):
|
||||||
|
Reference in New Issue
Block a user