Implement keep alive

This prevents clients from disconnecting after a while.
This commit is contained in:
Drew DeVault 2014-12-27 22:53:22 -07:00
parent 4d3d5ee8e0
commit adf3304f14
3 changed files with 14 additions and 1 deletions

View File

@ -41,6 +41,7 @@ namespace TrueCraft.Handlers
client.QueuePacket(new SpawnPositionPacket(0, 16, 0));
client.QueuePacket(new SetPlayerPositionPacket(0, 16, 17, 0, 0, 0, true));
client.QueuePacket(new ChatMessagePacket(string.Format("Welcome to the server, {0}!", client.Username)));
server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(10), client.SendKeepAlive);
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using TrueCraft.API.Server;
using TrueCraft.Core.Networking.Packets;
using TrueCraft.API.Networking;
namespace TrueCraft.Handlers
{
@ -11,5 +12,10 @@ namespace TrueCraft.Handlers
server.RegisterPacketHandler(new HandshakePacket().ID, LoginHandlers.HandleHandshakePacket);
server.RegisterPacketHandler(new LoginRequestPacket().ID, LoginHandlers.HandleLoginRequestPacket);
}
internal static void HandleKeepAlive(IPacket _packet, IRemoteClient _client, IMultiplayerServer server)
{
// TODO
}
}
}

View File

@ -51,6 +51,12 @@ namespace TrueCraft
PacketQueue.Enqueue(packet);
}
internal void SendKeepAlive(IMultiplayerServer server)
{
QueuePacket(new KeepAlivePacket());
server.Scheduler.ScheduleEvent(DateTime.Now.AddSeconds(10), SendKeepAlive);
}
internal void UpdateChunks()
{
var newChunks = new List<Coordinates2D>();
@ -106,7 +112,7 @@ namespace TrueCraft
LoadedChunks.Remove(position);
}
public static ChunkDataPacket CreatePacket(IChunk chunk)
private static ChunkDataPacket CreatePacket(IChunk chunk)
{
// TODO: Be smarter about this
var X = chunk.Coordinates.X;