Solved some code errors (variable namings)

This commit is contained in:
Robin Kanters 2015-05-08 23:58:16 +02:00
parent c3f55df77a
commit 23ea9aa267

View File

@ -4,7 +4,6 @@ using System.Linq;
using TrueCraft.API.Server;
using TrueCraft.API.Networking;
using TrueCraft.Core.Networking.Packets;
using TrueCraft.API.Logging;
using TrueCraft.API;
using TrueCraft.Core.Entities;
@ -12,58 +11,58 @@ namespace TrueCraft.Handlers
{
internal static class LoginHandlers
{
public static void HandleHandshakePacket(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
public static void HandleHandshakePacket(IPacket packet, IRemoteClient client, IMultiplayerServer server)
{
var packet = (HandshakePacket)_packet;
var client = (RemoteClient)_client;
client.Username = packet.Username;
client.QueuePacket(new HandshakeResponsePacket("-")); // TODO: Implement some form of authentication
var handshakePacket = (HandshakePacket) packet;
var remoteClient = (RemoteClient)client;
remoteClient.Username = handshakePacket.Username;
remoteClient.QueuePacket(new HandshakeResponsePacket("-")); // TODO: Implement some form of authentication
}
public static void HandleLoginRequestPacket(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
public static void HandleLoginRequestPacket(IPacket packet, IRemoteClient client, IMultiplayerServer server)
{
var packet = (LoginRequestPacket)_packet;
var client = (RemoteClient)_client;
if (packet.ProtocolVersion < server.PacketReader.ProtocolVersion)
client.QueuePacket(new DisconnectPacket("Client outdated! Use beta 1.7.3."));
else if (packet.ProtocolVersion > server.PacketReader.ProtocolVersion)
client.QueuePacket(new DisconnectPacket("Server outdated! Use beta 1.7.3."));
var loginRequestPacket = (LoginRequestPacket)packet;
var remoteClient = (RemoteClient)client;
if (loginRequestPacket.ProtocolVersion < server.PacketReader.ProtocolVersion)
remoteClient.QueuePacket(new DisconnectPacket("Client outdated! Use beta 1.7.3."));
else if (loginRequestPacket.ProtocolVersion > server.PacketReader.ProtocolVersion)
remoteClient.QueuePacket(new DisconnectPacket("Server outdated! Use beta 1.7.3."));
else if (server.Worlds.Count == 0)
client.QueuePacket(new DisconnectPacket("Server has no worlds configured."));
else if (!PlayerIsWhitelisted(client, server) && PlayerIsBlacklisted(client, server))
client.QueuePacket(new DisconnectPacket("You're banned from this server"));
remoteClient.QueuePacket(new DisconnectPacket("Server has no worlds configured."));
else if (!PlayerIsWhitelisted(remoteClient, server) && PlayerIsBlacklisted(remoteClient, server))
remoteClient.QueuePacket(new DisconnectPacket("You're banned from this server"));
else
{
client.LoggedIn = true;
client.Entity = new PlayerEntity(client.Username);
client.World = server.Worlds[0];
client.ChunkRadius = 2;
remoteClient.LoggedIn = true;
remoteClient.Entity = new PlayerEntity(remoteClient.Username);
remoteClient.World = server.Worlds[0];
remoteClient.ChunkRadius = 2;
if (!client.Load())
client.Entity.Position = client.World.SpawnPoint;
if (!remoteClient.Load())
remoteClient.Entity.Position = remoteClient.World.SpawnPoint;
// Send setup packets
client.QueuePacket(new LoginResponsePacket(0, 0, Dimension.Overworld));
client.UpdateChunks();
client.QueuePacket(new WindowItemsPacket(0, client.Inventory.GetSlots()));
client.QueuePacket(new SpawnPositionPacket((int)client.Entity.Position.X,
(int)client.Entity.Position.Y, (int)client.Entity.Position.Z));
client.QueuePacket(new SetPlayerPositionPacket(client.Entity.Position.X,
client.Entity.Position.Y + 1,
client.Entity.Position.Y + client.Entity.Size.Height + 1,
client.Entity.Position.Z, client.Entity.Yaw, client.Entity.Pitch, true));
client.QueuePacket(new TimeUpdatePacket(client.World.Time));
remoteClient.QueuePacket(new LoginResponsePacket(0, 0, Dimension.Overworld));
remoteClient.UpdateChunks();
remoteClient.QueuePacket(new WindowItemsPacket(0, remoteClient.Inventory.GetSlots()));
remoteClient.QueuePacket(new SpawnPositionPacket((int)remoteClient.Entity.Position.X,
(int)remoteClient.Entity.Position.Y, (int)remoteClient.Entity.Position.Z));
remoteClient.QueuePacket(new SetPlayerPositionPacket(remoteClient.Entity.Position.X,
remoteClient.Entity.Position.Y + 1,
remoteClient.Entity.Position.Y + remoteClient.Entity.Size.Height + 1,
remoteClient.Entity.Position.Z, remoteClient.Entity.Yaw, remoteClient.Entity.Pitch, true));
remoteClient.QueuePacket(new TimeUpdatePacket(remoteClient.World.Time));
// Start housekeeping for this client
var entityManager = server.GetEntityManagerForWorld(client.World);
entityManager.SpawnEntity(client.Entity);
entityManager.SendEntitiesToClient(client);
server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(10), client.SendKeepAlive);
server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(1), client.ExpandChunkRadius);
var entityManager = server.GetEntityManagerForWorld(remoteClient.World);
entityManager.SpawnEntity(remoteClient.Entity);
entityManager.SendEntitiesToClient(remoteClient);
server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(10), remoteClient.SendKeepAlive);
server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(1), remoteClient.ExpandChunkRadius);
if (!string.IsNullOrEmpty(Program.Configuration.MOTD))
client.SendMessage(Program.Configuration.MOTD);
server.SendMessage(ChatColor.Yellow + "{0} joined the server.", client.Username);
remoteClient.SendMessage(Program.Configuration.MOTD);
server.SendMessage(ChatColor.Yellow + "{0} joined the server.", remoteClient.Username);
}
}