private void FindEqualVersionMatchWithParticipant(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, string participantId, Action <bool> onFailure, Action <GooglePlayGames.Native.PInvoke.MultiplayerParticipant, NativeTurnBasedMatch> onFoundParticipantAndMatch)
 {
     this.FindEqualVersionMatch(match, onFailure, (Action <NativeTurnBasedMatch>)(foundMatch =>
     {
         if (participantId == null)
         {
             using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant multiplayerParticipant = GooglePlayGames.Native.PInvoke.MultiplayerParticipant.AutomatchingSentinel())
                 onFoundParticipantAndMatch(multiplayerParticipant, foundMatch);
         }
         else
         {
             using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant multiplayerParticipant = foundMatch.ParticipantWithId(participantId))
             {
                 if (multiplayerParticipant == null)
                 {
                     Logger.e(string.Format("Located match {0} but desired participant with ID {1} could not be found", (object)match.MatchId, (object)participantId));
                     onFailure(false);
                 }
                 else
                 {
                     onFoundParticipantAndMatch(multiplayerParticipant, foundMatch);
                 }
             }
         }
     }));
 }
Exemple #2
0
 internal void SendReliableMessage(NativeRealTimeRoom room, MultiplayerParticipant participant,
                                   byte[] data, Action <Status.MultiplayerStatus> callback)
 {
     C.RealTimeMultiplayerManager_SendReliableMessage(mGameServices.AsHandle(),
                                                      room.AsPointer(), participant.AsPointer(), data, PInvokeUtilities.ArrayToSizeT(data),
                                                      InternalSendReliableMessageCallback, Callbacks.ToIntPtr(callback));
 }
Exemple #3
0
        internal TurnBasedMatch AsTurnBasedMatch(string selfPlayerId)
        {
            List <Participant> participants         = new List <Participant>();
            string             selfParticipantId    = null;
            string             pendingParticipantId = null;

            using (MultiplayerParticipant participant = this.PendingParticipant())
            {
                if (participant != null)
                {
                    pendingParticipantId = participant.Id();
                }
            }
            foreach (MultiplayerParticipant participant2 in this.Participants())
            {
                using (participant2)
                {
                    using (NativePlayer player = participant2.Player())
                    {
                        if ((player != null) && player.Id().Equals(selfPlayerId))
                        {
                            selfParticipantId = participant2.Id();
                        }
                    }
                    participants.Add(participant2.AsParticipant());
                }
            }
            return(new TurnBasedMatch(this.Id(), this.Data(), (this.MatchStatus() == GooglePlayGames.Native.Cwrapper.Types.MatchStatus.COMPLETED) && !this.HasRematchId(), selfParticipantId, participants, this.AvailableAutomatchSlots(), pendingParticipantId, ToTurnStatus(this.MatchStatus()), ToMatchStatus(pendingParticipantId, this.MatchStatus()), this.Variant(), this.Version()));
        }
        internal GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch AsTurnBasedMatch(string selfPlayerId)
        {
            List <Participant> list = new List <Participant>();
            string             selfParticipantId    = null;
            string             pendingParticipantId = null;

            using (MultiplayerParticipant multiplayerParticipant = PendingParticipant())
            {
                if (multiplayerParticipant != null)
                {
                    pendingParticipantId = multiplayerParticipant.Id();
                }
            }
            foreach (MultiplayerParticipant item in Participants())
            {
                using (item)
                {
                    using (NativePlayer nativePlayer = item.Player())
                    {
                        if (nativePlayer != null && nativePlayer.Id().Equals(selfPlayerId))
                        {
                            selfParticipantId = item.Id();
                        }
                    }
                    list.Add(item.AsParticipant());
                }
            }
            bool canRematch = MatchStatus() == Types.MatchStatus.COMPLETED && !HasRematchId();

            return(new GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch(Id(), Data(), canRematch, selfParticipantId, list, AvailableAutomatchSlots(), pendingParticipantId, ToTurnStatus(MatchStatus()), ToMatchStatus(pendingParticipantId, MatchStatus()), Variant(), Version()));
        }
