Example #1
0
        //Send Rcon-Command to server.
        private static string SendRconCommand(List <string[]> request, int serverID)
        {
            Arma3Server server            = Arma3ServerUtility.FindArma3ServerByID(serverID);
            SrvProcPair serverProcessPair = Arma3ServerUtility.FindServerProcessPairByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }
            if (serverProcessPair == null)
            {
                return("Failed to find running server process");
            }

            string param;

            if (!FindRequestValue(request, "paramvalue", out param))
            {
                return("ParameterValue not found");
            }

            if (serverProcessPair.RemoteConsole == null)
            {
                return("Failed to send command. Rcon not initialized");
            }
            if (!serverProcessPair.RemoteConsole.RconEnabled)
            {
                return("Failed to send command. Rcon is not enabled");
            }

            serverProcessPair.RemoteConsole.Send(param);

            return("Rcon command-request sent");
        }
Example #2
0
        //Initialize new Rcon connection to server.
        private static string StartRcon(int serverID)
        {
            Arma3Server server            = Arma3ServerUtility.FindArma3ServerByID(serverID);
            SrvProcPair serverProcessPair = Arma3ServerUtility.FindServerProcessPairByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }
            if (serverProcessPair == null)
            {
                return("Failed to find running server process");
            }

            try
            {
                if (serverProcessPair.RemoteConsole == null)
                {
                    serverProcessPair.RemoteConsole = new Rcon.Rcon(server.RconParams.IPAddress, server.RconParams.Port, server.RconParams.Password);
                }
                serverProcessPair.RemoteConsole.SetRconEnabled(true);

                if (serverProcessPair.RemoteConsole.RconEnabled)
                {
                    return("Rcon Started");
                }
                return("Failed to start Rcon");
            }
            catch (Exception e)
            {
                return("Failed to initialize Rcon Conncetion: " + e.Message);
            }
        }
Example #3
0
        //Get list of scheduled events from the server and return as a JSON.
        private static string GetServerSchedules(int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            return(new JavaScriptSerializer().Serialize(server.Schedules.ServerEvents));
        }
Example #4
0
        //Get schedules state
        private static string GetSchedulesEnabled(int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            return(server.Schedules.Enabled.ToString());
        }
Example #5
0
        //Toggle schedules on/off
        private static string ToggleScheduleEnabled(int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            server.Schedules.Enabled = !server.Schedules.Enabled;

            return("Server Scheduling set to " + server.Schedules.Enabled.ToString());
        }
Example #6
0
        //Get Server Query class to JSON string.
        private static string GetQueryInfo(List <string[]> request, int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            SourceQuery query = new SourceQuery();

            return(new JavaScriptSerializer().Serialize(query.GetServerInfo(server.QueryParams.IPAddress, server.QueryParams.Port)));
        }
Example #7
0
        //Get Arma3Server class to JSON string.
        private static string GetServerInfo(List <string[]> request, int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            string result;

            Arma3ServerData.ServerToJSON(server, out result);
            return(result);
        }
Example #8
0
        //Update Server Game, Rcon or Query Port.
        private static string UpdatePort(List <string[]> request, int serverID, string portType)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            string paramValue;
            int    Port;

            if (!FindRequestValue(request, "paramvalue", out paramValue))
            {
                return("ParameterValue not found");
            }
            if (!int.TryParse(paramValue, out Port))
            {
                return("Port was not Integer");
            }
            if (Port < 0 || Port > 65535)
            {
                return("Port value out of range");
            }


            if (portType == "GamePort")
            {
                server.GamePort = Port;
                return("Updated GamePort to " + Port.ToString());
            }
            else if (portType == "QueryPort")
            {
                server.QueryParams.Port = Port;
                return("Updated QueryPort to " + Port.ToString());
            }
            else if (portType == "RconPort")
            {
                server.RconParams.Port = Port;
                return("Updated RconPort to " + Port.ToString());
            }

            return("PortType not found");
        }
Example #9
0
        //Update Rcon Password.
        private static string UpdateRconPassword(List <string[]> request, int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            string paramValue;

            if (!FindRequestValue(request, "paramvalue", out paramValue))
            {
                return("ParameterValue not found");
            }

            server.RconParams.Password = paramValue;
            return("Rcon Password Updated");
        }
Example #10
0
        //Update Server Profilename.
        private static string UpdateServerProfileName(List <string[]> request, int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            string paramValue;

            if (!FindRequestValue(request, "paramvalue", out paramValue))
            {
                return("ParameterValue not found");
            }

            server.ServerProfileName = paramValue;
            return("Server Profilename Updated");
        }
