SERVER DE LA MUERTE
This commit is contained in:
parent
918f2199a8
commit
6c6a7f87aa
@ -49,6 +49,15 @@ def handleRequest(connection, data):
|
|||||||
if arrayData[0] == "/pm":
|
if arrayData[0] == "/pm":
|
||||||
privateMsg(connection, arrayData[1], " ".join(arrayData[2:]))
|
privateMsg(connection, arrayData[1], " ".join(arrayData[2:]))
|
||||||
return
|
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
|
||||||
if arrayData[0] == "/enable":
|
if arrayData[0] == "/enable":
|
||||||
enableUser(connection)
|
enableUser(connection)
|
||||||
return
|
return
|
||||||
@ -67,7 +76,10 @@ def handleRequest(connection, data):
|
|||||||
connection.shutdown(socket.SHUT_RD)
|
connection.shutdown(socket.SHUT_RD)
|
||||||
return
|
return
|
||||||
connection.sendall("ERR_NO_NICKNAME".encode())
|
connection.sendall("ERR_NO_NICKNAME".encode())
|
||||||
"""except Exception as e :
|
"""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)
|
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())"""
|
||||||
|
|
||||||
@ -101,6 +113,8 @@ def userListAway(connection):
|
|||||||
def changeName(connection, pseudo):
|
def changeName(connection, pseudo):
|
||||||
if not re.match("^\w{3,15}$", pseudo):
|
if not re.match("^\w{3,15}$", pseudo):
|
||||||
connection.sendall("ERR_INVALID_NICKNAME".encode())
|
connection.sendall("ERR_INVALID_NICKNAME".encode())
|
||||||
|
elif getConnectionByPseudo(pseudo) is not None:
|
||||||
|
connection.sendall("ERR_NICKNAME_ALREADY_USED")
|
||||||
else:
|
else:
|
||||||
broadcastMsg(connection, "NAME_CHANGED {} {}".format(usersConnected[connection][1], pseudo))
|
broadcastMsg(connection, "NAME_CHANGED {} {}".format(usersConnected[connection][1], pseudo))
|
||||||
connection.sendall("SUCC_VALID_NICKNAME".encode())
|
connection.sendall("SUCC_VALID_NICKNAME".encode())
|
||||||
@ -110,6 +124,8 @@ def changeName(connection, pseudo):
|
|||||||
def newName(connection, pseudo):
|
def newName(connection, pseudo):
|
||||||
if not re.match("^\w{3,15}$", pseudo):
|
if not re.match("^\w{3,15}$", pseudo):
|
||||||
connection.sendall("ERR_INVALID_NICKNAME".encode())
|
connection.sendall("ERR_INVALID_NICKNAME".encode())
|
||||||
|
elif getConnectionByPseudo(pseudo) is not None:
|
||||||
|
connection.sendall("ERR_NICKNAME_ALREADY_USED".encode())
|
||||||
else:
|
else:
|
||||||
broadcastMsg(connection, "HAS_JOIN {} ".format(pseudo))
|
broadcastMsg(connection, "HAS_JOIN {} ".format(pseudo))
|
||||||
connection.sendall("SUCC_CHANNEL_JOINED".encode())
|
connection.sendall("SUCC_CHANNEL_JOINED".encode())
|
||||||
@ -146,6 +162,7 @@ def acceptPrivateMsg(connection, pseudo):
|
|||||||
askPM.remove(pm)
|
askPM.remove(pm)
|
||||||
validatePM.append(pm)
|
validatePM.append(pm)
|
||||||
connection.sendall("SUCC_PRIVATE_DISCUSSION_ACCEPTED".encode())
|
connection.sendall("SUCC_PRIVATE_DISCUSSION_ACCEPTED".encode())
|
||||||
|
c.sendall("SUCC_PRIVATE_DISCUSSION_OK {}".format(usersConnected[connection][1]).encode())
|
||||||
|
|
||||||
|
|
||||||
def rejectPrivateMsg(connection, pseudo):
|
def rejectPrivateMsg(connection, pseudo):
|
||||||
@ -159,15 +176,17 @@ def rejectPrivateMsg(connection, pseudo):
|
|||||||
if pm in validatePM :
|
if pm in validatePM :
|
||||||
validatePM.remove(pm)
|
validatePM.remove(pm)
|
||||||
connection.sendall("SUCC_PRIVATE_DISCUSSION_REFUSED".encode())
|
connection.sendall("SUCC_PRIVATE_DISCUSSION_REFUSED".encode())
|
||||||
|
c.sendall("SUCC_PRIVATE_DISCUSSION_REJECTED {}".format(usersConnected[connection][1]).encode())
|
||||||
|
elif pmr in validatePM :
|
||||||
|
validatePM.remove(pmr)
|
||||||
|
connection.sendall("SUCC_PRIVATE_DISCUSSION_REFUSED".encode())
|
||||||
|
c.sendall("SUCC_PRIVATE_DISCUSSION_REJECTED {}".format(usersConnected[connection][1]).encode())
|
||||||
else :
|
else :
|
||||||
if pmr in validatePM:
|
connection.sendall("ERR_USER_HAS_NOT_ASK".encode())
|
||||||
validatePM.remove(pmr)
|
|
||||||
connection.sendall("SUCC_PRIVATE_DISCUSSION_REFUSED".encode())
|
|
||||||
else :
|
|
||||||
connection.sendall("ERR_USER_HAS_NOT_ASK".encode())
|
|
||||||
else:
|
else:
|
||||||
askPM.remove(pm)
|
askPM.remove(pm)
|
||||||
connection.sendall("SUCC_PRIVATE_DISCUSSION_REFUSED".encode())
|
connection.sendall("SUCC_PRIVATE_DISCUSSION_REFUSED".encode())
|
||||||
|
c.sendall("SUCC_PRIVATE_DISCUSSION_REJECTED {}".format(usersConnected[connection][1]).encode())
|
||||||
|
|
||||||
|
|
||||||
def privateMsg(connection, pseudo, msg):
|
def privateMsg(connection, pseudo, msg):
|
||||||
@ -194,13 +213,13 @@ def askFile(connection, pseudo, file):
|
|||||||
connection.sendall("ERR_ALREADY_ONE".encode())
|
connection.sendall("ERR_ALREADY_ONE".encode())
|
||||||
else:
|
else:
|
||||||
askFT.append(f)
|
askFT.append(f)
|
||||||
log.printL("askPm {}".format(askPM), Log.lvl.DEBUG)
|
log.printL("askFT {}".format(askFT), Log.lvl.DEBUG)
|
||||||
c.sendall("HAS_ASKED_FILE {} {}".format(pseudo, file))
|
c.sendall("HAS_ASKED_FILE {} {}".format(usersConnected[connection][1], file).encode())
|
||||||
connection.sendall("SUCC_ASKED_FILE".encode())
|
connection.sendall("SUCC_ASKED_FILE".encode())
|
||||||
|
|
||||||
|
|
||||||
def acceptFile(connection, pseudo, file, ip, port):
|
def acceptFile(connection, pseudo, file, port):
|
||||||
log.printL("askFT {}".format(askPM), Log.lvl.DEBUG)
|
log.printL("askFT {}".format(askFT), Log.lvl.DEBUG)
|
||||||
c = getConnectionByPseudo(pseudo)
|
c = getConnectionByPseudo(pseudo)
|
||||||
if c is None:
|
if c is None:
|
||||||
connection.sendall("ERR_USER_NOT_FOUND".encode())
|
connection.sendall("ERR_USER_NOT_FOUND".encode())
|
||||||
@ -210,8 +229,8 @@ def acceptFile(connection, pseudo, file, ip, port):
|
|||||||
connection.sendall("ERR_USER_HAS_NOT_ASK".encode())
|
connection.sendall("ERR_USER_HAS_NOT_ASK".encode())
|
||||||
else:
|
else:
|
||||||
askFT.remove(f)
|
askFT.remove(f)
|
||||||
connection.sendall("SUCC_FILE_ACCEPTED".encode())
|
connection.sendall("SUCC_FILE_ACCEPTED {}".format(usersConnected[c][0][0]).encode())
|
||||||
c.sendall("CAN_SEND_FILE {} {} {} {}".format(file,pseudo,ip,port).encode())
|
c.sendall("CAN_SEND_FILE {} {} {} {}".format(file,pseudo,usersConnected[connection][0][0], port).encode())
|
||||||
|
|
||||||
|
|
||||||
def rejectFile(connection, pseudo, file):
|
def rejectFile(connection, pseudo, file):
|
||||||
@ -227,7 +246,6 @@ def rejectFile(connection, pseudo, file):
|
|||||||
connection.sendall("SUCC_FILE_REFUSED".encode())
|
connection.sendall("SUCC_FILE_REFUSED".encode())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def enableUser(connection):
|
def enableUser(connection):
|
||||||
if usersConnected[connection][2] == False:
|
if usersConnected[connection][2] == False:
|
||||||
usersConnected[connection][2] = True
|
usersConnected[connection][2] = True
|
||||||
|
Reference in New Issue
Block a user