Exemple #5
0
        internal static void InternalOnDataReceived(
            IntPtr room, IntPtr participant, IntPtr data, UIntPtr dataLength, bool isReliable,
            IntPtr userData)
        {
            Logger.d("Entering InternalOnDataReceived: " + userData.ToInt64());

            var callback = Callbacks.IntPtrToPermanentCallback
                           <Action <NativeRealTimeRoom, MultiplayerParticipant, byte[], bool> >(userData);

            using (var nativeRoom = NativeRealTimeRoom.FromPointer(room)) {
                using (var nativeParticipant = MultiplayerParticipant.FromPointer(participant)) {
                    if (callback == null)
                    {
                        return;
                    }

                    byte[] convertedData = null;

                    if (dataLength.ToUInt64() != 0)
                    {
                        convertedData = new byte[dataLength.ToUInt32()];
                        Marshal.Copy(data, convertedData, 0, (int)dataLength.ToUInt32());
                    }

                    try {
                        callback(nativeRoom, nativeParticipant, convertedData, isReliable);
                    } catch (Exception e) {
                        Logger.e("Error encountered executing InternalOnDataReceived. " +
                                 "Smothering to avoid passing exception into Native: " + e);
                    }
                }
            }
        }
        private void FindEqualVersionMatchWithParticipant(GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch match, string participantId, Action <bool> onFailure, Action <GooglePlayGames.Native.PInvoke.MultiplayerParticipant, NativeTurnBasedMatch> onFoundParticipantAndMatch)
        {
            FindEqualVersionMatch(match, onFailure, delegate(NativeTurnBasedMatch foundMatch)
            {
                if (participantId == null)
                {
                    using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant arg = GooglePlayGames.Native.PInvoke.MultiplayerParticipant.AutomatchingSentinel())
                    {
                        onFoundParticipantAndMatch(arg, foundMatch);
                        return;

                        IL_0023:;
                    }
                }
                using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant multiplayerParticipant = foundMatch.ParticipantWithId(participantId))
                {
                    if (multiplayerParticipant == null)
                    {
                        Logger.e($"Located match {match.MatchId} but desired participant with ID {participantId} could not be found");
                        onFailure(false);
                    }
                    else
                    {
                        onFoundParticipantAndMatch(multiplayerParticipant, foundMatch);
                    }
                }
            });
        }
        internal static void InternalOnDataReceived(IntPtr room, IntPtr participant, IntPtr data, UIntPtr dataLength, bool isReliable, IntPtr userData)
        {
            Logger.d("Entering InternalOnDataReceived: " + (object)userData.ToInt64());
            Action <NativeRealTimeRoom, MultiplayerParticipant, byte[], bool> permanentCallback = Callbacks.IntPtrToPermanentCallback <Action <NativeRealTimeRoom, MultiplayerParticipant, byte[], bool> >(userData);

            using (NativeRealTimeRoom nativeRealTimeRoom = NativeRealTimeRoom.FromPointer(room))
            {
                using (MultiplayerParticipant multiplayerParticipant = MultiplayerParticipant.FromPointer(participant))
                {
                    if (permanentCallback == null)
                    {
                        return;
                    }
                    byte[] destination = (byte[])null;
                    if ((long)dataLength.ToUInt64() != 0L)
                    {
                        destination = new byte[(IntPtr)dataLength.ToUInt32()];
                        Marshal.Copy(data, destination, 0, (int)dataLength.ToUInt32());
                    }
                    try
                    {
                        permanentCallback(nativeRealTimeRoom, multiplayerParticipant, destination, isReliable);
                    }
                    catch (Exception ex)
                    {
                        Logger.e("Error encountered executing InternalOnDataReceived. Smothering to avoid passing exception into Native: " + (object)ex);
                    }
                }
            }
        }
