GameTicker.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using Content.Server.Administration.Logs;
  2. using Content.Server.Administration.Managers;
  3. using Content.Server.Chat.Managers;
  4. using Content.Server.Chat.Systems;
  5. using Content.Server.Database;
  6. using Content.Server.Ghost;
  7. using Content.Server.Maps;
  8. using Content.Server.Players.PlayTimeTracking;
  9. using Content.Server.Preferences.Managers;
  10. using Content.Server.ServerUpdates;
  11. using Content.Server.Station.Systems;
  12. using Content.Shared.Chat;
  13. using Content.Shared.GameTicking;
  14. using Content.Shared.Mind;
  15. using Content.Shared.Roles;
  16. using Robust.Server;
  17. using Robust.Server.GameObjects;
  18. using Robust.Server.GameStates;
  19. using Robust.Shared.Audio.Systems;
  20. using Robust.Shared.Console;
  21. using Robust.Shared.EntitySerialization.Systems;
  22. using Robust.Shared.Map;
  23. using Robust.Shared.Prototypes;
  24. using Robust.Shared.Random;
  25. using Robust.Shared.Timing;
  26. using Robust.Shared.Utility;
  27. #if EXCEPTION_TOLERANCE
  28. using Robust.Shared.Exceptions;
  29. #endif
  30. namespace Content.Server.GameTicking
  31. {
  32. public sealed partial class GameTicker : SharedGameTicker
  33. {
  34. [Dependency] private readonly IAdminLogManager _adminLogger = default!;
  35. [Dependency] private readonly IBanManager _banManager = default!;
  36. [Dependency] private readonly IBaseServer _baseServer = default!;
  37. [Dependency] private readonly IChatManager _chatManager = default!;
  38. [Dependency] private readonly IConsoleHost _consoleHost = default!;
  39. [Dependency] private readonly IGameMapManager _gameMapManager = default!;
  40. [Dependency] private readonly IGameTiming _gameTiming = default!;
  41. [Dependency] private readonly ILogManager _logManager = default!;
  42. [Dependency] private readonly IMapManager _mapManager = default!;
  43. [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
  44. [Dependency] private readonly IRobustRandom _robustRandom = default!;
  45. #if EXCEPTION_TOLERANCE
  46. [Dependency] private readonly IRuntimeLog _runtimeLog = default!;
  47. #endif
  48. [Dependency] private readonly IServerPreferencesManager _prefsManager = default!;
  49. [Dependency] private readonly IServerDbManager _db = default!;
  50. [Dependency] private readonly ChatSystem _chatSystem = default!;
  51. [Dependency] private readonly MapLoaderSystem _loader = default!;
  52. [Dependency] private readonly SharedMapSystem _map = default!;
  53. [Dependency] private readonly GhostSystem _ghost = default!;
  54. [Dependency] private readonly SharedMindSystem _mind = default!;
  55. [Dependency] private readonly PlayTimeTrackingSystem _playTimeTrackings = default!;
  56. [Dependency] private readonly PvsOverrideSystem _pvsOverride = default!;
  57. [Dependency] private readonly ServerUpdateManager _serverUpdates = default!;
  58. [Dependency] private readonly SharedAudioSystem _audio = default!;
  59. [Dependency] private readonly StationJobsSystem _stationJobs = default!;
  60. [Dependency] private readonly StationSpawningSystem _stationSpawning = default!;
  61. [Dependency] private readonly SharedTransformSystem _transform = default!;
  62. [Dependency] private readonly UserDbDataManager _userDb = default!;
  63. [Dependency] private readonly MetaDataSystem _metaData = default!;
  64. [Dependency] private readonly SharedRoleSystem _roles = default!;
  65. [Dependency] private readonly ServerDbEntryManager _dbEntryManager = default!;
  66. [ViewVariables] private bool _initialized;
  67. [ViewVariables] private bool _postInitialized;
  68. [ViewVariables] public MapId DefaultMap { get; private set; }
  69. private ISawmill _sawmill = default!;
  70. public override void Initialize()
  71. {
  72. base.Initialize();
  73. DebugTools.Assert(!_initialized);
  74. DebugTools.Assert(!_postInitialized);
  75. _sawmill = _logManager.GetSawmill("ticker");
  76. _sawmillReplays = _logManager.GetSawmill("ticker.replays");
  77. // Initialize the other parts of the game ticker.
  78. InitializeStatusShell();
  79. InitializeCVars();
  80. InitializePlayer();
  81. InitializeLobbyBackground();
  82. InitializeGamePreset();
  83. DebugTools.Assert(_prototypeManager.Index<JobPrototype>(FallbackOverflowJob).Name == FallbackOverflowJobName,
  84. "Overflow role does not have the correct name!");
  85. InitializeGameRules();
  86. InitializeReplays();
  87. _initialized = true;
  88. }
  89. public void PostInitialize()
  90. {
  91. DebugTools.Assert(_initialized);
  92. DebugTools.Assert(!_postInitialized);
  93. // We restart the round now that entities are initialized and prototypes have been loaded.
  94. if (!DummyTicker)
  95. RestartRound();
  96. _postInitialized = true;
  97. }
  98. public override void Shutdown()
  99. {
  100. base.Shutdown();
  101. ShutdownGameRules();
  102. }
  103. private void SendServerMessage(string message)
  104. {
  105. var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
  106. _chatManager.ChatMessageToAll(ChatChannel.Server, message, wrappedMessage, default, false, true);
  107. }
  108. public override void Update(float frameTime)
  109. {
  110. if (DummyTicker)
  111. return;
  112. base.Update(frameTime);
  113. UpdateRoundFlow(frameTime);
  114. UpdateGameRules();
  115. }
  116. }
  117. }