public override void handleDisconnects() { double currentTimestamp = (DateTime.Now - DateTime.MinValue).TotalMilliseconds; foreach (MasterServerQTClient client in clients.ToList()) { if (currentTimestamp - client.lastHeartbeatTimestamp > ServerSettings.instance.heartbeatTimeout) { manager.onClientDisconnected(client); } if (currentTimestamp - lastHeartbeatRequest > ServerSettings.instance.heartbeatRate) { RequestHeartbeatMessage message = new RequestHeartbeatMessage(); message.createdTimestamp = currentTimestamp; message.onResponse += (QTResponsableMessage message) => { double currentTimestamp = (DateTime.Now - DateTime.MinValue).TotalMilliseconds; client.lastHeartbeatTimestamp = currentTimestamp; }; client.sendMessage(message); } } if (currentTimestamp - lastHeartbeatRequest > ServerSettings.instance.heartbeatRate) { lastHeartbeatRequest = currentTimestamp; } }
public void handleMessage(QTMessage message) { switch (message.messageType) { case QTMessage.type.REQUEST_HEARTBEAT: double currentTimestamp = (DateTime.Now - DateTime.MinValue).TotalMilliseconds; RequestHeartbeatMessage requestMessage = (RequestHeartbeatMessage)message; HeartbeatMessage heartbeatMessage = new HeartbeatMessage(requestMessage); heartbeatMessage.serverTimestamp = ((RequestHeartbeatMessage)message).createdTimestamp; heartbeatMessage.createdTimestamp = currentTimestamp; sendMessage(heartbeatMessage); break; case QTMessage.type.ROOM_INFO: RoomInfoMessage infoMessage = (RoomInfoMessage)message; WorkerServerManager.instance.room = infoMessage.room; WorkerInfoMessage workerMessage = new WorkerInfoMessage(); workerMessage.id = WorkerServerManager.instance.room.id; workerMessage.ip = "127.0.0.1"; sendMessage(workerMessage); QTDebugger.instance.debug(QTDebugger.debugType.BASE, "Sending worker info message..."); break; } }
public void handleMessage(QTMessage message) { switch (message.messageType) { case QTMessage.type.REQUEST_HEARTBEAT: double currentTimestamp = (DateTime.Now - DateTime.MinValue).TotalMilliseconds; RequestHeartbeatMessage requestMessage = (RequestHeartbeatMessage)message; HeartbeatMessage heartbeatMessage = new HeartbeatMessage(requestMessage); heartbeatMessage.serverTimestamp = ((RequestHeartbeatMessage)message).createdTimestamp; heartbeatMessage.createdTimestamp = currentTimestamp; sendMessage(heartbeatMessage); break; } }