Ejemplo n.º 1
0
        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)
            {
                KCPUserToken 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);
            }

            socket.Shutdown(SocketShutdown.Both);
            socket.Close();
        }
Ejemplo n.º 2
0
        public void Update(long dt)
        {
            this._updateContext.deltaTime = dt;
            this._updateContext.time     += dt;

            this.ProcessReceiveDatas();
            this.CheckClientOverRange();
            this.CheckClientAlive();
            this.UpdateClients();

            int count = this._tokenManager.count;

            for (int i = 0; i < count; i++)
            {
                KCPUserToken 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();
            }
        }