Beispiel #1
0
        public ClientAuth(TcpClient client, AuthPacketInfo packet)
        {
            Tcp = client;
            ServerInfo ClientData;

            ClientData = new ServerInfo()
            {
                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,
            };
            Info = ClientData;
        }
Beispiel #2
0
        protected override void OnAuthServerPacketReceive(ClientAuth client, AuthPacketInfo packet)
        {
            switch (packet.ID)
            {
            case AuthPacketEnum.SERVER_KEEPALIVE:
                break;

            case AuthPacketEnum.SERVER_CONNECT:
                break;

            case AuthPacketEnum.SERVER_COMMAND:
                break;

            case AuthPacketEnum.SERVER_UPDATE:
                break;

            case AuthPacketEnum.RECEIVES_USER_UID:
                break;

            case AuthPacketEnum.DISCONNECT_PLAYER_ALL_ON_SERVERS:
                break;

            case AuthPacketEnum.SERVER_RELEASE_CHAT:
                break;

            case AuthPacketEnum.SERVER_RELEASE_NOTICE_GM:
                break;

            case AuthPacketEnum.SERVER_RELEASE_TICKET:
                break;

            case AuthPacketEnum.SERVER_RELEASE_BOXRANDOM:
                break;

            case AuthPacketEnum.SERVER_RELEASE_NOTICE:
                break;

            case AuthPacketEnum.CHECK_PLAYER_DUPLICATE:
                break;

            case AuthPacketEnum.RESULT_PLAYER_DUPLICATE:
                break;

            case AuthPacketEnum.SEND_DISCONNECT_PLAYER:
                break;

            case AuthPacketEnum.LOGIN_RESULT:
                break;

            case AuthPacketEnum.PLAYER_LOGIN_RESULT:
                break;

            default:
                break;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Envia Packet sem aguardar uma Resposta
        /// </summary>
        public void Send(AuthPacketInfo packet)
        {
            var _stream = Tcp.GetStream();

            var json = JsonConvert.Serialize(packet);


            var result = json.Select(Convert.ToByte).ToArray();

            NetworkStream.Write(result, 0, result.Length);
        }
Beispiel #4
0
        /// <summary>
        /// Envia Packet aguardando uma resposta
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        public AuthPacketInfo SendAndReceive(AuthPacketInfo packet)
        {
            Send(packet);

            var messageBufferRead = new byte[500000]; //Tamanho do BUFFER á ler

            //Lê mensagem do cliente
            var bytesRead = this.NetworkStream.Read(messageBufferRead, 0, 500000);

            //variável para armazenar a mensagem recebida
            var message = new byte[bytesRead];

            //Copia mensagem recebida
            Buffer.BlockCopy(messageBufferRead, 0, message, 0, bytesRead);

            var json = System.Text.Encoding.Default.GetString(message);

            var response = JsonConvert.Deserialize <AuthPacketInfo>(json);

            return(response);
        }
Beispiel #5
0
        /// <summary>
        /// Conecta-se ao AuthServer
        /// </summary>
        /// <returns></returns>
        public bool Connect()
        {
            try
            {
                Tcp.Connect("127.0.0.1", Port);

                var packet = new AuthPacketInfo()
                {
                    ID      = AuthPacketEnum.SERVER_CONNECT,
                    Message = new
                    {
                        ServerName = Name,
                        ServerType = Type,
                        Key
                    }
                };

                var response = SendAndReceive(packet);

                if (response.Message.Success == true)
                {
                    //Inicia Thread KeepAlive
                    var authClienthread = new Thread(new ThreadStart(HandleAuthClient));
                    authClienthread.Start();

                    return(true);
                }
                else
                {
                    Console.WriteLine(response.Message.Exception);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
Beispiel #6
0
 protected abstract void OnAuthServerPacketReceive(ClientAuth client, AuthPacketInfo packet);
Beispiel #7
0
 /// <summary>
 /// É Disparado quando um packet é recebido do AuthServer
 /// </summary>
 private void AuthServer_OnPacketReceived(ClientAuth authClient, AuthPacketInfo packet)
 {
     OnAuthServerPacketReceive(authClient, packet);
 }
Beispiel #8
0
 protected void ClientRequestPacket(ClientAuth session, AuthPacketInfo packet)
 {
     OnPacketReceived?.Invoke(session, packet);
 }