예제 #1
0
        public GUIconfirm(GUImain gui, RCon rcon)
        {
            InitializeComponent();

            this.gui  = gui;
            this.rcon = rcon;
        }
예제 #2
0
        public GUIconfirm(GUImain gui, RCon rcon)
        {
            InitializeComponent();

            this.gui = gui;
            this.rcon = rcon;
        }
예제 #3
0
        public GUImanualBans(RCon rcon)
        {
            InitializeComponent();

            _rcon           = rcon;
            this.Text       = "Manually add ban(s)";
            this.input.Text = "Add bans like this:\r\ndartdartdartdartdartdartdartdart -1 Reason\r\ndartdartdartdartdartdartdartdart\r\nBoth formats are valid.";
        }
예제 #4
0
        public GUImanualBans(RCon rcon)
        {
            InitializeComponent();

            _rcon = rcon;
            this.Text = "Manually add ban(s)";
            this.input.Text = "Add bans like this:\r\ndartdartdartdartdartdartdartdart -1 Reason\r\ndartdartdartdartdartdartdartdart\r\nBoth formats are valid.";
        }
예제 #5
0
        public GUIban(RCon rcon, int id, string name, string guid, string ip, bool online)
        {
            InitializeComponent();

            _rcon         = rcon;
            _rcon.Pending = name;

            _ban = new Ban(id, name, guid, ip, online);

            if (_ban.Online)
            {
                this.Text = "Ban " + _ban.Name;
            }
            else
            {
                this.Text = "Ban " + _ban.Name + " (Offline)";
            }

            try
            {
                span.SelectedIndex = Settings.Default.span;
            }
            catch
            {
                Settings.Default.span = 0;
            }

            if (_ban.Online)
            {
                if (Settings.Default.banGUID && Settings.Default.banIP)
                {
                    mode.SelectedIndex = 2;
                }
                if (Settings.Default.banGUID)
                {
                    mode.SelectedIndex = 0;
                }
                else if (Settings.Default.banIP)
                {
                    mode.SelectedIndex = 1;
                }
            }
            else
            {
                mode.SelectedIndex = 0;
                mode.Enabled       = false;
            }
        }
예제 #6
0
파일: GUImain.cs 프로젝트: DomiStyle/DaRT
        public GUImain(String version)
        {
            // Initializing DaRT
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
            this.version = version;

            // Upgrading configuration
            if (Settings.Default.UpgradeConfig)
            {
                Settings.Default.Upgrade();
                Settings.Default.UpgradeConfig = false;
            }

            // Initializing RCon class
            rcon = new RCon(this);

            _buffer = new List<string>();

            InitializeComponent();
        }
예제 #7
0
파일: GUIban.cs 프로젝트: DomiStyle/DaRT
        public GUIban(RCon rcon, int id, string name, string guid, string ip, bool online)
        {
            InitializeComponent();

            _rcon = rcon;
            _rcon.Pending = name;

            _ban = new Ban(id, name, guid, ip, online);

            if (_ban.Online)
                this.Text = "Ban " + _ban.Name;
            else
                this.Text = "Ban " + _ban.Name + " (Offline)";

            try
            {
                span.SelectedIndex = Settings.Default.span;
            }
            catch
            {
                Settings.Default.span = 0;
            }

            if (_ban.Online)
            {
                if (Settings.Default.banGUID && Settings.Default.banIP)
                    mode.SelectedIndex = 2;
                if (Settings.Default.banGUID)
                    mode.SelectedIndex = 0;
                else if (Settings.Default.banIP)
                    mode.SelectedIndex = 1;
            }
            else
            {
                mode.SelectedIndex = 0;
                mode.Enabled = false;
            }
        }
