@@ -121,10 +121,10 @@ io.on('connection', function (socket) {
121
121
if ( editorCursorAndSelection != null ) {
122
122
socket . emit ( 'editorCursorChange' , editorCursorAndSelection ) ;
123
123
}
124
-
125
- // Initialize the turn (and timer) with first connected user
126
- // and create the initial GitHub gist on behlaf of the first user !
127
- if ( timerId == null ) {
124
+
125
+ // If there is 1 player logged in (the first player to join, who just triggered the "userLogin" event),
126
+ // START THE GAME!! !
127
+ if ( playerList . length === 1 ) {
128
128
timerId = startTurnTimer ( timerId , turnDuration , socket . id ) ;
129
129
130
130
// Notify the first user to create a new gist now!
@@ -169,18 +169,17 @@ io.on('connection', function (socket) {
169
169
currentPlayerIndex = null ;
170
170
171
171
// Turn off the timer
172
- clearInterval ( timerId ) ;
173
- timerId = null ;
172
+ clearInterval ( timerId ) ;
174
173
nextTurnChangeTimestamp = null ;
175
174
176
175
// Otherwise, if there are players left,
177
176
} else {
178
177
// If the disconnected user was the current player, restart timer and change the turn!
179
178
if ( socket . id === currentPlayerId ) {
180
179
console . log ( '\nCURRENT PLAYER disconnected! Restarting turn/timer.\n' ) ;
180
+
181
181
// Turn off the timer
182
- clearInterval ( timerId ) ;
183
- timerId = null ;
182
+ clearInterval ( timerId ) ;
184
183
nextTurnChangeTimestamp = null ;
185
184
186
185
// Re-initialize the turn (and timer), passing control to the next user
@@ -318,7 +317,7 @@ function startTurnTimer(timerId, turnDuration, socketId) {
318
317
console . log ( 'Next turn at: ' + new Date ( nextTurnChangeTimestamp ) . toString ( ) . substring ( 16 , 25 ) ) ;
319
318
320
319
// Initialize the turn data using given user ID
321
- changeTurn ( socketId ) ;
320
+ changeTurn ( socketId ) ;
322
321
323
322
// Every time the timer goes off,
324
323
timerId = setInterval ( ( ) => {
0 commit comments