예제 #1
0
 public void Poll()
 {
     if (SuspendUntil.Ticks == 0 | Position >= Commands.Count | DateTime.Now < SuspendUntil)
     {
         return;
     }
     if (Commands[Position].ToUpperInvariant() == "/RESTARTSEQUENCE" |
         Commands[Position].ToUpperInvariant() == "/RESTARTSEQUENCER" |
         Commands[Position].ToUpperInvariant() == "/SEQUENCE.RESTART" |
         Commands[Position].ToUpperInvariant() == "/SEQUENCER.RESTART")
     {
         Position = 0;
     }
     if (Commands[Position].ToUpperInvariant() == "/STOPSEQUENCE" |
         Commands[Position].ToUpperInvariant() == "/STOPSEQUENCER" |
         Commands[Position].ToUpperInvariant() == "/SEQUENCE.STOP" |
         Commands[Position].ToUpperInvariant() == "/SEQUENCER.STOP")
     {
         SuspendUntil = new DateTime(0);
         return;
     }
     if (Commands[Position].ToUpperInvariant().StartsWith("/SLEEP"))
     {
         int SleepTimeMicroSeconds = 0;
         Int32.TryParse(Commands[Position].Replace('\t', ' ').Split(' ')[1], out SleepTimeMicroSeconds);
         SuspendUntil = DateTime.Now + new TimeSpan(0, 0, 0, 0, SleepTimeMicroSeconds);
         Position++;
         return;
     }
     Sequencers.Process(Commands[Position]);
     Position++;
 }
