コード例 #1
0
 private bool LoadInit()
 {
     if (InstanceProvider.GetConfigManager().LoadConfigs())
     {
         _ = Updater.CheckUpdates();
     }
     return true;
 }
コード例 #2
0
 private static void ReplaceBuild(ServerInfo server)
 {
     try
     {
         if (Directory.Exists(server.ServerPath.Value))
             DeleteFilesRecursively(new DirectoryInfo(server.ServerPath.Value));
         ZipFile.ExtractToDirectory($@"{Program.ServiceDirectory}\Server\MCSFiles\Update.zip", server.ServerPath.Value);
         if (server.ServerExeName.Value != "bedrock_server.exe")
             File.Copy(server.ServerPath.Value + "\\bedrock_server.exe", server.ServerPath.Value + "\\" + server.ServerExeName.Value);
         InstanceProvider.GetConfigManager().WriteJSONFiles(server);
         InstanceProvider.GetConfigManager().SaveServerProps(server, false);
     }
     catch (Exception e)
     {
         InstanceProvider.GetServiceLogger().AppendLine($"ERROR: Got an exception deleting entire directory! {e.Message}");
     }
 }
コード例 #3
0
        public BedrockService()
        {
            CurrentServiceStatus = ServiceStatus.Starting;
            if (LoadInit())
            {
                //Program.ServiceLogger = new Program.ServiceLogger(localHost);
                TCPServerThread = new Thread(new ThreadStart(ClientHostThread));
                TCPServerThread.Start();
                try
                {
                    foreach (ServerInfo Server in InstanceProvider.GetHostInfo().GetServerInfos())
                    {
                        BedrockServer srv = new BedrockServer(Server);
                        shed = CrontabSchedule.TryParse(InstanceProvider.GetHostInfo().GetGlobalValue("BackupCron"));
                        if (InstanceProvider.GetHostInfo().GetGlobalValue("BackupEnabled") == "true" && shed != null)
                        {
                            cronTimer = new System.Timers.Timer((shed.GetNextOccurrence(DateTime.Now) - DateTime.Now).TotalMilliseconds);
                            cronTimer.Elapsed += CronTimer_Elapsed;
                            cronTimer.Start();
                        }

                        updater = CrontabSchedule.TryParse(InstanceProvider.GetHostInfo().GetGlobalValue("UpdateCron"));
                        if (InstanceProvider.GetHostInfo().GetGlobalValue("CheckUpdates") == "true" && updater != null)
                        {
                            updaterTimer = new System.Timers.Timer((updater.GetNextOccurrence(DateTime.Now) - DateTime.Now).TotalMilliseconds);
                            updaterTimer.Elapsed += UpdateTimer_Elapsed;
                            InstanceProvider.GetServiceLogger().AppendLine($"Updates Enabled, will be checked in: {((float)updaterTimer.Interval / 1000)} seconds.");
                            updaterTimer.Start();
                        }
                        InstanceProvider.GetConfigManager().WriteJSONFiles(Server);
                        InstanceProvider.GetConfigManager().SaveServerProps(Server, false);
                        bedrockServers.Add(srv);
                    }
                    CurrentServiceStatus = ServiceStatus.Started;
                }
                catch (Exception e)
                {
                    InstanceProvider.GetServiceLogger().AppendLine($"Error Instantiating BedrockServiceWrapper: {e.StackTrace}");
                }
            }
        }