Beispiel #1
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     string username;
        ///                     string password;
        /// </summary>
        private static void HandleLoginTry(ClientTCP client, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            buffer.ReadInteger();
            string username = buffer.ReadString();

            if (!Global.data.LoginExist(username))
            {
                SendDataTCP.SendClientAlert(client, "Username does not exist.");
                return;
            }
            if (!Global.data.PasswordIsOkay(username, buffer.ReadString()))
            {
                SendDataTCP.SendClientAlert(client, "Invalid password.");
                return;
            }
            client.LogIn(username);
            buffer.Dispose();
        }
Beispiel #2
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     string username;
        ///                     string password;
        ///                     string nickname;
        /// </summary>
        private static void HandleRegisterTry(ClientTCP client, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            buffer.ReadInteger();
            string username = buffer.ReadString();
            string password = buffer.ReadString();
            string nickname = buffer.ReadString();

            if (Global.data.LoginExist(username))
            {
                SendDataTCP.SendClientAlert(client, "Username already exist");
                return;
            }
            if (Global.data.NicknameExist(nickname))
            {
                SendDataTCP.SendClientAlert(client, "Nickname already exist");
                return;
            }
            Global.data.AddAccount(username, password, nickname);
            buffer.Dispose();
            SendDataTCP.SendRegisterOk(client);
        }