Esempio n. 1
0
        protected void ProcessMessage(ScertDatagramPacket packet)
        {
            var message = packet.Message;

            //
            switch (message)
            {
            case RT_MSG_CLIENT_CONNECT_AUX_UDP connectAuxUdp:
            {
                var clientObject = Program.TcpServer.GetClientByScertId(connectAuxUdp.ScertId);
                if (clientObject != ClientObject)
                {
                    break;
                }

                //
                AuthenticatedEndPoint = packet.Source;

                ClientObject.RemoteUdpEndpoint = AuthenticatedEndPoint as IPEndPoint;
                ClientObject.OnUdpConnected();

                //
                var msg = new RT_MSG_SERVER_CONNECT_ACCEPT_AUX_UDP()
                {
                    PlayerId    = (ushort)ClientObject.DmeId,
                    ScertId     = ClientObject.ScertId,
                    PlayerCount = (ushort)ClientObject.DmeWorld.Clients.Count,
                    EndPoint    = ClientObject.RemoteUdpEndpoint
                };

                // Send it twice in case of packet loss
                //_boundChannel.WriteAndFlushAsync(new ScertDatagramPacket(msg, packet.Source));
                _boundChannel.WriteAndFlushAsync(new ScertDatagramPacket(msg, packet.Source));
                break;
            }

            case RT_MSG_SERVER_ECHO serverEchoReply:
            {
                break;
            }

            case RT_MSG_CLIENT_ECHO clientEcho:
            {
                SendTo(new RT_MSG_CLIENT_ECHO()
                    {
                        Value = clientEcho.Value
                    }, packet.Source);
                break;
            }

            case RT_MSG_CLIENT_APP_BROADCAST clientAppBroadcast:
            {
                if (AuthenticatedEndPoint == null || !AuthenticatedEndPoint.Equals(packet.Source))
                {
                    break;
                }

                ClientObject.DmeWorld?.BroadcastUdp(ClientObject, clientAppBroadcast.Payload);
                break;
            }

            case RT_MSG_CLIENT_APP_LIST clientAppList:
            {
                if (AuthenticatedEndPoint == null || !AuthenticatedEndPoint.Equals(packet.Source))
                {
                    break;
                }

                ClientObject.DmeWorld?.SendUdpAppList(ClientObject, clientAppList.Targets, clientAppList.Payload);
                break;
            }

            case RT_MSG_CLIENT_APP_SINGLE clientAppSingle:
            {
                if (AuthenticatedEndPoint == null || !AuthenticatedEndPoint.Equals(packet.Source))
                {
                    break;
                }

                ClientObject.DmeWorld?.SendUdpAppSingle(ClientObject, clientAppSingle.TargetOrSource, clientAppSingle.Payload);
                break;
            }

            case RT_MSG_CLIENT_APP_TOSERVER clientAppToServer:
            {
                if (AuthenticatedEndPoint == null || !AuthenticatedEndPoint.Equals(packet.Source))
                {
                    break;
                }

                ProcessMediusMessage(clientAppToServer.Message);
                break;
            }

            case RT_MSG_CLIENT_DISCONNECT_WITH_REASON clientDisconnectWithReason:
            {
                break;
            }

            default:
            {
                Logger.Warn($"UNHANDLED MESSAGE: {message}");

                break;
            }
            }

            return;
        }
Esempio n. 2
0
        protected void ProcessMessage(ScertDatagramPacket packet)
        {
            var message = packet.Message;

            //
            switch (message)
            {
            case RT_MSG_CLIENT_CONNECT_AUX_UDP connectAuxUdp:
            {
                var clientObject = Program.TcpServer.GetClientByScertId(connectAuxUdp.ScertId);
                if (clientObject != ClientObject)
                {
                    break;
                }

                //
                AuthenticatedEndPoint = packet.Source;

                ClientObject.RemoteUdpEndpoint = AuthenticatedEndPoint as IPEndPoint;
                ClientObject.OnUdpConnected();
                SendTo(new RT_MSG_SERVER_CONNECT_ACCEPT_AUX_UDP()
                    {
                        PlayerId    = (ushort)ClientObject.DmeId,
                        ScertId     = ClientObject.ScertId,
                        PlayerCount = (ushort)ClientObject.DmeWorld.Clients.Count,
                        EndPoint    = ClientObject.RemoteUdpEndpoint
                    }, packet.Source);
                break;
            }

            case RT_MSG_SERVER_ECHO serverEchoReply:
            {
                break;
            }

            case RT_MSG_CLIENT_ECHO clientEcho:
            {
                SendTo(new RT_MSG_CLIENT_ECHO()
                    {
                        Value = clientEcho.Value
                    }, packet.Source);
                break;
            }

            case RT_MSG_CLIENT_APP_BROADCAST clientAppBroadcast:
            {
                if (AuthenticatedEndPoint == null || !AuthenticatedEndPoint.Equals(packet.Source))
                {
                    break;
                }

                /*
                 * // Don't send dupes
                 * if (_lastMessage != null && _lastMessage is RT_MSG_CLIENT_APP_BROADCAST lastBroadcast && lastBroadcast.Equals(clientAppBroadcast))
                 *  break;
                 *
                 * // Speedhack, reduce pad message in DL
                 * if (clientAppBroadcast.Payload.Length == 0x22 && clientAppBroadcast.Payload[0] == 2 && clientAppBroadcast.Payload[1] == 9)
                 * {
                 *  if (_lastMessage != null && _lastMessage is RT_MSG_CLIENT_APP_BROADCAST lb && lb.Payload.Length == 0x22)
                 *  {
                 *      int i;
                 *      for (i = 0; i < clientAppBroadcast.Payload.Length; ++i)
                 *      {
                 *          if (i >= 0x14 && i <= 0x17)
                 *              continue;
                 *
                 *          if (clientAppBroadcast.Payload[i] != lb.Payload[i])
                 *              goto dododood;
                 *      }
                 *
                 *      break;
                 *  }
                 * }
                 *
                 *
                 * dododood:;
                 */

                ClientObject.DmeWorld?.BroadcastUdp(ClientObject, clientAppBroadcast.Payload);
                break;
            }

            case RT_MSG_CLIENT_APP_LIST clientAppList:
            {
                if (AuthenticatedEndPoint == null || !AuthenticatedEndPoint.Equals(packet.Source))
                {
                    break;
                }

                var world = ClientObject.DmeWorld;
                if (world != null && clientAppList.Targets != null)
                {
                    foreach (var target in clientAppList.Targets)
                    {
                        world.SendUdpAppSingle(ClientObject, (short)target, clientAppList.Payload);
                    }
                }
                break;
            }

            case RT_MSG_CLIENT_APP_SINGLE clientAppSingle:
            {
                if (AuthenticatedEndPoint == null || !AuthenticatedEndPoint.Equals(packet.Source))
                {
                    break;
                }

                ClientObject.DmeWorld?.SendUdpAppSingle(ClientObject, clientAppSingle.TargetOrSource, clientAppSingle.Payload);
                break;
            }

            case RT_MSG_CLIENT_APP_TOSERVER clientAppToServer:
            {
                if (AuthenticatedEndPoint == null || !AuthenticatedEndPoint.Equals(packet.Source))
                {
                    break;
                }

                ProcessMediusMessage(clientAppToServer.Message);
                break;
            }

            case RT_MSG_CLIENT_DISCONNECT_WITH_REASON clientDisconnectWithReason:
            {
                break;
            }

            default:
            {
                Logger.Warn($"UNHANDLED MESSAGE: {message}");

                break;
            }
            }

            return;
        }