private SyncCooldownResponseMessage SyncCooldownResponse(SyncCooldownResponseMessage msg) { int currentTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; // msg.respawnTimes can be null, if the server sent empty list if (msg.RespawnTimes != null) { foreach (var respawnTime in msg.RespawnTimes) { var controllerId = new MyPlayer.PlayerId() { SteamId = MySteam.UserId, SerialId = respawnTime.ControllerId }; var key = new RespawnKey() { ControllerId = controllerId, RespawnShipId = respawnTime.ShipId }; m_globalRespawnTimesMs.Add(key, currentTime + respawnTime.RelativeRespawnTime, immediate: true); } } m_synced = true; return(msg); }
public void SyncCooldownToPlayer(ulong steamId) { int currentTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; m_tmpRespawnTimes.Clear(); foreach (var entry in m_globalRespawnTimesMs) { // Send only those respawn times that concern the given steam player if (entry.Key.ControllerId.SteamId != steamId) { continue; } RespawnCooldownEntry syncEntry = new RespawnCooldownEntry(); syncEntry.ControllerId = entry.Key.ControllerId.SerialId; syncEntry.ShipId = entry.Key.RespawnShipId; syncEntry.RelativeRespawnTime = entry.Value - currentTime; m_tmpRespawnTimes.Add(syncEntry); } SyncCooldownResponseMessage response = new SyncCooldownResponseMessage(); response.RespawnTimes = m_tmpRespawnTimes.ToArray(); Sync.Layer.SendMessage(response, steamId); m_tmpRespawnTimes.Clear(); }
static void OnSyncCooldownResponse(ref SyncCooldownResponseMessage msg, MyNetworkClient sender) { msg = MySpaceRespawnComponent.Static.SyncCooldownResponse(msg); }