Browse Source

Feste Farben für Admins implementiert

Alexander Vornam 3 years ago
parent
commit
20900f4058
2 changed files with 16 additions and 4 deletions
  1. 8 1
      config/admins.json
  2. 8 3
      index.js

+ 8 - 1
config/admins.json

@@ -1,3 +1,10 @@
 {
-  "André": "passwort"
+  "André": {
+    "password": "stockelsdorf",
+    "color": "#870909"
+  },
+  "Jacky": {
+    "password": "stockelsdorf",
+    "color": "#29f039"
+  }
 }

+ 8 - 3
index.js

@@ -115,12 +115,12 @@ io.on('connection', (socket) => {
         }
 
 
-        if (admins && admins[username]) {
+        if (admins && admins[username] && admins[username].password) {
             if (!password) {
                 log('- Attempted login as admin without password.', username, '(' + ip + ')');
                 socket.emit('passwordRequired');
                 return;
-            } else if (admins[username] != password) {
+            } else if (admins[username].password != password) {
                 log('- Attempted login as admin with wrong password.', username, '(' + ip + ')');
                 socket.emit('passwordWrong');
                 return;
@@ -128,6 +128,9 @@ io.on('connection', (socket) => {
 
             log('- Admin "' + username + '" login successful');
             user.admin = true;
+            if (admins[username].color) {
+                user.color = admins[username].color;
+            }
 
             socket.on('requestKick', (userToBeKicked) => {
                 log('- Admin "' + username + '" requested kick of User "' + userToBeKicked.name + '"');
@@ -143,7 +146,9 @@ io.on('connection', (socket) => {
         log('- New user logged in:', username, '(' + ip + ')');
 
         user.name = username;
-        user.color = getRandomColor(username);
+        if (!user.color) {
+            user.color = getRandomColor(username);
+        }
 
         socket.emit('serverLogin', getCleanUser(user), history);
         io.emit('userJoined', username);