Exemple #8
0
        internal GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch AsTurnBasedMatch(string selfPlayerId)
        {
            List <Participant> participants         = new List <Participant>();
            string             selfParticipantId    = (string)null;
            string             pendingParticipantId = (string)null;

            using (MultiplayerParticipant multiplayerParticipant = this.PendingParticipant())
            {
                if (multiplayerParticipant != null)
                {
                    pendingParticipantId = multiplayerParticipant.Id();
                }
            }
            foreach (MultiplayerParticipant participant in this.Participants())
            {
                using (participant)
                {
                    using (NativePlayer nativePlayer = participant.Player())
                    {
                        if (nativePlayer != null)
                        {
                            if (nativePlayer.Id().Equals(selfPlayerId))
                            {
                                selfParticipantId = participant.Id();
                            }
                        }
                    }
                    participants.Add(participant.AsParticipant());
                }
            }
            return(new GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch(this.Id(), this.Data(), this.MatchStatus() == Types.MatchStatus.COMPLETED && !this.HasRematchId(), selfParticipantId, participants, this.AvailableAutomatchSlots(), pendingParticipantId, NativeTurnBasedMatch.ToTurnStatus(this.MatchStatus()), NativeTurnBasedMatch.ToMatchStatus(pendingParticipantId, this.MatchStatus()), this.Variant(), this.Version()));
        }
