2017-04-24 21:04:52 +00:00
|
|
|
|
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-04-24 21:04:52 +00:00
|
|
|
|
|
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() {
|
2017-09-12 20:59:55 +00:00
|
|
|
|
if((DateTime.UtcNow - ConnectionOpened).TotalSeconds > 60) {
|
2017-05-12 21:05:18 +00:00
|
|
|
|
Disconnect(Frame.kClosingReason.ProtocolError, "Logon request timed out.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnReceive(byte[] data) {
|
2017-08-18 21:01:11 +00:00
|
|
|
|
Packet packet = Packet.FromBytes(data);
|
2017-05-30 17:44:27 +00:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-18 21:01:11 +00:00
|
|
|
|
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());
|
|
|
|
|
}
|
2017-04-24 21:04:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|