/// <summary>
 /// Registers a udp packetHandler. This handler will be invoked if this connection
 /// receives the given type.
 /// </summary>
 /// <param name="packetType">Type of the packet we would like to receive.</param>
 /// <param name="handler">The handler which should be invoked.</param>
 public void UDP_RegisterPacketHandler(Type packetType, PacketReceivedHandler handler)
 {
     if (udpConnection != null && udpConnection.IsAlive)
     {
         udpConnection.RegisterPacketHandler(packetType, handler);
     }
     udpPacketHandlerBuffer.Add(new Tuple <Type, PacketReceivedHandler>(packetType, handler));
 }
Пример #2
0
 /// <summary>
 /// Registers a packetHandler for UDP. This handler will be invoked if this connection
 /// receives the given type.
 /// </summary>
 /// <typeparam name="T">The type we would like to receive.</typeparam>
 /// <param name="handler">The handler which should be invoked.</param>
 /// <param name="obj">The object which wants to receive the packet.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public void UDP_RegisterPacketHandler <T>(PacketReceivedHandler <T> handler, object obj) where T : Packet
 {
     if (IsAlive_UDP)
     {
         udpConnection.RegisterPacketHandler <T>(handler, obj);
     }
     else
     {
         udpPacketHandlerBuffer.Add(new Tuple <Type, Delegate, object>(typeof(T), handler, obj));
     }
 }
        /// <summary>
        /// Opens the new UDP connection and applies the already registered packet handlers.
        /// </summary>
        private async Task <bool> OpenNewUDPConnection()
        {
            Tuple <UdpConnection, ConnectionResult> result = await ConnectionFactory.CreateUdpConnectionAsync(tcpConnection);

            if (result.Item2 != ConnectionResult.Connected)
            {
                Reconnect(); return(false);
            }
            udpConnection = result.Item1;
            udpPacketHandlerBuffer.ForEach(u => udpConnection.RegisterPacketHandler(u.Item1, u.Item2));
            udpConnection.ConnectionClosed += (c, cc) => { Reconnect(); connectionLost?.Invoke(udpConnection, ConnectionType.UDP, c); };
            sendFastBuffer.ForEach(s => udpConnection.Send(s));
            connectionEstablished?.Invoke(udpConnection, ConnectionType.UDP);
            return(true);
        }
 /// <summary>
 /// Opens the new UDP connection and applies the already registered packet handlers.
 /// </summary>
 private async Task<bool> OpenNewUDPConnection()
 {
     Tuple<UdpConnection, ConnectionResult> result = await ConnectionFactory.CreateUdpConnectionAsync(tcpConnection);
     if (result.Item2 != ConnectionResult.Connected) { Reconnect(); return false; }
     udpConnection = result.Item1;
     udpPacketHandlerBuffer.ForEach(u => udpConnection.RegisterPacketHandler(u.Item1, u.Item2));
     udpConnection.ConnectionClosed += (c, cc) => { Reconnect(); connectionLost?.Invoke(udpConnection, ConnectionType.UDP, c); };
     sendFastBuffer.ForEach(s => udpConnection.Send(s));
     connectionEstablished?.Invoke(udpConnection, ConnectionType.UDP);
     return true;
 }