BG 63
This commit is contained in:
parent
e140cf3f97
commit
86f33b67b9
@ -20,7 +20,7 @@ def handleConnection(connection, client_address):
|
||||
|
||||
|
||||
def handleRequest(connection, data):
|
||||
try:
|
||||
#try:
|
||||
arrayData = data.split(" ")
|
||||
if usersConnected[connection][1] is not None:
|
||||
if (not arrayData[0][0] == "/"):
|
||||
@ -67,9 +67,9 @@ def handleRequest(connection, data):
|
||||
connection.shutdown(socket.SHUT_RD)
|
||||
return
|
||||
connection.sendall("ERR_NO_NICKNAME".encode())
|
||||
except Exception as e :
|
||||
"""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):
|
||||
@ -128,18 +128,18 @@ def askPrivateMsg(connection, pseudo):
|
||||
connection.sendall("ALREADY_ASKED".encode())
|
||||
else:
|
||||
askPM.append(pm)
|
||||
log.printL("askPm []".format(askPM), Log.lvl.DEBUG)
|
||||
log.printL("askPm {}".format(askPM), Log.lvl.DEBUG)
|
||||
c.sendall("ASKING_FOR_PM {}".format(usersConnected[connection][1]).encode())
|
||||
connection.sendall("SUCC_INVITED".encode())
|
||||
|
||||
|
||||
def acceptPrivateMsg(connection, pseudo):
|
||||
log.printL("askPm []".format(askPM), Log.lvl.DEBUG)
|
||||
log.printL("askPm {}".format(askPM), Log.lvl.DEBUG)
|
||||
c = getConnectionByPseudo(pseudo)
|
||||
if c is None:
|
||||
connection.sendall("ERR_USER_NOT_FOUND".encode())
|
||||
else:
|
||||
pm = (connection, c)
|
||||
pm = (c, connection)
|
||||
if pm not in askPM:
|
||||
connection.sendall("ERR_USER_HAS_NOT_ASK".encode())
|
||||
else:
|
||||
@ -153,7 +153,7 @@ def rejectPrivateMsg(connection, pseudo):
|
||||
if c is None:
|
||||
connection.sendall("ERR_USER_NOT_FOUND".encode())
|
||||
else:
|
||||
pm = (connection, c)
|
||||
pm = (c, connection)
|
||||
if pm not in askPM:
|
||||
connection.sendall("ERR_USER_HAS_NOT_ASK".encode())
|
||||
else:
|
||||
@ -174,6 +174,50 @@ def privateMsg(connection, pseudo, msg):
|
||||
connection.sendall("SUCC_PM_SENDED".encode())
|
||||
|
||||
|
||||
def askFile(connection, pseudo, file):
|
||||
c = getConnectionByPseudo(pseudo)
|
||||
if c is None:
|
||||
connection.sendall("ERR_USER_NOT_FOUND".encode())
|
||||
else:
|
||||
f = (connection, c, file)
|
||||
if f in askFT:
|
||||
connection.sendall("ERR_ALREADY_ONE".encode())
|
||||
else:
|
||||
askFT.append(f)
|
||||
log.printL("askPm {}".format(askPM), Log.lvl.DEBUG)
|
||||
c.sendall("HAS_ASKED_FILE {} {}".format(pseudo, file))
|
||||
connection.sendall("SUCC_ASKED_FILE".encode())
|
||||
|
||||
|
||||
def acceptFile(connection, pseudo, file, ip, port):
|
||||
log.printL("askFT {}".format(askPM), Log.lvl.DEBUG)
|
||||
c = getConnectionByPseudo(pseudo)
|
||||
if c is None:
|
||||
connection.sendall("ERR_USER_NOT_FOUND".encode())
|
||||
else:
|
||||
f = (c, connection, file)
|
||||
if f not in askFT:
|
||||
connection.sendall("ERR_USER_HAS_NOT_ASK".encode())
|
||||
else:
|
||||
askFT.remove(f)
|
||||
connection.sendall("SUCC_FILE_ACCEPTED".encode())
|
||||
c.sendall("CAN_SEND_FILE {} {} {} {}".format(file,pseudo,ip,port).encode())
|
||||
|
||||
|
||||
def rejectFile(connection, pseudo, file):
|
||||
c = getConnectionByPseudo(pseudo)
|
||||
if c is None:
|
||||
connection.sendall("ERR_USER_NOT_FOUND".encode())
|
||||
else:
|
||||
f = (c, connection, file)
|
||||
if f not in askFT:
|
||||
connection.sendall("ERR_USER_HAS_NOT_ASK".encode())
|
||||
else:
|
||||
askPM.remove(f)
|
||||
connection.sendall("SUCC_FILE_REFUSED".encode())
|
||||
|
||||
|
||||
|
||||
def enableUser(connection):
|
||||
if usersConnected[connection][2] == False:
|
||||
usersConnected[connection][2] = True
|
||||
@ -216,10 +260,11 @@ def main():
|
||||
# Global vars
|
||||
global usersConnected, log, sock
|
||||
global askPM, validatePM
|
||||
global askFT, validateFT
|
||||
global askFT
|
||||
usersConnected = {}
|
||||
askPM = []
|
||||
validatePM = []
|
||||
askFT = []
|
||||
config = configparser.ConfigParser()
|
||||
if not os.path.isfile("dncserver.conf"):
|
||||
config['NETWORK'] = {'port': '2222'}
|
||||
|
Reference in New Issue
Block a user