private Player( [NotNull] TcpClient tcpClient )
{
if ( tcpClient == null )
throw new ArgumentNullException( "tcpClient" );
State = SessionState.Connecting;
LoginTime = DateTime.UtcNow;
LastActiveTime = DateTime.UtcNow;
LastPatrolTime = DateTime.UtcNow;
LeaveReason = LeaveReason.Unknown;
LastUsedBlockType = Block.Undefined;
client = tcpClient;
client.SendTimeout = SocketTimeout;
client.ReceiveTimeout = SocketTimeout;
Brush = NormalBrushFactory.Instance;
Metadata = new MetadataCollection<object>();
try {
IP = ( ( IPEndPoint )( client.Client.RemoteEndPoint ) ).Address;
if ( Server.RaiseSessionConnectingEvent( IP ) )
return;
stream = client.GetStream();
reader = new BinaryReader( stream );
writer = new PacketWriter( stream );
ioThread = new Thread( IoLoop ) {
Name = "800Craft.Session",
IsBackground = true
};
ioThread.Start();
} catch ( SocketException ) {
// Mono throws SocketException when accessing Client.RemoteEndPoint on disconnected sockets
Disconnect();
} catch ( Exception ex ) {
Logger.LogAndReportCrash( "Session failed to start", "800Craft", ex, false );
Disconnect();
}
}