Example #1
0
        private static void Packet_CNewAccount(long index, byte[] data)
        {
            Console.WriteLine("Received request CNewAccount from: " + index);

            ByteBuffer buffer = new ByteBuffer();

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

            try {
                AccountManager.CreateAccount(username, password);
                ServerSendData.SendServerMessage(index, "Account created!");
                Console.WriteLine("Account created.");
            } catch (AccountExistsException) {
                ServerSendData.SendServerMessage(index, "Account already exists!");
                Console.WriteLine("Account already exists.");
            }
        }
Example #2
0
        private static void Packet_CLogin(long index, byte[] data)
        {
            Console.WriteLine("Received request CLogin from: " + index);

            ByteBuffer buffer = new ByteBuffer();

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

            try {
                AccountManager.Login(index, username, password);
                ServerSendData.SendLoginResponse(index, LoginResponse.OK);
                Console.WriteLine("Player logged.");
            } catch (AccountDoesNotExist) {
                ServerSendData.SendLoginResponse(index, LoginResponse.DOES_NOT_EXISTS);
                Console.WriteLine("Account does not exists.");
            }  catch (IncorrectPasswordException) {
                ServerSendData.SendLoginResponse(index, LoginResponse.INCORRECT_PASSWORD);
                Console.WriteLine("Incorrect password.");
            }
        }