internal static void InternalOnDataReceived(IntPtr room, IntPtr participant, IntPtr data, UIntPtr dataLength, bool isReliable, IntPtr userData)
        {
            Logger.d("Entering InternalOnDataReceived: " + userData.ToInt64());
            Action <NativeRealTimeRoom, GooglePlayGames.Native.PInvoke.MultiplayerParticipant, byte[], bool> action = Callbacks.IntPtrToPermanentCallback <Action <NativeRealTimeRoom, GooglePlayGames.Native.PInvoke.MultiplayerParticipant, byte[], bool> >(userData);

            using (NativeRealTimeRoom room2 = NativeRealTimeRoom.FromPointer(room))
            {
                using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant participant2 = GooglePlayGames.Native.PInvoke.MultiplayerParticipant.FromPointer(participant))
                {
                    if (action != null)
                    {
                        byte[] destination = null;
                        if (dataLength.ToUInt64() != 0L)
                        {
                            destination = new byte[dataLength.ToUInt32()];
                            Marshal.Copy(data, destination, 0, (int)dataLength.ToUInt32());
                        }
                        try
                        {
                            action(room2, participant2, destination, isReliable);
                        }
                        catch (Exception exception)
                        {
                            Logger.e("Error encountered executing InternalOnDataReceived. Smothering to avoid passing exception into Native: " + exception);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 internal void LeaveRoom(NativeRealTimeRoom room, Action <Status.ResponseStatus> callback)
 {
     C.RealTimeMultiplayerManager_LeaveRoom(mGameServices.AsHandle(),
                                            room.AsPointer(),
                                            InternalLeaveRoomCallback,
                                            Callbacks.ToIntPtr(callback));
 }
Beispiel #3
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);
                        }
                    }
                }
            }
        }
Beispiel #5
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));
 }
        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);
                    }
                }
            }
        }
Beispiel #7
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);
                    }
                }
            }
        }
 internal void ShowWaitingRoomUI(NativeRealTimeRoom room, uint minimumParticipantsBeforeStarting,
     Action<WaitingRoomUIResponse> callback) {
     Misc.CheckNotNull(room);
     C.RealTimeMultiplayerManager_ShowWaitingRoomUI(mGameServices.AsHandle(),
         room.AsPointer(),
         minimumParticipantsBeforeStarting,
         InternalWaitingRoomUICallback,
         Callbacks.ToIntPtr(callback, WaitingRoomUIResponse.FromPointer));
 }
Beispiel #9
0
 internal void ShowWaitingRoomUI(NativeRealTimeRoom room, uint minimumParticipantsBeforeStarting,
                                 Action <WaitingRoomUIResponse> callback)
 {
     Misc.CheckNotNull(room);
     C.RealTimeMultiplayerManager_ShowWaitingRoomUI(mGameServices.AsHandle(),
                                                    room.AsPointer(),
                                                    minimumParticipantsBeforeStarting,
                                                    InternalWaitingRoomUICallback,
                                                    Callbacks.ToIntPtr(callback, WaitingRoomUIResponse.FromPointer));
 }
Beispiel #10
0
 internal void SendUnreliableMessageToSpecificParticipants(NativeRealTimeRoom room,
                                                           List <MultiplayerParticipant> recipients, byte[] data)
 {
     C.RealTimeMultiplayerManager_SendUnreliableMessage(
         mGameServices.AsHandle(),
         room.AsPointer(),
         recipients.Select(r => r.AsPointer()).ToArray(),
         new UIntPtr((ulong)recipients.LongCount()),
         data,
         PInvokeUtilities.ArrayToSizeT(data));
 }
 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);
     }
 }
        private static IntPtr ToCallbackPointer(Action <NativeRealTimeRoom> callback)
        {
            Action <IntPtr> callback2 = delegate(IntPtr result)
            {
                NativeRealTimeRoom nativeRealTimeRoom = NativeRealTimeRoom.FromPointer(result);
                if (callback != null)
                {
                    callback(nativeRealTimeRoom);
                }
                else
                {
                    nativeRealTimeRoom?.Dispose();
                }
            };

            return(Callbacks.ToIntPtr(callback2));
        }
