internal override void HandleConnectedSetChanged(NativeRealTimeRoom room)
            {
                HashSet <string> newConnectedSet = new HashSet <string>();

                foreach (var participant in room.Participants())
                {
                    using (participant)
                    {
                        if (participant.IsConnectedToRoom())
                        {
                            newConnectedSet.Add(participant.Id());
                        }
                    }
                }

                // If the connected set hasn't actually changed, bail out.
                if (mConnectedParticipants.Equals(newConnectedSet))
                {
                    Logger.w("Received connected set callback with unchanged connected set!");
                    return;
                }

                var noLongerConnected = mConnectedParticipants.Except(newConnectedSet);

                // Check whether a participant that was in the connected set has left it.
                // If so, we will never reach a fully connected state, and should fail room
                // creation.
                if (noLongerConnected.Any())
                {
                    Logger.e("Participants disconnected during room setup, failing. " +
                             "Participants were: " + string.Join(",", noLongerConnected.ToArray()));
                    LeaveRoom();
                    return;
                }

                var newlyConnected = newConnectedSet.Except(mConnectedParticipants);

                Logger.d("New participants connected: " +
                         string.Join(",", newlyConnected.ToArray()));

                // If we're fully connected, transition to the Active state and signal the client.
                if (newConnectedSet.Count() == room.ParticipantCount())
                {
                    Logger.d("Fully connected! Transitioning to active state.");
                    mSession.EnterState(new ActiveState(room, mSession));
                    mSession.OnGameThreadListener().RoomConnected(true);
                    return;
                }

                // Otherwise, we're not fully there. Increment the progress by the appropriate
                // amount and inform the client.
                mPercentComplete      += mPercentPerParticipant * (float)newlyConnected.Count();
                mConnectedParticipants = newConnectedSet;
                mSession.OnGameThreadListener().RoomSetupProgress(mPercentComplete);
            }
            internal override void HandleConnectedSetChanged(NativeRealTimeRoom room)
            {
                HashSet <string> hashSet = new HashSet <string>();

                if ((room.Status() == Types.RealTimeRoomStatus.AUTO_MATCHING || room.Status() == Types.RealTimeRoomStatus.CONNECTING) && mSession.MinPlayersToStart <= room.ParticipantCount())
                {
                    mSession.MinPlayersToStart += room.ParticipantCount();
                    mPercentPerParticipant      = 80f / (float)(double)mSession.MinPlayersToStart;
                }
                foreach (GooglePlayGames.Native.PInvoke.MultiplayerParticipant item in room.Participants())
                {
                    using (item)
                    {
                        if (item.IsConnectedToRoom())
                        {
                            hashSet.Add(item.Id());
                        }
                    }
                }
                if (mConnectedParticipants.Equals(hashSet))
                {
                    Logger.w("Received connected set callback with unchanged connected set!");
                }
                else
                {
                    IEnumerable <string> source = mConnectedParticipants.Except(hashSet);
                    if (room.Status() == Types.RealTimeRoomStatus.DELETED)
                    {
                        Logger.e("Participants disconnected during room setup, failing. Participants were: " + string.Join(",", source.ToArray()));
                        mSession.OnGameThreadListener().RoomConnected(false);
                        mSession.EnterState(new ShutdownState(mSession));
                    }
                    else
                    {
                        IEnumerable <string> source2 = hashSet.Except(mConnectedParticipants);
                        Logger.d("New participants connected: " + string.Join(",", source2.ToArray()));
                        if (room.Status() == Types.RealTimeRoomStatus.ACTIVE)
                        {
                            Logger.d("Fully connected! Transitioning to active state.");
                            mSession.EnterState(new ActiveState(room, mSession));
                            mSession.OnGameThreadListener().RoomConnected(true);
                        }
                        else
                        {
                            mPercentComplete      += mPercentPerParticipant * (float)source2.Count();
                            mConnectedParticipants = hashSet;
                            mSession.OnGameThreadListener().RoomSetupProgress(mPercentComplete);
                        }
                    }
                }
            }
Beispiel #3
0
 internal ConnectingState(NativeRealTimeRoom room, RoomSession session)
     : base(session, room)
 {
     mPercentPerParticipant =
         (100.0f - InitialPercentComplete) / (float)room.ParticipantCount();
 }