Skip to content

Commit 5507edb

Browse files
committed
admin mode
Only admin can move robot after voltage drops below a set limit (12.5V)
1 parent 74e3e20 commit 5507edb

File tree

6 files changed

+65
-7
lines changed

6 files changed

+65
-7
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# sandbot-node
22

33
sandbot-node
4+
5+
1. install nodejs
6+
2. cd to directory
7+
3. run "npm install"
8+
4. run "node app.js"

app.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ var numUsers = 0;
3535

3636
io.on('connection', function(socket)
3737
{
38-
39-
/*
40-
console.log(io.sockets.sockets.map(function(e) {
41-
return e.username;
42-
}));
43-
*/
44-
4538
var addedUser = false;
4639

4740
console.log('user connected: ' + socket.id);
@@ -71,6 +64,12 @@ io.on('connection', function(socket)
7164
}
7265
}
7366

67+
if(username == "admin")
68+
{
69+
fn('Du bist kein Administrator');
70+
return;
71+
}
72+
7473
fn(null);
7574
});
7675

@@ -85,6 +84,17 @@ io.on('connection', function(socket)
8584
}
8685
}
8786

87+
// administrator benutzer name
88+
if(username == "hansdampf42")
89+
{
90+
socket.isAdmin = true;
91+
username = "admin";
92+
}
93+
else
94+
{
95+
socket.isAdmin = false;
96+
}
97+
8898
// we store the username in the socket session for this client
8999
socket.username = username;
90100

@@ -136,12 +146,26 @@ io.on('connection', function(socket)
136146

137147
socket.on('add control user', function(fn)
138148
{
149+
var info = theInfo.getInfo();
150+
151+
if(!socket.isAdmin && info.Voltage < info.VoltageLimit)
152+
{
153+
return fn(false);
154+
}
155+
139156
theQueue.addUserToQueue(socket.username, socket.id, fn);
140157
io.emit('queue', theQueue.getQueue());
141158
});
142159

143160
socket.on('move', function(data, fn)
144161
{
162+
var info = theInfo.getInfo();
163+
164+
if(!socket.isAdmin && info.Voltage < info.VoltageLimit)
165+
{
166+
return fn(false);
167+
}
168+
145169
if(socket.id == global.ControllingSocketId)
146170
{
147171
move.moveRobot(data, fn);

public/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@
9999

100100
<div class="panel-footer text-right">
101101
Spannung: <div id="voltage" class="inline"></div>V
102+
<div id="robotOffline" class="inline">
103+
(Der Roboter kann nur über einer Spannung von
104+
<div id="voltageLimit" class="inline"></div>
105+
V gesteuert werden)
106+
</div>
102107
</div>
103108
</div>
104109

public/js/sandbot-chat.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ socket.on('login', function (data) {
3838
prepend: true
3939
});
4040
addParticipantsMessage(data);
41+
42+
if(data.username == "admin")
43+
{
44+
// Admin darf immer steuern
45+
// Dies wird auch vom Server kontrolliert
46+
$('#bJoinControl').prop('disabled', false);
47+
}
48+
4149
});
4250

4351
// Whenever the server emits 'new message', update the chat body

public/js/sandbot.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ socket.on('queue', function(msg)
3333
socket.on('info', function(data)
3434
{
3535
$('#voltage').text(data.Voltage);
36+
$('#voltageLimit').text(data.VoltageLimit);
37+
38+
// Roboter unter eine Spannungsgrenze sperren
39+
// Dies wird auch vom Server gesperrt, sinnlos zu versuchen den Browser zu ueberlisten
40+
if(data.Voltage < data.VoltageLimit)
41+
{
42+
$('#bJoinControl').prop('disabled', true);
43+
$("#robotOffline").removeClass('hidden');
44+
}
45+
else
46+
{
47+
$('#bJoinControl').prop('disabled', false);
48+
$("#robotOffline").addClass('hidden');
49+
}
50+
3651
});
3752

3853
socket.on('ControlStart', function(data)

routes/info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = function Info(io)
1111
var myInfo = new function InfoData()
1212
{
1313
this.Voltage = 0;
14+
this.VoltageLimit = 12.5;
1415
}
1516

1617
this.getInfo = function()

0 commit comments

Comments
 (0)