Beispiel #13
0
        // This is a workaround to the fact that we're lacking proper copy constructors on the cwrapper
        // structs. Clients of the RealTimeEventListener need to hold long-lived references to the
        // room returned by the callback, but the default implementation of the utility callback method
        // cleans up all arguments to the callback. This can be gotten rid of when copy constructors
        // are present in the native sdk.
        private static IntPtr ToCallbackPointer(Action <NativeRealTimeRoom> callback)
        {
            Action <IntPtr> pointerReceiver = result => {
                NativeRealTimeRoom converted = NativeRealTimeRoom.FromPointer(result);
                if (callback != null)
                {
                    callback(converted);
                }
                else
                {
                    if (converted != null)
                    {
                        converted.Dispose();
                    }
                }
            };

            return(Callbacks.ToIntPtr(pointerReceiver));
        }
 private static IntPtr ToCallbackPointer(Action <NativeRealTimeRoom> callback)
 {
     return(Callbacks.ToIntPtr((Delegate)(result =>
     {
         NativeRealTimeRoom nativeRealTimeRoom = NativeRealTimeRoom.FromPointer(result);
         if (callback != null)
         {
             callback(nativeRealTimeRoom);
         }
         else
         {
             if (nativeRealTimeRoom == null)
             {
                 return;
             }
             nativeRealTimeRoom.Dispose();
         }
     })));
 }
 internal static void PerformRoomAndParticipantCallback(string callbackName, IntPtr room, IntPtr participant, IntPtr data)
 {
     Logger.d("Entering " + callbackName);
     try
     {
         NativeRealTimeRoom room2 = NativeRealTimeRoom.FromPointer(room);
         using (GooglePlayGames.Native.PInvoke.MultiplayerParticipant participant2 = GooglePlayGames.Native.PInvoke.MultiplayerParticipant.FromPointer(participant))
         {
             Action <NativeRealTimeRoom, GooglePlayGames.Native.PInvoke.MultiplayerParticipant> action = Callbacks.IntPtrToPermanentCallback <Action <NativeRealTimeRoom, GooglePlayGames.Native.PInvoke.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);
     }
 }
Beispiel #17
0
 internal void ShowWaitingRoomUI(NativeRealTimeRoom room, uint minimumParticipantsBeforeStarting, Action <RealtimeManager.WaitingRoomUIResponse> callback)
 {
     Misc.CheckNotNull <NativeRealTimeRoom>(room);
     RealTimeMultiplayerManager.RealTimeMultiplayerManager_ShowWaitingRoomUI(this.mGameServices.AsHandle(), room.AsPointer(), minimumParticipantsBeforeStarting, new RealTimeMultiplayerManager.WaitingRoomUICallback(RealtimeManager.InternalWaitingRoomUICallback), Callbacks.ToIntPtr <RealtimeManager.WaitingRoomUIResponse>(callback, new Func <IntPtr, RealtimeManager.WaitingRoomUIResponse>(RealtimeManager.WaitingRoomUIResponse.FromPointer)));
 }
Beispiel #18
0
 internal void SendUnreliableMessageToAll(NativeRealTimeRoom room, byte[] data)
 {
     C.RealTimeMultiplayerManager_SendUnreliableMessageToOthers(mGameServices.AsHandle(),
                                                                room.AsPointer(), data, PInvokeUtilities.ArrayToSizeT(data));
 }
 internal void SendUnreliableMessageToSpecificParticipants(NativeRealTimeRoom room,
     List<MultiplayerParticipant> recipients, byte[] data) {
     C.RealTimeMultiplayerManager_SendUnreliableMessage(
         mGameServices.AsHandle(),
         room.AsPointer(),
         recipients.Select(r => r.AsPointer()).ToArray(),
         new UIntPtr((ulong) recipients.LongCount()),
         data,
         PInvokeUtilities.ArrayToSizeT(data));
 }
 internal void SendUnreliableMessageToAll(NativeRealTimeRoom room, byte[] data) {
     C.RealTimeMultiplayerManager_SendUnreliableMessageToOthers(mGameServices.AsHandle(),
         room.AsPointer(), data, PInvokeUtilities.ArrayToSizeT(data));
 }
 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 void LeaveRoom(NativeRealTimeRoom room, Action<Status.ResponseStatus> callback) {
     C.RealTimeMultiplayerManager_LeaveRoom(mGameServices.AsHandle(),
         room.AsPointer(),
         InternalLeaveRoomCallback,
         Callbacks.ToIntPtr(callback));
 }
 internal void LeaveRoom(NativeRealTimeRoom room, Action <GooglePlayGames.Native.Cwrapper.CommonErrorStatus.ResponseStatus> callback)
 {
     RealTimeMultiplayerManager.RealTimeMultiplayerManager_LeaveRoom(this.mGameServices.AsHandle(), room.AsPointer(), new RealTimeMultiplayerManager.LeaveRoomCallback(RealtimeManager.InternalLeaveRoomCallback), Callbacks.ToIntPtr(callback));
 }
 internal void SendReliableMessage(NativeRealTimeRoom room, GooglePlayGames.Native.PInvoke.MultiplayerParticipant participant, byte[] data, Action <GooglePlayGames.Native.Cwrapper.CommonErrorStatus.MultiplayerStatus> callback)
 {
     RealTimeMultiplayerManager.RealTimeMultiplayerManager_SendReliableMessage(this.mGameServices.AsHandle(), room.AsPointer(), participant.AsPointer(), data, PInvokeUtilities.ArrayToSizeT <byte>(data), new RealTimeMultiplayerManager.SendReliableMessageCallback(RealtimeManager.InternalSendReliableMessageCallback), Callbacks.ToIntPtr(callback));
 }
 internal void SendUnreliableMessageToSpecificParticipants(NativeRealTimeRoom room, List <GooglePlayGames.Native.PInvoke.MultiplayerParticipant> recipients, byte[] data)
 {
     if (< > f__am$cache1 == null)
     {