public void StartAll(int interval)
 {
     if (_opertaionThread.ThreadState == ThreadState.Running || _opertaionThread.ThreadState == ThreadState.WaitSleepJoin)
     {
         return;
     }
     _opertaionThread = ThreadUtil.GetThread(() =>
     {
         int serversDone = 0;
         foreach (IServer server in Servers)
         {
             serversDone++;
             if (ProgressUpdated != null)
             {
                 ProgressUpdated(this, new ServersControlEventArgs()
                 {
                     ServersDone = serversDone, ServersCount = Servers.Count
                 });
             }
             if (!server.ServerStatus.Status)
             {
                 server.Start();
                 Thread.Sleep(interval);
             }
         }
     });
     _opertaionThread.Start();
 }
        public ServersControl()
        {
            _logger = HldslLogManager.GetLogManager().GetCurrentClassLogger();
            Servers = new ObservableCollection <IServer>();

            _pipeServer = new NamedPipeServerStream("andOneHldsLauncher2");
            _dialogBoxErrorReceiveThread = ThreadUtil.GetThread(DialogBoxErrorReceive);
            _dialogBoxErrorReceiveThread.IsBackground = true;
            _dialogBoxErrorReceiveThread.Start();
        }
 public void StopAllInOtherThread()
 {
     if (_opertaionThread != null)
     {
         if (_opertaionThread.ThreadState == ThreadState.Running || _opertaionThread.ThreadState == ThreadState.WaitSleepJoin)
         {
             return;
         }
     }
     _opertaionThread = ThreadUtil.GetThread(StopAll);
     _opertaionThread.Start();
 }
 public override void Start()
 {
     _stoping         = false;
     _crashWithDialog = false;
     if (_serverThread == null)
     {
         ResetStatus();
         _refreshInfoThread = ThreadUtil.GetThread(RefreshText);
     }
     else if (_serverThread.ThreadState != System.Threading.ThreadState.Running && _serverThread.ThreadState != System.Threading.ThreadState.WaitSleepJoin)
     {
         ResetStatus();
         _refreshInfoThread = ThreadUtil.GetThread(RefreshText);
     }
     base.Start();
 }
