parent
e3a56c5069
commit
f8813485d3
1 changed files with 40 additions and 22 deletions
62
server.py
62
server.py
|
@ -252,41 +252,59 @@ def multiserverhost(sock, client):
|
||||||
try:
|
try:
|
||||||
threading.Thread(target=multiserverpinger, args=[sock]).start()
|
threading.Thread(target=multiserverpinger, args=[sock]).start()
|
||||||
global sessions
|
global sessions
|
||||||
|
global cache_properties
|
||||||
sessions[client[0]] = sock
|
sessions[client[0]] = sock
|
||||||
|
cache_properties[client[0]] = {}
|
||||||
global channels_list
|
global channels_list
|
||||||
global property_list
|
global property_list
|
||||||
global nickname_list
|
global nickname_list
|
||||||
global topic_list
|
global topic_list
|
||||||
if sock.recv(2048).decode() == "meow":
|
if sock.recv(2048).decode() == "meow":
|
||||||
sock.sendall("woem")
|
sock.sendall(bytes("woem", "UTF-8"))
|
||||||
else:
|
else:
|
||||||
raise Exception("Something wrong happened")
|
raise Exception("This isn't an IRCat server!!")
|
||||||
while True:
|
while True:
|
||||||
txt = fnet.decrypt(sock.recv(2048)).decode()
|
txt = fnet.decrypt(sock.recv(2048)).decode()
|
||||||
if txt.split(" ")[0] == "VERIFYUSER":
|
if txt.split(" ")[0] == "VERIFYUSER": # When a user from a different server logs in
|
||||||
nck = txt.split(" ")[1]
|
nck = txt.split(" ")[1] # Nickname
|
||||||
usr = json.loads(" ".join(txt.split(" ")[2:]))
|
usr = json.loads(" ".join(txt.split(" ")[2:])) # New JSON properties
|
||||||
property_list[nck] = usr
|
property_list[nck] = usr # Add the properties
|
||||||
nickname_list[nck] = "external"
|
nickname_list[nck] = {"external": client[0]} # Add the nickname indicating it's external
|
||||||
lower_nicks[nck.lower()] = usr
|
lower_nicks[nck.lower()] = usr # Add the lowercase nickname
|
||||||
users_externalservers[nck] = client[0]
|
users_externalservers[nck] = client[0] #
|
||||||
elif txt.split(" ")[0] == "SND":
|
"""
|
||||||
property_list[txt.split(" ")[1]]["pendingSend"] += " ".join(txt.split(" ")[2:])
|
elif txt.split(" ")[0] == "COLLIDE": # Fix connection collision, choose which server would have the outgoing connection.
|
||||||
elif txt.split(" ")[0] == "CNGPROP":
|
if multi_server == "loner":
|
||||||
nck = txt.split(" ")[1]
|
sock.sendall(fnet.encrypt(bytes("THIS", "UTF-8"))) # Keep this connection
|
||||||
usr = json.loads(" ".join(txt.split(" ")[2:]))
|
elif random.randint(0,1):
|
||||||
property_list[nck] = usr
|
sock.sendall(fnet.encrypt(bytes("THAT", "UTF-8"))) # Move to other connection
|
||||||
elif txt.split(" ")[0] == "CNGNICK":
|
time.sleep(3)
|
||||||
nck = txt.split(" ")[1]
|
raise Exception("THAT sent, closing.") # Close the connection
|
||||||
nnck = txt.split(" ")[2]
|
else:
|
||||||
nickname_list[nnck] = nickname_list.pop(nck)
|
sock.sendall(fnet.encrypt(bytes("THIS", "UTF-8"))) # Keep this connection
|
||||||
property_list[nnck] = property_list.pop(nck)
|
""" # We won't need colliding, they will connect to eachother.
|
||||||
del lower_nicks[nck.lower()]
|
elif txt.split(" ")[0] == "SPLIT": # When the remote host realizes it doesn't have an outgoing connection to this server.
|
||||||
lower_nicks[nnck.lower()] = nnck
|
|
||||||
|
elif txt.split(" ")[0] == "SND": # When a token was sent by another server
|
||||||
|
property_list[txt.split(" ")[1]]["pendingSend"] += " ".join(txt.split(" ")[2:]) # Send the text to the specified user
|
||||||
|
elif txt.split(" ")[0] == "CNGPROP": # When properties changed on another server
|
||||||
|
nck = txt.split(" ")[1] # Nickname
|
||||||
|
usr = json.loads(" ".join(txt.split(" ")[2:])) # JSON
|
||||||
|
property_list[nck] = usr # Change the JSON...
|
||||||
|
cache_properties[client[0]][nck] = usr # ...And cache it
|
||||||
|
elif txt.split(" ")[0] == "CNGNICK": # When nick changed on another server
|
||||||
|
nck = txt.split(" ")[1] # Old nickname
|
||||||
|
nnck = txt.split(" ")[2] # New nickname
|
||||||
|
nickname_list[nnck] = nickname_list.pop(nck) # Move old nickname from list
|
||||||
|
property_list[nnck] = property_list.pop(nck) # Move properties...
|
||||||
|
cache_properties[client[0]][nnck] = cache_properties[client[0]].pop(nck) # ...And cache it
|
||||||
|
del lower_nicks[nck.lower()] # Remove the old lowercase nickname...
|
||||||
|
lower_nicks[nnck.lower()] = nnck # ...And replace it
|
||||||
elif txt == "PING":
|
elif txt == "PING":
|
||||||
sock.sendall(fnet.encrypt(bytes("PONG", "UTF-8")))
|
sock.sendall(fnet.encrypt(bytes("PONG", "UTF-8")))
|
||||||
finally:
|
finally:
|
||||||
netsplit(client[0])
|
netsplit(client[0])
|
||||||
|
sock.close()
|
||||||
def session(connection, client, ip, isssl=False):
|
def session(connection, client, ip, isssl=False):
|
||||||
global channels_list
|
global channels_list
|
||||||
global property_list
|
global property_list
|
||||||
|
|
Loading…
Add table
Reference in a new issue