Beispiel #1
0
        private bool CheckForForbiddenPlayfield(PlayerInfo player)
        {
            if (player.permission >= (int)Configuration.Current.FreeTravelPermision)
            {
                return(true);
            }

            var checkplayfield = Configuration.Current.ForbiddenPlayfields.FirstOrDefault(P => P.Name == player.playfield);

            if (checkplayfield == null)
            {
                return(true);
            }

            var faction = FactionData?.factions?.FirstOrDefault(F => F.factionId == player.factionId);

            if (faction.HasValue &&
                checkplayfield.FactionInfo != null &&
                checkplayfield.FactionInfo.Any(F => string.Compare(F.Abbr, faction.Value.abbrev?.Trim(), StringComparison.InvariantCultureIgnoreCase) == 0))
            {
                return(true);
            }

            var checkplayer = checkplayfield.PlayerInfo?.FirstOrDefault(P => P.SteamId == player.steamId);

            if (checkplayer != null)
            {
                if (string.IsNullOrEmpty(checkplayer.Name))
                {
                    checkplayer.Name = player.playerName;
                    Configuration.Save();
                }
                return(true);
            }

            checkplayer = checkplayfield.PlayerInfo?.FirstOrDefault(P => string.Compare(P.Name, player.playerName.Trim(), StringComparison.InvariantCultureIgnoreCase) == 0);
            if (checkplayer != null)
            {
                if (string.IsNullOrEmpty(checkplayer.SteamId))
                {
                    checkplayer.SteamId = player.steamId;
                    Configuration.Save();
                }
                return(true);
            }

            if (string.IsNullOrEmpty(checkplayfield.WarpBackTo))
            {
                if (!PlayerAlerts.TryGetValue(player.steamId, out _))
                {
                    PlayerAlerts.TryAdd(player.steamId,
                                        TaskTools.Intervall(10000, () =>
                    {
                        Request_InGameMessage_SinglePlayer(Timeouts.NoResponse,
                                                           (string.IsNullOrEmpty(checkplayfield.CustomMessage) ? $"Please leave this playfield '{player.playfield}', it is reserved!" : checkplayfield.CustomMessage)
                                                           .ToIdMsgPrio(player.entityId,
                                                                        checkplayfield.MessageType ?? Configuration.Current.MessageType,
                                                                        checkplayfield.RepeatSeconds ?? Configuration.Current.RepeatSeconds));
                        CheckPlayerLocation(player.entityId).Wait();
                    })
                                        );
                }

                return(false);
            }

            return(false);
        }