@quakejs/master 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/master-base.js +36 -26
- package/master-server.js +4 -4
- package/package.json +1 -1
package/master-base.js
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
function generateChallenge () {
|
|
2
|
-
const CHALLENGE_CHARS = [
|
|
3
|
-
'!', '#', '$', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '<', '=', '>', '?', '@',
|
|
4
|
-
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
5
|
-
'[', ']', '^', '_', '`',
|
|
6
|
-
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
7
|
-
'{', '|', '}', '~'
|
|
8
|
-
];
|
|
9
|
-
const CHALLENGE_MIN_LENGTH = 9;
|
|
10
|
-
const CHALLENGE_MAX_LENGTH = 12;
|
|
11
|
-
|
|
12
|
-
let challenge = '';
|
|
13
|
-
let length = CHALLENGE_MIN_LENGTH - 1;
|
|
14
|
-
|
|
15
|
-
length += parseInt(Math.random() * (CHALLENGE_MAX_LENGTH - CHALLENGE_MIN_LENGTH + 1), 10);
|
|
16
|
-
|
|
17
|
-
for (let i = 0; i < length; i++) {
|
|
18
|
-
challenge += CHALLENGE_CHARS[Math.floor(Math.random() * CHALLENGE_CHARS.length)];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return challenge;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
1
|
function parseInfoString (str) {
|
|
25
2
|
const info = {};
|
|
26
3
|
let i = 0;
|
|
@@ -112,14 +89,24 @@ class Subscribe extends Message {
|
|
|
112
89
|
class GetInfo extends Message {
|
|
113
90
|
static id = 'getinfo';
|
|
114
91
|
|
|
115
|
-
constructor (
|
|
92
|
+
constructor (from) {
|
|
116
93
|
super();
|
|
117
94
|
|
|
118
|
-
|
|
95
|
+
if (typeof from === 'string') {
|
|
96
|
+
this.challenge = from.substring(12);
|
|
97
|
+
} else {
|
|
98
|
+
this.challenge = from.challenge;
|
|
99
|
+
}
|
|
119
100
|
}
|
|
120
101
|
|
|
121
102
|
toString () {
|
|
122
|
-
|
|
103
|
+
let str = this.type;
|
|
104
|
+
|
|
105
|
+
if (this.challenge) {
|
|
106
|
+
str += ` ${this.challenge}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return str;
|
|
123
110
|
}
|
|
124
111
|
}
|
|
125
112
|
|
|
@@ -328,6 +315,29 @@ class MasterBase {
|
|
|
328
315
|
|
|
329
316
|
return out;
|
|
330
317
|
}
|
|
318
|
+
|
|
319
|
+
generateChallenge () {
|
|
320
|
+
const CHALLENGE_CHARS = [
|
|
321
|
+
'!', '#', '$', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '<', '=', '>', '?', '@',
|
|
322
|
+
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
323
|
+
'[', ']', '^', '_', '`',
|
|
324
|
+
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
325
|
+
'{', '|', '}', '~'
|
|
326
|
+
];
|
|
327
|
+
const CHALLENGE_MIN_LENGTH = 9;
|
|
328
|
+
const CHALLENGE_MAX_LENGTH = 12;
|
|
329
|
+
|
|
330
|
+
let challenge = '';
|
|
331
|
+
let length = CHALLENGE_MIN_LENGTH - 1;
|
|
332
|
+
|
|
333
|
+
length += parseInt(Math.random() * (CHALLENGE_MAX_LENGTH - CHALLENGE_MIN_LENGTH + 1), 10);
|
|
334
|
+
|
|
335
|
+
for (let i = 0; i < length; i++) {
|
|
336
|
+
challenge += CHALLENGE_CHARS[Math.floor(Math.random() * CHALLENGE_CHARS.length)];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return challenge;
|
|
340
|
+
}
|
|
331
341
|
}
|
|
332
342
|
|
|
333
343
|
export default MasterBase;
|
package/master-server.js
CHANGED
|
@@ -118,11 +118,11 @@ class MasterServer extends MasterBase {
|
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
session.lastChallenge = this.generateChallenge();
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
const req = this.encode('getinfo', { challenge: session.lastChallenge });
|
|
124
124
|
|
|
125
|
-
session.
|
|
125
|
+
console.log(`${session.addr}:${session.port} <--- ${this.pretty(req)}`);
|
|
126
126
|
|
|
127
127
|
session.write(req);
|
|
128
128
|
}
|
|
@@ -199,7 +199,7 @@ class MasterServer extends MasterBase {
|
|
|
199
199
|
this.#handleInfoResponse(session, msg);
|
|
200
200
|
break;
|
|
201
201
|
default:
|
|
202
|
-
console.error('
|
|
202
|
+
console.error('Invalid message');
|
|
203
203
|
break;
|
|
204
204
|
}
|
|
205
205
|
}
|