public static void ServerSetRaidingWindow(DayTimeInterval newWindowUTC)
        {
            if (newWindowUTC.DurationHours <= 0 ||
                newWindowUTC.DurationHours > 24)
            {
                // full day raiding - disable raiding protection
                newWindowUTC = new DayTimeInterval(fromHour: newWindowUTC.FromHour,
                                                   toHour: newWindowUTC.FromHour + 24);
            }

            if (ServerRaidingWindowUTC.Equals(newWindowUTC))
            {
                return;
            }

            ServerRaidingWindowUTC = newWindowUTC;
            Server.Database.Set(nameof(RaidingProtectionSystem),
                                DatabaseKeyRaidingWindowUTC,
                                ServerRaidingWindowUTC);
            Logger.Important($"Set raiding window: {ServerRaidingWindowUTC} (UTC time)");

            var allCharacters = Server.Characters.EnumerateAllPlayerCharacters(onlyOnline: true,
                                                                               exceptSpectators: false);

            Instance.CallClient(allCharacters,
                                _ => _.ClientRemote_RaidingWindowInfo(ServerRaidingWindowUTC));
        }
        private void ClientRemote_RaidingWindowInfo(DayTimeInterval gameDayTimeInterval)
        {
            Logger.Important($"Received raiding window: {gameDayTimeInterval} (UTC time)");

            ClientRaidingWindowUTC = gameDayTimeInterval;
            if (ClientRaidingWindowChanged != null)
            {
                Api.SafeInvoke(ClientRaidingWindowChanged);
            }
        }
 public override void ServerInitialize(IServerConfiguration serverConfiguration)
 {
     if (Server.Database.TryGet(nameof(RaidingProtectionSystem),
                                DatabaseKeyRaidingWindowUTC,
                                out DayTimeInterval window))
     {
         ServerRaidingWindowUTC = window;
         Logger.Important($"Loaded raiding window: {ServerRaidingWindowUTC} (UTC time)");
     }
     else
     {
         // no raiding window - unrestricted raiding hours
         ServerRaidingWindowUTC = new DayTimeInterval(0, 24);
     }
 }
Пример #4
0
        public string Execute(double UTC, double fromHour, double duration)
        {
            UTC      %= 24;
            fromHour %= 24;
            if (duration > 24)
            {
                duration = 24;
            }

            var window = new DayTimeInterval(fromHour - UTC,
                                             fromHour - UTC + duration);

            RaidingProtectionSystem.ServerSetRaidingWindow(window);
            return("Server raiding window set. Please check Politics/Diplomacy menu!");
        }