private void OnIncoming(IrcClient irc, IRCQEvent ev) { if (ev is ServerStatusEvent) { if (((ServerStatusEvent)ev).Status == ServerStatus.Connected) { _channel = GameChannel.Config["Channel"]; _irc.JoinChannel(_channel); PostConnect(); } else { // Disconnected for some reason. _irc.Connect(); } } // At this point checking if the bot somehow left its channel else if (ev is PartEvent) { var pe = (PartEvent)ev; if (pe.Sender.IsClient) { _irc.JoinChannel(_channel); } } else if (ev is KickEvent) { var ke = (KickEvent)ev; if (ke.Target.IsClient) { _irc.JoinChannel(_channel); } } }
public ConnectManager(IrcClient irc, GameManager dispatcher) { _irc = irc; _disp = dispatcher; _irc.OnIRCQEvent += PrintIncoming; _irc.OnIRCQEvent += OnIncoming; }
public IRCQueue(IrcClient ext) { _external = ext; _queue = new BlockingCollection<IRCQEvent>(new ConcurrentQueue<IRCQEvent>()); _runner = new Thread(Worker); _runner.Name = "IRCQueue"; _runner.IsBackground = true; // background by default _runner.Start(); }
private Timer _ticker; // Helps generate the periodic tick used by games #endregion Fields #region Constructors internal GameManager(IrcClient irc, Loader loader) { _irc = irc; _irc.OnIRCQEvent += OnIncoming; _loader = loader; _tickCount = 0; _ticker = new Timer( delegate { _irc.Enqueue(new TickEvent()); }, null, Timeout.Infinite, Timeout.Infinite); _commands = new Dictionary<string, CommandHandler>(); CommandSetup(); }
private void PrintIncoming(IrcClient irc, IRCQEvent ev) { if (ev is TickEvent) { return; } else if (ev is ChannelEvent) { if (((ChannelEvent)ev).Channel == _channel.ToLower()) { GameChannel.Out(_channel, ev.ToString()); } } else if (ev is IrcEvent) { GameChannel.Out("IRCQueue", ev.ToString()); } else if (ev is UserMessageEvent) { GameChannel.Out(GameChannel.Config["Server"], ev.ToString()); } else { GameChannel.Out("GameChannel", ev.ToString()); } }
public static void Main(string[] args) { GameChannel.Out("GameChannel", "Version " + Version); IrcClient irc = new IrcClient(); irc.IsBackground = false; Loader loader = new Loader(); dispatcher = new GameManager(irc, loader); manager = new ConnectManager(irc, dispatcher); Console.CancelKeyPress += OnConsoleInterrupt; AppDomain.CurrentDomain.UnhandledException += UnhandledException; GameChannel.Out("GameChannel", "Reading configuration"); ConnectionSettings serverconf = LoadServerConfig(); GameChannel.Out("GameChannel", "Applying configuration and connecting"); irc.Settings = serverconf; irc.Connect(); }
// Common processing for events done here before branching private void OnIncoming(IrcClient irc, IRCQEvent ev) { if (ev is ServerStatusEvent) { if (((ServerStatusEvent)ev).Status == ServerStatus.Connected) { // Get channel name from config Channel = GameChannel.Config["Channel"]; } else { // Connection lost KillGame(); return; } } else if (ev is KickEvent) { // Kicked out if (((KickEvent)ev).Target.IsClient) { KillGame(); return; } } else if (ev is ChannelMessageEvent) { var cme = (ChannelMessageEvent)ev; if (cme.Channel == Channel.ToLower()) { string[] line = cme.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (line.Length != 0 && line[0].Length > 0 && line[0][0] == '%') { line[0] = line[0].Substring(1).ToLower(); CommandHandler command; if (_commands.TryGetValue(line[0], out command)) { // GameChannel command command(cme, line); return; } else if (_game == null && _loader.CreateInstance(line[0], out _game, out _gameDispName)) { // Game start command GameChannel.Out(GameDisplayName, "Instance created."); _game.Insert(this, _irc); try { _game.OnInit(cme.Sender, cme.Channel.Users, line); } catch (Exception ex) { _irc.SendMessage(Channel, "\u000300,04An error occurred during game startup " + "(" + ex.GetType().FullName + " - Details in log)."); _irc.SendMessage(Channel, "\u000300,04The game will now be killed."); GameChannel.Out(line[0], ex.ToString()); KillGame(); return; } _gameStartTime = DateTime.Now; reqTickReset = false; reqEndGame = false; _tickCount = 0; _ticker.Change(_tickInterval, Timeout.Infinite); _canKill = false; return; } } } } if (_game != null) DispatchToGame(ev); }