コード例 #1
0
ファイル: kIRCCore.cs プロジェクト: lavery98/Rocket_kIRC
        public void parse(string data, kIRC unturnedclass)
        {
            if (data == "") return;
            if(data.Substring(0, 6) == "ERROR ")
            {
                Rocket.Unturned.Logging.Logger.LogError("Error: IRC socket has closed. Reload the plugin for reconnection.");
                this.Destruct();
            }
            // Regex taken from (http://calebdelnay.com/blog/2010/11/parsing-the-irc-message-format-as-a-client)
            string
                prefix = "",
                command = "",
                //parameters,
                trailing = ""
                ;
            string[] parameters = new string[] { };
            Regex parsingRegex = new Regex(@"^(:(?<prefix>\S+) )?(?<command>\S+)( (?!:)(?<params>.+?))?( :(?<trail>.+))?$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
            Match messageMatch = parsingRegex.Match(data);

            if (messageMatch.Success)
            {
                prefix = messageMatch.Groups["prefix"].Value;
                command = messageMatch.Groups["command"].Value;
                parameters = messageMatch.Groups["params"].Value.Split(' ');
                trailing = messageMatch.Groups["trail"].Value;

                if (!String.IsNullOrEmpty(trailing))
                    parameters = parameters.Concat(new string[] { trailing }).ToArray();
            }

            if (command == "PING")
            {
                this.Send("PONG :" + trailing);
                this.Send("NAMES " + this._channel);
            }

            if (command == "001")
            {
                this.Registered = true;
            //}
            //if (command == "005")
            //{
                if(!String.IsNullOrEmpty(this._password))
                    this.Say("NickServ", "IDENTIFY " + this._password);
                this.Send("JOIN " + _channel);
                // Perform
                for(int i = 0; i < this.cperform.Count; i++)
                {
                    this.Send(this.cperform[i].pcommand);
                }
                // -------
                kIRCVersionChecker.CheckUpdate(this, this._channel); // Update checker
            }
            if (command == "353")
            {
                // Names list

                if(!this.__NAMES)
                {
                    this.__NAMES = true;
                    this.userlist.Clear();
                }

                string[] _userlist = trailing.Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < _userlist.Length; i++)
                {
                    string lerank = Convert.ToString(_userlist[i][0]);
                    string lename = _userlist[i].Remove(0, 1);
                    if (lerank == "~" || lerank == "&" || lerank == "@" || lerank == "%" || lerank == "+")
                    {
                        lename = _userlist[i].Remove(0, 1);
                    }
                    else
                    {
                        lename = _userlist[i];
                        lerank = "";
                    }

                    this.userlist.Add(new[] { lename, lerank });
                }
            }
            if (command == "433")
            {
                Rocket.Unturned.Logging.Logger.LogError("Error: Nickname taken. Reload the plugin for reconnection.");
                this.Destruct();
            }
            if(command == "JOIN")
            {
                string user = prefix.Split('!')[0];
                string ident = prefix.Split('!')[1].Split('@')[0];
                string host = prefix.Split('@')[1];
                //RocketChat.Say("[IRC JOIN] "+ user +" has joined IRC channel.", Color.gray);
                kIRCTranslate.Rocket_ChatSay("game_ircjoin", Color.gray, new Dictionary<string, string>()
                {
                    {"time", DateTime.Now.ToString()},
                    {"irc_usernick", user},
                    {"irc_userident", ident},
                    {"irc_userhost", host},
                    {"irc_channel", this._channel}
                });

                this.userlist.Add(new[] { user, "" });
            }
            else if(command == "PART")
            {
                string user = prefix.Split('!')[0];
                string ident = prefix.Split('!')[1].Split('@')[0];
                string host = prefix.Split('@')[1];
                //RocketChat.Say("[IRC PART] " + user + " has left IRC channel.", Color.gray);
                kIRCTranslate.Rocket_ChatSay("game_ircpart", Color.gray, new Dictionary<string, string>()
                {
                    {"time", DateTime.Now.ToString()},
                    {"irc_usernick", user},
                    {"irc_userident", ident},
                    {"irc_userhost", host},
                    {"irc_channel", this._channel},
                    {"irc_partreason", trailing.Trim()}
                });

                for(int i = 0; i < this.userlist.Count; i++)
                {
                    if(this.userlist[i][0] == user)
                    {
                        this.userlist.Remove(new[] { user, this.userlist[i][1]});
                        break;
                    }
                }
            }
            if (command == "366")
            { // End of /NAMES
                this.__NAMES = false;
            }
            if (command == "MODE")
            {
                if (String.IsNullOrEmpty(trailing))
                {
                    this.Send("NAMES "+this._channel);
                }
            }
            if (command == "PRIVMSG")
            {
                if (trailing[0] == this._command_prefix)
                {
                    string cmd;
                    try
                    {
                        cmd = trailing.Split(' ')[0].ToLower();
                        if (String.IsNullOrEmpty(cmd.Trim()))
                            cmd = trailing.Trim().ToLower();
                    }
                    catch
                    {
                        cmd = trailing.Trim().ToLower();
                    }
                    string msg = "";
                    string user = prefix.Split('!')[0];
                    string ident = prefix.Split('!')[1].Split('@')[0];
                    string host = prefix.Split('@')[1];
                    cmd = cmd.Remove(0, 1); // remove the prefix pls

                    msg = trailing.Remove(0, 1 + cmd.Length).Trim();
                    cmd = cmd.Trim();

                    if (cmd == "help")
                    {
                        if (!IsVoice(user, false))
                        {
                            this.Say(this._channel, "Error: You need voice to use the commands.");
                            return;
                        }
                        this.Say(this._channel, "====Unturned IRC Commands====");
                        this.Say(this._channel, "- " + this._command_prefix+"help => This command");
                        this.Say(this._channel, "- " + this._command_prefix + "say <text> => Send a message to ingame users");
                        this.Say(this._channel, "- " + this._command_prefix + "players => Shows a list of online players");
                        this.Say(this._channel, "- " + this._command_prefix + "pm => Sends a personal message to a specific player");
                        // Custom commands
                        for(int i = 0; i < this.custom_commands.Count; i++)
                        {
                            if(this.custom_commands[i].FlagNeeded == "v" || this.custom_commands[i].FlagNeeded == "")
                            {
                                this.Say(this._channel, "+ " + this._command_prefix + this.custom_commands[i].BotCommand + " " + this.custom_commands[i].BotSyntax);
                            }
                        }
                        // ---------------
                        if (IsHalfOp(user, false))
                        {
                            this.Say(this._channel, "- " + this._command_prefix + "info <player name> => Show information about given username");
                            this.Say(this._channel, "- " + this._command_prefix + "broadcast <text> => Sends a broadcast to the players");
                            // Custom commands
                            for (int i = 0; i < this.custom_commands.Count; i++)
                            {
                                if (this.custom_commands[i].FlagNeeded == "h")
                                {
                                    this.Say(this._channel, "+ " + this._command_prefix + this.custom_commands[i].BotCommand + " " + this.custom_commands[i].BotSyntax);
                                }
                            }
                            // ---------------
                        }
                        if (IsOp(user, false))
                        {
                            this.Say(this._channel, "- " + this._command_prefix + "kick <player name> <reason> => Kicks a player from the server with a given reason");
                            // Custom commands
                            for (int i = 0; i < this.custom_commands.Count; i++)
                            {
                                if (this.custom_commands[i].FlagNeeded == "o")
                                {
                                    this.Say(this._channel, "+ " + this._command_prefix + this.custom_commands[i].BotCommand + " " + this.custom_commands[i].BotSyntax);
                                }
                            }
                            // ---------------
                        }
                        if (IsAdmin(user, false))
                        {
                            this.Say(this._channel, "- " + this._command_prefix + "ban <player name|SteamID> <duration in seconds> <reason> => Bans a player from the server with a given duration and reason");
                            this.Say(this._channel, "- " + this._command_prefix + "unban <SteamID> => Unbans a player from the server with a given SteamID");
                            this.Say(this._channel, "- " + this._command_prefix + "bans => Shows ban list");
                            this.Say(this._channel, "- " + this._command_prefix + "save => Saves the game data.");
                            this.Say(this._channel, "- " + this._command_prefix + "shutdown => shuts down the server.");
                            // Custom commands
                            for (int i = 0; i < this.custom_commands.Count; i++)
                            {
                                if (this.custom_commands[i].FlagNeeded == "a")
                                {
                                    this.Say(this._channel, "+ " + this._command_prefix + this.custom_commands[i].BotCommand + " " + this.custom_commands[i].BotSyntax);
                                }
                            }
                            // ---------------
                        }
                        if (IsOwner(user, false))
                        {
                            // Custom commands
                            for (int i = 0; i < this.custom_commands.Count; i++)
                            {
                                if (this.custom_commands[i].FlagNeeded == "q")
                                {
                                    this.Say(this._channel, "+ " + this._command_prefix + this.custom_commands[i].BotCommand + " " + this.custom_commands[i].BotSyntax);
                                }
                            }
                            // ---------------
                        }
                        this.Say(this._channel, "=============================");
                    }
                    else if (cmd == "say" && IsVoice(user, false))
                    {
                        if(String.IsNullOrEmpty(msg))
                        {
                            string[] ParamSyntax = { "text" };
                            this.SendSyntax(this._channel, cmd, ParamSyntax);
                            return;
                        }
                        //RocketChat.Say("[IRC] " + user + ": " + msg, Color.yellow);
                        kIRCTranslate.Rocket_ChatSay("game_ircsay", Color.yellow, new Dictionary<string, string>()
                        {
                            {"irc_usernick", user},
                            {"irc_userident", ident},
                            {"irc_userhost", host},
                            {"irc_channel", this._channel},
                            {"irc_message", msg}
                        });

                    }
                    else if (cmd == "players" && IsVoice(user, false))
                    {
                        string playerlist = "";
                        for(int i = 0; i < Steam.Players.Count; i++)
                        {
                            playerlist += Steam.Players[i].SteamPlayerID.CharacterName/* + ", "*/;
                            if (i != (Steam.Players.Count - 1))
                                playerlist += ", ";
                        }
                        //this.Say(this._channel, "Connected Players[" + Steam.Players.Count + "/"+Steam.MaxPlayers+"]: " + playerlist);
                        kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_playerslist", new Dictionary<string, string>()
                        {
                            {"time", DateTime.Now.ToString()},
                            {"irc_usernick", user},
                            {"irc_userident", ident},
                            {"irc_userhost", host},
                            {"players_amount", Steam.Players.Count.ToString()},
                            {"players_max", Steam.MaxPlayers.ToString()},
                            {"players_list", playerlist}
                        });
                    }
                    else if (cmd == "pm" && IsVoice(user, false))
                    {
                        if (msg.Split(this._parameter_delimiter).Length < 2)
                        {
                            string[] ParamSyntax = { "Player Name", "Message" };
                            this.SendSyntax(this._channel, cmd, ParamSyntax);
                            return;
                        }
                        else
                        {
                            string pname = msg.Split(this._parameter_delimiter)[0];
                            string message = msg.Split(this._parameter_delimiter)[1];

                            RocketPlayer pPointer = RocketPlayer.FromName(pname);
                            if (pPointer == null || pPointer.CharacterName != pname)
                                this.Say(this._channel, "[ERROR] Player " + pname + " not found.");
                            else
                            {
                                //RocketChat.Say(pPointer, "[IRC PM] " + user + ": " + message, Color.magenta);
                                kIRCTranslate.Rocket_ChatSay("game_ircpm", Color.magenta, new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"irc_message", message}
                                }, pPointer);
                            }
                        }
                    }
                    else if (cmd == "info" && IsHalfOp(user, false))
                    {
                        if (String.IsNullOrEmpty(msg))
                        {
                            string[] ParamSyntax = {"Player Name"};
                            this.SendSyntax(this._channel, cmd, ParamSyntax);
                        }
                        else
                        {
                            string pname = msg.Trim();
                            RocketPlayer pPointer = RocketPlayer.FromName(pname);

                            if (pPointer == null || pPointer.CharacterName != pname)
                            {
                                this.Say(this._channel, "[ERROR] Player " + pname + " not found.");
                                return;
                            }
                            this.Notice(user, "Info about {" + pname + "}");
                            this.Notice(user, "Character name: " + pPointer.CharacterName);
                            this.Notice(user, "Steam name: " + pPointer.SteamName);
                            this.Notice(user, "SteamID: " + pPointer.CSteamID.ToString());
                            //this.Notice(user, "Health: " + pPointer.Health + "%"); // pPointer.Health ALWAYS returns zero for some reason..
                                                                                     // Therefore using another method to update player health
                                                                                     // on each health update event.
                            this.Notice(user, "Health: " + unturnedclass._playershealth[pPointer.CharacterName] + "%");
                            this.Notice(user, "Hunger: " + pPointer.Hunger + "%");
                            this.Notice(user, "Thirst: " + pPointer.Thirst + "%");
                            this.Notice(user, "Infection: " + pPointer.Infection + "%");
                            this.Notice(user, "Stamina: " + pPointer.Stamina + "%");
                            this.Notice(user, "Experience: " + pPointer.Experience);
                            this.Notice(user, "Admin: " + (pPointer.IsAdmin == true ? "Yes" : "No"));
                            this.Notice(user, "Dead: " + (pPointer.Dead == true ? "Yes" : "No"));
                            this.Notice(user, "Godmode: " + (pPointer.Features.GodMode == true ? "Enabled" : "Disabled"));
                            this.Notice(user, "Position: X:" + pPointer.Position.x + ", Y:" + pPointer.Position.y + ", Z:" + pPointer.Position.z);

                        }
                    }
                    else if (cmd == "broadcast" && IsHalfOp(user, false))
                    {
                        if (String.IsNullOrEmpty(msg))
                        {
                            string[] ParamSyntax = { "text" };
                            this.SendSyntax(this._channel, cmd, ParamSyntax);
                            return;
                        }
                        //RocketChat.Say("[IRC Broadcast]: " + msg, Color.red);
                        kIRCTranslate.Rocket_ChatSay("game_ircbroadcast", Color.red, new Dictionary<string, string>()
                        {
                            {"time", DateTime.Now.ToString()},
                            {"irc_usernick", user},
                            {"irc_userident", ident},
                            {"irc_userhost", host},
                            {"irc_channel", this._channel},
                            {"irc_message", msg}
                        });
                    }
                    else if (cmd == "kick" && IsOp(user, false))
                    {
                        if (msg.Split(this._parameter_delimiter).Length < 2)
                        {
                            string[] ParamSyntax = { "Player Name", "Reason" };
                            this.SendSyntax(this._channel, cmd, ParamSyntax);
                        }
                        else
                        {
                            string pname = msg.Split(this._parameter_delimiter)[0];
                            string reason = msg.Split(this._parameter_delimiter)[1];
                            RocketPlayer pPointer = RocketPlayer.FromName(pname);
                            if (pPointer == null || pPointer.CharacterName!=pname)
                                this.Say(this._channel, "[ERROR] Player " + pname + " not found.");
                            else
                            {
                                RocketPlayer.FromName(pname).Kick(reason);
                                //this.Say(this._channel, "[SUCCESS] Player " + pname + " is kicked!");
                                kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_kicksuccess", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"irc_targetnick", pname},
                                    {"irc_kickreason", reason}
                                });
                            }
                        }
                    }
                    else if (cmd == "ban" && IsAdmin(user, false))
                    {
                        if (msg.Split(this._parameter_delimiter).Length < 3)
                        {
                            string[] ParamSyntax = { "Player Name|SteamID", "Duration in seconds", "Reason" };
                            this.SendSyntax(this._channel, cmd, ParamSyntax);
                        }
                        else
                        {
                            string pname = msg.Split(this._parameter_delimiter)[0];
                            string durationstr = msg.Split(this._parameter_delimiter)[1];
                            int duration = 0;
                            if (!int.TryParse(durationstr, out duration))
                            {
                                this.Say(this._channel, "[ERROR] duration \"" + durationstr + "\" is not valid.");
                                return;
                            }

                            string reason = msg.Split(this._parameter_delimiter/*' '*/)[2];
                            if (!Regex.IsMatch(pname, @"^\d+$")) // If not SteamID
                            {
                                RocketPlayer pPointer = RocketPlayer.FromName(pname);
                                if (pPointer == null || pPointer.CharacterName != pname)
                                {
                                    this.Say(this._channel, "[ERROR] Player " + pname + " not found.");
                                    return;
                                }
                                else
                                {
                                    // pPointer.Ban(reason, (uint) duration); // Doesn't work (https://github.com/RocketFoundation/Rocket/issues/173)
                                    //this.Say(this._channel, "[SUCCESS] Player " + pname + " is banned!");
                                    kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_pbansuccess", new Dictionary<string, string>()
                                    {
                                        {"time", DateTime.Now.ToString()},
                                        {"irc_usernick", user},
                                        {"irc_userident", ident},
                                        {"irc_userhost", host},
                                        {"irc_channel", this._channel},
                                        {"irc_targetnick", pname},
                                        {"irc_banreason", reason},
                                        {"irc_banduration", durationstr}
                                    });
                                }
                            }
                            else
                            {
                                //this.Say(this._channel, "[SUCCESS] SteamID "+pname+" is banned.");
                                kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_sbansuccess", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"irc_targetsteamid", pname},
                                    {"irc_banreason", reason},
                                    {"irc_banduration", durationstr}
                                });
                            }

                            kIRC_PushCommand pcmd = new kIRC_PushCommand();
                            pcmd.command = "ban {0}/{1}/{2}";
                            pcmd.parameters = new string[] { pname, reason, durationstr };
                            pcmd.onfire(() => { });
                            pcmd.onexec((string response) => { });

                            pcmd.execute = true;

                            pcmd.push(unturnedclass); // Sends it to the main unturned thread
                        }
                    }
                    else if (cmd == "unban" && IsAdmin(user, false))
                    {
                        if(String.IsNullOrEmpty(msg))
                        {
                            string[] ParamSyntax = { "SteamID" };
                            this.SendSyntax(this._channel, cmd, ParamSyntax);
                            return;
                        }
                        else
                        {

                            kIRC_PushCommand pcmd = new kIRC_PushCommand();
                            pcmd.command = "unban {0}";
                            pcmd.parameters = new string[] { msg };
                            pcmd.onfire(() => { } );
                            pcmd.onexec((string response) => {
                                //this.Say(this._channel, "Unban response: " + response);
                                kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_unbanresponse", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"irc_targetsteamid", msg},
                                    {"irc_response", response}
                                });
                            });

                            pcmd.execute = true;

                            pcmd.push(unturnedclass); // Sends it to the main unturned thread
                        }
                    }
                    else if (cmd == "bans" && IsAdmin(user, false))
                    {
                        kIRC_PushCommand pcmd = new kIRC_PushCommand();
                        pcmd.command = "bans";
                        pcmd.parameters = new string[] { };
                        pcmd.onfire(() =>
                        {
                            this.Say(this._channel, user + ": Response is sent to your query.");
                        });
                        pcmd.onexec((string response) =>
                        {
                            this.Say(user, "Response from bans:");
                            string[] bans = response.Split('\n');
                            for (int i = 0; i < bans.Length; i++)
                            {
                                this.Say(user, bans[i]);
                            }
                        });

                        pcmd.execute = true;

                        pcmd.push(unturnedclass); // Sends it to the main unturned thread
                    }
                    else if (cmd == "save" && IsAdmin(user, false))
                    {
                        kIRC_PushCommand pcmd = new kIRC_PushCommand();
                        pcmd.command = "save";
                        pcmd.parameters = new string[] { };
                        pcmd.onfire(() => {
                            //this.Say(this._channel, "Saving server settings...");
                            //RocketChat.Say("[IRC] Saving server settings...");
                            kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_onsave", new Dictionary<string, string>()
                            {
                                {"time", DateTime.Now.ToString()},
                                {"irc_usernick", user},
                                {"irc_userident", ident},
                                {"irc_userhost", host},
                                {"irc_channel", this._channel}
                            });
                            kIRCTranslate.Rocket_ChatSay("game_onsave", new Dictionary<string, string>()
                            {
                                {"time", DateTime.Now.ToString()},
                                {"irc_usernick", user},
                                {"irc_userident", ident},
                                {"irc_userhost", host},
                                {"irc_channel", this._channel}
                            });
                        });
                        pcmd.onexec((string response) => {
                            //this.Say(this._channel, "Save response: " + response);
                            //RocketChat.Say("[IRC] Server settings, Player items saved!");
                            kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_saveexec", new Dictionary<string, string>()
                            {
                                {"time", DateTime.Now.ToString()},
                                {"irc_usernick", user},
                                {"irc_userident", ident},
                                {"irc_userhost", host},
                                {"irc_channel", this._channel},
                                {"irc_response", response}
                            });
                            kIRCTranslate.Rocket_ChatSay("game_saveexec", new Dictionary<string, string>()
                            {
                                {"time", DateTime.Now.ToString()},
                                {"irc_usernick", user},
                                {"irc_userident", ident},
                                {"irc_userhost", host},
                                {"irc_channel", this._channel},
                                {"irc_response", response}
                            });
                        });

                        pcmd.execute = true;

                        pcmd.push(unturnedclass); // Sends it to the main unturned thread
                    }
                    else if (cmd == "shutdown" && IsAdmin(user, false))
                    {
                        kIRC_PushCommand pcmd = new kIRC_PushCommand();
                        pcmd.command = "save";
                        pcmd.parameters = new string[] { };
                        pcmd.onfire(() =>
                        {
                            //RocketChat.Say("[IRC WARNING]: SERVER IS SHUTTING DOWN IN 5 SECONDS!", Color.red);
                            //this.Say(this._channel, "Shutting down in 5 seconds");
                            kIRCTranslate.Rocket_ChatSay("game_shutdownwarning", new Dictionary<string, string>()
                            {
                                {"time", DateTime.Now.ToString()},
                                {"irc_usernick", user},
                                {"irc_userident", ident},
                                {"irc_userhost", host},
                                {"irc_channel", this._channel},
                                {"shutdown_secs", "5"}
                            });
                            kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_shutdownwarning", new Dictionary<string, string>()
                            {
                                {"time", DateTime.Now.ToString()},
                                {"irc_usernick", user},
                                {"irc_userident", ident},
                                {"irc_userhost", host},
                                {"irc_channel", this._channel},
                                {"shutdown_secs", "5"}
                            });
                            Thread.Sleep(1000);
                        });
                        pcmd.onexec((string response) =>
                        {
                            //RocketChat.Say("[IRC] Server settings, Player items saved!");
                            kIRCTranslate.Rocket_ChatSay("game_saveexec", new Dictionary<string, string>()
                            {
                                {"time", DateTime.Now.ToString()},
                                {"irc_usernick", user},
                                {"irc_userident", ident},
                                {"irc_userhost", host},
                                {"irc_channel", this._channel},
                                {"irc_response", response}
                            });

                            kIRC_PushCommand pcmd2 = new kIRC_PushCommand();
                            pcmd2.command = "shutdown";
                            pcmd2.parameters = new string[] { };

                            pcmd2.onfire(() =>
                            {
                                /*RocketChat.Say("[IRC WARNING]: SERVER IS SHUTTING DOWN IN 4 SECONDS!", Color.red);
                                this.Say(this._channel, "Shutting down in 4 seconds");
                                Thread.Sleep(1000);
                                RocketChat.Say("[IRC WARNING]: SERVER IS SHUTTING DOWN IN 3 SECONDS!", Color.red);
                                this.Say(this._channel, "Shutting down in 3 seconds");
                                Thread.Sleep(1000);
                                RocketChat.Say("[IRC WARNING]: SERVER IS SHUTTING DOWN IN 2 SECONDS!", Color.red);
                                this.Say(this._channel, "Shutting down in 2 seconds");
                                Thread.Sleep(1000);
                                RocketChat.Say("[IRC WARNING]: SERVER IS SHUTTING DOWN IN 1 SECOND!", Color.red);
                                this.Say(this._channel, "Shutting down in 1 second");
                                Thread.Sleep(1000);*/
                                kIRCTranslate.Rocket_ChatSay("game_shutdownwarning", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"shutdown_secs", "4"}
                                });
                                kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_shutdownwarning", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"shutdown_secs", "4"}
                                });
                                Thread.Sleep(1000);
                                kIRCTranslate.Rocket_ChatSay("game_shutdownwarning", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"shutdown_secs", "3"}
                                });
                                kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_shutdownwarning", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"shutdown_secs", "3"}
                                });
                                Thread.Sleep(1000);
                                kIRCTranslate.Rocket_ChatSay("game_shutdownwarning", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"shutdown_secs", "2"}
                                });
                                kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_shutdownwarning", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"shutdown_secs", "2"}
                                });
                                Thread.Sleep(1000);
                                kIRCTranslate.Rocket_ChatSay("game_shutdownwarning", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"shutdown_secs", "1"}
                                });
                                kIRCTranslate.IRC_SayTranslation(this, this._channel, "irc_shutdownwarning", new Dictionary<string, string>()
                                {
                                    {"time", DateTime.Now.ToString()},
                                    {"irc_usernick", user},
                                    {"irc_userident", ident},
                                    {"irc_userhost", host},
                                    {"irc_channel", this._channel},
                                    {"shutdown_secs", "1"}
                                });
                                Thread.Sleep(1000);
                            });

                            pcmd2.onexec((string response2) => { });

                            pcmd2.execute = true;
                            pcmd2.push(unturnedclass);

                        });

                        pcmd.execute = true;

                        pcmd.push(unturnedclass); // Sends it to the main unturned thread
                    }
                    else
                    {
                        for(int i = 0; i < this.custom_commands.Count; i++)
                        {
                            kIRC_Commands refer = this.custom_commands[i];

                            if(refer.BotCommand.ToLower().Trim() == cmd)
                            {
                                bool hasperms = false;
                                if (refer.FlagNeeded == "q")
                                    hasperms = IsOwner(user);
                                else if (refer.FlagNeeded == "a")
                                    hasperms = IsAdmin(user);
                                else if (refer.FlagNeeded == "o")
                                    hasperms = IsOp(user);
                                else if (refer.FlagNeeded == "h")
                                    hasperms = IsHalfOp(user);
                                else if (refer.FlagNeeded == "v")
                                    hasperms = IsVoice(user);
                                else
                                    hasperms = false;

                                if (hasperms)
                                {
                                    kIRC_PushCommand pcmd = new kIRC_PushCommand();
                                    pcmd.command = refer.ConsoleCommand;
                                    pcmd.parameters = (!String.IsNullOrEmpty(msg) && msg.Split(this._parameter_delimiter).Length>0) ? msg.Split(this._parameter_delimiter) : new string[] { };
                                    pcmd.extradata.Add("Syntax", refer.BotSyntax);
                                    pcmd.onfire(() =>
                                    {
                                        if (!String.IsNullOrEmpty(refer.IRCmsg_onfire.Trim()))
                                        {
                                            this.Say(this._channel, refer.IRCmsg_onfire);
                                        }
                                        if (!String.IsNullOrEmpty(refer.GAMEmsg_onfire.Trim()))
                                        {
                                            RocketChat.Say(refer.GAMEmsg_onfire);
                                        }
                                    });
                                    pcmd.onexec((string response) =>
                                    {
                                        if (!String.IsNullOrEmpty(refer.IRCmsg_onexec.Trim()))
                                        {
                                            this.Say(this._channel, refer.IRCmsg_onexec);
                                        }
                                        if (!String.IsNullOrEmpty(refer.GAMEmsg_onexec.Trim()))
                                        {
                                            RocketChat.Say(refer.GAMEmsg_onexec);
                                        }

                                        if(refer.printresponse == true)
                                            this.Say(this._channel, "Response from ("+cmd+"): "+response);
                                    });

                                    pcmd.execute = true;

                                    pcmd.push(unturnedclass); // Sends it to the main unturned thread

                                }

                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: kIRCPCommand.cs プロジェクト: lavery98/Rocket_kIRC
 public void push(kIRC __ref)
 {
     __ref.do_command.Add(this);
     return;
 }
コード例 #3
0
ファイル: kIRCCore.cs プロジェクト: lavery98/Rocket_kIRC
 public void loopparsing(kIRC uclass)
 {
     while (isConnected)
     {
         this.parse(this.Read(), uclass);
     }
 }