forked from bitbreaker373/EmulatorJS-netplay-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.js
90 lines (81 loc) · 2.21 KB
/
room.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class Room {
/**
* Create a Room
* @param {string} domain
* @param {number} game_id
* @param {string} sessionid
* @param {string} name
* @param {number} max
* @param {number} current
* @param {string} password
* @param {string} userid
* @param { import("socket.io").Socket } socket
* @param {any} extra
* @param {string} coreVer
*
*/
constructor(domain, game_id, sessionid, name, max, current, password, userid, socket, extra, coreVer) {
/** @type string */
this.domain = domain;
/** @type number */
this.game_id = game_id;
/** @type string */
this.sessionid = sessionid;
/** @type string */
this.name = name;
/** @type number */
this.max = max;
/** @type number */
this.current = current;
/** @type string */
this.password = password.trim();
/** @type boolean */
this.hasPassword = !!this.password;
/** @type string */
this.id = domain + ':' + game_id + ':' + sessionid;
/** @type number */
this.coreVer = parseInt(coreVer);
// define user type
/**
* @typedef {Object} User
* @property {string} userid
* @property { import("socket.io").Socket } socket
* @property {any} extra
*/
/**
* @type User
*/
this.owner = {
userid,
socket,
extra
}
/** @type User[] */
this.users = [this.owner];
}
/**
* Checks to see if the specified password matches this password
* @param {string} password
* @returns
*/
checkPassword(password) {
return password.trim() === this.password;
}
/**
* Adds the user
* @param {User} user
*
* @typedef {Object} User
* @property {string} userid
* @property { import("socket.io").Socket } socket
* @property {any} extra
*/
addUser(user) {
this.users.forEach(userr => {
user.socket.emit('user-connected', userr.userid);
})
this.users.push(user);
this.current++;
}
}
module.exports = Room;