This commit is contained in:
Dominic Zimmer 2020-04-17 00:34:44 +02:00
parent 408fec350b
commit b5cee96d7a

View File

@ -22,9 +22,9 @@ class Model:
def assert_model(self):
if not "clients" in self.model:
self.model["clients"] = []
self.model["clients"] = {}
if not "sessions" in self.model:
self.model["sessions"] = []
self.model["sessions"] = {}
def handle_post(self, data):
print("I have received P O S T data: " + str(data))
@ -50,13 +50,13 @@ class Model:
def create_client(self) -> str:
clientname = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(10)))[:16].decode().lower()
newclient = {"id": clientname}
self.model["clients"].append(newclient)
self.model["clients"][clientname] = newclient
return clientname
def create_session(self) -> str:
sessionname = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(10)))[:16].decode().lower()
newsession = {"id": sessionname, "clients": []}
self.model["sessions"].append(newsession)
self.model["sessions"][sessionname] = newsession
return sessionname
def subscribe(self, clientid, socket):