Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            AcServerPluginManager pluginManager = null;

            try
            {
                pluginManager = new AcServerPluginManager(new FileLogWriter("log", "minoplugin.txt")
                {
                    CopyToConsole = true, LogWithTimestamp = true,
                })
                {
                    AcServerKeepAliveIntervalSeconds = 60
                };

                pluginManager.LoadInfoFromServerConfig();
                pluginManager.AddPlugin(new MinoratingPlugin());
                pluginManager.LoadPluginsFromAppConfig();
                DriverInfo.MsgCarUpdateCacheSize = 100;

                pluginManager.RunUntilAborted();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                try
                {
                    pluginManager.Log(ex);
                }
                catch (Exception) { }
            }
        }
Ejemplo n.º 2
0
        public LocalAuthCache(int httpPort, AcServerPluginManager log)
        {
            this.port = httpPort;
            this.Log  = log;

            LiveDataServer = new LiveDataDumpClient(
                new BasicHttpBinding()
            {
                MaxReceivedMessageSize = MaxMessageSize,
                ReaderQuotas           = new System.Xml.XmlDictionaryReaderQuotas()
                {
                    MaxStringContentLength = MaxMessageSize
                }
            }, new EndpointAddress("http://plugin.minorating.com:805/minorating/12"));
        }
Ejemplo n.º 3
0
        public static void RunUntilAborted(this AcServerPluginManager pluginManager)
        {
            if (pluginManager == null)
            {
                throw new ArgumentNullException("pluginManager");
            }

            var pluginManagerService = new RunPluginInConsoleServiceHelper(pluginManager);

            try
            {
                pluginManagerService.InteractiveStart();
                // Important note: Everything until pluginManagerService.InteractiveStop() won't happen for the services,
                // so please do only place console-related stuff here
                var input = GetBlockingInput();
                while (input != "x" && input != "exit" && pluginManager.IsConnected)
                {
                    // Basically we're blocking the Main Thread until exit.
                    // Ugly, but pretty easy to use by the deriving Plugin

                    // To have a bit of functionality we'll let the server admin
                    // type in commands that can be understood by the deriving plugin
                    if (!string.IsNullOrEmpty(input))
                    {
                        pluginManager.ProcessEnteredCommand(input);
                    }

                    input = GetBlockingInput();
                }
                pluginManagerService.InteractiveStop();
            }
            catch (Exception ex)
            {
                pluginManager.Log("Error in RunUntilAborted");
                pluginManager.Log(ex);
            }
            finally
            {
                if (pluginManager.IsConnected)
                {
                    pluginManager.Disconnect();
                }
                pluginManager.Log("Disconnected...");
            }
        }
