Example #1
0
 public async Task ExecuteHandler(RecvOpcode opcode, Client client, PacketReader reader)
 {
     PacketHandler handler;
     if (handlers.TryGetValue(opcode, out handler))
     {
         await handler(client, reader);
     }
     else throw new Exception("No handler found for: " + ((byte)opcode).ToString("X2"));
 }
Example #2
0
 public static async Task HandleClientSettings(Client client, PacketReader reader)
 {
     //TODO: save these settings in Player
     string locale = await reader.ReadString();
     byte viewDistance = await reader.ReadByte();
     byte chatFlags = await reader.ReadByte();
     byte difficulty = await reader.ReadByte();
     bool cape = await reader.ReadBoolean();
 }
Example #3
0
        public static async Task HandleServerStats(Client client, PacketReader reader)
        {
            await reader.ReadByte();
            using (var packet = new PacketWriter(SendOpcode.Kick))
            {
                packet.WriteString("ยง1\0{0}\0{1}\0{2}\0{3}\0{4}", 
                    Server.Protocol, Server.Version, Server.Instance.GetMOTD(),
                    Server.Instance.PlayerCount, Server.Instance.Max);

                client.Send(packet);
            }
        }
Example #4
0
 // TODO: does 3rd param still have a function?
 private static async Task SetPosition(Client client, PacketReader reader, bool has_stance = true)
 {
     double x = await reader.ReadDouble();
     double y = await reader.ReadDouble();
     if (has_stance)
     {
         double stance = await reader.ReadDouble();
         client.Player.Stance = stance;
     }
     double z = await reader.ReadDouble();
     client.Player.Move(x, y, z);
 }
Example #5
0
 public static async Task HandlePlayerPositionAndLook(Client client, PacketReader reader)
 {
     await SetPosition(client, reader);
     await SetView(client, reader);
     await SetOnGround(client, reader);
     using (var packet = new PacketWriter(SendOpcode.PlayerPosition))
     {
         Player player = client.Player;
         packet.Write(player.Position.X);
         packet.Write(player.Position.Y);
         packet.Write(player.Stance);
         packet.Write(player.Position.Z);
         packet.Write(player.View.yaw);
         packet.Write(player.View.pitch);
         packet.Write(player.OnGround);
         //Console.WriteLine("Pos: X={0}, Y={1}, Z={2}", player.Position.X, player.Position.Y, player.Position.Z);
         client.Send(packet);
     }
 }
Example #6
0
        public static async Task HandleHandshake(Client client, PacketReader reader)
        {
            byte protocol = await reader.ReadByte();
            string username = await reader.ReadString();
            string host = await reader.ReadString();
            uint port = await reader.ReadUInt32();

            // TODO: This has to happen as a seperate task!! not on this thread
            LoginResult res = client.Authenticate(username, host, port);
            if (res != LoginResult.LoggedIn)
            {
                using (var packet = new PacketWriter(SendOpcode.Kick))
                {
                    packet.WriteString("DERP!!! Server disconnected, reason: {0}", res.ToString());
                    client.Send(packet);
                }
            }
            else
            {
                //TODO: chunks?
            }
        }
Example #7
0
        public static async Task HandlePlayerAbility(Client client, PacketReader reader)
        {
            byte flags = await reader.ReadByte();
            byte flySpeed = await reader.ReadByte();
            byte walkSpeed = await reader.ReadByte();

            Player player = client.Player;
            player.GodMode = (flags & 8) != 0;
            player.FlyingAllowed = (flags & 4) != 0;
            player.IsFlying = (flags & 2) != 0;
            player.CreativeMode = (flags & 1) != 0;
            Console.WriteLine("Godmode is {0}, flymode is {1}, flying is {2}, creative is {3}", player.GodMode, player.FlyingAllowed, player.IsFlying, player.CreativeMode);
            player.FlySpeed = flySpeed;
            player.WalkSpeed = walkSpeed;

            using (var packet = new PacketWriter(SendOpcode.PlayerAbility))
            {
                packet.Write(flags);
                packet.Write(flySpeed);
                packet.Write(walkSpeed);
                client.Send(packet);
            }
        }
Example #8
0
 public static async Task HandlePlayerLook(Client client, PacketReader reader)
 {
     await SetView(client, reader);
     await SetOnGround(client, reader);
 }
Example #9
0
 public static async Task HandlePlayerPosition(Client client, PacketReader reader)
 {
     await SetPosition(client, reader);
     await SetOnGround(client, reader);
 }
Example #10
0
 public static async Task HandlePlayerGround(Client client, PacketReader reader)
 {
     await SetOnGround(client, reader);
     //Console.WriteLine("Client flying: {0}", !ground);
 }
Example #11
0
 private static async Task SetView(Client client, PacketReader reader)
 {
     float yaw = await reader.ReadFloat();
     float pitch = await reader.ReadFloat();
     client.Player.SetView(yaw, pitch);
 }
Example #12
0
 private static async Task SetOnGround(Client client, PacketReader reader)
 {
     bool ground = await reader.ReadBoolean();
     client.Player.OnGround = ground;
     //Console.WriteLine("Faling is {0}", ground);
 }
Example #13
0
 public static async Task HandleKeepAlive(Client client, PacketReader reader)
 {
     // we don't need the id
     await reader.SkipBytes(4);
 }
Example #14
0
 public static async Task HandleLoginRequest(Client client, PacketReader reader)
 {
     SendLoginInformation(client);
 }