internal void Tick(double time) { this.listenSocket.Pump(); double dt = time - this.time; this.time = time; // send keep alive to clients 10 times per second keepAlive += dt; while (keepAlive >= 0.1) { keepAlive -= 0.1; for (int i = 0; i < clientSlots.Length; i++) { if (clientSlots[i] != null) { sendKeepAlive(clientSlots[i]); } } } // disconnect any clients which have not responded for timeout seconds for (int i = 0; i < clientSlots.Length; i++) { if (clientSlots[i] == null) { continue; } double timeRemaining = time - clientSlots[i].lastResponseTime; // timeout < 0 disables timeouts if (clientSlots[i].timeoutSeconds >= 0 && (time - clientSlots[i].lastResponseTime) >= clientSlots[i].timeoutSeconds) { if (OnClientDisconnected != null) { OnClientDisconnected(clientSlots[i]); } log("Client {0} timed out", NetcodeLogLevel.Debug, clientSlots[i].RemoteEndpoint.ToString()); disconnectClient(clientSlots[i]); } } // process datagram queue Datagram packet; while (listenSocket != null && listenSocket.Read(out packet)) { processDatagram(packet.payload, packet.payloadSize, packet.sender); packet.Release(); } }
public void Tick(double time) { if (this.socket == null) { return; } this.socket.Pump(); this.dt = time - this.time; this.time = time; // process buffered packets Datagram datagram; while (socket != null && socket.Read(out datagram)) { processDatagram(datagram); datagram.Release(); } // process current state switch (state) { case ClientState.SendingConnectionRequest: sendingConnectionRequest(); break; case ClientState.SendingChallengeResponse: sendingChallengeResponse(); break; case ClientState.Connected: connected(); break; } }