Exemple #9
0
        internal static void PerformRoomAndParticipantCallback(string callbackName,
                                                               IntPtr room, IntPtr participant, IntPtr data)
        {
            Logger.d("Entering " + callbackName);

            try
            {
                // This is a workaround to the fact that we're lacking proper copy constructors -
                // see comment below.
                var nativeRoom = NativeRealTimeRoom.FromPointer(room);
                using (var nativeParticipant = MultiplayerParticipant.FromPointer(participant))
                {
                    var callback = Callbacks.IntPtrToPermanentCallback
                                   <Action <NativeRealTimeRoom, MultiplayerParticipant> >(data);
                    if (callback != null)
                    {
                        callback(nativeRoom, nativeParticipant);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.e("Error encountered executing " + callbackName + ". " +
                         "Smothering to avoid passing exception into Native: " + e);
            }
        }
        internal static void InternalOnDataReceived(IntPtr room, IntPtr participant, IntPtr data, UIntPtr dataLength, bool isReliable, IntPtr userData)
        {
            Logger.d("Entering InternalOnDataReceived: " + userData.ToInt64());
            Action <NativeRealTimeRoom, MultiplayerParticipant, byte[], bool> action = Callbacks.IntPtrToPermanentCallback <Action <NativeRealTimeRoom, MultiplayerParticipant, byte[], bool> >(userData);

            using (NativeRealTimeRoom arg = NativeRealTimeRoom.FromPointer(room))
            {
                using (MultiplayerParticipant arg2 = MultiplayerParticipant.FromPointer(participant))
                {
                    if (action != null)
                    {
                        byte[] array = null;
                        if (dataLength.ToUInt64() != 0L)
                        {
                            array = new byte[dataLength.ToUInt32()];
                            Marshal.Copy(data, array, 0, (int)dataLength.ToUInt32());
                        }
                        try
                        {
                            action(arg, arg2, array, isReliable);
                        }
                        catch (Exception arg3)
                        {
                            Logger.e("Error encountered executing InternalOnDataReceived. Smothering to avoid passing exception into Native: " + arg3);
                        }
                    }
                }
            }
        }
 internal void OnParticipantStatusChanged(NativeRealTimeRoom room, GooglePlayGames.Native.PInvoke.MultiplayerParticipant participant)
 {
     lock (mLifecycleLock)
     {
         mState.OnParticipantStatusChanged(room, participant);
     }
 }
Exemple #12
0
 internal NativePlayer Player()
 {
     if (!MultiplayerParticipant.MultiplayerParticipant_HasPlayer(base.SelfPtr()))
     {
         return(null);
     }
     return(new NativePlayer(MultiplayerParticipant.MultiplayerParticipant_Player(base.SelfPtr())));
 }
            internal override void HandleConnectedSetChanged(NativeRealTimeRoom room)
            {
                List <string> list  = new List <string>();
                List <string> list2 = new List <string>();
                Dictionary <string, GooglePlayGames.Native.PInvoke.MultiplayerParticipant> dictionary = room.Participants().ToDictionary((GooglePlayGames.Native.PInvoke.MultiplayerParticipant p) => p.Id());

                foreach (string key in mNativeParticipants.Keys)
                {
                    GooglePlayGames.Native.PInvoke.MultiplayerParticipant multiplayerParticipant  = dictionary[key];
                    GooglePlayGames.Native.PInvoke.MultiplayerParticipant multiplayerParticipant2 = mNativeParticipants[key];
                    if (!multiplayerParticipant.IsConnectedToRoom())
                    {
                        list2.Add(key);
                    }
                    if (!multiplayerParticipant2.IsConnectedToRoom() && multiplayerParticipant.IsConnectedToRoom())
                    {
                        list.Add(key);
                    }
                }
                foreach (GooglePlayGames.Native.PInvoke.MultiplayerParticipant value in mNativeParticipants.Values)
                {
                    value.Dispose();
                }
                mNativeParticipants = dictionary;
                mParticipants       = (from p in mNativeParticipants.Values
                                       select p.AsParticipant()).ToDictionary((Participant p) => p.ParticipantId);
                Logger.d("Updated participant statuses: " + string.Join(",", (from p in mParticipants.Values
                                                                              select p.ToString()).ToArray()));
                if (list2.Contains(GetSelf().ParticipantId))
                {
                    Logger.w("Player was disconnected from the multiplayer session.");
                }
                string selfId = GetSelf().ParticipantId;

                list = (from peerId in list
                        where !peerId.Equals(selfId)
                        select peerId).ToList();
                list2 = (from peerId in list2
                         where !peerId.Equals(selfId)
                         select peerId).ToList();
                if (list.Count > 0)
                {
                    list.Sort();
                    mSession.OnGameThreadListener().PeersConnected((from peer in list
                                                                    where !peer.Equals(selfId)
                                                                    select peer).ToArray());
                }
                if (list2.Count > 0)
                {
                    list2.Sort();
                    mSession.OnGameThreadListener().PeersDisconnected((from peer in list2
                                                                       where !peer.Equals(selfId)
                                                                       select peer).ToArray());
                }
            }
Exemple #14
0
        internal MultiplayerParticipant PendingParticipant()
        {
            MultiplayerParticipant participant = new MultiplayerParticipant(TurnBasedMatch.TurnBasedMatch_PendingParticipant(base.SelfPtr()));

            if (!participant.Valid())
            {
                participant.Dispose();
                return(null);
            }
            return(participant);
        }
        internal MultiplayerParticipant Inviter()
        {
            MultiplayerParticipant multiplayerParticipant = new MultiplayerParticipant(GooglePlayGames.Native.Cwrapper.MultiplayerInvitation.MultiplayerInvitation_InvitingParticipant(this.SelfPtr()));

            if (multiplayerParticipant.Valid())
            {
                return(multiplayerParticipant);
            }
            multiplayerParticipant.Dispose();
            return((MultiplayerParticipant)null);
        }
Exemple #16
0
    internal MultiplayerParticipant Inviter() {
        MultiplayerParticipant participant =
            new MultiplayerParticipant(C.MultiplayerInvitation_InvitingParticipant(SelfPtr()));

        if (!participant.Valid()) {
            participant.Dispose();
            return null;
        }

        return participant;
    }
Exemple #17
0
        internal MultiplayerParticipant Inviter()
        {
            MultiplayerParticipant participant = new MultiplayerParticipant(MultiplayerInvitation.MultiplayerInvitation_InvitingParticipant(base.SelfPtr()));

            if (!participant.Valid())
            {
                participant.Dispose();
                return(null);
            }
            return(participant);
        }
Exemple #18
0
 internal void LeaveDuringMyTurn(NativeTurnBasedMatch match,
                                 MultiplayerParticipant nextParticipant, Action <MultiplayerStatus> callback)
 {
     TurnBasedMultiplayerManager.TurnBasedMultiplayerManager_LeaveMatchDuringMyTurn(
         mGameServices.AsHandle(),
         match.AsPointer(),
         nextParticipant.AsPointer(),
         InternalMultiplayerStatusCallback,
         Callbacks.ToIntPtr(callback)
         );
 }
        internal Invitation AsInvitation()
        {
            Invitation.InvType invType = MultiplayerInvitation.ToInvType(this.Type());
            string             invId   = this.Id();
            int         variant        = (int)this.Variant();
            Participant inviter;

            using (MultiplayerParticipant multiplayerParticipant = this.Inviter())
                inviter = multiplayerParticipant != null?multiplayerParticipant.AsParticipant() : (Participant)null;
            return(new Invitation(invType, invId, inviter, variant));
        }
Exemple #20
0
        internal MultiplayerParticipant PendingParticipant()
        {
            MultiplayerParticipant multiplayerParticipant = new MultiplayerParticipant(GooglePlayGames.Native.Cwrapper.TurnBasedMatch.TurnBasedMatch_PendingParticipant(this.SelfPtr()));

            if (multiplayerParticipant.Valid())
            {
                return(multiplayerParticipant);
            }
            multiplayerParticipant.Dispose();
            return((MultiplayerParticipant)null);
        }
        internal MultiplayerParticipant Inviter()
        {
            MultiplayerParticipant participant =
                new MultiplayerParticipant(C.MultiplayerInvitation_InvitingParticipant(SelfPtr()));

            if (!participant.Valid())
            {
                participant.Dispose();
                return null;
            }

            return participant;
        }
Exemple #22
0
        internal Invitation AsInvitation()
        {
            Invitation.InvType invType = ToInvType(Type());
            string             invId   = Id();
            int         variant        = (int)Variant();
            Participant inviter        = default(Participant);

            using (MultiplayerParticipant multiplayerParticipant = Inviter())
            {
                inviter = multiplayerParticipant?.AsParticipant();
            }
            return(new Invitation(invType, invId, inviter, variant));
        }
Exemple #23
0
        internal Invitation AsInvitation()
        {
            Participant participant;

            Invitation.InvType invType = ToInvType(this.Type());
            string             invId   = this.Id();
            int variant = (int)this.Variant();

            using (MultiplayerParticipant participant2 = this.Inviter())
            {
                participant = participant2?.AsParticipant();
            }
            return(new Invitation(invType, invId, participant, variant));
        }
Exemple #24
0
 internal void TakeTurn(NativeTurnBasedMatch match, byte[] data,
                        MultiplayerParticipant nextParticipant, Action <TurnBasedMatchResponse> callback)
 {
     TurnBasedMultiplayerManager.TurnBasedMultiplayerManager_TakeMyTurn(
         mGameServices.AsHandle(),
         match.AsPointer(),
         data,
         new UIntPtr((uint)data.Length),
         // Just pass along the old results. Technically the API allows updates here, but
         // we never need them.
         match.Results().AsPointer(),
         nextParticipant.AsPointer(),
         InternalTurnBasedMatchCallback,
         ToCallbackPointer(callback));
 }
 internal static void PerformRoomAndParticipantCallback(string callbackName, IntPtr room, IntPtr participant, IntPtr data)
 {
     Logger.d("Entering " + callbackName);
     try
     {
         NativeRealTimeRoom arg = NativeRealTimeRoom.FromPointer(room);
         using (MultiplayerParticipant arg2 = MultiplayerParticipant.FromPointer(participant))
         {
             Callbacks.IntPtrToPermanentCallback <Action <NativeRealTimeRoom, MultiplayerParticipant> >(data)?.Invoke(arg, arg2);
         }
     }
     catch (Exception ex)
     {
         Logger.e("Error encountered executing " + callbackName + ". Smothering to avoid passing exception into Native: " + ex);
     }
 }
 internal static void PerformRoomAndParticipantCallback(string callbackName, IntPtr room, IntPtr participant, IntPtr data)
 {
     Logger.d("Entering " + callbackName);
     try
     {
         NativeRealTimeRoom room2 = NativeRealTimeRoom.FromPointer(room);
         using (MultiplayerParticipant participant2 = MultiplayerParticipant.FromPointer(participant))
         {
             Action <NativeRealTimeRoom, MultiplayerParticipant> action = Callbacks.IntPtrToPermanentCallback <Action <NativeRealTimeRoom, MultiplayerParticipant> >(data);
             if (action != null)
             {
                 action(room2, participant2);
             }
         }
     }
     catch (Exception exception)
     {
         Logger.e(string.Concat(new object[] { "Error encountered executing ", callbackName, ". Smothering to avoid passing exception into Native: ", exception }));
     }
 }
 internal static void PerformRoomAndParticipantCallback(string callbackName, IntPtr room, IntPtr participant, IntPtr data)
 {
     Logger.d("Entering " + callbackName);
     try
     {
         NativeRealTimeRoom nativeRealTimeRoom = NativeRealTimeRoom.FromPointer(room);
         using (MultiplayerParticipant multiplayerParticipant = MultiplayerParticipant.FromPointer(participant))
         {
             Action <NativeRealTimeRoom, MultiplayerParticipant> permanentCallback = Callbacks.IntPtrToPermanentCallback <Action <NativeRealTimeRoom, MultiplayerParticipant> >(data);
             if (permanentCallback == null)
             {
                 return;
             }
             permanentCallback(nativeRealTimeRoom, multiplayerParticipant);
         }
     }
     catch (Exception ex)
     {
         Logger.e("Error encountered executing " + callbackName + ". Smothering to avoid passing exception into Native: " + (object)ex);
     }
 }
Exemple #28
0
 internal bool Valid() =>
 MultiplayerParticipant.MultiplayerParticipant_Valid(base.SelfPtr());
 internal void SendReliableMessage(NativeRealTimeRoom room, MultiplayerParticipant participant,
     byte[] data, Action<Status.MultiplayerStatus> callback) {
     C.RealTimeMultiplayerManager_SendReliableMessage(mGameServices.AsHandle(),
         room.AsPointer(), participant.AsPointer(), data, PInvokeUtilities.ArrayToSizeT(data),
         InternalSendReliableMessageCallback, Callbacks.ToIntPtr(callback));
 }
        internal MultiplayerParticipant PendingParticipant()
        {
            var participant = new MultiplayerParticipant(
                              C.TurnBasedMatch_PendingParticipant(SelfPtr()));

            if (!participant.Valid())
            {
                participant.Dispose();
                return null;
            }

            return participant;
        }
 internal void TakeTurn(NativeTurnBasedMatch match, byte[] data, MultiplayerParticipant nextParticipant, Action <TurnBasedManager.TurnBasedMatchResponse> callback)
 {
     TurnBasedMultiplayerManager.TurnBasedMultiplayerManager_TakeMyTurn(this.mGameServices.AsHandle(), match.AsPointer(), data, new UIntPtr((uint)data.Length), match.Results().AsPointer(), nextParticipant.AsPointer(), new TurnBasedMultiplayerManager.TurnBasedMatchCallback(TurnBasedManager.InternalTurnBasedMatchCallback), TurnBasedManager.ToCallbackPointer(callback));
 }
 internal void LeaveDuringMyTurn(NativeTurnBasedMatch match, MultiplayerParticipant nextParticipant, Action <CommonErrorStatus.MultiplayerStatus> callback)
 {
     TurnBasedMultiplayerManager.TurnBasedMultiplayerManager_LeaveMatchDuringMyTurn(this.mGameServices.AsHandle(), match.AsPointer(), nextParticipant.AsPointer(), new TurnBasedMultiplayerManager.MultiplayerStatusCallback(TurnBasedManager.InternalMultiplayerStatusCallback), Callbacks.ToIntPtr((Delegate)callback));
 }
Exemple #33
0
 internal Types.ParticipantStatus Status() =>
 MultiplayerParticipant.MultiplayerParticipant_Status(base.SelfPtr());