예제 #8
0
        static void Main(string[] args)
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);

            version = fvi.FileVersion;
            if (args.Length == 0)
            {
                if (Debugger.IsAttached)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    gui = new GUImain(version);
                    Application.Run(gui);
                    return;
                }
                Application.ThreadException += CatchThreadException;
                AppDomain.CurrentDomain.UnhandledException += CatchUnhandledException;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                gui = new GUImain(version);
                Application.Run(gui);
            }
            else
            {
                #region Read Config
                String ip       = "127.0.0.1";
                int    port     = 2302;
                String password = "******";
                String command  = "";
                String output   = "";
                String script   = "";
                int    loop     = 0;
                bool   close    = false;
                bool   window   = true;

                foreach (String arg in args)
                {
                    if (arg.StartsWith("-ip="))
                    {
                        ip = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];;
                    }
                    else if (arg.StartsWith("-port="))
                    {
                        try
                        {
                            port = Int32.Parse(arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1]);
                        }
                        catch
                        {
                            port = 2302;
                        }
                    }
                    else if (arg.StartsWith("-password="******"-pass="******"-pw="))
                    {
                        password = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    else if (arg.StartsWith("-command=") || arg.StartsWith("-cmd="))
                    {
                        command = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    else if (arg.StartsWith("-output="))
                    {
                        output = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    else if (arg.StartsWith("-close"))
                    {
                        close = true;
                    }
                    else if (arg.StartsWith("-nowindow"))
                    {
                        window = false;
                    }
                    else if (arg.StartsWith("-script="))
                    {
                        script = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    else if (arg.StartsWith("-loop="))
                    {
                        loop = Int32.Parse(arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1]);
                    }
                }
                #endregion

                #region Establish Connection
                RCon rcon = new RCon(null);
                rcon.Connect(IPAddress.Parse(ip), port, password);
                #endregion

                if (window)
                {
                    AllocConsole();
                }

                #region Writing header
                if (output != "")
                {
                    writer = File.CreateText(output);
                }

                Write("DaRT " + version + " - DayZ RCon Tool");
                if (command != "")
                {
                    Write("Running in command mode.");
                }
                else if (script != "")
                {
                    Write("Running in script mode.");
                }
                Write("---------------------");
                Write("Supplied arguments:");
                foreach (String arg in args)
                {
                    Write(arg);
                }
                Write("---------------------");
                Write("Output:");
                #endregion

                if (command != "")
                {
                    #region Command mode
                    if (command == "players")
                    {
                        List <Player> players = rcon.getPlayers();
                        foreach (Player player in players)
                        {
                            Write(player.ToString());
                        }
                    }
                    else if (command == "bans")
                    {
                        List <Ban> bans = rcon.getBans();
                        foreach (Ban ban in bans)
                        {
                            Write(ban.ToString());
                        }
                    }
                    else if (command == "admins")
                    {
                        List <String> admins = rcon.getAdmins();
                        foreach (String admin in admins)
                        {
                            Write(admin);
                        }
                    }
                    else
                    {
                        rcon.execute(command);
                        Write("Command executed successfully!");
                    }
                    #endregion
                }
                else if (script != "")
                {
                    #region Script mode
                    Write("Running " + script);

                    String[]      lines    = File.ReadAllLines(script);
                    List <String> commands = new List <String>();

                    foreach (String line in lines)
                    {
                        if (line != "")
                        {
                            if (!line.StartsWith("//"))
                            {
                                commands.Add(line);
                            }
                        }
                    }

                    bool looping = true;
                    int  run     = 0;
                    do
                    {
                        foreach (String c in commands)
                        {
                            if (c.StartsWith("wait="))
                            {
                                int amount = Int32.Parse(c.Split('=')[1]);
                                Write("Waiting " + (amount / 1000) + "s");
                                Thread.Sleep(amount);
                                continue;
                            }
                            else if (c.StartsWith("exit") || c.StartsWith("quit") || c.StartsWith("close"))
                            {
                                Write("Stopped script.");
                                break;
                            }

                            String exec = c;

                            int    players;
                            int    admins;
                            int    bans;
                            String randomPlayer;
                            if (c.Contains("%p"))
                            {
                                players = rcon.getPlayers().Count;
                                exec    = c.Replace("%p", players.ToString());
                            }
                            if (c.Contains("%a"))
                            {
                                admins = rcon.getAdmins().Count;
                                exec   = c.Replace("%a", admins.ToString());
                            }
                            if (c.Contains("%b"))
                            {
                                bans = rcon.getBans().Count;
                                exec = c.Replace("%b", bans.ToString());
                            }
                            if (c.Contains("%r"))
                            {
                                List <Player> p = rcon.getPlayers();
                                if (p.Count > 0)
                                {
                                    Random random = new Random();
                                    randomPlayer = p[random.Next(0, p.Count)].name;
                                    exec         = c.Replace("%r", randomPlayer);
                                }
                            }
                            if (c.Contains("%l"))
                            {
                                exec = c.Replace("%l", run.ToString());
                            }

                            if (c.StartsWith("if"))
                            {
                                String[] items = exec.Split(new char[] { ':' }, 3, StringSplitOptions.RemoveEmptyEntries);

                                String[] flags  = items[0].Split(new char[] { ' ' }, 4, StringSplitOptions.RemoveEmptyEntries);
                                String   param1 = flags[1];
                                String   op     = flags[2];
                                String   param2 = flags[3];

                                bool fulfilled = false;

                                if (op == ">")
                                {
                                    if (Int32.Parse(param1) > Int32.Parse(param2))
                                    {
                                        fulfilled = true;
                                    }
                                }
                                else if (op == "<")
                                {
                                    if (Int32.Parse(param1) < Int32.Parse(param2))
                                    {
                                        fulfilled = true;
                                    }
                                }
                                else if (op == "=" || op == "==")
                                {
                                    if (param1 == param2)
                                    {
                                        fulfilled = true;
                                    }
                                }
                                else
                                {
                                }

                                if (fulfilled)
                                {
                                    exec = items[1];
                                }
                                else if (items.Length == 3)
                                {
                                    exec = items[2];
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if (exec.StartsWith("kickAll"))
                            {
                                Write("Kicking all players...");
                                String reason;
                                if (exec.Contains("="))
                                {
                                    reason = exec.Split('=')[1];
                                }
                                else
                                {
                                    reason = "Admin Kick";
                                }

                                List <Player> p = rcon.getPlayers();

                                foreach (Player player in p)
                                {
                                    rcon.kick(new Kick(player.number, player.name, reason));
                                }
                            }
                            else if (exec.StartsWith("banAll"))
                            {
                                Write("Banning all players...");
                                String reason;
                                if (exec.Contains("="))
                                {
                                    reason = exec.Split('=')[1];
                                }
                                else
                                {
                                    reason = "Admin Ban";
                                }

                                List <Player> p = rcon.getPlayers();

                                foreach (Player player in p)
                                {
                                    rcon.Ban(new Ban(player.number, player.name, player.guid, player.ip, 0, reason, true));
                                }
                            }
                            else if (exec.StartsWith("exec"))
                            {
                                String execute = exec.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                                Write(execute);
                                rcon.execute(execute);
                            }
                        }

                        if (run == loop)
                        {
                            looping = false;
                        }

                        if (loop != -1)
                        {
                            run++;
                        }
                    } while (looping);
                    #endregion
                }
                else
                {
                    Write("Params: -port=2302 ,-password= (-pass= -pw=), -command= (-cmd=), -output=file, -close, -nowindow, -loop=[-1,count], -script=file");
                }

                rcon.Disconnect();
                if (writer != null)
                {
                    writer.Close();
                    writer.Dispose();
                }
                if (!close && window)
                {
                    Console.WriteLine("All done. Press any key to close.");
                    Console.ReadKey();
                    Console.WriteLine("Closing...");
                }
            }
        }
예제 #9
0
파일: Program.cs 프로젝트: DomiStyle/DaRT
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                if (Debugger.IsAttached)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    gui = new GUImain(version);
                    Application.Run(gui);
                    return;
                }
                Application.ThreadException += CatchThreadException;
                AppDomain.CurrentDomain.UnhandledException += CatchUnhandledException;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                gui = new GUImain(version);
                Application.Run(gui);
            }
            else
            {
                AllocConsole();

                #region Read Config
                String ip = "127.0.0.1";
                int port = 2302;
                String password = "******";
                String command = "";
                String output = "";
                String script = "";
                int loop = 0;
                bool close = false;

                foreach (String arg in args)
                {
                    if (arg.StartsWith("-ip="))
                    {
                        ip = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1]; ;
                    }
                    else if (arg.StartsWith("-port="))
                    {
                        try
                        {
                            port = Int32.Parse(arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1]);
                        }
                        catch
                        {
                            port = 2302;
                        }
                    }
                    else if (arg.StartsWith("-password="******"-pass="******"-pw="))
                    {
                        password = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    else if (arg.StartsWith("-command="))
                    {
                        command = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    else if (arg.StartsWith("-output="))
                    {
                        output = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    else if(arg.StartsWith("-close"))
                    {
                        close = true;
                    }
                    else if (arg.StartsWith("-script="))
                    {
                        script = arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                    }
                    else if (arg.StartsWith("-loop="))
                    {
                        loop = Int32.Parse(arg.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1]);
                    }
                }
                #endregion

                #region Establish Connection
                RCon rcon = new RCon(null);
                rcon.Connect(IPAddress.Parse(ip), port, password);
                #endregion

                #region Writing header
                if (output != "")
                    writer = File.CreateText(output);

                Write("DaRT " + version + " - DayZ RCon Tool");
                if (command != "")
                    Write("Running in command mode.");
                else if (script != "")
                    Write("Running in script mode.");
                Write("---------------------");
                Write("Supplied arguments:");
                foreach (String arg in args)
                {
                    Write(arg);
                }
                Write("---------------------");
                Write("Output:");
                #endregion

                if (command != "")
                {
                    #region Command mode
                    if (command == "players")
                    {
                        List<String> players = rcon.getRawPlayers();
                        foreach (String player in players)
                            Write(player);
                    }
                    else if (command == "bans")
                    {
                        List<String> bans = rcon.getRawBans();
                        foreach (String ban in bans)
                            Write(ban);
                    }
                    else if (command == "admins")
                    {
                        List<String> admins = rcon.getRawAdmins();
                        foreach (String admin in admins)
                            Write(admin);
                    }
                    else
                    {
                        rcon.execute(command);
                        Write("Command executed successfully!");
                    }
                    #endregion
                }
                else if (script != "")
                {
                    #region Script mode
                    Write("Running " + script);

                    String[] lines = File.ReadAllLines(script);
                    List<String> commands = new List<String>();

                    foreach (String line in lines)
                    {
                        if (line != "")
                        {
                            if (!line.StartsWith("//"))
                            {
                                commands.Add(line);
                            }
                        }
                    }

                    bool looping = true;
                    int run = 0;
                    do
                    {
                        foreach (String c in commands)
                        {
                            if (c.StartsWith("wait="))
                            {
                                int amount = Int32.Parse(c.Split('=')[1]);
                                Write("Waiting " + (amount / 1000) + "s");
                                Thread.Sleep(amount);
                                continue;
                            }
                            else if (c.StartsWith("exit") || c.StartsWith("quit") || c.StartsWith("close"))
                            {
                                Write("Stopped script.");
                                break;
                            }

                            String exec = c;

                            int players;
                            int admins;
                            int bans;
                            String randomPlayer;
                            if (c.Contains("%p"))
                            {
                                players = rcon.getPlayers().Count;
                                exec = c.Replace("%p", players.ToString());
                            }
                            if (c.Contains("%a"))
                            {
                                admins = rcon.getAdmins();
                                exec = c.Replace("%a", admins.ToString());
                            }
                            if (c.Contains("%b"))
                            {
                                bans = rcon.getBans().Count;
                                exec = c.Replace("%b", bans.ToString());
                            }
                            if (c.Contains("%r"))
                            {
                                List<Player> p = rcon.getPlayers();
                                if (p.Count > 0)
                                {
                                    Random random = new Random();
                                    randomPlayer = p[random.Next(0, p.Count)].name;
                                    exec = c.Replace("%r", randomPlayer);
                                }
                            }
                            if (c.Contains("%l"))
                            {
                                exec = c.Replace("%l", run.ToString());
                            }

                            if (c.StartsWith("if"))
                            {
                                String[] items = exec.Split(new char[] { ':' }, 3, StringSplitOptions.RemoveEmptyEntries);

                                String[] flags = items[0].Split(new char[] { ' ' }, 4, StringSplitOptions.RemoveEmptyEntries);
                                String param1 = flags[1];
                                String op = flags[2];
                                String param2 = flags[3];

                                bool fulfilled = false;

                                if (op == ">")
                                {
                                    if (Int32.Parse(param1) > Int32.Parse(param2))
                                        fulfilled = true;
                                }
                                else if (op == "<")
                                {
                                    if (Int32.Parse(param1) < Int32.Parse(param2))
                                        fulfilled = true;
                                }
                                else if (op == "=" || op == "==")
                                {
                                    if (param1 == param2)
                                        fulfilled = true;
                                }
                                else
                                {
                                }

                                if (fulfilled)
                                    exec = items[1];
                                else if (items.Length == 3)
                                    exec = items[2];
                                else
                                    continue;
                            }

                            if (exec.StartsWith("kickAll"))
                            {
                                Write("Kicking all players...");
                                String reason;
                                if (exec.Contains("="))
                                    reason = exec.Split('=')[1];
                                else
                                    reason = "Admin Kick";

                                List<Player> p = rcon.getPlayers();

                                foreach (Player player in p)
                                {
                                    rcon.kick(new Kick(player.number, player.name, reason));
                                }
                            }
                            else if (exec.StartsWith("banAll"))
                            {
                                Write("Banning all players...");
                                String reason;
                                if (exec.Contains("="))
                                    reason = exec.Split('=')[1];
                                else
                                    reason = "Admin Ban";

                                List<Player> p = rcon.getPlayers();

                                foreach (Player player in p)
                                {
                                    rcon.Ban(new Ban(player.number.ToString(), player.name, "0", reason));
                                }
                            }
                            else if (exec.StartsWith("exec"))
                            {
                                String execute = exec.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries)[1];
                                Write(execute);
                                rcon.execute(execute);
                            }
                        }

                        if (run == loop)
                            looping = false;

                        if (loop != -1)
                            run++;
                    } while (looping);
                    #endregion
                }
                else
                {
                    Write("You need to run atleast one command or one script.");
                }
                
                rcon.Disconnect();
                if (writer != null)
                {
                    writer.Close();
                    writer.Dispose();
                }
                if (!close)
                {
                    Console.WriteLine("All done. Press any key to close.");
                    Console.ReadKey();
                    Console.WriteLine("Closing...");
                }
            }
        }