//Record change handler for initial game sync void HandleDidChangeRecordSync(string arg1, ChannelTemplate arg2, IDictionary arg3, string[] arg4) { if (arg2.receiver_id == clientID) //if this message applies to us (the receiverID is us) { clientSyncPosition = (clientStatuses)System.Enum.Parse(typeof(clientStatuses), arg2.payload); Debug.Log("client Sync position is: " + clientSyncPosition.ToString()); sessionSyncPosition = (sessionStatuses)(int)(clientSyncPosition + 1); Debug.Log("session Sync position is: " + sessionSyncPosition.ToString()); if ((int)sessionSyncPosition > (int)sessionStatuses.running) //last stage of sync is 'running' //don't broadcast anything to the client, they are running { playersSynced++; Debug.Log("One more client is fully synced!" + sessionSyncPosition + ", total: " + playersSynced); if (numberOfPlayers != playersSynced) { Debug.Log("number of players != playersSynced! numplayers: " + numberOfPlayers + ", playersSynced: " + playersSynced); } } else { Debug.Log("recieved message for sync: " + arg2.payload + "; on state: " + sessionSyncPosition); StartCoroutine(callUpdateSessionStatus(sessionSyncPosition.ToString())); } } else { Debug.Log("this message is not directed at us, senderID: " + arg2.sender_id + ", receiverID: '" + arg2.receiver_id + "', our clientID: '" + clientID + "'"); } }
//this recordchange handler only is run during inital game sync phase void HandleDidChangeRecordSync(string arg1, ChannelTemplate arg2, IDictionary arg3, string[] arg4) { Debug.Log("HH is syncing"); if (arg2.receiver_id == clientID) //if this message applies to us (the receiver_id is us) { if ((int)sessionSyncPosition > (int)sessionStatuses.running) //when game is running, we can stop setup { Debug.Log("done with sync"); channelCollection.DidChangeRecord -= HandleDidChangeRecordSync; //remove this handler } else if (arg2.payload == sessionSyncPosition.ToString()) //if the channel broadcasts what we are expecting { StartCoroutine(callReportToTabletopClient(clientSyncPosition.ToString())); clientSyncPosition++; sessionSyncPosition++; } else { Debug.LogError("Uh oh! Sync routine error, expecting: " + sessionSyncPosition.ToString() + ", recieved: " + arg2.payload + " on client step: " + clientSyncPosition.ToString()); } } else //message not directed to us { Debug.LogError("this message is not directed at us, senderID: " + arg2.sender_id + ", receiverID: '" + arg2.receiver_id + "', our clientID: '" + clientID + "'"); } }
//Record change handler for initial game sync void HandleDidChangeRecordSync(string arg1, ChannelTemplate arg2, IDictionary arg3, string[] arg4) { if (arg2.receiver_id == clientID) { //if this message applies to us (the receiverID is us) clientSyncPosition = (clientStatuses) System.Enum.Parse (typeof(clientStatuses), arg2.payload); Debug.Log ("client Sync position is: " + clientSyncPosition.ToString()); sessionSyncPosition = (sessionStatuses)(int)(clientSyncPosition + 1); Debug.Log ("session Sync position is: " + sessionSyncPosition.ToString()); if ((int)sessionSyncPosition > (int)sessionStatuses.running) { //last stage of sync is 'running' //don't broadcast anything to the client, they are running playersSynced++; Debug.Log ("One more client is fully synced!" + sessionSyncPosition + ", total: " + playersSynced); if (numberOfPlayers != playersSynced) { Debug.Log ("number of players != playersSynced! numplayers: " + numberOfPlayers + ", playersSynced: " + playersSynced); } } else { Debug.LogError ("recieved message for sync: " + arg2.payload + "; on state: " + sessionSyncPosition); StartCoroutine (callUpdateSessionStatus (sessionSyncPosition.ToString ())); } } else { Debug.LogError ("this message is not directed at us, senderID: " + arg2.sender_id + ", receiverID: '" + arg2.receiver_id + "', our clientID: '" + clientID + "'"); } }