Exemple #1
0
        private void OnPerformanceTick(GameServer server, double ram, double cpu)
        {
            try {
                if (ram >= 220)
                {
                    server.PerformanceWarnings.Add("[" + DateTime.Now + "]" + " RAM usage too high: " + ram + " MB");
                    form.errorLog.Items.Add("[" + DateTime.Now + "]" + "RAM usage too high, Server " + server.Id + ", RAM (MB): " + ram + ", CPU: " + cpu);
                }

                if (cpu >= 10)
                {
                    server.PerformanceWarnings.Add("[" + DateTime.Now + "]" + "CPU usage too high: " + cpu + " %");
                    form.errorLog.Items.Add("[" + DateTime.Now + "]" + "CPU usage too high, Server " + server.Id + ", RAM (MB): " + ram + ", CPU: " + cpu);
                }

                if (server.PerformanceWarnings.Count > 100)
                {
                    List <string> messages;

                    if (server.Stop(out messages))
                    {
                        form.errorLog.Items.Add("[" + DateTime.Now + "]" + "PerformanceWarnings OVER 100:: Stopped server: " + string.Join(",", messages.ToArray()));
                    }
                }
            }
            catch (Exception ex) {
                form.Error("OnPerformanceTick:: " + ex.ToString());
            }
        }
Exemple #2
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);
        }
        private void OnPerformanceTick(GameServer server, double ram, double cpu)
        {
            try {
                if (ram >= 220) {
                    server.PerformanceWarnings.Add("[" + DateTime.Now + "]" + " RAM usage too high: " + ram + " MB");
                    form.errorLog.Items.Add("[" + DateTime.Now + "]" + "RAM usage too high, Server " + server.Id + ", RAM (MB): " + ram + ", CPU: " + cpu);
                }

                if (cpu >= 10) {
                    server.PerformanceWarnings.Add("[" + DateTime.Now + "]" + "CPU usage too high: " + cpu + " %");
                    form.errorLog.Items.Add("[" + DateTime.Now + "]" + "CPU usage too high, Server " + server.Id + ", RAM (MB): " + ram + ", CPU: " + cpu);
                }

                if(server.PerformanceWarnings.Count > 100) {
                    List<string> messages;

                    if (server.Stop(out messages)) {
                        form.errorLog.Items.Add("[" + DateTime.Now + "]" + "PerformanceWarnings OVER 100:: Stopped server: " + string.Join(",", messages.ToArray()));
                    }
                }
            }
            catch (Exception ex) {
                form.Error("OnPerformanceTick:: " + ex.ToString());
            }
        }