update register cmd

This commit is contained in:
Laila van Reenen 2024-07-01 20:27:24 +02:00
parent 73b71a60f5
commit f17bf03eaf
Signed by: LailaTheElf
GPG Key ID: 1F4E6EE3E6DDF769
2 changed files with 22 additions and 8 deletions

View File

@ -33,7 +33,7 @@
connection.onopen = function ()
{
connection.send(clientId + ';' + Math.floor(new Date().getTime()/1000.0).toString());
connection.send(clientId + ';3440;' + Math.floor(new Date().getTime()/1000.0).toString());
setTimeout(() => { connection.send(clientId + ';boats'); }, 100);
};

View File

@ -41,7 +41,7 @@ async def echoBoats(client):
if (boat["state"] == BOAT_STATE_AVAILABLE):
data += 'available:'
elif (boat["state"] == BOAT_STATE_INCTRL):
data += 'in:'
data += 'inctrl:'
await client['ws'].send(data)
async def echoLockedBoats(client):
@ -88,9 +88,8 @@ async def onMessage(message, client):
else:
print("something else: '" + data[1] + "'")
async def newClient(message, ws):
message = message.split(';')
client = { "id": message[0], "boat": None, "ws": ws, "state": "active" }
async def newClient(clientId, ws):
client = { "id": clientId, "boat": None, "ws": ws, "state": "active" }
print("new client connected: " + client['id'])
for clie in clients:
if (clie['id'] == client['id']):
@ -102,10 +101,25 @@ async def newClient(message, ws):
await echoClients(client)
return client
async def newBoat(boatId, name, ws):
boat = { "id": boatId, "name": name, "ws": ws, "state": "active" }
print("new client connected: " + client['id'])
for bo in boats:
if (bo['id'] == boat['id']):
bo['state'] = 'terminated'
boats.append(boat)
return boat
async def run(ws, path):
client = None
async for message in ws:
client = await newClient(message, ws)
message = message.split(';')
if (len(message) == 3 and message[1] == "4675"):
client = await newClient(message[1], ws)
if (client is not None):
break
elif (len(message) == 3 and message[1] == "3440"):
client = await newBoat(message[1], message[2], ws)
if (client is not None):
break