Skip to content

Commit f2bbd2a

Browse files
committed
Cleanup "/list"
1 parent f640dc0 commit f2bbd2a

4 files changed

Lines changed: 122 additions & 1072 deletions

File tree

functions.js

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,88 @@
11
let dev;
2+
global.rooms = [];
3+
4+
class Room {
5+
/**
6+
* Create a Room
7+
* @param {string} domain
8+
* @param {number} game_id
9+
* @param {string} sessionid
10+
* @param {string} name
11+
* @param {number} max
12+
* @param {number} current
13+
* @param {string} password
14+
* @param {string} userid
15+
* @param { import("socket.io").Socket } socket
16+
* @param {any} extra
17+
*
18+
19+
*/
20+
constructor(domain, game_id, sessionid, name, max, current, password, userid, socket, extra) {
21+
/** @type string */
22+
this.domain = domain;
23+
/** @type number */
24+
this.game_id = game_id;
25+
/** @type string */
26+
this.sessionid = sessionid;
27+
/** @type string */
28+
this.name = name;
29+
/** @type number */
30+
this.max = max;
31+
/** @type number */
32+
this.current = current;
33+
/** @type string */
34+
this.password = password.trim();
35+
/** @type boolean */
36+
this.hasPassword = !!this.password;
37+
/** @type string */
38+
39+
this.id = domain + ':' + game_id + ':' + sessionid;
40+
41+
// define user type
42+
43+
/**
44+
* @typedef {Object} User
45+
* @property {string} userid
46+
* @property { import("socket.io").Socket } socket
47+
* @property {any} extra
48+
*/
49+
50+
/**
51+
* @type User
52+
*/
53+
this.owner = {
54+
userid,
55+
socket,
56+
extra
57+
}
58+
/** @type User[] */
59+
this.users = [this.owner];
60+
}
61+
/**
62+
* Checks to see if the specified password matches this password
63+
* @param {string} password
64+
* @returns
65+
*/
66+
checkPassword(password) {
67+
return password.trim() === this.password;
68+
}
69+
/**
70+
* Adds the user
71+
* @param {User} user
72+
*
73+
* @typedef {Object} User
74+
* @property {string} userid
75+
* @property { import("socket.io").Socket } socket
76+
* @property {any} extra
77+
*/
78+
addUser(user) {
79+
this.users.forEach(userr => {
80+
user.socket.emit('user-connected', userr.userid);
81+
})
82+
this.users.push(user);
83+
this.current++;
84+
}
85+
}
286

387
function start(io, rooms, numusers, devv) {
488
dev = devv;
@@ -17,6 +101,15 @@ function start(io, rooms, numusers, devv) {
17101
}
18102
}
19103

104+
function getRoom(domain, game_id, sessionid) {
105+
for (let i=0; i<global.rooms.length; i++) {
106+
if (global.rooms[i].id === domain + ':' + game_id + ':' + sessionid) {
107+
return global.rooms[i];
108+
}
109+
}
110+
return null;
111+
}
112+
20113
function transformArgs(url) {
21114
var args = {}
22115
var idx = url.indexOf('?')
@@ -37,4 +130,4 @@ function consolelog(message){
37130
console.log(message);
38131
}
39132
}
40-
module.exports = { start, transformArgs };
133+
module.exports = { getRoom, start, transformArgs };

old/oldroom.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ class Room {
1313
* @param {string} userid
1414
* @param { import("socket.io").Socket } socket
1515
* @param {any} extra
16-
* @param {string} coreVer
1716
*
1817
1918
*/
20-
constructor(domain, game_id, sessionid, name, max, current, password, userid, socket, extra, coreVer) {
19+
constructor(domain, game_id, sessionid, name, max, current, password, userid, socket, extra) {
2120
/** @type string */
2221
this.domain = domain;
2322
/** @type number */
@@ -37,8 +36,6 @@ class Room {
3736
/** @type string */
3837

3938
this.id = domain + ':' + game_id + ':' + sessionid;
40-
/** @type number */
41-
this.coreVer = parseInt(coreVer);
4239

4340
// define user type
4441

0 commit comments

Comments
 (0)