-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsocket.js
More file actions
165 lines (149 loc) · 6.72 KB
/
socket.js
File metadata and controls
165 lines (149 loc) · 6.72 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* Created by dylancross on 5/04/17.
*/
const app = require('./app.js'),
team = require('./team.js'),
outfit = require('./outfit.js'),
password = require('./password.js'),
ps2ws = require('./ps2ws.js'),
items = require('./items.js');
let running = false; // stores whether a match is running or not
module.exports = {
init: function(io) {
io.on('connection', function (sock) {
sock.on('backchat', function () {
const t1 = team.getT1(),
t2 = team.getT2();
send('teams', { teamOne: t1, teamTwo: t2});
send('score', { teamOne: t1, teamTwo: t2 });
});
sock.on('start', function (data) {
send('redirect', '');
const event = data.obj;
if (event.auth === password.KEY) {
if ((event.hasOwnProperty('teamOne')) && (event.hasOwnProperty('teamTwo'))) {
if (running !== true) {
app.start(event.teamOne, event.teamTwo).then(function () {
console.log('Admin entered a start match command involving: ' + event.teamOne + ' ' + event.teamTwo);
}).catch(function (err) {
console.error("Failed to start match between " + event.teamOne + ' ' + event.teamTwo);
console.error(err);
});
}
else {
console.error('Admin entered a start match command involving: ' + event.teamOne + ' ' + event.teamTwo + ' But a match is already running');
}
} else {
console.error('No data sent: ' + event.teamOne + ' ' + event.teamTwo);
}
}
});
sock.on('newRound', function (data) {
send('redirect', '');
const event = data.obj;
if (event.auth === password.KEY) {
if (running !== true) {
console.log('Admin entered New Round command, new round starting: ' + JSON.stringify(event));
ps2ws.newRound();
running = true;
}
else {
console.error('Admin entered New Round command, but a match is already running');
}
}
});
sock.on('stop', function (data) {
send('redirect', '');
const event = data.obj;
if (event.auth === password.KEY) {
console.log('Admin entered Stop command, match stopping: ' + JSON.stringify(event));
ps2ws.stopTheMatch();
}
});
sock.on('adjust', function (data) {
send('redirect', '');
const event = data.obj;
if (event.auth === password.KEY) {
console.log('Admin adjusted score: ' + JSON.stringify(event));
team.adjustScore(event.t1, event.t2, event.reason);
}
});
sock.on('weaponDefault', function (data) {
const event = data.obj;
if (event.auth === password.KEY && running === false) {
send('rerender', '');
if (event.ruleset === "weaponThunderdome") { items.updateCategoryMap(0); }
if (event.ruleset === "weaponEmerald") { items.updateCategoryMap(1); }
if (event.ruleset === "weaponOvO") { items.updateCategoryMap(2); }
console.log('Admin set default weapon rules: ' + JSON.stringify(event));
} else {
// wrong password redirect
send('redirect', '');
}
});
sock.on('classDefault', function (data) {
const event = data.obj;
if (event.auth === password.KEY && running === false) {
send('rerender', '');
if (event.ruleset === "classThunderdome") { ps2ws.updatePointMap(0); }
if (event.ruleset === "classEmerald") { ps2ws.updatePointMap(1); }
if (event.ruleset === "classOvO") { ps2ws.updatePointMap(2); }
console.log('Admin set default class rules: ' + JSON.stringify(event));
} else {
// wrong password redirect
send('redirect', '');
}
});
sock.on('weaponUpdate', function (data) {
const event = data.obj;
if (event.auth === password.KEY && running === false) {
send('rerender', '');
console.log('Admin updated weapon rules ' + JSON.stringify(event));
items.individualCategoryUpdate(event);
}
});
sock.on('classUpdate', function (data) {
const event = data.obj;
if (event.auth === password.KEY && running === false) {
send('rerender', '');
console.log('Admin updated class rules: ' + JSON.stringify(event));
ps2ws.individualPointUpdate(event);
} else {
// wrong password redirect
send('redirect', '');
}
});
sock.on('addAlias', function (data) {
const event = data.obj;
if (event.auth === password.KEY && running === false) {
send('rerender', '');
console.log('Admin updated aliases: ' + JSON.stringify(event));
outfit.addAlias(event.character_id, event.name, event.alias);
} else {
// wrong password redirect
send('redirect', '');
}
});
sock.on('deleteAlias', function (data) {
const event = data.obj;
if (event.auth === password.KEY && running === false) {
send('rerender', '');
console.log('Admin updated aliases: ' + JSON.stringify(event));
outfit.deleteAlias(event.character_id);
} else {
// wrong password redirect
send('redirect', '');
}
});
});
function send(name, obj) {
io.emit(name, obj);
}
},
sendData : function (name, obj, io) {
io.emit(name, obj);
},
setRunning : function (run) {
running = run;
},
};