@@ -121,10 +121,10 @@ io.on('connection', function (socket) {
121121 if ( editorCursorAndSelection != null ) {
122122 socket . emit ( 'editorCursorChange' , editorCursorAndSelection ) ;
123123 }
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 ) {
128128 timerId = startTurnTimer ( timerId , turnDuration , socket . id ) ;
129129
130130 // Notify the first user to create a new gist now!
@@ -169,18 +169,17 @@ io.on('connection', function (socket) {
169169 currentPlayerIndex = null ;
170170
171171 // Turn off the timer
172- clearInterval ( timerId ) ;
173- timerId = null ;
172+ clearInterval ( timerId ) ;
174173 nextTurnChangeTimestamp = null ;
175174
176175 // Otherwise, if there are players left,
177176 } else {
178177 // If the disconnected user was the current player, restart timer and change the turn!
179178 if ( socket . id === currentPlayerId ) {
180179 console . log ( '\nCURRENT PLAYER disconnected! Restarting turn/timer.\n' ) ;
180+
181181 // Turn off the timer
182- clearInterval ( timerId ) ;
183- timerId = null ;
182+ clearInterval ( timerId ) ;
184183 nextTurnChangeTimestamp = null ;
185184
186185 // Re-initialize the turn (and timer), passing control to the next user
@@ -318,7 +317,7 @@ function startTurnTimer(timerId, turnDuration, socketId) {
318317 console . log ( 'Next turn at: ' + new Date ( nextTurnChangeTimestamp ) . toString ( ) . substring ( 16 , 25 ) ) ;
319318
320319 // Initialize the turn data using given user ID
321- changeTurn ( socketId ) ;
320+ changeTurn ( socketId ) ;
322321
323322 // Every time the timer goes off,
324323 timerId = setInterval ( ( ) => {
0 commit comments