Пример #1
0
        public void UnbanPlayer(string player, Entity inflictor = null)
        {
            List <string> bannedPlayers = File.ReadAllLines(Config.GetFile("banned_players")).ToList();

            foreach (string ban in bannedPlayers)
            {
                if (ban.Contains(player))
                {
                    File.WriteAllText(Config.GetFile("banned_players"), String.Join("\n", bannedPlayers));
                    WriteLog.Info($"{player} has been unbanned.");

                    if (inflictor == null)
                    {
                        SayToAll(FormatMessage(Config.GetString("unban_message"), new Dictionary <string, string>()
                        {
                            { "target", player },
                            { "instigator", "Nightingale" }
                        }));
                    }
                    else
                    {
                        SayToAll(FormatMessage(Config.GetString("unban_message"), new Dictionary <string, string>()
                        {
                            { "target", player },
                            { "instigator", inflictor.Name }
                        }));
                    }
                }
                else
                {
                    SayToAll(FormatMessage(Config.GetString("unban_entry_not_found"), new Dictionary <string, string>()
                    {
                        { "target", player }
                    }));
                }
            }
        }
Пример #2
0
        public void ProcessCommand(Entity sender, string name, string message, string[] group)
        {
            string commandname = message.Substring(1).Split(' ')[0].ToLowerInvariant();

            WriteLog.Info(sender.Name + " attempted " + commandname);

            Command commandToBeRun;

            commandToBeRun = FindCommand(commandname.ToLower());

            if (commandToBeRun == null)
            {
                SayToPlayer(sender, Config.GetString("unknown_cmd"));
            }
            else if (!group[2].Contains(commandToBeRun.name) && !group[2].Contains("*ALL*"))
            {
                SayToPlayer(sender, "Insufficient privileges.");
                return;
            }
            else
            {
                commandToBeRun.Run(sender, message);
            }
        }
Пример #3
0
        public void OnPlayerConnect(Entity player)
        {
            WriteLog.Info($"{player.Name} connected.");

            string bannedStatus = IsPlayerBanned(player);

            if (bannedStatus != null)
            {
                AfterDelay(2000, () =>
                {
                    if (bannedStatus == "temp")
                    {
                        Utilities.ExecuteCommand($"kickclient {player.EntRef} \"{Config.GetString("tempbanned_message")}\"");
                        WriteLog.Warning($"{player.Name} is banned. Kicked.");
                    }
                    if (bannedStatus == "perm")
                    {
                        Utilities.ExecuteCommand($"kickclient {player.EntRef} \"{Config.GetString("banned_message")}\"");
                        WriteLog.Warning($"{player.Name} is banned. Kicked.");
                    }
                    return;
                });
            }
            if (AntiHacker.HasBadName(player))
            {
                AfterDelay(2000, () => {
                    KickPlayer(player, Config.GetString("bad_name"));
                    WriteLog.Warning($"{player.Name} has been kicked for a bad name.");
                    return;
                });
            }
            if (AntiHacker.HasBadIP(player))
            {
                AfterDelay(2000, () =>
                {
                    KickPlayer(player, Config.GetString("bad_ip"));
                    WriteLog.Warning($"{player.Name} has been kicked for a bad ip (vpn, proxy).");
                    return;
                });
            }
            if (AntiHacker.HasInvalidID(player))
            {
                AfterDelay(2000, () =>
                {
                    KickPlayer(player, Config.GetString("bad_id"));
                    WriteLog.Warning($"{player.Name} has been kicked for a bad id (hwid,guid,uid).");
                    return;
                });
            }



            //Check for config file
            if (File.Exists(Config.GetPath("players") + $"{player.HWID}.dat"))
            {
                string[] options = File.ReadAllLines(Config.GetPath("players") + $"{player.HWID}.dat");
                foreach (string option_ in options)
                {
                    string   optionTrimmed = option_.Trim();
                    string[] option        = optionTrimmed.Split('=');

                    if (option[0] == "OriginalName")
                    {
                        player.SetField(option[0], option[1]);
                    }
                    if (option[0] == "Alias")
                    {
                        player.SetField(option[0], option[1]);
                    }
                    if (option[0] == "GroupName")
                    {
                        player.SetField(option[0], option[1]);
                    }
                    if (option[0] == "Warns")
                    {
                        player.SetField(option[0], Int32.Parse(option[1]));
                    }
                }
            }
            else
            {
                WriteLog.Info($"Writing data to Players/{player.HWID}.dat");
                File.WriteAllText(Config.GetPath("players") + $"{player.HWID}.dat", File.ReadAllText(Config.GetPath("players") + "Default.dat").Replace("<name>", player.Name).Replace("<HWID>", player.HWID).Replace("<GUID>", player.GUID.ToString()).Replace("<XUID>", player.GetXUID()));
                WriteLog.Info($"Done");

                string[] options = File.ReadAllLines(Config.GetPath("players") + $"{player.HWID}.dat");
                foreach (string option_ in options)
                {
                    string   optionTrimmed = option_.Trim();
                    string[] option        = optionTrimmed.Split('=');

                    if (option[0] == "OriginalName")
                    {
                        player.SetField(option[0], option[1]);
                    }
                    if (option[0] == "Alias")
                    {
                        player.SetField(option[0], option[1]);
                    }
                    if (option[0] == "GroupName")
                    {
                        player.SetField(option[0], option[1]);
                    }
                    if (option[0] == "Warns")
                    {
                        player.SetField(option[0], Int32.Parse(option[1]));
                    }
                }
            }

            string[] groupsFile = File.ReadAllLines(Config.GetFile("groups"));
            foreach (string group_ in groupsFile)
            {
                //RankName;RankTag;Commands
                string[] group = group_.Split(';');
                if (group[0] == (string)player.GetField("GroupName"))
                {
                    player.SetField("GroupPrefix", group[1]);
                    player.SetField("GroupAvailableCommands", group[2]);
                }
            }

            if (!((string)player.GetField("Alias") == "None"))
            {
                AfterDelay(3000, () => player.Name = (string)player.GetField("Alias"));
            }

            // Set dvars
            player.SetClientDvar("waypointIconWidth", "0");
            player.SetClientDvar("waypointIconHeight", "0");
            player.SetClientDvar("cg_objectiveText", $"^3This server is powered by ^1Nightingale {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}^3.");
        }
