-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
652 lines (563 loc) · 23.5 KB
/
server.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
const express = require('express');
const server = express();
const http = require('http').createServer(server);
const io = require('socket.io')(http);
// Room class
// Live rooms will have a name and password and keep track of game options / players in room
server.use(express.static(__dirname + '/client/src/assets'));
class Room {
constructor(name, pass){
this.room = '' + name
this.password = '' + pass
this.players = {} //playerId to player
this.playersArr = [];
this.game = new Game()
this.difficulty = 'normal'
this.mode = 'casual'
this.removedPlayers = {}; //name to player
// Add room to room list
ROOM_LIST[this.room] = this
}
}
let SOCKET_LIST = {} //socket id to socket
let ROOM_LIST = {} // room name to room
let PLAYER_LIST = {} //socketid/playerid to player
class Player {
constructor(nickname, room, socket){
this.id = socket.id
/*
// If someone in the room has the same name, append (1) to their nickname
let nameAvailable = false
let nameExists = false;
let tempName = nickname
let counter = 0
while (!nameAvailable){
if (ROOM_LIST[room]){
nameExists = false;
for (let i in ROOM_LIST[room].players){
if (ROOM_LIST[room].players[i].nickname === tempName) nameExists = true
}
if (nameExists) tempName = nickname + "(" + ++counter + ")"
else nameAvailable = true
}
}
*/
this.nickname = nickname
this.room = room
this.timeout = 2100 // # of seconds until kicked for afk (35min)
this.afktimer = this.timeout
this.hand = []; //cards in his hands
this.lastDealt = [];
this.currentDealt = [];
this.updateHand = false;
// Add player to player list and add their socket to the socket list
PLAYER_LIST[this.id] = this
}
clear(){
this.hand = []; //cards in his hands
this.lastDealt = [];
this.currentDealt = [];
}
}
class Game {
constructor(){
this.decks = [] ;
//this.decks.push(new Deck());
//this.decks.forEach(deck => deck.shuffle());
this.cardsOnTable = [];
this.cardDealt = false;
this.gameTableHidden = false;
this.showRandomCards = false;
this.lastPlayer = null;
this.lastPlayerId = null;
this.autoSubmit = false;
}
drawOneCard(){
this.suffleDecks();
var card = null;
for(let i = 0; i < this.decks.length; i++){
card = this.decks[i].drawCard();
if(card){
break;
}
}
return card;
}
peekOneCard(){
this.suffleDecks();
var card = null;
for(let i = 0; i < this.decks.length; i++){
card = this.decks[i].peekCard();
if(card){
break;
}
}
return card;
}
suffleDecks(){
this.decks.forEach(deck => deck.shuffle());
}
}
class Card {
constructor(imageUrl, backImageUrl){
this.imageUrl = imageUrl;
this.backImageUrl = backImageUrl;
}
show(scene,x,y,sprite) {
let card = scene.add.image(x, y, sprite).setScale(0.3, 0.3).setInteractive();
scene.input.setDraggable(card);
return card;
}
}
var sortCardFun = function compare_qty(a, b){
if(a.imageUrl < b.imageUrl){
return -1;
// a should come after b in the sorted order
}else if(a.imageUrl > b.imageUrl){
return 1;
// a and b are the same
}else{
return 0;
}
}
class Deck {
constructor() {
this.cards = [];
this.drawnCards = [];
}
shuffle() {
const { cards } = this;
let m = cards.length, i;
while (m) {
i = Math.floor(Math.random() * m--);
[cards[m], cards[i]] = [cards[i], cards[m]];
}
return this;
}
drawCard(){
var tmp = this.cards.pop();
if(tmp) this.drawnCards.push(tmp);
return tmp;
}
peekCard() {
if(this.cards.length > 0){
return this.cards[0];
}
return null;
}
}
class UnoDeck extends Deck {
constructor() {
super();
var images = "Blue_0.png Blue_6.png Blue_Skip.png Green_5.png Green_Reverse.png Red_4.png Red_Draw.png Yellow_1.png Yellow_7.png Blue_1.png Blue_7.png Green_0.png Green_6.png Green_Skip.png Red_5.png Red_Reverse.png Yellow_2.png Yellow_8.png Blue_2.png Blue_8.png Green_1.png Green_7.png Red_0.png Red_6.png Red_Skip.png Yellow_3.png Yellow_9.png Blue_3.png Blue_9.png Green_2.png Green_8.png Red_1.png Red_7.png Wild.png Yellow_4.png Yellow_Draw.png Blue_4.png Blue_Draw.png Green_3.png Green_9.png Red_2.png Red_8.png Wild_Draw.png Yellow_5.png Yellow_Reverse.png Blue_5.png Blue_Reverse.png Green_4.png Green_Draw.png Red_3.png Red_9.png Yellow_0.png Yellow_6.png Yellow_Skip.png"
var res = images.split(" ");
var dir = "uno/"
this.size = 0;
res.forEach( file => {
this.cards.push(new Card(dir+file,'uno/Deck.png'));
});
this.size = this.cards.length;
super.shuffle();
}
}
class StandardDeck extends Deck {
constructor() {
super();
var images = "10C.jpg 10H.jpg 2C.jpg 2H.jpg 3C.jpg 3H.jpg 4C.jpg 4H.jpg 5C.jpg 5H.jpg 6C.jpg 6H.jpg 7C.jpg 7H.jpg 8C.jpg 8H.jpg 9C.jpg 9H.jpg AC.jpg AH.jpg JC.jpg JH.jpg KC.jpg KH.jpg QC.jpg QH.jpg 10D.jpg 10S.jpg 2D.jpg 2S.jpg 3D.jpg 3S.jpg 4D.jpg 4S.jpg 5D.jpg 5S.jpg 6D.jpg 6S.jpg 7D.jpg 7S.jpg 8D.jpg 8S.jpg 9D.jpg 9S.jpg AD.jpg AS.jpg JD.jpg JS.jpg KD.jpg KS.jpg QD.jpg QS.jpg"
var res = images.split(" ");
var dir = "playingCards/"
res.forEach( file => {
this.cards.push(new Card(dir+file,'standard_card_back_blue.png'));
});
this.size = this.cards.length;
console.log("size: " + this.size)
super.shuffle();
}
}
io.on('connection', function (socket) {
try {
SOCKET_LIST[socket.id] = socket;
console.log('A user connected: ' + socket.id + "socket:" + socket);
io.emit('serverStats',
{
players: Object.keys(PLAYER_LIST).length,
rooms: Object.keys(ROOM_LIST).length }
);
socket.on('createRoom', (data) => {createRoom(socket, data)})
// Room Joining. Called when client attempts to join a room
// Data: player nickname, room name, room password
socket.on('joinRoom', (data) => {joinRoom(socket, data)})
// Room Leaving. Called when client leaves a room
socket.on('leaveRoom', () =>{leaveRoom(socket)})
// Client Disconnect
socket.on('disconnect', () => {socketDisconnect(socket)})
// New Game. Called when client starts a new game
socket.on('newGame', function(){
let player = PLAYER_LIST[socket.id];
newGame(ROOM_LIST[player.room])
})
socket.on('dealCards', function () {
let player = PLAYER_LIST[socket.id];
dealCards(ROOM_LIST[player.room])
//socket.emit('dealCards');
});
socket.on('suffle', function () {
let player = PLAYER_LIST[socket.id];
ROOM_LIST[player.room].game.decks.forEach(deck => deck.shuffle());
});
socket.on('cardPlayed', function (playerJSON) {
let player = PLAYER_LIST[socket.id];
player.updateHand = false;
let playerRemote = JSON.parse(playerJSON);
PLAYER_LIST[player.id].hand = playerRemote.hand;
if(playerRemote.currentDealt.length >0) {
playerRemote.currentDealt.forEach(card => ROOM_LIST[player.room].game.cardsOnTable.push(card));
PLAYER_LIST[player.id].lastDealt = playerRemote.currentDealt;
PLAYER_LIST[player.id].currentDealt = [];
ROOM_LIST[player.room].game.lastPlayer = playerRemote.nickname;
ROOM_LIST[player.room].game.lastPlayerId = player.id;
gameUpdate(player.room);
}
});
socket.on('pick', function(number) {
let player = PLAYER_LIST[socket.id];
player.updateHand = true;
if(number == -1){
console.log("pushing all from table" + ROOM_LIST[player.room].game.cardsOnTable + "to "+ player.hand)
ROOM_LIST[player.room].game.cardsOnTable.forEach(card => player.hand.push(card));
console.log(player.hand);
ROOM_LIST[player.room].game.cardsOnTable = [];
} else {
for(let i=0; i<number; i++){
player.hand.push(ROOM_LIST[player.room].game.cardsOnTable.pop());
}
}
player.updateHand = true;
gameUpdate(player.room);
});
socket.on('showLast', function() {
let player = PLAYER_LIST[socket.id];
if(ROOM_LIST[player.room].game.lastPlayerId && socket.id == ROOM_LIST[player.room].game.lastPlayerId){
showCards(player.room, player.lastDealt.length)
}
});
socket.on('revert', function() {
try {
let player = PLAYER_LIST[socket.id];
player.updateHand = true;
if(ROOM_LIST[player.room].game.lastPlayerId && socket.id == ROOM_LIST[player.room].game.lastPlayerId){
for(var i=0; i < player.lastDealt.length ; i++){
if(ROOM_LIST[player.room].game.cardsOnTable.length > 0 )
player.hand.push(ROOM_LIST[player.room].game.cardsOnTable.pop());
}
player.lastDealt = [];
gameUpdate(player.room);
}
} catch (err) {
console.log("ERROR:" + err.message)
}
});
socket.on('sortHand', function(){
try {
let player = PLAYER_LIST[socket.id];
player.updateHand = true;
player.hand.sort(sortCardFun);
console.log("player id for sort" + player.id);
gameUpdate(player.room, {'players' : [player.id]});
} catch (err) {
console.log("ERROR:" + err.message)
}
});
socket.on('hideTable', function() {
let player = PLAYER_LIST[socket.id];
ROOM_LIST[player.room].game.gameTableHidden = true;
gameUpdate(player.room);
});
socket.on('showTable', function() {
let player = PLAYER_LIST[socket.id];
ROOM_LIST[player.room].game.gameTableHidden = false;
gameUpdate(player.room);
});
socket.on('MoveToDeck', function() {
let player = PLAYER_LIST[socket.id];
ROOM_LIST[player.room].game.cardsOnTable.forEach(card => ROOM_LIST[player.room].game.decks[0].cards.push(card));
ROOM_LIST[player.room].game.cardsOnTable = [];
gameUpdate(player.room);
});
socket.on('RandomFromDeck', function() {
let player = PLAYER_LIST[socket.id];
ROOM_LIST[player.room].game.showRandomCards = true;
gameUpdate(player.room);
});
socket.on('HideRandomFromDeck', function() {
let player = PLAYER_LIST[socket.id];
ROOM_LIST[player.room].game.showRandomCards = false;
gameUpdate(player.room);
});
socket.on('AddStandardDeck', function() {
let player = PLAYER_LIST[socket.id];
ROOM_LIST[player.room].game.decks.push(new StandardDeck());
ROOM_LIST[player.room].game.decks.forEach(deck => deck.shuffle());
//ROOM_LIST[player.room].game.decks[ROOM_LIST[player.room].game.decks.length-1].suffle();
gameUpdate(player.room);
});
socket.on('AddUnoDeck', function() {
let player = PLAYER_LIST[socket.id];
ROOM_LIST[player.room].game.decks.push(new UnoDeck());
//ROOM_LIST[player.room].game.decks[ROOM_LIST[player.room].game.decks.length-1].suffle();
gameUpdate(player.room);
});
socket.on('DrawFromDeck', function() {
let player = PLAYER_LIST[socket.id];
var card = ROOM_LIST[player.room].game.drawOneCard();
if(card){
player.hand.push(card);
console.log("player id for draw" + player.id);
gameUpdate(player.room, {'players' : [player.id]});
}
player.updateHand = true;
});
socket.on('sendMessage', function(data) {
var playerObjs = ROOM_LIST[PLAYER_LIST[socket.id].room].playersArr;
playerObjs.forEach(player => { // For everyone in the passed room// Add specific clients team info
if(player != socket.id){
SOCKET_LIST[player].emit('recieveMessage', data) // Pass data to the client
}
});
});
socket.on('autoSubmit', function() {
let player = PLAYER_LIST[socket.id];
console.log('ROOM_LIST[player.room].game.autoSubmit' + ROOM_LIST[player.room].game.autoSubmit)
if(ROOM_LIST[player.room].game.autoSubmit) {
ROOM_LIST[player.room].game.autoSubmit = false;
} else {
ROOM_LIST[player.room].game.autoSubmit = true;
}
console.log('ROOM_LIST[player.room].game.autoSubmit' + ROOM_LIST[player.room].game.autoSubmit)
gameUpdate(player.room);
});
} catch (err) {
console.log("ERROR" + err.message);
}
});
http.listen(3000,'0.0.0.0', function () {
console.log('Server started!');
});
// Create room function
// Gets a room name and password and attempts to make a new room if one doesn't exist
// On creation, the client that created the room is created and added to the room
function createRoom(socket, data){
let roomName = data.room.trim() // Trim whitespace from room name
let passName = data.password.trim() // Trim whitespace from password
let userName = data.nickname.trim() // Trim whitespace from nickname
if (ROOM_LIST[roomName]) { // If the requested room name is taken
// Tell the client the room arleady exists
socket.emit('createResponse', {success:false, msg:'Room Already Exists'})
} else {
if (roomName === "") {
// Tell the client they need a valid room name
socket.emit('createResponse', {success:false, msg:'Enter A Valid Room Name'})
} else {
if (userName === ''){
// Tell the client they need a valid nickname
socket.emit('createResponse', {success:false, msg:'Enter A Valid Nickname'})
} else { // If the room name and nickname are both valid, proceed
new Room(roomName, passName) // Create a new room
let player = new Player(userName, roomName, socket) // Create a new player
ROOM_LIST[roomName].players[socket.id] = player
ROOM_LIST[roomName].playersArr.push(socket.id);
// Add player to room
//player.joinTeam() // Distribute player to team
socket.emit('createResponse', {success:true, msg: "", players: [userName]})// Tell client creation was successful
//gameUpdate(roomName) // Update the game for everyone in this room
logStats(socket.id + "(" + player.nickname + ") CREATED '" + ROOM_LIST[player.room].room + "'(" + Object.keys(ROOM_LIST[player.room].players).length + ")")
}
}
}
}
// Join room function
// Gets a room name and poassword and attempts to join said room
// On joining, the client that joined the room is created and added to the room
function joinRoom(socket, data){
let roomName = data.room.trim() // Trim whitespace from room name
let pass = data.password.trim() // Trim whitespace from password
let userName = data.nickname.trim() // Trim whitespace from nickname
if (!ROOM_LIST[roomName]){
// Tell client the room doesnt exist
socket.emit('joinResponse', {success:false, msg:"Room Not Found"})
} else {
if (ROOM_LIST[roomName].password !== pass){
// Tell client the password is incorrect
socket.emit('joinResponse', {success:false, msg:"Incorrect Password"})
} else {
if (userName === ''){
// Tell client they need a valid nickname
socket.emit('joinResponse', {success:false, msg:'Enter A Valid Nickname'})
} else {
//room exist card already dealt
for (let i in ROOM_LIST[roomName].players){
if (ROOM_LIST[roomName].players[i].nickname === userName){
socket.emit('joinResponse', {success:false, msg:'Name already taken in the room, Please try again'});
return;
}
}
var player;
var nameExists = false;
if(ROOM_LIST[roomName].game.cardDealt == true){
for (let i in ROOM_LIST[roomName].removedPlayers){
if (ROOM_LIST[roomName].removedPlayers[i].nickname === userName){
nameExists = true;
player = ROOM_LIST[roomName].removedPlayers[i];
player.id = socket.id;
PLAYER_LIST[player.id] = player;
delete ROOM_LIST[roomName].removedPlayers[i];
}
}
if(!nameExists){
socket.emit('joinResponse', {success:false, msg:'Game already in progress, ask to start new Game'})
return;
}
}
// If the room exists and the password / nickname are valid, proceed
if(!nameExists) {
player = new Player(userName, roomName, socket) // Create a new player
}
ROOM_LIST[roomName].players[socket.id] = player
ROOM_LIST[roomName].playersArr.push(socket.id);
player.updateHand = true; // Add player to room
//player.joinTeam() // Distribute player to team
let players = [];
for(var key in ROOM_LIST[roomName].players) {players.push(ROOM_LIST[roomName].players[key].nickname)};
socket.emit('joinResponse', {success:true, msg:"", players: players}) // Tell client join was successful
gameUpdate(roomName) // Update the game for everyone in this room
// Server Log
logStats(socket.id + "(" + player.nickname + ") JOINED '" + ROOM_LIST[player.room].room + "'(" + Object.keys(ROOM_LIST[player.room].players).length + ")")
}
}
}
}
// Leave room function
// Gets the client that left the room and removes them from the room's player list
function leaveRoom(socket){
if (!PLAYER_LIST[socket.id]) return // Prevent Crash
let player = PLAYER_LIST[socket.id] // Get the player that made the request
delete PLAYER_LIST[player.id] // Delete the player from the player list
delete ROOM_LIST[player.room].players[player.id] // Remove the player from their room
console.log("leaveRoom" + ROOM_LIST[player.room].playersArr.length);
for(let i=0; i<ROOM_LIST[player.room].playersArr.length; i++){
if(ROOM_LIST[player.room].playersArr[i] == socket.id ){
ROOM_LIST[player.room].removedPlayers[player.nickname] = player;
ROOM_LIST[player.room].playersArr.splice(i, 1);
}
}
gameUpdate(player.room) // Update everyone in the room
// Server Log
logStats(socket.id + "(" + player.nickname + ") LEFT '" + ROOM_LIST[player.room].room + "'(" + Object.keys(ROOM_LIST[player.room].players).length + ")")
// If the number of players in the room is 0 at this point, delete the room entirely
if (Object.keys(ROOM_LIST[player.room].players).length === 0) {
delete ROOM_LIST[player.room]
logStats("DELETE ROOM: '" + player.room + "'")
}
socket.emit('leaveResponse', {success:true}) // Tell the client the action was successful
}
// Disconnect function
// Called when a client closes the browser tab
function socketDisconnect(socket){
let player = PLAYER_LIST[socket.id] // Get the player that made the request
delete SOCKET_LIST[socket.id] // Delete the client from the socket list
delete PLAYER_LIST[socket.id] // Delete the player from the player list
if(player){ // If the player was in a room
delete ROOM_LIST[player.room].players[socket.id] // Remove the player from their room
console.log("socketDisconnect" + ROOM_LIST[player.room].playersArr.length);
for(let i=0; i<ROOM_LIST[player.room].playersArr.length; i++){
if(ROOM_LIST[player.room].playersArr[i] == socket.id ){
ROOM_LIST[player.room].removedPlayers[player.nickname] = player;
ROOM_LIST[player.room].playersArr.splice(i, 1);
}
}
gameUpdate(player.room) // Update everyone in the room
// Server Log
logStats(socket.id + "(" + player.nickname + ") LEFT '" + ROOM_LIST[player.room].room + "'(" + Object.keys(ROOM_LIST[player.room].players).length + ")")
// If the number of players in the room is 0 at this point, delete the room entirely
if (Object.keys(ROOM_LIST[player.room].players).length === 0) {
delete ROOM_LIST[player.room]
logStats("DELETE ROOM: '" + player.room + "'")
}
}
// Server Log
logStats('DISCONNECT: ' + socket.id)
}
// Update the gamestate for every client in the room that is passed to this function
function gameUpdate(roomName, opts){
let players = [];
let playerCardsNum = [];
ROOM_LIST[roomName].playersArr.forEach(playerId => {
console.log("playerId : " +playerId)
players.push(PLAYER_LIST[playerId].nickname)
playerCardsNum.push(PLAYER_LIST[playerId].hand.length);
});
// Create data package to send to the client
var randomCard = ROOM_LIST[roomName].game.peekOneCard();;
if(randomCard){
randomCard= JSON.stringify(randomCard);
}
let gameState = {
room: roomName,
players: players,
playerCardsNum: playerCardsNum,
cardsOnTable: JSON.stringify(ROOM_LIST[roomName].game.cardsOnTable),
cardDealt: ROOM_LIST[roomName].game.cardDealt,
gameTableHidden: ROOM_LIST[roomName].game.gameTableHidden,
deckSize: ROOM_LIST[roomName].game.decks.length,
randomCard: randomCard,
showRandomCards: ROOM_LIST[roomName].game.showRandomCards,
lastPlayer: ROOM_LIST[roomName].game.lastPlayer,
autoSubmit: ROOM_LIST[roomName].game.autoSubmit,
}
var playerObjs = ROOM_LIST[roomName].playersArr;
if(opts != undefined && opts['players']) playerObjs = opts['players'];
playerObjs.forEach(player => { // For everyone in the passed room// Add specific clients team info
gameState.player = JSON.stringify(ROOM_LIST[roomName].players[player]);
console.log("emmiting game state for player:" + player + "autoSubmit" + gameState.autoSubmit +" socket:" + SOCKET_LIST[player] + "gamestate player: " + gameState.player + "random:" + gameState.randomCard);
console.log("gamestate cardsontable: " + gameState.cardsOnTable)
SOCKET_LIST[player].emit('gameState', gameState) // Pass data to the client
PLAYER_LIST[player].updateHand = false;
});
}
function dealCards(room){
var playerCount = 0;
for(var key in room.players){ playerCount++; };
console.log(playerCount +":playerCount");
room.game.decks.forEach(deck => {
var handSize = parseInt(deck.cards.length/playerCount);
console.log("handsize: " + handSize + "deck size: " + deck.cards.length);
for(var key in room.players){
room.players[key].updateHand = true;
for (let i = 0; i < handSize; i++) {
var card = deck.drawCard();
if(card) room.players[key].hand.push(card);
}
}
});
gameUpdate(room.room);
room.game.cardDealt = true;
}
function showCards(roomName, cardSize){
for (let player in ROOM_LIST[roomName].players){ // For everyone in the passed room// Add specific clients team info
SOCKET_LIST[player].emit('showCards', cardSize) // Pass data to the client
}
}
function newGame(room){
console.log("rooms" + room);
for (let player in room.players){
room.players[player].updateHand = true;
PLAYER_LIST[player].clear()
}
room.game = new Game();
gameUpdate(room.room);
}
function logStats(addition){
let inLobby = Object.keys(SOCKET_LIST).length - Object.keys(PLAYER_LIST).length
let stats = '[R:' + Object.keys(ROOM_LIST).length + " P:" + Object.keys(PLAYER_LIST).length + " L:" + inLobby + "] "
console.log(stats + addition)
}