2025-03-09 23:29:20 +03:00
using Content.Server.GameTicking ;
using Content.Shared.CCVar ;
2025-05-21 21:06:44 +03:00
using Robust.Server ;
2025-03-09 23:29:20 +03:00
using Robust.Shared.Audio ;
using Robust.Shared.Console ;
namespace Content.Server._CP14.RoundEnd ;
public sealed partial class CP14RoundEndSystem
{
[Dependency] private readonly IConsoleHost _consoleHost = default ! ;
[Dependency] private readonly GameTicker _ticker = default ! ;
2025-05-21 21:06:44 +03:00
[Dependency] private readonly IBaseServer _baseServer = default ! ;
2025-03-09 23:29:20 +03:00
private TimeSpan _nextUpdateTime = TimeSpan . Zero ;
2025-05-21 21:06:44 +03:00
private readonly TimeSpan _updateFrequency = TimeSpan . FromSeconds ( 50f ) ;
2025-03-09 23:29:20 +03:00
private bool _enabled ;
private void InitCbt ( )
{
2025-04-15 23:09:49 +03:00
_enabled = _cfg . GetCVar ( CCVars . CP14ClosedBetaTest ) ;
_cfg . OnValueChanged ( CCVars . CP14ClosedBetaTest ,
_ = > { _enabled = _cfg . GetCVar ( CCVars . CP14ClosedBetaTest ) ; } ,
true ) ;
2025-03-09 23:29:20 +03:00
}
// Вы можете сказать: Эд, ты ебанулся? Это же лютый щиткод!
2025-05-21 21:06:44 +03:00
// И я вам отвечу: Да. Н о сама система ограничения времени работы сервера - временная штука на этап разработки, которая будет удалена.
// Мне просто лень каждый раз запускать и выключать сервер ручками.
2025-03-09 23:29:20 +03:00
private void UpdateCbt ( float _ )
{
2025-04-15 23:09:49 +03:00
if ( ! _enabled | | _timing . CurTime < _nextUpdateTime )
2025-03-09 23:29:20 +03:00
return ;
_nextUpdateTime = _timing . CurTime + _updateFrequency ;
2025-04-15 23:09:49 +03:00
var now = DateTime . UtcNow . AddHours ( 3 ) ; // Moscow time
2025-03-09 23:29:20 +03:00
2025-05-21 21:06:44 +03:00
OpenSaturdayRule ( now ) ;
LanguageRule ( now ) ;
2025-04-15 23:09:49 +03:00
LimitPlaytimeRule ( now ) ;
ApplyAnnouncements ( now ) ;
}
2025-05-21 21:06:44 +03:00
private void OpenSaturdayRule ( DateTime now )
2025-04-15 23:09:49 +03:00
{
var curWhitelist = _cfg . GetCVar ( CCVars . WhitelistEnabled ) ;
2025-05-21 21:06:44 +03:00
var isOpenWeened = now . DayOfWeek is DayOfWeek . Saturday ;
2025-03-09 23:29:20 +03:00
2025-04-15 23:09:49 +03:00
if ( isOpenWeened & & curWhitelist )
2025-03-09 23:29:20 +03:00
{
2025-04-15 23:09:49 +03:00
_cfg . SetCVar ( CCVars . WhitelistEnabled , false ) ;
}
else if ( ! isOpenWeened & & ! curWhitelist )
{
_cfg . SetCVar ( CCVars . WhitelistEnabled , true ) ;
}
}
2025-03-09 23:29:20 +03:00
2025-05-21 21:06:44 +03:00
private void LanguageRule ( DateTime now )
2025-04-15 23:09:49 +03:00
{
var curLang = _cfg . GetCVar ( CCVars . Language ) ;
2025-05-22 14:53:46 +03:00
var ruHalfDay = now . Hour < 19 & & now . Hour > = 9 ;
2025-05-21 21:06:44 +03:00
if ( ruHalfDay & & curLang ! = "ru-RU" )
2025-04-15 23:09:49 +03:00
{
2025-05-21 21:06:44 +03:00
_cfg . SetCVar ( CCVars . Language , "ru-RU" ) ;
2025-04-15 23:09:49 +03:00
_chatSystem . DispatchGlobalAnnouncement (
2025-05-21 21:06:44 +03:00
"WARNING: The server changes its language to Russian. For the changes to apply to your device, reconnect to the server." ,
2025-04-15 23:09:49 +03:00
announcementSound : new SoundPathSpecifier ( "/Audio/Effects/beep1.ogg" ) ,
sender : "Server"
) ;
}
2025-05-21 21:06:44 +03:00
else if ( ! ruHalfDay & & curLang ! = "en-US" )
2025-04-15 23:09:49 +03:00
{
2025-05-21 21:06:44 +03:00
_cfg . SetCVar ( CCVars . Language , "en-US" ) ;
2025-04-15 23:09:49 +03:00
_chatSystem . DispatchGlobalAnnouncement (
2025-05-21 21:06:44 +03:00
"WARNING: The server changes its language to English. For the changes to apply to your device, reconnect to the server." ,
2025-04-15 23:09:49 +03:00
announcementSound : new SoundPathSpecifier ( "/Audio/Effects/beep1.ogg" ) ,
sender : "Server"
) ;
}
}
private void LimitPlaytimeRule ( DateTime now )
{
2025-05-21 21:06:44 +03:00
var playtime = ( now . Hour is > = 15 and < 19 ) | | ( now . Hour is > = 20 and < 24 ) ;
2025-04-15 23:09:49 +03:00
if ( playtime )
{
if ( _ticker . Paused )
2025-03-09 23:29:20 +03:00
_ticker . TogglePause ( ) ;
}
else
{
2025-04-15 23:09:49 +03:00
if ( _ticker . RunLevel = = GameRunLevel . InRound )
_roundEnd . EndRound ( ) ;
if ( ! _ticker . Paused )
2025-03-09 23:29:20 +03:00
_ticker . TogglePause ( ) ;
}
2025-04-15 23:09:49 +03:00
}
2025-03-09 23:29:20 +03:00
2025-04-15 23:09:49 +03:00
private void ApplyAnnouncements ( DateTime now )
{
var timeMap = new ( int Hour , int Minute , Action Action ) [ ]
2025-03-09 23:29:20 +03:00
{
2025-05-21 21:06:44 +03:00
( 18 , 45 , ( ) = >
{
_chatSystem . DispatchGlobalAnnouncement (
Loc . GetString ( "cp14-cbt-close-15m" ) ,
announcementSound : new SoundPathSpecifier ( "/Audio/Effects/beep1.ogg" ) ,
sender : "Server"
) ;
} ) ,
( 19 , 2 , ( ) = >
{
_baseServer . Shutdown ( "Русский ОБТ подошел к концу. Следующие 3 часа будет английский ОБТ. Просьба не мешать англоязычным ребятам играть в свое время :)" ) ;
} ) ,
( 23 , 45 , ( ) = >
2025-04-15 23:09:49 +03:00
{
_chatSystem . DispatchGlobalAnnouncement (
Loc . GetString ( "cp14-cbt-close-15m" ) ,
announcementSound : new SoundPathSpecifier ( "/Audio/Effects/beep1.ogg" ) ,
sender : "Server"
) ;
} ) ,
2025-05-21 21:06:44 +03:00
( 00 , 2 , ( ) = >
2025-04-15 23:09:49 +03:00
{
_consoleHost . ExecuteCommand ( "golobby" ) ;
} ) ,
} ;
foreach ( var ( hour , minute , action ) in timeMap )
2025-03-09 23:29:20 +03:00
{
2025-04-15 23:09:49 +03:00
if ( now . Hour = = hour & & now . Minute = = minute )
action . Invoke ( ) ;
2025-03-09 23:29:20 +03:00
}
}
}