sockscape/server/Socks/PlayerConnection.cs

43 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
2017-06-16 21:00:01 +00:00
using Kneesocks;
2017-07-22 19:27:41 +00:00
using Glove;
using SockScape.Encryption;
2017-07-22 19:27:41 +00:00
namespace SockScape {
2017-06-06 21:13:25 +00:00
class PlayerConnection : Connection {
2017-05-12 21:05:18 +00:00
private DateTime ConnectionOpened;
protected override void OnOpen() {
ConnectionOpened = DateTime.UtcNow;
}
protected override void OnParse() {
if((DateTime.UtcNow - ConnectionOpened).Seconds > 60) {
Disconnect(Frame.kClosingReason.ProtocolError, "Logon request timed out.");
}
}
protected override void OnReceive(byte[] data) {
Packet packet = Packet.FromBytes(data);
2017-08-16 21:01:08 +00:00
if(packet == null) {
2017-05-25 21:08:21 +00:00
Disconnect(Frame.kClosingReason.ProtocolError, "Packet received was not legal.");
return;
}
switch((kClientServerId)packet.Id) {
2017-05-30 21:05:02 +00:00
default:
Disconnect(Frame.kClosingReason.ProtocolError, "Packet ID could not be understood at this time.");
break;
2017-05-25 21:08:21 +00:00
}
2017-05-12 21:05:18 +00:00
Console.WriteLine(Id + " says " + data.GetString());
}
}
}