in UnityProject/Assets/Scripts/Server/Server.cs [206:257]
void FixedUpdate()
{
// 1. If we're waiting for termination, only check if all containers in this Task are done
if (this.waitingForTermination)
{
this.HandleWaitingForTermination();
return;
}
// 2. Otherwise run regular update
// Update the Network server to check client status and get messages
server.Update();
// Process any messages we received
this.ProcessMessages();
// Move players based on latest input and update player states to clients
for (int i = 0; i < this.players.Count; i++)
{
var player = this.players[i];
// Move
player.Move();
// Send state if changed
var positionMessage = player.GetPositionMessage();
if (positionMessage != null)
{
positionMessage.clientId = player.GetPlayerId();
this.server.TransmitMessage(positionMessage, player.GetPlayerId());
//Send to the player him/herself
positionMessage.messageType = MessageType.PositionOwn;
this.server.SendMessage(player.GetPlayerId(), positionMessage);
}
}
// Update the server state to Redis every 30 seconds with a 60 second expiration. This will also get done when new clients connect
this.redisUpdateCounter += Time.fixedDeltaTime;
if(this.redisUpdateCounter > Server.redisUpdateIntervalSeconds && this.taskDataArnWithContainer != null)
{
this.UpdateRedis();
this.redisUpdateCounter = 0.0f;
}
// If a new player joined, update Redis as well
if(this.server.GetPlayerCount() > this.lastPlayerCount)
{
Debug.Log("New player joined, update Redis");
this.UpdateRedis();
this.lastPlayerCount = this.server.GetPlayerCount();
}
}