Пример #4
0
        public void InitCommands()
        {
            WriteLog.Info("Initializing commands...");


            CommandList.Add(new Command("help", (sender, args) =>
            {
                string helpMessage = "^3";
                if ((string)sender.GetField("GroupAvailableCommands") == "*ALL*")
                {
                    foreach (Command cmd in CommandList)
                    {
                        helpMessage = helpMessage + cmd.name + ", ";
                    }
                }
                else
                {
                    foreach (string cmd in sender.GetField("GroupAvailableCommands").ToString().Split(','))
                    {
                        helpMessage = helpMessage + cmd + ", ";
                    }
                }
                SayToPlayer(sender, "^3Commands for ^1Nightingale^3:");
                SayToPlayer(sender, helpMessage);
            }));


            CommandList.Add(new Command("res", (sender, args) =>
            {
                Utilities.ExecuteCommand("fast_restart");
            }));

            CommandList.Add(new Command("map", (sender, args) =>
            {
                ChangeMap(args[0]);
            }));

            CommandList.Add(new Command("myalias", (sender, args) =>
            {
                string newAlias = String.Join(" ", args);
                if (newAlias == "")
                {
                    SetPlayerAlias(sender, (string)sender.GetField("Alias"), (string)sender.GetField("OriginalName"));
                    SayToPlayer(sender, FormatMessage(Config.GetString("alias_reset"), new Dictionary <string, string>()
                    {
                        { "target", (string)sender.GetField("OriginalName") }
                    }));
                    return;
                }
                else if (newAlias.Length > 15)
                {
                    SayToPlayer(sender, FormatMessage(Config.GetString("alias_invalid"), new Dictionary <string, string>()
                    {
                        { "var", newAlias }
                    }));
                    return;
                }
                else
                {
                    WriteLog.None((string)sender.GetField("Alias"));
                    SetPlayerAlias(sender, (string)sender.GetField("Alias"), newAlias);
                    SayToPlayer(sender, FormatMessage(Config.GetString("alias_success"), new Dictionary <string, string>()
                    {
                        { "target", (string)sender.GetField("OriginalName") },
                        { "var", newAlias }
                    }));
                }
            }));

            CommandList.Add(new Command("alias", (sender, args) =>
            {
                Entity target   = FindSinglePlayer(args[0]);
                string newAlias = String.Join(" ", args).Replace(args[0], "").Trim();
                if (newAlias == "")
                {
                    SetPlayerAlias(target, (string)target.GetField("Alias"), (string)target.GetField("OriginalName"));
                    SayToPlayer(sender, FormatMessage(Config.GetString("alias_reset"), new Dictionary <string, string>()
                    {
                        { "target", (string)target.GetField("OriginalName") }
                    }));
                    return;
                }
                else if (newAlias.Length > 15)
                {
                    SayToPlayer(sender, FormatMessage(Config.GetString("alias_invalid"), new Dictionary <string, string>()
                    {
                        { "var", newAlias }
                    }));
                    return;
                }
                else
                {
                    SetPlayerAlias(target, (string)target.GetField("Alias"), newAlias);
                    SayToPlayer(sender, FormatMessage(Config.GetString("alias_success"), new Dictionary <string, string>()
                    {
                        { "target", (string)sender.GetField("OriginalName") },
                        { "var", newAlias }
                    }));
                }
            }));

            CommandList.Add(new Command("cmd", (sender, args) =>
            {
                Utilities.ExecuteCommand(String.Join(" ", args));
            }));

            CommandList.Add(new Command("yell", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);
                if (target == null)
                {
                    SayToPlayer(sender, Config.GetString("player_not_found"));
                }
                target.IPrintLnBold(String.Join(" ", args).Replace(args[0], "").Trim());
            }));

            CommandList.Add(new Command("afk", (sender, args) =>
            {
                SetPlayerTeam(sender, "spectator");
            }));

            CommandList.Add(new Command("afk", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);
                SetPlayerTeam(target, "spectator");
            }));

            CommandList.Add(new Command("setgroup", (sender, args) => {
                Entity target   = FindSinglePlayer(args[0]);
                string newGroup = args[1].ToLower();

                string[] groupsFile = File.ReadAllLines(Config.GetFile("groups"));

                foreach (string group_ in groupsFile)
                {
                    //RankName;RankTag;Commands
                    string[] group = group_.Split(';');
                    if (group[0] == newGroup)
                    {
                        SetPlayerGroup(target, (string)target.GetField("GroupName"), newGroup, group[1], group[2]);
                        SayToPlayer(sender, FormatMessage(Config.GetString("group_change_success"), new Dictionary <string, string>()
                        {
                            { "target", (string)target.GetField("OriginalName") },
                            { "var", newGroup }
                        }));
                        return;
                    }
                }
                SayToPlayer(sender, FormatMessage(Config.GetString("group_not_found"), new Dictionary <string, string>()
                {
                    { "var", newGroup }
                }));
            }));

            CommandList.Add(new Command("admins", (sender, args) =>
            {
                List <Entity> admins = new List <Entity>();
                foreach (Entity player in Players)
                {
                    if ((string)player.GetField("GroupName") != "default")
                    {
                        admins.Add(player);
                    }
                }

                foreach (Entity admin in admins)
                {
                    SayToPlayer(sender, $"{(string)admin.GetField("GroupPrefix")}{(string)admin.GetField("OriginalName")}");
                }
            }));

            bool hideEnabled = false;

            CommandList.Add(new Command("wh", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);
                if (target == null)
                {
                    target = sender;
                }
                if (hideEnabled == false)
                {
                    target.Hide();
                    hideEnabled = true;
                }
                else
                {
                    //UNHIDE???
                    hideEnabled = false;
                }
            }));

            bool whEnabled = false;

            CommandList.Add(new Command("wh", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);
                if (target == null)
                {
                    target = sender;
                }
                if (whEnabled == false)
                {
                    target.ThermalVisionFOFOverlayOn();
                    whEnabled = true;
                }
                else
                {
                    target.ThermalVisionFOFOverlayOff();
                    whEnabled = false;
                }
            }));

            CommandList.Add(new Command("warn", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);
                string reason = String.Join(" ", args).Replace(args[0], "").Trim();

                WarnPlayer(target, reason, sender);
            }));

            CommandList.Add(new Command("unwarn", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);

                UnwarnPlayer(target, sender);
            }));

            CommandList.Add(new Command("kick", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);

                string reason = String.Join(" ", args).Replace(args[0], "").Trim();
                KickPlayer(target, reason, sender);
            }));

            CommandList.Add(new Command("ban", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);
                string reason = String.Join(" ", args).Replace(args[0], "").Trim();

                PermBanPlayer(target, reason, sender);
            }));

            CommandList.Add(new Command("tempban", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);
                int minutes   = Int32.Parse(args[1]);
                string reason = String.Join(" ", args).Replace(args[0], "").Replace(args[1], "").Trim();

                TempBanPlayer(target, minutes, reason, sender);
            }));

            CommandList.Add(new Command("unban", (sender, args) =>
            {
                string target = args[0];

                UnbanPlayer(target, sender);
            }));

            CommandList.Add(new Command("fakeban", (sender, args) =>
            {
                Entity target = FindSinglePlayer(args[0]);
                string reason = String.Join(" ", args).Replace(args[0], "").Trim();

                SayToAll(FormatMessage(Config.GetString("ban_message"), new Dictionary <string, string>()
                {
                    { "target", (string)target.Name },
                    { "instigator", sender.Name },
                    { "reason", reason }
                }));
            }));

            WriteLog.Info("Initialized commands.");
        }