update register cmd
This commit is contained in:
parent
73b71a60f5
commit
f17bf03eaf
@ -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);
|
||||
};
|
||||
|
||||
|
||||
24
recever.py
24
recever.py
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user