예제 #1
0
        public List <GameServer> GetAllGameServers()
        {
            Open();

            List <GameServer> gameServers = new List <GameServer>();

            MySqlCommand command = new MySqlCommand("SELECT server_instance.id, server_instance.root_folder, server_instance.port, server_instance.executeable, server_instance.server_instance_package_id, game.game, game.clean_game_directory, master_server.ftp_executeable, master_server.ftp_xml, master_server.ftp_port, server_instance.ftp_user FROM server_instance JOIN game ON server_instance.game_id = game_id JOIN master_server ON server_instance.master_server_id = master_server.id WHERE master_server.ip = @ip", connection);

            command.Parameters.AddWithValue("@ip", Utility.GetExternalIP()); /*Utility.GetExternalIP()*/

            MySqlDataReader reader = command.ExecuteReader();

            int _id             = reader.GetOrdinal("id");
            int _path           = reader.GetOrdinal("root_folder");
            int _port           = reader.GetOrdinal("port");
            int _executeable    = reader.GetOrdinal("executeable");
            int _game           = reader.GetOrdinal("game");
            int _gameDir        = reader.GetOrdinal("clean_game_directory");
            int _ftpExecuteable = reader.GetOrdinal("ftp_executeable");
            int _ftpXml         = reader.GetOrdinal("ftp_xml");
            int _ftpPort        = reader.GetOrdinal("ftp_port");
            int _ftpUser        = reader.GetOrdinal("ftp_user");
            int _packageId      = reader.GetOrdinal("server_instance_package_id");

            while (reader.Read())
            {
                int    id             = reader.GetInt32(_id);
                int    port           = reader.GetInt32(_port);
                string path           = reader.GetString(_path);
                string executeable    = reader.GetString(_executeable);
                string game           = reader.GetString(_game);
                string gameDirectory  = reader.GetString(_gameDir);
                string ftpExecuteable = reader.GetString(_ftpExecuteable);
                string ftpXml         = reader.GetString(_ftpXml);
                int    ftpPort        = reader.GetInt32(_ftpPort);
                string ftpUser        = reader.GetString(_ftpUser);
                int    packageId      = reader.GetInt32(_packageId);

                if (game == "SA:MP")
                {
                    SAMPServer sampServer = new SAMPServer(id, port, path, executeable, new FTPData(ftpExecuteable, ftpXml, ftpPort, ftpUser), packageId);
                    sampServer.CleanGameDirectory = gameDirectory;

                    gameServers.Add(sampServer);
                }
                else
                {
                    server.Form.Error("Invalid game found: " + game);
                }
            }

            reader.Close();
            Close();

            return(gameServers);
        }
예제 #2
0
        public List<GameServer> GetAllGameServers()
        {
            Open();

            List<GameServer> gameServers = new List<GameServer>();

            MySqlCommand command = new MySqlCommand("SELECT server_instance.id, server_instance.root_folder, server_instance.port, server_instance.executeable, server_instance.server_instance_package_id, game.game, game.clean_game_directory, master_server.ftp_executeable, master_server.ftp_xml, master_server.ftp_port, server_instance.ftp_user FROM server_instance JOIN game ON server_instance.game_id = game_id JOIN master_server ON server_instance.master_server_id = master_server.id WHERE master_server.ip = @ip", connection);
            command.Parameters.AddWithValue("@ip", Utility.GetExternalIP()); /*Utility.GetExternalIP()*/

            MySqlDataReader reader = command.ExecuteReader();

            int _id = reader.GetOrdinal("id");
            int _path = reader.GetOrdinal("root_folder");
            int _port = reader.GetOrdinal("port");
            int _executeable = reader.GetOrdinal("executeable");
            int _game = reader.GetOrdinal("game");
            int _gameDir = reader.GetOrdinal("clean_game_directory");
            int _ftpExecuteable = reader.GetOrdinal("ftp_executeable");
            int _ftpXml = reader.GetOrdinal("ftp_xml");
            int _ftpPort = reader.GetOrdinal("ftp_port");
            int _ftpUser = reader.GetOrdinal("ftp_user");
            int _packageId = reader.GetOrdinal("server_instance_package_id");

            while (reader.Read()) {
                int id = reader.GetInt32(_id);
                int port = reader.GetInt32(_port);
                string path = reader.GetString(_path);
                string executeable = reader.GetString(_executeable);
                string game = reader.GetString(_game);
                string gameDirectory = reader.GetString(_gameDir);
                string ftpExecuteable = reader.GetString(_ftpExecuteable);
                string ftpXml = reader.GetString(_ftpXml);
                int ftpPort = reader.GetInt32(_ftpPort);
                string ftpUser = reader.GetString(_ftpUser);
                int packageId = reader.GetInt32(_packageId);

                if (game == "SA:MP") {
                    SAMPServer sampServer = new SAMPServer(id, port, path, executeable, new FTPData(ftpExecuteable, ftpXml, ftpPort, ftpUser), packageId);
                    sampServer.CleanGameDirectory = gameDirectory;

                    gameServers.Add(sampServer);
                }
                else
                    server.Form.Error("Invalid game found: " + game);
            }

            reader.Close();
            Close();

            return gameServers;
        }
