private void ExecuteAction(PluginReaction a) { if (a == null) { return; } LastBackendActivity = DateTime.Now; try { PluginManager.Log("Action for car " + a.CarId + ": " + a.Reaction + " " + a.Text); switch (a.Reaction) { case PluginReaction.ReactionType.None: break; case PluginReaction.ReactionType.Whisper: PluginManager.SendChatMessage(a.CarId, a.Text); break; case PluginReaction.ReactionType.Broadcast: PluginManager.BroadcastChatMessage(a.Text); break; case PluginReaction.ReactionType.Ballast: break; case PluginReaction.ReactionType.Pit: break; case PluginReaction.ReactionType.Kick: { // To be 100% sure we kick the right person we'll have to compare the steam id DriverInfo c; if (this.PluginManager.TryGetDriverInfo(a.CarId, out c)) { if (c.IsConnected && c.DriverGuid == a.SteamId) { PluginManager.BroadcastChatMessage("" + c.DriverName + " has been kicked by minorating.com"); PluginManager.RequestKickDriverById(a.CarId); } } } break; case PluginReaction.ReactionType.Ban: break; case PluginReaction.ReactionType.NextSession: PluginManager.NextSession(); break; case PluginReaction.ReactionType.RestartSession: PluginManager.RestartSession(); break; case PluginReaction.ReactionType.AdminCmd: PluginManager.AdminCommand(a.Text); break; default: break; } } catch (Exception ex) { Console.WriteLine("Execute action: Error for car " + a.CarId + "/" + a.Text + ": " + ex.Message); } }
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); } }