Exemple #5
0
 public virtual void Start()
 {
     if (_serverThread == null)
     {
         _logger.Info(string.Format(Properties.Resources.log_TryingToStart, Options.HostName));
         Statistics.Reset();
         _serverThread = ThreadUtil.GetThread(Run);
         _serverThread.Start();
     }
     else if (_serverThread.ThreadState != System.Threading.ThreadState.Running && _serverThread.ThreadState != System.Threading.ThreadState.WaitSleepJoin)
     {
         _logger.Info(string.Format(Properties.Resources.log_TryingToStart, Options.HostName));
         Statistics.Reset();
         _serverThread = ThreadUtil.GetThread(Run);
         _serverThread.Start();
     }
     else
     {
         _logger.Info(string.Format(Properties.Resources.log_ServerAlreadyStarted, Options.HostName));
     }
 }
        protected override void Run()
        {
            ServerProcess = new Process();
            if (!string.IsNullOrEmpty(Options.ExecutablePath))
            {
                FileInfo executablePath = new FileInfo(Options.ExecutablePath);
                if (executablePath.Exists)
                {
                    string injectError            = "";
                    WinAPI.SECURITY_ATTRIBUTES SA = new WinAPI.SECURITY_ATTRIBUTES();
                    SA.nLength              = (uint)(Marshal.SizeOf(typeof(WinAPI.SECURITY_ATTRIBUTES)));
                    SA.bInheritHandle       = true;
                    SA.lpSecurityDescriptor = IntPtr.Zero;
                    IntPtr SAPtr = Marshal.AllocHGlobal(Marshal.SizeOf(SA));
                    Marshal.StructureToPtr(SA, SAPtr, true);

                    _hHookBufInfo[0] = WinAPI.CreateFileMapping((IntPtr)(-1), SAPtr, WinAPI.FileMapProtection.PageReadWrite, 0, 16384, null);
                    _hHookBufInfo[1] = WinAPI.CreateEvent(SAPtr, false, false, null);
                    _hHookBufInfo[2] = WinAPI.CreateEvent(SAPtr, false, false, null);

                    ServerProcess.StartInfo.FileName         = executablePath.FullName;
                    ServerProcess.StartInfo.WorkingDirectory = executablePath.Directory.FullName;
                    ServerProcess.StartInfo.Arguments        = string.Format("{0} -HFILE {1} -HPARENT {2} -HCHILD {3} -conheight 24",
                                                                             Options.CommandLine(),
                                                                             _hHookBufInfo[0],
                                                                             _hHookBufInfo[1],
                                                                             _hHookBufInfo[2]);
                    ServerProcess.StartInfo.UseShellExecute = false;

                    do
                    {
                        ServerProcess.Start();
                        Thread.Sleep(50);
                        try
                        {
                            DllHookUtil.CreateHook(CommonUtils.GetProgramDirectory() + @"\Dlls\ErrorsHook.dll", ref _hHook, ServerProcess.Threads[0].Id);
                        }
                        catch (Exception e)
                        {
                            _logger.DebugException(Properties.Resources.log_UnableToCreateHook, e);
                        }
                        try
                        {
                            ServerProcess.WaitForInputIdle(5000);
                        }
                        catch (Exception e)
                        {
                            _logger.DebugException(Properties.Resources.log_UnableToSetAffinity, e);
                        }
                        DllInjectUtil.DoInject(ServerProcess, CommonUtils.GetProgramDirectory() + @"\Dlls\Inject.dll", out injectError);

                        if ((Options as ValveGameServerOptions).ConsoleType == ConsoleType.Integrated)
                        {
                            WinAPI.ShowWindow(ServerProcess.MainWindowHandle, WinAPI.SW_HIDE);
                        }
                        else
                        {
                            WinAPI.SetWindowPos(ServerProcess.MainWindowHandle,
                                                (IntPtr)WinAPI.HWND_TOP,
                                                (Options as ValveGameServerOptions).ConsolePositionX,
                                                (Options as ValveGameServerOptions).ConsolePositionY,
                                                0, 0, WinAPI.SWP_NOSIZE);
                        }

                        if (Options.ProcessorAffinity != (IntPtr)0)
                        {
                            try
                            {
                                ServerProcess.ProcessorAffinity = Options.ProcessorAffinity;
                            }
                            catch (Exception e)
                            {
                                _logger.DebugException(Properties.Resources.log_UnableToSetAffinity, e);
                            }
                        }
                        try
                        {
                            ServerProcess.PriorityClass = Options.Priority;
                        }
                        catch (Exception e)
                        {
                            _logger.DebugException(Properties.Resources.log_UnableToSetPriority, e);
                        }
                        _refreshInfoThread.Start();
                        _logger.Info(string.Format(Properties.Resources.log_SuccessfulStarted, Options.HostName));
                        ServerStatus.Status = true;
                        OnServerStarted(this, new EventArgs());
                        ServerProcess.WaitForExit();

                        ServerStatus.Status = false;
                        _refreshInfoThread.Abort();
                        _refreshInfoThread = ThreadUtil.GetThread(RefreshText);

                        CrashWithoutDialog();

                        if (!string.IsNullOrWhiteSpace(ServerStatus.Map))
                        {
                            ServerProcess.StartInfo.Arguments = string.Format("{0} -HFILE {1} -HPARENT {2} -HCHILD {3} -conheight 24",
                                                                              Options.CommandLine().Replace((Options as ValveGameServerOptions).Map, ServerStatus.Map),
                                                                              _hHookBufInfo[0],
                                                                              _hHookBufInfo[1],
                                                                              _hHookBufInfo[2]);
                        }

                        ResetStatus();
                        Statistics.AddCrashInfo(ServerStatus.Map);
                        DllHookUtil.CloseHook(_hHook);
                        if (!CanRestart())
                        {
                            _logger.Info(string.Format(Properties.Resources.log_CrashCountMaxLimit, Options.HostName, Options.MaxCrashCount, Options.CrashCountTime));

                            break;
                        }
                    }while (Options.AutoRestart);
                    OnServerStoped(this, new EventArgs());
                }
                else
                {
                    _logger.Warn(string.Format(Properties.Resources.log_StartFailedFileIsNotExists, Options.ExecutablePath));
                }
            }
            else
            {
                _logger.Warn(string.Format(Properties.Resources.log_StartFailedFileIsNotExists, Options.ExecutablePath));
            }
        }