예제 #2
0
        public bool _Count()
        {
Restart:
            foreach (string ThisCommand in _Commands)
            {
                if (ThisCommand.ToUpperInvariant() == "/RESTARTSEQUENCE" |
                    ThisCommand.ToUpperInvariant() == "/RESTARTSEQUENCER" |
                    ThisCommand.ToUpperInvariant() == "/SEQUENCE.RESTART" |
                    ThisCommand.ToUpperInvariant() == "/SEQUENCER.RESTART")
                {
                    goto Restart;
                }
                if (ThisCommand.ToUpperInvariant() == "/STOPSEQUENCE" |
                    ThisCommand.ToUpperInvariant() == "/STOPSEQUENCER" |
                    ThisCommand.ToUpperInvariant() == "/SEQUENCE.STOP" |
                    ThisCommand.ToUpperInvariant() == "/SEQUENCER.STOP")
                {
                    break;
                }
                Sequencers.Process(ThisCommand);
            }
            return(true);
        }
            private static void Run(string[] args)
            {
                //Initialisation
                #region Initialisation
                Thread.CurrentThread.Name = "OpenYS Server Core";
                Threads.List.Add(Thread.CurrentThread);

                Console._LogOutput    = Log.ConsoleOutput;
                Console._Process      = CommandManager.ProcessConsole;
                Console.ConsolePrompt = "&3OpenYS&f->&f";
                Console.Locked        = true;

                System.Console.CursorVisible = false;
                System.Console.Title         = "OpenYS - YSFlight Open Source Server";
                System.Console.Clear();

                #region OYS_Console
                OpenYS.OpenYSConsole.SetConsole();
                OpenYS.OpenYSConsole.SetFakeClient();
                OpenYS.OpenYSConsole.Username = Settings.Options.ConsoleName;
                OpenYS.OpenYSConsole.OP();
                OpenYS.OpenYSConsole.YSFClient.ConnectionContext = ClientIO.ConnectionContexts.Connectionless;
                #endregion
                #region OYS_BackgroundHandler
                OpenYS.OpenYSBackGround.SetController();
                OpenYS.OpenYSBackGround.SetFakeClient();
                OpenYS.OpenYSBackGround.Username = Settings.Options.SchedulerName;
                OpenYS.OpenYSBackGround.OP();
                OpenYS.OpenYSBackGround.YSFClient.ConnectionContext = ClientIO.ConnectionContexts.Connectionless;
                #endregion

                Sequencers.Process = CommandManager.ProcessScheduler;
                Schedulers.Process = CommandManager.ProcessScheduler;

                OpenYS.BuildType          = OpenYS._BuildType.Server;
                Environment.EntryAssembly = Assembly.GetExecutingAssembly();
                #endregion

                //Begin Program.
                #region TRY:
#if RELEASE
                try
                {
#endif
                #endregion
                #region MAIN LOOP
                while (!Environment.TerminateSignal.WaitOne(0))
                {
                    //Loading
                    #region Loading
                    #region ? Argument
                    if (args.Length > 0)
                    {
                        if (args[0] == "/?" | args[0] == "?")
                        {
                            System.Console.WriteLine("OpenYS Open Source Server Project. (C) OfficerFlake 2015");
                            System.Console.WriteLine("    ");
                            System.Console.WriteLine("    Usage: OpenYS_Client.exe [HostAddress] [HostPort] [ListenerPortNumber]");
                            System.Console.WriteLine("    ");
                            System.Console.WriteLine("Thanks for using OpenYS!");
                            System.Environment.Exit(0);
                        }
                    }
                    #endregion
                    #region Clear Logs
                    Files.FileDelete("./Logs/Client_Debug.Log");
                    Files.FileDelete("./Logs/Console.Log");
                    #endregion
                    #region Introduction
                    Console.WriteLine(ConsoleColor.Cyan, "Welcome to OpenYS Client!");
                    Console.WriteLine();
                    #endregion
                    #region Version Number
                    Console.WriteLine(ConsoleColor.DarkCyan, "You are using version:&e " + Environment.GetCompilationDate());
                    Console.WriteLine();
                    #endregion
                    #region LoadSettings
                    SettingsHandler.LoadAll();
                    SettingsHandler.Monitor();
                    #endregion
                    #region InitialSettings
                    OpenYS.OpenYSConsole.Username    = Settings.Options.ConsoleName;
                    OpenYS.OpenYSBackGround.Username = Settings.Options.SchedulerName;
                    Environment.OwnerName            = Settings.Options.OwnerName;
                    Environment.OwnerEmail           = Settings.Options.OwnerEmail;
                    Environment.ServerName           = Settings.Options.ServerName;
                    OpenYS.Field = new Packets.Packet_04_FieldName(Settings.Loading.FieldName);
                    #endregion
                    #region Check Arguments
                    CheckArguments(args);
                    #endregion
                    #region Load Commands
                    Commands.LoadAll();
                    #endregion
                    #region Load YSF
                    FormatYSFDirectory();
                    if (!Directories.DirectoryExists(Settings.Loading.YSFlightDirectory))
                    {
                        Console.TerminateConsole("YSFlight Directory Not Found.");
                    }
                    LoadAllMetaData();
                    if (!World.Load(OpenYS.Field.FieldName))
                    {
                        Console.TerminateConsole("FLD Name not found.");
                    }
                    #endregion
                    #region Load Games
                    Games.Racing.Initialise();
                    //Console.WriteLine();
                    #endregion
                    #region Loading Complete!
                    Console.WriteLine("");
                    Console.WriteLine(ConsoleColor.DarkYellow, "Loading Complete!");
                    Console.WriteLine("");
                    #endregion
                    #endregion

                    //Connection Handling Services.
                    #region Start Server
                    Server.Listener.Start();
                    OpenYS.YSFListener.ServerStarted.WaitOne();
                    #endregion

                    #region External IP & IRC
                    Threads.Add(() =>
                    {
                        #region IRC
                        IRC.Init();
                        IRC.Start();
                        #endregion
                        #region External IP
                        //Console.WriteLine();
                        //Console.WriteLine("&6Fetching External IP...");
                        //Console.WriteLine();
                        var ExternalIP = Environment.ExternalIP;
                        //Console.WriteLine("&6External IP: " + Environment.ExternalIP.ToString());
                        #endregion
                    }, "IRC/External IP Loading...");
                    //Console.WriteLine();
                    #endregion

                    //Timing Services.
                    #region Restart Timer
                    OpenYS.StartResetTimer();
                    #endregion
                    #region Lock/Unlock Console Input
                    Console.Locked = false;
                    Console.WriteLine("\r");     //effectively refreshes the prompt...
                    #endregion
                    #region SetServerTime
                    OpenYS.SetServerTimeTicks(Settings.Weather.Time * 10);
                    #endregion
                    int SeqLoaded = Sequencers.LoadAll();
                    int SchLoaded = Schedulers.LoadAll();

                    Thread.Sleep(10);
                    int LoopsPassed = 0;

                    while (!OpenYS.Signal_ResetServer.WaitOne(0))
                    {
                        #region Start Tick Update!
                        DateTime StartUpdate = DateTime.Now;
                        #endregion

                        OpenYS.PollResetTimer();
                        //OpenYS.MicroTick();
                        //OpenYS.MacroTick();
                        //OpenYS.UpdateTimeOfDay();
                        //Schedulers.Poll();
                        //Sequencers.Poll();
                        //YSFlightReplays.ServerReplay.SendUpdate();

                        #region End Tick Update!
                        DateTime EndUpdate = DateTime.Now;
                        #endregion
                        #region MicroTick Delay
                        OpenYS.Time_LastMicroTick = DateTime.Now;
                        int ThisUpdateTotalTime = (int)Math.Ceiling(((TimeSpan)(EndUpdate - StartUpdate)).TotalMilliseconds);
                        if (ThisUpdateTotalTime < 100)
                        {
                            Thread.Sleep(100 - ThisUpdateTotalTime);     //Micro Tick Delay.
                        }
                        //No Delay, resume immediately! - The update took over 100m/s!
                        #endregion
                        LoopsPassed++;
                    }
                    //We should reset now.
                    //OpenYS.TickUpdaterThread.Abort();
                    Schedulers.StopAll();
                    Sequencers.StopAll();
                    Server.Listener.Stop();
                    Console.Clear();
                    args = Environment.CommandLineArguments;
                    //Utilities.Restart();
                }
                #endregion
                #region CATCH
#if RELEASE
            }

            catch (Exception e)
            {
                if (e is ThreadAbortException)
                {
                    return;
                }
                Log.Error(e);
                #region TRY:
#if RELEASE
                try
                {
#endif
                #endregion
                #region Terminate
                Console.Locked = true;
                Console.WriteLine(ConsoleColor.Red, "OpenYS Has been terminated with error:");
                Console.WriteLine();
                Console.WriteLine(Debug.GetStackTrace(e));
                Emailing.SendCrashReportEmail(e);
                Thread.Sleep(5000);
                //RemovePDB();
                System.Environment.Exit(0);
                Console.WriteLine();
                Console.Terminate.Set();
                Console.Reader.Abort();
                for (int i = 10 - 1; i > 0; i--)
                {
                    Console.WriteLine(String.Format("\r&cOpenYS Will Restart In &f{0}&c Seconds.   ", i + 1));
                    Thread.Sleep(1000);
                }
                Console.WriteLine(String.Format("\r&cOpenYS Will Restart In &f1&c Second.   "));
                Thread.Sleep(1000);
                for (int i = 3; i > 0; i--)
                {
                    Console.WriteLine("\r&c!!!&f OpenYS Restarting &c!!!                            ");
                    Thread.Sleep(500);
                    Console.WriteLine("\r                                                  ");
                    Thread.Sleep(500);
                }
                Environment.RestartNow();
                #endregion
                #region CATCH
#if RELEASE
            }
            catch (Exception e2)
            {
                Console.WriteLine("Safe Restart Failed... Sorry!");
                Console.WriteLine(e2.Message);
                Log.Error(e2);
                Thread.Sleep(Timeout.Infinite);
                Console.TerminateConsole("End Of Program");
                return;
            }
#endif
                #endregion
            }
#endif
                #endregion
            }