Ejemplo n.º 1
0
        private void ProcessAccountPacket(ClientConnection client, SubPacket packet)
        {
            ap = new AccountPacket();
            ErrorPacket ep = new ErrorPacket();

            ap.Read(packet.GetAccountHeaderBytes(), packet.data);
            if (!ap.register)//if account is logging in
            {
                Database      db      = new Database();
                List <string> account = db.CheckUserInDb(ap.userName, ap.password);
                switch (account.Count)
                {
                case 0:
                    var packetToSend = ep.buildPacket(GamePacketOpCode.AccountError, ErrorCodes.NoAccount, "Account does not exist");
                    Console.WriteLine("Attempted log in for username: {0} pw: {1}, account does not exist", ap.userName, ap.password);
                    QueueErrorPacket(packetToSend);
                    break;

                case 1:
                    //password incorrect
                    packetToSend = ep.buildPacket(GamePacketOpCode.AccountError, ErrorCodes.WrongPassword, "Wrong username or password");
                    Console.WriteLine("Attempted log in for username: {0} pw: {1}, password incorrect", ap.userName, ap.password);
                    QueueErrorPacket(packetToSend);
                    break;

                case 2:
                    //user and password found
                    Console.WriteLine("Username: {0} Password: {1} has logged in successfully", account[0], account[1]);
                    SubPacket success = new SubPacket(GamePacketOpCode.AccountSuccess, 0, 0, System.Text.Encoding.Unicode.GetBytes("Login Successful"), SubPacketTypes.GamePacket);
                    client.authenticated = true;
                    BasePacket basePacket = BasePacket.CreatePacket(success, client.authenticated, false);
                    client.QueuePacket(basePacket);
                    break;

                default:
                    throw new Exception("somehow found more than 2 colums in DB");
                }
            }
            else //account is registering
            {
                Database db        = new Database();
                var      succeeded = db.AddUserToDb(ap.userName, ap.password);
                if (succeeded)
                {
                    Console.WriteLine("Username: {0} Password: {1} has been registered successfully", ap.userName, ap.password);
                    SubPacket  success    = new SubPacket(GamePacketOpCode.RegisterSuccess, 0, 0, System.Text.Encoding.Unicode.GetBytes("Registration Successful"), SubPacketTypes.GamePacket);
                    BasePacket basePacket = BasePacket.CreatePacket(success, false, false);
                    client.QueuePacket(basePacket);
                }
                else
                {
                    var packetToSend = ep.buildPacket(GamePacketOpCode.AccountError, ErrorCodes.DuplicateAccount, "Account already registered");
                    QueueErrorPacket(packetToSend);
                }
            }
        }
Ejemplo n.º 2
0
        private void ProcessCharacterDeleteRequest(SubPacket receivedPacket)
        {
            Database db = new Database();
            CharacterDeletePacket deletePacket = new CharacterDeletePacket(receivedPacket);
            int error = db.DeleteCharacterFromDb(deletePacket.CharId);

            if (error == -1)
            {
                SubPacket  success    = new SubPacket(GamePacketOpCode.CharacterDeleteSuccess, 0, 0, System.Text.Encoding.Unicode.GetBytes("Character deleted successfully"), SubPacketTypes.GamePacket);
                BasePacket basePacket = BasePacket.CreatePacket(success, client.authenticated, false);
                client.QueuePacket(basePacket);
            }
            else
            {
                //send error packet here
            }
        }
Ejemplo n.º 3
0
        private void AckResponseToWorldServer(BasePacket packetToSend)
        {
            packetToSend.header.connectionType = (ushort)BasePacketConnectionTypes.Generic;
            IPAddress[] ip       = Dns.GetHostAddresses("127.0.0.1");
            IPEndPoint  remoteEP = new IPEndPoint(ip[0], 3435);
            Socket      socket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(remoteEP);
            ClientConnection temp = new ClientConnection();

            temp.socket = socket;
            temp.QueuePacket(packetToSend);
            temp.FlushQueuedSendPackets();
        }