commander update
This commit is contained in:
parent
8619022374
commit
8b0735fca2
@ -26,9 +26,9 @@
|
|||||||
height: 200px;
|
height: 200px;
|
||||||
}
|
}
|
||||||
.btn {
|
.btn {
|
||||||
padding: 10px 20px;
|
padding: 5px 10px;
|
||||||
background-color: #808080;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
display: inline-block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@ -46,6 +46,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
<caption>bootjes</caption>
|
||||||
<tr>
|
<tr>
|
||||||
<th>id</th>
|
<th>id</th>
|
||||||
<th>naam</th>
|
<th>naam</th>
|
||||||
@ -56,6 +57,7 @@
|
|||||||
</table>
|
</table>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
<caption>clients</caption>
|
||||||
<tr>
|
<tr>
|
||||||
<th>id</th>
|
<th>id</th>
|
||||||
<th>boat</th>
|
<th>boat</th>
|
||||||
@ -191,7 +193,7 @@
|
|||||||
if (boatRow.dataset['state'] == "locked")
|
if (boatRow.dataset['state'] == "locked")
|
||||||
{
|
{
|
||||||
lockBtn.innerHTML = openIcon;
|
lockBtn.innerHTML = openIcon;
|
||||||
lockBtn.addEventListener('click', unlockBoat);
|
lockBtn.addEventListener('click', freeBoat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -224,36 +226,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDataFomEl(el)
|
|
||||||
{
|
|
||||||
while (el.tagName != "BODY" && el.dataset['id'] == null)
|
|
||||||
{
|
|
||||||
el = el.parentElement;
|
|
||||||
}
|
|
||||||
return el.dataset;
|
|
||||||
}
|
|
||||||
|
|
||||||
function kickClient(e)
|
|
||||||
{
|
|
||||||
let client = getDataFomEl(e.target);
|
|
||||||
console.log("kickClient", client);
|
|
||||||
conn.send(passEl.value + ";kick;" + client['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function unlockBoat(e)
|
|
||||||
{
|
|
||||||
let boat = getDataFomEl(e.target);
|
|
||||||
console.log("unlockBoat", boat);
|
|
||||||
conn.send(passEl.value + ";unlock;" + boat['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function lockBoat(e)
|
|
||||||
{
|
|
||||||
let boat = getDataFomEl(e.target);
|
|
||||||
console.log("lockBoat", boat);
|
|
||||||
conn.send(passEl.value + ";lock;" + boat['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addClient(client)
|
function addClient(client)
|
||||||
{
|
{
|
||||||
client = client.split(';')
|
client = client.split(';')
|
||||||
@ -288,6 +260,36 @@
|
|||||||
{
|
{
|
||||||
console.warn("addClient(): incorect number of args (" + client.length.toString() + "; " + client.toString() + ")");
|
console.warn("addClient(): incorect number of args (" + client.length.toString() + "; " + client.toString() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDataFomEl(el)
|
||||||
|
{
|
||||||
|
while (el.tagName != "BODY" && el.dataset['id'] == null)
|
||||||
|
{
|
||||||
|
el = el.parentElement;
|
||||||
|
}
|
||||||
|
return el.dataset;
|
||||||
|
}
|
||||||
|
|
||||||
|
function kickClient(e)
|
||||||
|
{
|
||||||
|
let client = getDataFomEl(e.target);
|
||||||
|
console.log("kickClient", client);
|
||||||
|
conn.send(passEl.value + ";kick;" + client['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function freeBoat(e)
|
||||||
|
{
|
||||||
|
let boat = getDataFomEl(e.target);
|
||||||
|
console.log("unlockBoat", boat);
|
||||||
|
conn.send(passEl.value + ";free;" + boat['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lockBoat(e)
|
||||||
|
{
|
||||||
|
let boat = getDataFomEl(e.target);
|
||||||
|
console.log("lockBoat", boat);
|
||||||
|
conn.send(passEl.value + ";lock;" + boat['id']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@ -17,8 +17,8 @@ Boats = []
|
|||||||
Clients = []
|
Clients = []
|
||||||
|
|
||||||
async def sendToBoat(boat, cmd):
|
async def sendToBoat(boat, cmd):
|
||||||
client['boat']['log'].append({"t": datetime.timestamp(datetime.now()), "type": "tx", "msg": cmd})
|
boat['log'].append({"t": datetime.timestamp(datetime.now()), "type": "tx", "msg": cmd})
|
||||||
await client['boat']['ws'].send(cmd)
|
await boat['ws'].send(cmd)
|
||||||
|
|
||||||
async def echo_boats(client):
|
async def echo_boats(client):
|
||||||
"""echo list of all not locked boats to client"""
|
"""echo list of all not locked boats to client"""
|
||||||
@ -46,6 +46,9 @@ async def echo_clients(client):
|
|||||||
if client['id'] == ADMIN_ID:
|
if client['id'] == ADMIN_ID:
|
||||||
data = "clients:"
|
data = "clients:"
|
||||||
for clie in Clients:
|
for clie in Clients:
|
||||||
|
if (clie['id'] == ADMIN_ID):
|
||||||
|
data += "admin;" + str(clie['boat']) + ";" + str(clie['state']) + ":"
|
||||||
|
else:
|
||||||
data += str(clie['id']) + ";" + str(clie['boat']) + ";" + str(clie['state']) + ":"
|
data += str(clie['id']) + ";" + str(clie['boat']) + ";" + str(clie['state']) + ":"
|
||||||
await client['ws'].send(data + '\n')
|
await client['ws'].send(data + '\n')
|
||||||
|
|
||||||
@ -74,7 +77,6 @@ async def free_boat(boat):
|
|||||||
break
|
break
|
||||||
for b in Boats:
|
for b in Boats:
|
||||||
if b['id'] == boat and b['state'] != BOAT_STATE_TERMINATED:
|
if b['id'] == boat and b['state'] != BOAT_STATE_TERMINATED:
|
||||||
if b['state'] == BOAT_STATE_INCTRL:
|
|
||||||
b["state"] = BOAT_STATE_AVAILABLE
|
b["state"] = BOAT_STATE_AVAILABLE
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -142,6 +144,8 @@ async def on_message(message, client):
|
|||||||
await getlog(client, data)
|
await getlog(client, data)
|
||||||
elif data[1] == "sendcmd" and client['id'] == ADMIN_ID:
|
elif data[1] == "sendcmd" and client['id'] == ADMIN_ID:
|
||||||
await sendcmd(data)
|
await sendcmd(data)
|
||||||
|
elif client['id'] == ADMIN_ID:
|
||||||
|
print("WARN: invalid command (admin): '" + data[1] + "'")
|
||||||
else:
|
else:
|
||||||
print("WARN: invalid command (" + client['id'] + "): '" + data[1] + "'")
|
print("WARN: invalid command (" + client['id'] + "): '" + data[1] + "'")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user