Major overall of data
This commit is contained in:
1 parent
64dbd02874
commit
6126b8259c
12 files changed
+160
-126
No files matched your search
@@ -7,12 +7,10 @@ namespace Mistox.Server {
|
||||
public class TCPConnection : IDisposable {
|
||||
|
||||
TcpClient _client;
|
||||
MistoxServer _instance;
|
||||
string _connectionID;
|
||||
|
||||
public TCPConnection( TcpClient tcpClient, MistoxServer ServerInstance, string ConnectionID ) {
|
||||
public TCPConnection( TcpClient tcpClient, string ConnectionID ) {
|
||||
_client = tcpClient;
|
||||
_instance = ServerInstance;
|
||||
_connectionID = ConnectionID;
|
||||
_client.NoDelay = true;
|
||||
|
||||
@@ -22,15 +20,15 @@ namespace Mistox.Server {
|
||||
}
|
||||
|
||||
public async Task ReceiveThread() {
|
||||
while( _client.Connected && _instance.Connections[_connectionID].Connected ) {
|
||||
while( _client.Connected && ServerInterface.Connections[_connectionID].Connected ) {
|
||||
try {
|
||||
_instance.Connections[_connectionID].LastHeartbeat = DateTime.UtcNow;
|
||||
ServerInterface.Connections[_connectionID].LastHeartbeat = DateTime.UtcNow;
|
||||
byte[] StreamData = new byte[1024];
|
||||
int bytesRead = await _client.GetStream().ReadAsync(StreamData, 0, StreamData.Length);
|
||||
if( bytesRead > 0 ) {
|
||||
dynamic data = mSerialize.tReceive( StreamData.Sub( 0, bytesRead ) );
|
||||
if( data != null ) {
|
||||
_instance.onReceived?.Invoke( data, new EventArgs() );
|
||||
ServerInterface.ServerInstance.InvokeOnReceived( data );
|
||||
}
|
||||
}
|
||||
} catch( Exception ) {
|
||||
@@ -46,9 +44,9 @@ namespace Mistox.Server {
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_instance.Connections[_connectionID].Connected = false;
|
||||
_instance.onUserDisconnected?.Invoke( _instance.Connections[_connectionID], new EventArgs() );
|
||||
_instance.Connections.TryRemove( _connectionID, out _ );
|
||||
ServerInterface.Connections[_connectionID].Connected = false;
|
||||
ServerInterface.ServerInstance.InvokeOnUserDisconnected( ServerInterface.Connections[_connectionID] );
|
||||
ServerInterface.Connections.TryRemove( _connectionID, out _ );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user