2015-05-12 17:30:56 -06:00
|
|
|
|
using System;
|
|
|
|
|
using TrueCraft.API.Networking;
|
|
|
|
|
using TrueCraft.Core.Networking.Packets;
|
|
|
|
|
using TrueCraft.Core.Networking;
|
2015-05-16 21:50:10 -06:00
|
|
|
|
using TrueCraft.Client.Events;
|
2015-05-13 16:26:23 -06:00
|
|
|
|
using TrueCraft.API;
|
2015-05-17 16:52:16 -06:00
|
|
|
|
using System.Diagnostics;
|
2015-05-12 17:30:56 -06:00
|
|
|
|
|
2015-05-16 21:50:10 -06:00
|
|
|
|
namespace TrueCraft.Client.Handlers
|
2015-05-12 17:30:56 -06:00
|
|
|
|
{
|
|
|
|
|
internal static class PacketHandlers
|
|
|
|
|
{
|
|
|
|
|
public static void RegisterHandlers(MultiplayerClient client)
|
|
|
|
|
{
|
|
|
|
|
client.RegisterPacketHandler(new HandshakeResponsePacket().ID, HandleHandshake);
|
2015-05-13 11:30:29 -06:00
|
|
|
|
client.RegisterPacketHandler(new ChatMessagePacket().ID, HandleChatMessage);
|
2015-05-13 16:26:23 -06:00
|
|
|
|
client.RegisterPacketHandler(new SetPlayerPositionPacket().ID, HandlePositionAndLook);
|
2015-05-17 16:18:09 -06:00
|
|
|
|
client.RegisterPacketHandler(new LoginResponsePacket().ID, HandleLoginResponse);
|
2015-05-13 14:20:35 -06:00
|
|
|
|
|
|
|
|
|
client.RegisterPacketHandler(new ChunkPreamblePacket().ID, ChunkHandler.HandleChunkPreamble);
|
|
|
|
|
client.RegisterPacketHandler(new ChunkDataPacket().ID, ChunkHandler.HandleChunkData);
|
2015-05-29 18:20:24 -06:00
|
|
|
|
client.RegisterPacketHandler(new BlockChangePacket().ID, ChunkHandler.HandleBlockChange);
|
2015-05-13 11:30:29 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void HandleChatMessage(IPacket _packet, MultiplayerClient client)
|
|
|
|
|
{
|
|
|
|
|
var packet = (ChatMessagePacket)_packet;
|
|
|
|
|
client.OnChatMessage(new ChatMessageEventArgs(packet.Message));
|
2015-05-12 17:30:56 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void HandleHandshake(IPacket _packet, MultiplayerClient client)
|
|
|
|
|
{
|
|
|
|
|
var packet = (HandshakeResponsePacket)_packet;
|
2015-05-17 16:52:16 -06:00
|
|
|
|
if (packet.ConnectionHash != "-")
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Online mode is not supported");
|
|
|
|
|
Process.GetCurrentProcess().Kill();
|
|
|
|
|
}
|
|
|
|
|
// TODO: Authentication
|
2015-05-30 16:45:43 -06:00
|
|
|
|
client.QueuePacket(new LoginRequestPacket(PacketReader.Version, client.User.Username));
|
2015-05-12 17:30:56 -06:00
|
|
|
|
}
|
2015-05-13 16:26:23 -06:00
|
|
|
|
|
2015-05-17 16:18:09 -06:00
|
|
|
|
public static void HandleLoginResponse(IPacket _packet, MultiplayerClient client)
|
|
|
|
|
{
|
|
|
|
|
client.QueuePacket(new PlayerGroundedPacket());
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-13 16:26:23 -06:00
|
|
|
|
public static void HandlePositionAndLook(IPacket _packet, MultiplayerClient client)
|
|
|
|
|
{
|
|
|
|
|
var packet = (SetPlayerPositionPacket)_packet;
|
|
|
|
|
client._Position = new Vector3(packet.X, packet.Y, packet.Z);
|
2015-05-17 16:18:09 -06:00
|
|
|
|
client.QueuePacket(packet);
|
|
|
|
|
client.LoggedIn = true;
|
2015-05-13 16:26:23 -06:00
|
|
|
|
// TODO: Pitch and yaw
|
|
|
|
|
}
|
2015-05-12 17:30:56 -06:00
|
|
|
|
}
|
|
|
|
|
}
|