Ejemplo n.º 4
0
 static void Main(string[] args)
 {
     try
     {
         AcServerPluginManager pluginManager = new AcServerPluginManager(new FileLogWriter(".", "log.txt")
         {
             CopyToConsole = true, LogWithTimestamp = true
         });
         pluginManager.LoadInfoFromServerConfig();
         pluginManager.AddPlugin(new Admin2ChatPlugin());
         pluginManager.LoadPluginsFromAppConfig();
         RunPluginInConsole.RunUntilAborted(pluginManager);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 5
0
        protected override void OnStart(string[] args)
        {
            // TODO: Add code here to start your service.
            RaceTimeACPlugin raceTimePlugin = new RaceTimeACPlugin();

            AcServerPluginManager pluginManager = new AcServerPluginManager();

            pluginManager.LoadInfoFromServerConfig();
            pluginManager.AddPlugin(raceTimePlugin);
            pluginManager.LoadPluginsFromAppConfig();
            pluginManager.Connect();

            parser           = new AssettoCorsaFileParser(raceTimePlugin);
            parser.FileAlive = true;
            Thread thread = new Thread(new ParameterizedThreadStart(StartFileParser));

            thread.Start(parser);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            RaceTimeACPlugin raceTimePlugin = new RaceTimeACPlugin();

            AcServerPluginManager pluginManager = new AcServerPluginManager();

            pluginManager.LoadInfoFromServerConfig();
            pluginManager.AddPlugin(raceTimePlugin);
            pluginManager.LoadPluginsFromAppConfig();
            pluginManager.Connect();

            var parser = new AssettoCorsaFileParser(raceTimePlugin);

            parser.FileAlive = true;
            Thread thread = new Thread(new ParameterizedThreadStart(StartFileParser));

            thread.Start(parser);

            Console.ReadLine();
            parser.FileAlive = false;
            Console.ReadLine();
        }
Ejemplo n.º 7
0
 void IAcServerPlugin.OnInit(AcServerPluginManager manager)
 {
     PluginManager = manager;
     OnInit();
 }
Ejemplo n.º 8
0
        protected override void OnLapCompleted(LapInfo lap)
        {
            DriverInfo driver = PluginManager.GetDriverByConnectionId(lap.ConnectionId);

            driver.LapCount = lap.LapNo;
            if (lap.Cuts == 0 && (lap.Laptime < driver.BestLap || driver.BestLap == 0))
            {
                driver.BestLap = lap.Laptime;
            }

            if (this.BroadcastFastestLap > 0)
            {
                // check if this is a new fastest lap for this session
                if (lap.Cuts == 0 && this.PluginManager.CurrentSession.Laps.FirstOrDefault(l => l.Cuts == 0 && l.Laptime < lap.Laptime) == null)
                {
                    this.PluginManager.BroadcastChatMessage(
                        string.Format("{0} has set a new fastest lap: {1}", driver.DriverName, AcServerPluginManager.FormatTimespan((int)lap.Laptime)));
                }
                else if (this.BroadcastFastestLap > 1)
                {
                    if (lap.Cuts == 0)
                    {
                        this.PluginManager.BroadcastChatMessage(
                            string.Format("{0} completed a lap: {1}", driver.DriverName, AcServerPluginManager.FormatTimespan((int)lap.Laptime)));
                    }
                    else
                    {
                        this.PluginManager.BroadcastChatMessage(
                            string.Format("{0} did a lap with {1} cut(s): {2}", driver.DriverName, lap.Cuts, AcServerPluginManager.FormatTimespan((int)lap.Laptime)));
                    }
                }
            }
        }
 public RunPluginInConsoleServiceHelper(AcServerPluginManager mgrToRun)
 {
     _pluginManager = mgrToRun;
 }
Ejemplo n.º 10
0
 public BackendMessageQueue(AcServerPluginManager pluginManager)
 {
     PluginManager = pluginManager;
     Init();
 }
Ejemplo n.º 11
0
        private static void Main()
        {
            try
            {
                FileLogWriter logWriter = null;

                IConfigManager config = new AppConfigConfigurator();

                bool interactiveConsole = config.GetSettingAsInt("interactive_console", 0) == 1;

                if (config.GetSettingAsInt("log_to_console", 0) == 0)
                {
                    if (config.GetSettingAsInt("overwrite_log_file", 0) == 1)
                    {
                        logWriter = new FileLogWriter(
                            Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "logs"),
                            "TrackCycle.log")
                        {
                            LogWithTimestamp = true
                        };
                    }
                    else
                    {
                        logWriter = new FileLogWriter(
                            Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "logs"),
                            DateTime.UtcNow.ToString("yyyyMMdd_HHmmss") + "_Startup.log")
                        {
                            LogWithTimestamp = true
                        };
                    }
                }

                try
                {
                    trackCycler = new TrackCyclePlugin();

                    AcServerPluginManager pluginManager = new AcServerPluginManager(logWriter, config);
                    pluginManager.LoadInfoFromServerConfig();
                    pluginManager.AddPlugin(trackCycler);
                    pluginManager.LoadPluginsFromAppConfig();

                    if (!MonoHelper.IsLinux)
                    {
                        // Some boilerplate to react to close window event, CTRL-C, kill, etc
                        _handler += new EventHandler(Handler);
                        SetConsoleCtrlHandler(_handler, true);
                    }

                    trackCycler.StartServer();
                    Console.Out.WriteLine("Server running...");

                    if (interactiveConsole)
                    {
                        Console.Out.WriteLine("Write 'next_track' to cycle to the next track.");
                        Console.Out.WriteLine("Write 'exit' to shut the server down.");
                    }

                    while (true)
                    {
                        if (interactiveConsole)
                        {
                            string line = Console.ReadLine();
                            if (line.ToLower() == "exit")
                            {
                                break;
                            }
                            else if (line.ToLower() == "next_track")
                            {
                                trackCycler.NextTrackAsync(true);
                            }
                            else
                            {
                                pluginManager.BroadcastChatMessage(line);
                            }
                        }
                        else
                        {
                            Thread.Sleep(500);
                        }
                    }

                    trackCycler.StopServer();
                }
                catch (Exception ex)
                {
                    if (logWriter != null)
                    {
                        logWriter.Log(ex);
                    }
                    else
                    {
                        throw;
                    }
                }
                if (logWriter != null)
                {
                    logWriter.StopLoggingToFile();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 12
0
        public TrackCyclerForm()
        {
            this.InitializeComponent();
            this.trackMapControl        = new TrackMapControl();
            this.trackMapControl.Dock   = DockStyle.Fill;
            this.trackMapControl.Paint += trackMapControl_Paint;
            this.tabPage_PositionGraph.Controls.Add(this.trackMapControl);

            this.logWriter = new GuiLogWriter(
                this,
                Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "logs"),
                DateTime.UtcNow.ToString("yyyyMMdd_HHmmss") + "_Startup.log")
            {
                LogWithTimestamp = true
            };
            this.logWriter.LogMessagesToFile = this.checkBoxCreateLogs.Checked;

            this.trackCycler = new GuiTrackCyclePlugin(this);

            this.pluginManager = new AcServerPluginManager(this.logWriter);
            this.pluginManager.LoadInfoFromServerConfig();
            this.pluginManager.AddPlugin(this.trackCycler);
            this.pluginManager.LoadPluginsFromAppConfig();

            if (!this.trackCycler.HasCycle)
            {
                this.buttonNextTrack.Enabled         = false;
                this.checkBoxAutoChangeTrack.Checked = false;
                this.checkBoxAutoChangeTrack.Enabled = false;
                this.button_ChangeTrack.Enabled      = false;
            }
            else
            {
                this.listBox_CycleSessions.DataSource = this.trackCycler.Sessions;
            }

            this.checkBoxAutoChangeTrack.Checked = this.trackCycler.AutoChangeTrack;

            this.origBroadcastResultCount = this.trackCycler.BroadcastResults;
            if (origBroadcastResultCount <= 0)
            {
                origBroadcastResultCount = 10;
            }
            else
            {
                this.checkBox_BroadcastResults.Checked = true;
            }

            if (this.trackCycler.BroadcastIncidents < 0 || this.trackCycler.BroadcastIncidents > 2)
            {
                this.trackCycler.BroadcastIncidents = 0;
            }

            this.checkBox_BroadcastIncidents.CheckState = (CheckState)this.trackCycler.BroadcastIncidents;

            this.checkBox_BroadcastFastestLap.CheckState = (CheckState)this.trackCycler.BroadcastFastestLap;

            this.dataGridView_connections.AutoGenerateColumns = false;

            if (this.trackCycler.CreateServerWindow || this.trackCycler.HasAdditionalExes)
            {
                this.TopMost = true;
            }

            if (File.Exists(whiteListStoragePath))
            {
                string[] data = File.ReadAllLines(whiteListStoragePath);
                whiteList = data.ToList();
                listBox_whitelist.DataSource = whiteList;
            }
            else
            {
                FileStream f = File.Create(whiteListStoragePath);
                f.Close();
                whiteList = new List <string>();
            }
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            checkBox_enableWhiteList.Checked = (config.AppSettings.Settings["enable_white_list"].Value == "1" ? true : false);
        }
Ejemplo n.º 13
0
 internal void Initialize(AcServerPluginManager manager)
 {
     this.PluginManager = manager;
     this.OnInit();
 }