Пример #1
0
        static void TcpServer_OnPacketReceived(AuthClient client, AuthPacket packet)
        {
            WriteConsole.WriteLine($"[SYNC_CALL_PACKET]: [{packet.ID}, {client.Data.Name}]", ConsoleColor.Cyan);
            switch (packet.ID)
            {
            case AuthPacketEnum.SERVER_KEEPALIVE:
            {
                client.Send(new AuthPacket()
                    {
                        ID = AuthPacketEnum.SERVER_KEEPALIVE
                    });
            }
            break;

            case AuthPacketEnum.SERVER_CONNECT:
            {
                var response = new AuthPacket();

                if (client.Data.Key != AuthKey)
                {
                    response.Message = new
                    {
                        Success   = false,
                        Exception = "Chave de autenticação inválida"
                    };

                    Server.Send(client, response);
                    Server.DisconnectClient(client);
                }
                else
                {
                    response.Message = new
                    {
                        Success = true,
                    };

                    Server.Send(client, response);
                }
            }
            break;

            case AuthPacketEnum.RECEIVES_USER_UID:
            {
                HandlePlayerUID(packet);
            }
            break;

            case AuthPacketEnum.DISCONNECT_PLAYER_ALL_ON_SERVERS:
            {
                HandlePlayerDisconnect(packet);
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_CHAT:
            {
                byte Type = packet.Message.IsGM;
                if (Type == 15 || Type == 4)
                {
                    var response = new AuthPacket
                    {
                        ID      = AuthPacketEnum.SERVER_RELEASE_CHAT,
                        Message = new { PlayerNick = packet.Message.GetNickName, PlayerMessage = packet.Message.GetMessage }
                    };
                    Server.Send(AuthClientTypeEnum.GameServer, response);
                }
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_TICKET:
            {
                HandleTicket(packet);
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_BOXRANDOM:
            {
                HandleWinBoxRandomNotice(packet);
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_NOTICE_GM:
            {
                HandleNotice(packet);
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_NOTICE:
            {
                HandleNotice(packet);
            }
            break;

            case AuthPacketEnum.LOGIN_RESULT:
            {
                HandleLogin(client, packet);
            }
            break;

            case AuthPacketEnum.SERVER_COMMAND:
                break;

            default:
                WriteConsole.WriteLine("[SYNC_REQUEST_PACKET_UNK]: " + packet.ID);
                break;
            }
        }
Пример #2
0
        static void TcpServer_OnPacketReceived(AuthClient client, AuthPacket packet)
        {
            WriteConsole.WriteLine($"[SYNC_CALL_PACKET]: [{packet.ID}, {client.Data.Name}]", ConsoleColor.Cyan);
            switch (packet.ID)
            {
            case AuthPacketEnum.SERVER_KEEPALIVE:
            {
                client.Send(new AuthPacket()
                    {
                        ID = AuthPacketEnum.SERVER_KEEPALIVE
                    });
            }
            break;

            case AuthPacketEnum.SERVER_CONNECT:
            {
                var response = new AuthPacket();

                if (client.Data.Key != AuthKey)
                {
                    response.Message = new
                    {
                        Success   = false,
                        Exception = "Chave de autenticação inválida"
                    };

                    Server.Send(client, response);
                    Server.DisconnectClient(client);
                }
                else
                {
                    response.Message = new
                    {
                        Success = true,
                    };

                    Server.Send(client, response);
                }
            }
            break;

            case AuthPacketEnum.RECEIVES_USER_UID:
            {
                HandlePlayerUID(packet);
            }
            break;

            case AuthPacketEnum.SERVER_UPDATE:
            {
                ServerSettings ClientData;
                ClientData = new ServerSettings()
                {
                    UID             = packet.Message._data.UID,
                    Type            = packet.Message._data.Type,
                    AuthServer_Ip   = packet.Message._data.AuthServer_Ip,
                    AuthServer_Port = packet.Message._data.AuthServer_Port,
                    Port            = packet.Message._data.Port,
                    MaxPlayers      = packet.Message._data.MaxPlayers,
                    IP          = packet.Message._data.IP,
                    Key         = packet.Message._data.Key,
                    Name        = packet.Message._data.Name,
                    BlockFunc   = packet.Message._data.BlockFunc,
                    EventFlag   = packet.Message._data.EventFlag,
                    GameVersion = packet.Message._data.GameVersion,
                    ImgNo       = packet.Message._data.ImgNo,
                    Property    = packet.Message._data.Property,
                    Version     = packet.Message._data.Version,
                };
                client.Data = ClientData;

                client.Data.Update();
            }
            break;

            case AuthPacketEnum.DISCONNECT_PLAYER_ALL_ON_SERVERS:
            {
                HandlePlayerDisconnect(packet);
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_CHAT:
            {
                byte Type = packet.Message.IsGM;
                if (Type == 15 || Type == 4)
                {
                    var response = new AuthPacket
                    {
                        ID      = AuthPacketEnum.SERVER_RELEASE_CHAT,
                        Message = new { PlayerNick = packet.Message.GetNickName, PlayerMessage = packet.Message.GetMessage }
                    };
                    Server.Send(AuthClientTypeEnum.GameServer, response);
                }
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_TICKET:
            {
                HandleTicket(packet);
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_BOXRANDOM:
            {
                HandleWinBoxRandomNotice(packet);
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_NOTICE_GM:
            {
                HandleNotice(packet);
            }
            break;

            case AuthPacketEnum.SERVER_RELEASE_NOTICE:
            {
                HandleNotice(packet);
            }
            break;

            case AuthPacketEnum.LOGIN_RESULT:
            {
                HandleLogin(client, packet);
            }
            break;

            case AuthPacketEnum.SERVER_COMMAND:
                break;

            default:
                WriteConsole.WriteLine("[SYNC_REQUEST_PACKET_UNK]: " + packet.ID);
                break;
            }
        }