shittyserver: squish a couple bugs

This commit is contained in:
Marks Polakovs 2020-04-11 15:59:54 +02:00
parent 150596920f
commit bcef6fe319

View file

@ -146,6 +146,7 @@ class Session(object):
connection_state: Optional[str]
pc: Optional[Any]
connection_id: str
lock: asyncio.Lock
def __init__(self) -> None:
self.websocket = None
@ -154,6 +155,7 @@ class Session(object):
self.connection_state = None
self.connection_id = str(uuid.uuid4())
self.ended = False
self.lock = asyncio.Lock()
def to_dict(self) -> Dict[str, str]:
return {"connection_id": self.connection_id}
@ -169,6 +171,7 @@ class Session(object):
async def end(self) -> None:
global active_sessions
async with self.lock:
if self.ended:
print(self.connection_id, "already over")
else:
@ -193,6 +196,9 @@ class Session(object):
else:
print(self.connection_id, "wasn't in active_sessions!")
if live_session == self:
live_session = None
await notify_mattserver_about_sessions()
print(self.connection_id, "bye bye")
self.ended = True
@ -333,10 +339,10 @@ async def telnet_server(
print(parts)
if parts[0] == "Q":
data: Dict[str, Dict[str, str]] = {}
result: Dict[str, Dict[str, str]] = {}
for sid, sess in active_sessions.items():
data[sid] = sess.to_dict()
writer.write((json.dumps(data) + "\r\n").encode("utf-8"))
result[sid] = sess.to_dict()
writer.write((json.dumps(result) + "\r\n").encode("utf-8"))
elif parts[0] == "SEL":
sid = parts[1]