Пример #1
0
 //Catch the output from the server process
 private void ServerOutput(object sender, DataReceivedEventArgs e)
 {
     if (e.Data != null && e.Data != ">")
     {
         YAMS.Database.AddLog(DateTime.Now, e.Data, "server", "out", false, this.ServerID);
         if (TelnetServer.Running)
         {
             TelnetServer.SendMessage(e.Data, this.ServerID);
         }
     }
 }
Пример #2
0
 public static void ShutDown()
 {
     WebServer.Stop();
     foreach (KeyValuePair <int, MCServer> kvp in Core.Servers)
     {
         kvp.Value.Stop();
     }
     YAMS.Database.AddLog("Shutting Down");
     if (TelnetServer.Running)
     {
         TelnetServer.Stop();
     }
 }
Пример #3
0
        public static void ShutDown()
        {
            WebServer.Stop();
            foreach (KeyValuePair <int, MCServer> kvp in Core.Servers)
            {
                kvp.Value.Stop();
            }
            YAMS.Database.AddLog("Shutting Down");

            foreach (TelnetClient client in TelnetServer.lstClients)
            {
                client.Stop();
            }
            TelnetServer.Stop();
        }
Пример #4
0
        private void ServerError(object sender, DataReceivedEventArgs e)
        {
            DateTime datTimeStamp = DateTime.Now;

            //Catch null messages (usually as server is going down)
            if (e.Data == null || e.Data == ">")
            {
                return;
            }

            //MC's server seems to use stderr for things that aren't really errors, so we need some logic to catch that.
            string strLevel   = "info";
            string strMessage = e.Data;

            //Strip out date and time info
            strMessage = this.regRemoveDateStamp.Replace(strMessage, "");
            strMessage = this.regRemoveTimeStamp.Replace(strMessage, "");

            //Work out the error level then remove it from the string
            Match regMatch = this.regErrorLevel.Match(strMessage);

            strMessage = this.regErrorLevel.Replace(strMessage, "").Trim();

            if (regMatch.Success)
            {
                switch (regMatch.Groups[1].Value)
                {
                case "INFO":
                    //Check if it's player chat
                    if (regPlayerChat.Match(strMessage).Success || regPlayerPM.Match(strMessage).Success || regConsoleChat.Match(strMessage).Success)
                    {
                        strLevel = "chat";
                    }
                    else
                    {
                        strLevel = "info";
                    }

                    //See if it's a log in or log out event
                    if (regPlayerLoggedIn.Match(strMessage).Success)
                    {
                        this.PlayerLogin(regPlayerLoggedIn.Match(strMessage).Groups[1].Value);                                                  //is a login event
                    }
                    if (regPlayerLoggedOut.Match(strMessage).Success)
                    {
                        this.PlayerLogout(regPlayerLoggedOut.Match(strMessage).Groups[1].Value);                                                   //logout event
                    }
                    //See if it's the server version tag
                    if (regServerVersion.Match(strMessage).Success)
                    {
                        this.ServerVersion = strMessage.Replace("Starting minecraft server version ", "");
                    }

                    //Detect game type
                    if (regGameMode.Match(strMessage).Success)
                    {
                        this.GameMode = Convert.ToInt32(regGameMode.Match(strMessage).Groups[1].Value);
                    }
                    break;

                case "WARNING":
                    strLevel = "warn";
                    break;

                default:
                    strLevel = "error";
                    break;
                }
            }
            else
            {
                strLevel = "error";
            }

            if (strMessage.IndexOf("Invalid or corrupt jarfile ") > -1)
            {
                //We have downloaded a corrupt jar, clear the download cache and force a re-download now
                this.SafeStop = true;
                AutoUpdate.CheckUpdates(true);
                this.Start();
            }

            Database.AddLog(datTimeStamp, strMessage, "server", strLevel, false, this.ServerID);
            if (Database.GetSetting("EnableTelnet", "YAMS") == "true")
            {
                TelnetServer.SendMessage(e.Data, this.ServerID);
            }
        }
Пример #5
0
        public static void StartUp()
        {
            //Clear out old files if they exist, if it doesn't work we'll just do it on next startup.
            try { if (File.Exists(RootFolder + @"\YAMS-Library.dll.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Library.dll.OLD");
                  }
            }
            catch { };
            try { if (File.Exists(RootFolder + @"\YAMS-Service.exe.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Service.exe.OLD");
                  }
            }
            catch { };
            try { if (File.Exists(RootFolder + @"\YAMS-Service.exe.config.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Service.exe.config.OLD");
                  }
            }
            catch { };

            //Start DB Connection
            Database.init();
            Database.AddLog("Starting Up");

            //Is this the first run?
            if (Database.GetSetting("FirstRun", "YAMS") != "true")
            {
                YAMS.Util.FirstRun();
            }

            //Fill up some vars
            AutoUpdate.bolUpdateAddons = Convert.ToBoolean(Database.GetSetting("UpdateAddons", "YAMS"));
            AutoUpdate.bolUpdateGUI    = Convert.ToBoolean(Database.GetSetting("UpdateGUI", "YAMS"));
            AutoUpdate.bolUpdateJAR    = Convert.ToBoolean(Database.GetSetting("UpdateJAR", "YAMS"));
            AutoUpdate.bolUpdateSVC    = Convert.ToBoolean(Database.GetSetting("UpdateSVC", "YAMS"));
            AutoUpdate.bolUpdateWeb    = Convert.ToBoolean(Database.GetSetting("UpdateWeb", "YAMS"));
            StoragePath = Database.GetSetting("StoragePath", "YAMS");

            //Are there any PIDs we previously started still running?
            if (File.Exists(Core.RootFolder + "\\pids.txt"))
            {
                try
                {
                    StreamReader trPids = new StreamReader(Core.RootFolder + "\\pids.txt");
                    string       line;
                    while ((line = trPids.ReadLine()) != null)
                    {
                        try
                        {
                            Process.GetProcessById(Convert.ToInt32(line)).Kill();
                        }
                        catch (Exception e)
                        {
                            Database.AddLog("Process " + line + " not killed: " + e.Message);
                        }
                    }

                    trPids.Close();
                }
                catch (Exception e)
                {
                    Database.AddLog("Not all processes killed: " + e.Message);
                }
                try
                {
                    File.Delete(Core.RootFolder + "\\pids.txt");
                }
                catch (Exception e)
                {
                    Database.AddLog("Unable to delete the pids.txt file: " + e.Message);
                }
            }
            ;

            //Check for updates
            AutoUpdate.CheckUpdates();

            //Load any servers
            SqlCeDataReader readerServers = YAMS.Database.GetServers();

            while (readerServers.Read())
            {
                Database.AddLog("Starting Server " + readerServers["ServerID"]);
                MCServer myServer = new MCServer(Convert.ToInt32(readerServers["ServerID"]));
                if (Convert.ToBoolean(readerServers["ServerAutostart"]))
                {
                    myServer.Start();
                }
                Servers.Add(Convert.ToInt32(readerServers["ServerID"]), myServer);
            }

            //Start job engine
            JobEngine.Init();

            //Start Webserver
            WebServer.Init();

            //Start Telnet Server
            if (Database.GetSetting("EnableTelnet", "YAMS") == "true")
            {
                TelnetServer.Init();
            }
        }