Example #11
0
        //Add new scheduled event to server.
        private static string AddServerScheduledEvent(List <string[]> request, int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            string description, eventType, scheduleType, date, interval;

            if (!FindRequestValue(request, "description", out description))
            {
                return("Event Description not found");
            }
            if (!FindRequestValue(request, "eventtype", out eventType))
            {
                return("Event Action not found");
            }
            if (!FindRequestValue(request, "scheduletype", out scheduleType))
            {
                return("Event Repeat type not found");
            }
            if (!FindRequestValue(request, "date", out date))
            {
                return("Event date not found");
            }
            if (!FindRequestValue(request, "interval", out interval))
            {
                return("Event repeat interval not found");
            }

            EventType    evtType     = String2EventType(eventType);
            ScheduleType evtScType   = String2ScheduleType(scheduleType);
            DateTime     evtDate     = String2DateTime(date);
            int          evtInterval = 0;

            int.TryParse(interval, out evtInterval);

            server.Schedules.ServerEvents.Add(new ScheduledEvent(description, "", evtDate, evtType, evtScType, evtInterval));
            return("Added new scheduled event");
        }
Example #12
0
        //Remove mission from missioncycle.
        private static string RemoveMissionFromCycle(List <string[]> request, int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            string param;

            if (!FindRequestValue(request, "param", out param))
            {
                return("Parameter not found");
            }

            int removedCount = server.Missions.RemoveSubclassesByName(param);

            return("Removed " + removedCount + " missions from missioncycle.");
        }
Example #13
0
        //Update Arma3Server member / property.
        public static string UpdateConfigParam(int serverId, string paramName, object value)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverId);

            if (server == null)
            {
                return("Failed to update config parameter. Given ID didn't match any server.");
            }
            SrvParam param = FindSrvParam(server, paramName);

            if (param == null)
            {
                return("Failed to update config parameter. Given parameter not found");
            }

            param.paramValue = value;
            //Serverlist saving

            return(paramName + " updated");
        }
Example #14
0
        //Stop Rcon connection.
        private static string StopRcon(int serverID)
        {
            Arma3Server server            = Arma3ServerUtility.FindArma3ServerByID(serverID);
            SrvProcPair serverProcessPair = Arma3ServerUtility.FindServerProcessPairByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }
            if (serverProcessPair == null)
            {
                return("Failed to find running server process");
            }

            if (serverProcessPair.RemoteConsole != null)
            {
                serverProcessPair.RemoteConsole.SetRconEnabled(false);
            }

            return("Rcon is stopped");
        }
Example #15
0
        //Get Rcon Data
        private static string GetRconData(int serverID)
        {
            Arma3Server server            = Arma3ServerUtility.FindArma3ServerByID(serverID);
            SrvProcPair serverProcessPair = Arma3ServerUtility.FindServerProcessPairByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }
            if (serverProcessPair == null)
            {
                return("Failed to find running server process");
            }

            if (serverProcessPair.RemoteConsole == null)
            {
                return("Failed to get data. Rcon is not enabled");
            }

            return(new JavaScriptSerializer().Serialize(serverProcessPair.RemoteConsole.Handler.Data));
        }
Example #16
0
        //Update Arma3Server member/property -state.
        public static string UpdateConfigParamState(int serverId, string paramName, bool state)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverId);

            if (server == null)
            {
                return("Failed to update config parameter. Given ID didn't match any server.");
            }
            SrvParam param = FindSrvParam(server, paramName);

            if (param == null)
            {
                return("Failed to update config parameter. Given parameter not found");
            }


            param.include = state;
            //Serverlist saving

            return(paramName + " state updated to " + state.ToString());
        }
Example #17
0
        //Update Rcon or Query IP-Address.
        private static string UpdateIPAddress(List <string[]> request, int serverID, string addressType)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            string paramValue;

            System.Net.IPAddress ipAddress;

            if (!FindRequestValue(request, "paramvalue", out paramValue))
            {
                return("ParameterValue not found");
            }

            if (System.Net.IPAddress.TryParse(paramValue, out ipAddress))
            {
                if (addressType == "RconIP")
                {
                    server.RconParams.IPAddress = ipAddress.ToString();
                    return("Updater Rcon IP-Address to " + ipAddress.ToString());
                }

                if (addressType == "QueryIP")
                {
                    server.QueryParams.IPAddress = ipAddress.ToString();
                    return("Updater Query IP-Address to " + ipAddress.ToString());
                }

                return("IP-Address Target not found");
            }

            return("Invalid IP-Address String");
        }