예제 #3
0
        private string ProcessRequest(dynamic jsonObject)
        {
            string message = "";

            if (jsonObject.server_status != null)
            {
                int        serverId   = jsonObject.server_status.id;
                GameServer gameServer = Find(serverId);

                if (gameServer != null)
                {
                    try {
                        if (gameServer.IsActive())
                        {
                            form.ServerOutput(gameServer, "Server is online");
                            message += "Server is online";
                        }
                        else
                        {
                            form.ServerOutput(gameServer, "Server is offline");
                            message += "Server is offline";
                        }
                    }
                    catch (Exception ex) {
                        form.Error("FATAL ERROR:: Could not execute server_status: " + ex);
                    }
                }
                else
                {
                    form.Error("Server_status: Could not find id " + jsonObject.server_start.id);
                    message += "Server_status: Could not find id " + jsonObject.server_start.id;
                }
            }
            else if (jsonObject.server_start != null)
            {
                int        serverId   = jsonObject.server_start.id;
                GameServer gameServer = Find(serverId);

                if (gameServer != null)
                {
                    List <string> messages;
                    try {
                        if (gameServer.Start(out messages))
                        {
                            form.ServerOutput(gameServer, "Started server: " + string.Join(",", messages.ToArray()));
                            message += "Started server: " + string.Join(",", messages.ToArray());
                        }
                        else
                        {
                            form.ServerOutput(gameServer, "Could not start server: " + string.Join(",", messages.ToArray()));
                            message += "Could not start server: " + string.Join(",", messages.ToArray());
                        }
                    }
                    catch (Exception ex) {
                        form.Error("FATAL ERROR:: Could not execute server_stats: " + ex);
                    }
                }
                else
                {
                    form.Error("Server_start: Could not find id " + jsonObject.server_start.id);
                    message += "Server_start: Could not find id " + jsonObject.server_start.id;
                }
            }
            else if (jsonObject.server_stop != null)
            {
                int        serverId   = jsonObject.server_stop.id;
                GameServer gameServer = Find(serverId);

                if (gameServer != null)
                {
                    List <string> messages;
                    try {
                        if (gameServer.Stop(out messages))
                        {
                            form.ServerOutput(gameServer, "Stopped server: " + string.Join(",", messages.ToArray()));
                            message += "Stopped server: " + string.Join(",", messages.ToArray());
                        }
                        else
                        {
                            form.ServerOutput(gameServer, "Could not stop server: " + string.Join(",", messages.ToArray()));
                            message += "Could not stop server: " + string.Join(",", messages.ToArray());
                        }
                    }
                    catch (Exception ex) {
                        form.Error("FATAL ERROR:: Could not execute server_stop: " + ex);
                    }
                }
                else
                {
                    form.Error("Server_stop: Could not find id " + jsonObject.server_start.id);
                    message += "Server_stop: Could not find id " + jsonObject.server_start.id;
                }
            }
            else if (jsonObject.server_reinstall != null)
            {
                int        serverId   = jsonObject.server_reinstall.id;
                GameServer gameServer = Find(serverId);

                if (gameServer != null)
                {
                    List <string> messages;
                    try {
                        if (gameServer.Reinstall(out messages))
                        {
                            form.ServerOutput(gameServer, "Reinstalled server: " + string.Join(",", messages.ToArray()));
                            message += "Reinstalled server: " + string.Join(",", messages.ToArray());
                        }
                        else
                        {
                            form.ServerOutput(gameServer, "Could not reinstall server: " + string.Join(",", messages.ToArray()));
                            message += "Could not reinstall server: " + string.Join(",", messages.ToArray());
                        }
                    }
                    catch (Exception ex) {
                        form.Error("FATAL ERROR:: Could not execute server_reinstall: " + ex);
                    }
                }
                else
                {
                    form.Error("Server_reinstall: Could not find id " + jsonObject.server_start.id);
                    message += "Server_reinstall: Could not find id " + jsonObject.server_start.id;
                }
            }
            else if (jsonObject.ftp_generate != null)
            {
                int        serverId   = jsonObject.ftp_generate.id;
                GameServer gameServer = Find(serverId);

                if (gameServer != null)
                {
                    List <string> messages;
                    try {
                        if (gameServer.GenerateFTP(out messages))
                        {
                            form.ServerOutput(gameServer, "Generated FTP: " + string.Join(",", messages.ToArray()));
                            message += "Generated FTP: " + string.Join(",", messages.ToArray());
                        }
                        else
                        {
                            form.ServerOutput(gameServer, "Could not generate FTP: " + string.Join(",", messages.ToArray()));
                            message += "Could not generate FTP: " + string.Join(",", messages.ToArray());
                        }
                    }
                    catch (Exception ex) {
                        form.Error("FATAL ERROR:: Could not execute ftp_generate: " + ex);
                    }
                }
                else
                {
                    form.Error("Ftp_generate: Could not find id " + jsonObject.server_start.id);
                    message += "Ftp_generate: Could not find id " + jsonObject.server_start.id;
                }
            }
            else if (jsonObject.set_server_package != null)
            {
                int        serverId   = jsonObject.set_server_package.id;
                int        packageId  = jsonObject.set_server_package.packageId;
                GameServer gameServer = Find(serverId);

                if (gameServer != null)
                {
                    if (gameServer is SAMPServer)
                    {
                        SAMPServer sampServer = (SAMPServer)gameServer;
                        sampServer.PackageId = packageId;

                        form.ServerOutput(gameServer, "Set to packageId: " + sampServer.PackageId);
                        message += "Set to packageId: " + sampServer.PackageId;
                    }
                }
                else
                {
                    form.Error("Set_server_package: Could not find id " + jsonObject.server_start.id);
                    message += "Set_server_package: Could not find id " + jsonObject.server_start.id;
                }
            }

            return(message);
        }