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); } }
public static async void SetCompas(Client client) { using (var packet = new PacketWriter(SendOpcode.SetCompas)) { // TODO: set real compas data int x = 0; int y = 0; int z = 0; packet.Write(x); packet.Write(y); packet.Write(z); client.Send(packet); } }
public static void SendTestChunk(Client client, int x, int y, byte type, byte metaData) { bool groundUp = true; ushort bitmap = 15; ushort addbitmap = 0; List<byte> data = new List<byte>(); // add 4096 dirt blocks for (int i = 0; i < 4096; i++) { data.Add(type); } // add metadata for (int i = 0; i < 2048; i++) { data.Add(metaData); } // add light for (int i = 0; i < 2048; i++) { data.Add(0xFF); } // addArray for (int i = 0; i < 2048; i++) { data.Add(0x00); } byte[] compressedData = ZlibStream.CompressBuffer(data.ToArray()); using (var packet = new PacketWriter(SendOpcode.ChunkData)) { packet.Write(x/16); packet.Write(y/16); packet.Write(groundUp); packet.Write(bitmap); packet.Write(addbitmap); packet.Write(compressedData.Length); packet.Write(compressedData); client.Send(packet); } }
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? } }
public static async void TestSpawn(Client client) { // Temp code to test chunks ChunkTest.SendTestChunk(client, 0, 0, 0x03, 0xAA); ChunkTest.SendTestChunk(client, -16, 0, 0x03, 0xAA); ChunkTest.SendTestChunk(client, 0, -16, 0x03, 0xAA); ChunkTest.SendTestChunk(client, -16, -16, 0x03, 0xAA); SetCompas(client); using (var packet = new PacketWriter(SendOpcode.PlayerPosition)) { Player player = client.Player; packet.Write(8d); packet.Write(100d); packet.Write(0.0d); packet.Write(8d); packet.Write(0.0f); packet.Write(0.0f); packet.Write(false); client.Send(packet); } }
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); } }
private static async void SendLoginInformation(Client client) { using (var packet = new PacketWriter(SendOpcode.Login)) { uint entityID = 4432; // TODO: make dynamic string levelType = "default"; byte gameMode = 1; byte dimension = 0; byte difficulty = 2; byte maxPlayers = Server.MaxPlayers; packet.Write(entityID); packet.WriteString(levelType); packet.Write(gameMode); packet.Write(dimension); packet.Write(difficulty); // unused byte packet.Write((byte)0); packet.Write(maxPlayers); client.Send(packet); } WorldHandler.TestSpawn(client); }
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); } }