mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Hadle disconnection properly
This commit is contained in:
parent
45129c5cda
commit
0a522ccb21
@ -86,7 +86,6 @@ class Session:
|
|||||||
self.name = ""
|
self.name = ""
|
||||||
self.host_uuid = ""
|
self.host_uuid = ""
|
||||||
self.clients_uuid = []
|
self.clients_uuid = []
|
||||||
self.players = []
|
|
||||||
self.connections = []
|
self.connections = []
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -110,6 +109,19 @@ class Session:
|
|||||||
gc.clientInit = True
|
gc.clientInit = True
|
||||||
self.connections.append(gc)
|
self.connections.append(gc)
|
||||||
|
|
||||||
|
def removeConnection(self, conn: socket):
|
||||||
|
newConnections = []
|
||||||
|
for c in self.connections:
|
||||||
|
if c.server == conn:
|
||||||
|
c.server = None
|
||||||
|
c.serverInit = False
|
||||||
|
if c.client == conn:
|
||||||
|
c.client = None
|
||||||
|
c.clientInit = False
|
||||||
|
if c.server != None or c.client != None:
|
||||||
|
newConnections.append(c)
|
||||||
|
self.connections = newConnections
|
||||||
|
|
||||||
def validPipe(self, conn) -> bool:
|
def validPipe(self, conn) -> bool:
|
||||||
for gc in self.connections:
|
for gc in self.connections:
|
||||||
if gc.server == conn or gc.client == conn:
|
if gc.server == conn or gc.client == conn:
|
||||||
@ -218,8 +230,12 @@ def handleDisconnection(client: socket):
|
|||||||
updateStatus(sender.client.room)
|
updateStatus(sender.client.room)
|
||||||
updateRooms()
|
updateRooms()
|
||||||
|
|
||||||
if sender.isPipe():
|
if sender.isPipe() and sender.client.auth:
|
||||||
pass
|
if sender.client.session in sessions:
|
||||||
|
sender.client.session.removeConnection(client)
|
||||||
|
if not len(sender.client.session.connections):
|
||||||
|
print(f"[*] Destroying session {sender.client.session.name}")
|
||||||
|
sessions.remove(sender.client.session)
|
||||||
|
|
||||||
client.close()
|
client.close()
|
||||||
client_sockets.pop(client)
|
client_sockets.pop(client)
|
||||||
@ -261,6 +277,7 @@ def deleteRoom(room: Room):
|
|||||||
msg2 = msg + f":{client_sockets[player].client.username}"
|
msg2 = msg + f":{client_sockets[player].client.username}"
|
||||||
send(player, msg2)
|
send(player, msg2)
|
||||||
|
|
||||||
|
print(f"[*] Destroying room {room.name}")
|
||||||
rooms.pop(room.name)
|
rooms.pop(room.name)
|
||||||
|
|
||||||
|
|
||||||
@ -291,6 +308,7 @@ def startRoom(room: Room):
|
|||||||
client_sockets.pop(player)
|
client_sockets.pop(player)
|
||||||
|
|
||||||
#this room shall not exist anymore
|
#this room shall not exist anymore
|
||||||
|
print(f"[*] Destroying room {room.name}")
|
||||||
rooms.pop(room.name)
|
rooms.pop(room.name)
|
||||||
|
|
||||||
|
|
||||||
@ -336,7 +354,7 @@ def dispatch(cs: socket, sender: Sender, arr: bytes):
|
|||||||
# WARNING: reversed byte order is not supported
|
# WARNING: reversed byte order is not supported
|
||||||
sender.client.prevmessages.append(cs.recv(1))
|
sender.client.prevmessages.append(cs.recv(1))
|
||||||
print(f" binding server connection to session {session.name}")
|
print(f" binding server connection to session {session.name}")
|
||||||
return
|
break
|
||||||
|
|
||||||
if sender.client.apptype == "client":
|
if sender.client.apptype == "client":
|
||||||
for p in session.clients_uuid:
|
for p in session.clients_uuid:
|
||||||
|
Loading…
Reference in New Issue
Block a user