Example #18
0
        //Add mission to missioncycle.
        private static string AddMissionToCycle(List <string[]> request, int serverID)
        {
            Arma3Server server = Arma3ServerUtility.FindArma3ServerByID(serverID);

            if (server == null)
            {
                return("Server with id " + serverID + " not found");
            }

            string name, file, difficulty;

            if (!FindRequestValue(request, "missionname", out name) || !FindRequestValue(request, "missionfile", out file) || !FindRequestValue(request, "difficulty", out difficulty))
            {
                return("Mission Name, FileName or Difficulty not defined");
            }

            if (name.Length > 0 && file.Length > 0 && difficulty.Length > 0) //
            {
                server.Missions.SubClasses.Add(new Arma3MissionClass(name, file, difficulty));
                return("New Mission Added.");
            }

            return("Mission Name, FileName or Difficulty not defined");
        }
Example #19
0
 //Start Arma 3 Server Executable.
 public static bool StartServer(SrvProcPair serverProcessPair, out string result)
 {
     return(Arma3ServerUtility.StartServer(serverProcessPair, appSettings.BattlEyePath, out result));
 }
Example #20
0
        public static string HandleRequest(List <string[]> request)
        {
            string requestName;

            if (!FindRequestValue(request, "request", out requestName))
            {
                return("Request was not defined.");
            }

            string sid;
            int    serverID = -1;

            if (FindRequestValue(request, "serverid", out sid))
            {
                if (sid.Length > 0)
                {
                    int.TryParse(sid, out serverID);
                }
            }

            switch (requestName)
            {
            case "updateserverparam":
                return(UpdateServerParam(request, serverID));

            case "updateserverparamstate":
                return(UpdateServerParamState(request, serverID));

            case "updateport":
                return(UpdatePort(request, serverID, "GamePort"));

            case "updatequeryport":
                return(UpdatePort(request, serverID, "QueryPort"));

            case "updatequeryip":
                return(UpdateIPAddress(request, serverID, "QueryIP"));

            case "updaterconip":
                return(UpdateIPAddress(request, serverID, "RconIP"));

            case "updaterconport":
                return(UpdatePort(request, serverID, "RconPort"));

            case "updaterconpassword":
                return(UpdateRconPassword(request, serverID));

            case "updateprofilename":
                return(UpdateServerProfileName(request, serverID));

            case "startserver":
                string startResult;
                Arma3ServerUtility.RestartServer(Arma3ServerUtility.FindServerProcessPairByID(serverID), out startResult);
                return(startResult);

            case "stopserver":
                string stopResult;
                Arma3ServerUtility.StopServer(Arma3ServerUtility.FindServerProcessPairByID(serverID), out stopResult);
                return(stopResult);

            case "serverinfo":
                return(GetServerInfo(request, serverID));

            case "queryinfo":
                return(GetQueryInfo(request, serverID));

            case "deletemission":
                return(RemoveMissionFromCycle(request, serverID));

            case "getmissionfiles":
                return(new JavaScriptSerializer().Serialize(GetMissionFiles()));

            case "addnewserver":
                return("Added new server with id " + Arma3ServerUtility.CreateNewServer().ToString());

            case "addmissiontocycle":
                return(AddMissionToCycle(request, serverID));

            case "serverlist":
                return(new JavaScriptSerializer().Serialize(Arma3ServerUtility.ServerList.Select(x => new { x.serverData.ServerID, x.serverData.HostName }).ToArray()));

            case "sendrconcommand":
                return(SendRconCommand(request, serverID));

            case "startrcon":
                return(StartRcon(serverID));

            case "stoprcon":
                return(StopRcon(serverID));

            case "getrcondata":
                return(GetRconData(serverID));

            case "updatesettings":
                return(UpdateGeneralSettings(request));

            case "restartwrapper":
                return(RestartWrapper());

            case "getwrappersettings":
                return(GetGeneralSettings());

            case "getschedules":
                return(GetServerSchedules(serverID));

            case "addscheduledevent":
                return(AddServerScheduledEvent(request, serverID));

            case "toggleschedules":
                return(ToggleScheduleEnabled(serverID));

            case "getschedulesstate":
                return(GetSchedulesEnabled(serverID));

            default:
                return("That kind of request doesn't exists!");
            }
        }