Poulet
This commit is contained in:
parent
3ac76d2b55
commit
6651367b2a
@ -3,20 +3,22 @@ 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)
|
||||||
#userListActive(connection)
|
#userListActive(connection)
|
||||||
#userListAway(connection)
|
#userListAway(connection)
|
||||||
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)
|
||||||
|
finally:
|
||||||
|
quit
|
||||||
|
|
||||||
|
|
||||||
def handleRequest(connection, data):
|
def handleRequest(connection, data):
|
||||||
@ -66,8 +68,9 @@ def handleRequest(connection, data):
|
|||||||
|
|
||||||
|
|
||||||
def broadcastMsg(connection,message):
|
def broadcastMsg(connection,message):
|
||||||
|
log.printL(usersConnected, Log.lvl.DEBUG)
|
||||||
for con, value in usersConnected.items() :
|
for con, value in usersConnected.items() :
|
||||||
if usersConnected[con][1] is not None and con != connection:
|
if usersConnected[con][1] is not None and con != connection and connection[con][2] == True:
|
||||||
try:
|
try:
|
||||||
con.sendall(message.encode())
|
con.sendall(message.encode())
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
@ -182,8 +185,10 @@ def quit(connection) :
|
|||||||
connection.sendall("SUCCESSFUL_LOGOUT".encode())
|
connection.sendall("SUCCESSFUL_LOGOUT".encode())
|
||||||
connection.close()
|
connection.close()
|
||||||
log.printL("Disconnection from IP -> {}".format(usersConnected[connection][0]), Log.lvl.INFO)
|
log.printL("Disconnection from IP -> {}".format(usersConnected[connection][0]), Log.lvl.INFO)
|
||||||
|
pseudo = usersConnected[connection][1]
|
||||||
usersConnected.pop(connection)
|
usersConnected.pop(connection)
|
||||||
broadcastMsg("HAS_LEFT {}".format(usersConnected[connection][1]))
|
broadcastMsg(connection,"HAS_LEFT {}".format(pseudo))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getConnectionByPseudo(pseudo):
|
def getConnectionByPseudo(pseudo):
|
||||||
|
Reference in New Issue
Block a user