예제 #1
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);
                    }
                }
            }
        }
예제 #2
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: " + (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);
                    }
                }
            }
        }
        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 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);
     }
 }