public void Stop() { Socket socket = this._socket; lock (this._receivedDatas) { if (this._socket == null) { return; } this._socket = null; this._receivedDatas.Clear(); while (this._tokenManager.count > 0) { TCPUserToken token = this._tokenManager[0]; this.OnSocketEvent?.Invoke(new SocketEvent(SocketEvent.Type.Disconnect, "Server stoped", SocketError.Shutdown, token)); token.OnDespawn(); this._rpcManager.OnUserTokenDespawn(token); this._tokenManager.Destroy(0); } } if (socket.Connected) { socket.Shutdown(SocketShutdown.Both); } socket.Close(); }
public void Update(long dt) { this._updateContext.deltaTime = dt; this._updateContext.time += dt; this.ProcessReceiveDatas(); this.CheckClientOverRange(); int count = this._tokenManager.count; for (int i = 0; i < count; i++) { TCPUserToken token = this._tokenManager[i]; if (token.disconnectEvent == null) { continue; } this.OnSocketEvent?.Invoke(token.disconnectEvent.Value); token.OnDespawn(); this._rpcManager.OnUserTokenDespawn(token); this._tokenManager.Destroy(i); --i; --count; } if (this._closeEvent != null) { this.OnSocketEvent?.Invoke(this._closeEvent.Value); this._closeEvent = null; this.Stop(); } }