Ejemplo n.º 1
0
        private static void OnErrorMessage(object sender, IrcEventArgs e)
        {
            string message;

            switch (e.Data.ReplyCode)
            {
            case ReplyCode.ErrorBannedFromChannel:
                message = CRCStrings.Localize("client_banned");
                CRCDisplay.AddError(message);
                CRCGame.AddError(message);
                break;

            // What's the difference?
            case ReplyCode.ErrorNicknameInUse:
            case ReplyCode.ErrorNicknameCollision:
                message = CRCStrings.Localize("client_nick_collision");
                CRCDisplay.AddError(message);
                CRCGame.AddError(message);
                break;

            // Don't care
            case ReplyCode.ErrorNoMotd:
            case ReplyCode.ErrorNotRegistered:
                break;

            default:
                CRCDisplay.AddError(e.Data.Message);
                CRCGame.AddError(e.Data.Message);
                break;
            }
        }
Ejemplo n.º 2
0
        private static void OnTopicChange(object sender, TopicChangeEventArgs e)
        {
            string message = CRCStrings.Localize("client_topic_change") + e.NewTopic;

            CRCDisplay.AddInformation(message);
            CRCGame.AddInformation(message);
        }
Ejemplo n.º 3
0
        private static void OnNickChange(object sender, NickChangeEventArgs e)
        {
            string oldNick = e.OldNickname;
            string newNick = e.NewNickname;

            Users.Remove(oldNick);
            Users.Add(newNick);
            Users.Sort();
            CRCDisplay.UpdateUsers();
            CRCGame.UpdateUsers();
            if (newNick != client.Nickname)
            {
                if (crcNicks.ContainsKey(oldNick))
                {
                    crcNicks[newNick] = crcNicks[oldNick];
                    crcNicks.Remove(oldNick);
                }
                string message = oldNick + CRCStrings.Localize("client_nick_change") + newNick;
                CRCDisplay.AddInformation(message);
                CRCGame.AddInformation(message);
            }
            else
            {
                CRCOptions.Name = newNick;
                string message = CRCStrings.Localize("client_own_nick_change") + newNick;
                CRCDisplay.AddInformation(message);
                CRCGame.AddInformation(message);
            }
        }
Ejemplo n.º 4
0
        public static void SendDeath(string message)
        {
            string nick = CRCStrings.RandomName(CRCOptions.GameFaction);

            client.SendMessage(SendType.Message, CRCOptions.ChannelProxy(), nick + FAKE_DELIM + CRCOptions.GetFaction() + META_DELIM + message);
            CRCDisplay.OnChannelMessage(nick, message);
            CRCGame.OnChannelMessage(nick, CRCOptions.GameFaction, message);
        }
Ejemplo n.º 5
0
 private static void OnDisconnected(object sender, EventArgs e)
 {
     if (retry)
     {
         string message = CRCStrings.Localize("client_reconnecting");
         CRCDisplay.AddInformation(message);
         CRCGame.AddInformation(message);
         client.Connect(CRCOptions.Server, 6667);
     }
 }
Ejemplo n.º 6
0
 private static void OnChannelActiveSynced(object sender, IrcEventArgs e)
 {
     foreach (ChannelUser user in client.GetChannel(e.Data.Channel).Users.Values)
     {
         Users.Add(user.Nick);
     }
     Users.Sort();
     CRCDisplay.UpdateUsers();
     CRCGame.UpdateUsers();
     client.SendMessage(SendType.CtcpRequest, e.Data.Channel, "CLIENTINFO");
 }
Ejemplo n.º 7
0
        private static void OnQuit(object sender, QuitEventArgs e)
        {
            crcNicks.Remove(e.Who);
            Users.Remove(e.Who);
            Users.Sort();
            CRCDisplay.UpdateUsers();
            CRCGame.UpdateUsers();
            string message = e.Who + CRCStrings.Localize("client_part");

            CRCDisplay.AddInformation(message);
            CRCGame.AddInformation(message);
        }
Ejemplo n.º 8
0
        private static void OnQueryMessage(object sender, IrcEventArgs e)
        {
            lastQuery = e.Data.Nick;
            // Metadata should not be used in queries, just throw it out
            string fakeNick, faction;
            string message = GetMetadata(e.Data.Message, out fakeNick, out faction);
            string nick    = e.Data.Nick;

            faction = crcNicks.ContainsKey(nick) ? crcNicks[nick] : "actor_stalker";
            CRCDisplay.OnQueryMessage(nick, CRCOptions.Name, message);
            CRCGame.OnQueryMessage(nick, CRCOptions.Name, faction, message);
        }
Ejemplo n.º 9
0
        public static void Start()
        {
#if DEBUG
            debugThread = new Thread(() => Application.Run(debug));
            debugThread.Start();
#endif
            client.Encoding             = Encoding.UTF8;
            client.SendDelay            = 200;
            client.ActiveChannelSyncing = true;

            client.OnConnected           += new EventHandler(OnConnected);
            client.OnChannelActiveSynced += new IrcEventHandler(OnChannelActiveSynced);
            client.OnRawMessage          += new IrcEventHandler(OnRawMessage);
            client.OnChannelMessage      += new IrcEventHandler(OnChannelMessage);
            client.OnQueryMessage        += new IrcEventHandler(OnQueryMessage);
            client.OnJoin         += new JoinEventHandler(OnJoin);
            client.OnPart         += new PartEventHandler(OnPart);
            client.OnQuit         += new QuitEventHandler(OnQuit);
            client.OnNickChange   += new NickChangeEventHandler(OnNickChange);
            client.OnErrorMessage += new IrcEventHandler(OnErrorMessage);
            client.OnKick         += new KickEventHandler(OnKick);
            client.OnDisconnected += new EventHandler(OnDisconnected);
            client.OnTopic        += new TopicEventHandler(OnTopic);
            client.OnTopicChange  += new TopicChangeEventHandler(OnTopicChange);
            client.OnCtcpRequest  += new CtcpEventHandler(OnCtcpRequest);
            client.OnCtcpReply    += new CtcpEventHandler(OnCtcpReply);

            try
            {
                client.Connect(CRCOptions.Server, 6667);
                client.Listen();
            }
            catch (CouldNotConnectException)
            {
                MessageBox.Show(CRCStrings.Localize("client_connection_error"), CRCStrings.Localize("crc_name"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                CRCDisplay.Stop();
            }
#if DEBUG
            debug.Invoke(new Action(() => debug.Close()));
            debugThread.Join();
#endif
        }
Ejemplo n.º 10
0
 private static void OnPart(object sender, PartEventArgs e)
 {
     if (e.Who != CRCOptions.Name)
     {
         crcNicks.Remove(e.Who);
         Users.Remove(e.Who);
         Users.Sort();
         CRCDisplay.UpdateUsers();
         CRCGame.UpdateUsers();
         string message = e.Who + CRCStrings.Localize("client_part");
         CRCDisplay.AddInformation(message);
         CRCGame.AddInformation(message);
     }
     else
     {
         string message = CRCStrings.Localize("client_own_part");
         CRCDisplay.AddInformation(message);
         CRCGame.AddInformation(message);
     }
 }
Ejemplo n.º 11
0
 private static void OnJoin(object sender, JoinEventArgs e)
 {
     if (e.Who != client.Nickname)
     {
         Users.Add(e.Who);
         Users.Sort();
         CRCDisplay.UpdateUsers();
         CRCGame.UpdateUsers();
         string message = e.Who + CRCStrings.Localize("client_join");
         CRCDisplay.AddInformation(message);
         CRCGame.AddInformation(message);
     }
     else
     {
         CRCOptions.Name = e.Who;
         string message = CRCStrings.Localize("client_connected");
         CRCDisplay.AddInformation(message);
         CRCGame.AddInformation(message);
         CRCDisplay.OnConnected();
     }
 }
Ejemplo n.º 12
0
        private static void OnKick(object sender, KickEventArgs e)
        {
            string victim = e.Whom;

            if (victim == CRCOptions.Name)
            {
                Users.Clear();
                string message = CRCStrings.Localize("client_got_kicked") + e.KickReason;
                CRCDisplay.AddError(message);
                CRCGame.AddError(message);
                CRCDisplay.OnGotKicked();
            }
            else
            {
                crcNicks.Remove(e.Who);
                Users.Remove(victim);
                Users.Sort();
                string message = victim + CRCStrings.Localize("client_kicked") + e.KickReason;
                CRCDisplay.AddInformation(message);
                CRCGame.AddInformation(message);
            }
            CRCDisplay.UpdateUsers();
            CRCGame.UpdateUsers();
        }
Ejemplo n.º 13
0
        private static void OnChannelMessage(object sender, IrcEventArgs e)
        {
            string fakeNick, faction;
            string message = GetMetadata(e.Data.Message, out fakeNick, out faction);

            // If some cheeky m8 just sends delimiters, ignore it
            if (message.Length > 0)
            {
                string nick;
                if (fakeNick == null)
                {
                    nick    = e.Data.Nick;
                    faction = crcNicks.ContainsKey(nick) ? crcNicks[nick] : "actor_stalker";
                }
                else if (CRCOptions.ReceiveDeath && (DateTime.Now - lastDeath).TotalSeconds > CRCOptions.DeathInterval)
                {
                    lastDeath = DateTime.Now;
                    nick      = e.Data.Nick; //fakeNick;
                }
                else
                {
                    return;
                }
                if (message.Contains(CRCOptions.Name))
                {
                    SystemSounds.Asterisk.Play();
                    CRCDisplay.OnHighlightMessage(nick, message);
                    CRCGame.OnHighlightMessage(nick, faction, message);
                }
                else
                {
                    CRCDisplay.OnChannelMessage(nick, message);
                    CRCGame.OnChannelMessage(nick, faction, message);
                }
            }
        }
Ejemplo n.º 14
0
 public static void SendQuery(string nick, string message)
 {
     client.SendMessage(SendType.Message, nick, CRCOptions.GetFaction() + META_DELIM + message);
     CRCDisplay.OnQueryMessage(CRCOptions.Name, nick, message);
     CRCGame.OnQueryMessage(CRCOptions.Name, nick, CRCOptions.GetFaction(), message);
 }
Ejemplo n.º 15
0
 public static void Send(string message)
 {
     client.SendMessage(SendType.Message, CRCOptions.ChannelProxy(), message);
     CRCDisplay.OnOwnChannelMessage(CRCOptions.Name, message);
     CRCGame.OnChannelMessage(CRCOptions.Name, CRCOptions.GetFaction(), message);
 }
Ejemplo n.º 16
0
        public static void GameUpdate()
        {
            if (disable || processID == -1)
            {
                return;
            }

            // Wipe game output when first discovered
            if (!firstClear)
            {
                try
                {
                    File.WriteAllText(gamePath + CRCOptions.OutPath, "", encoding);
                    firstClear = true;
                }
                catch (IOException)
                {
                    return;
                }
                catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException)
                {
                    Disable();
                    return;
                }
            }

            // Get messages from game
            try
            {
                string[] lines = File.ReadAllLines(gamePath + CRCOptions.OutPath, encoding);
                File.WriteAllText(gamePath + CRCOptions.OutPath, "", encoding);
                foreach (string line in lines)
                {
                    Match  typeMatch = outputRx.Match(line);
                    string type      = typeMatch.Groups[1].Value;
                    if (type == "Handshake")
                    {
                        if (Convert.ToInt16(typeMatch.Groups[2].Value) < SCRIPT_VERSION)
                        {
                            AddError(CRCStrings.Localize("game_script_version_error"));
                            CRCDisplay.AddError(CRCStrings.Localize("game_script_version_error"));
                        }
                        UpdateSettings();
                        UpdateUsers();
                    }
                    else if (type == "Message")
                    {
                        Match  messageMatch = messageRx.Match(typeMatch.Groups[2].Value);
                        string faction      = messageMatch.Groups[1].Value;
                        string message      = messageMatch.Groups[2].Value;
                        if (message[0] == '/')
                        {
                            CRCCommands.ProcessCommand(message, wrapper);
                        }
                        else
                        {
                            CRCOptions.GameFaction = CRCStrings.ValidateFaction(faction);
                            CRCClient.UpdateSettings();
                            if (CRCOptions.GameFaction == "actor_zombied")
                            {
                                CRCClient.Send(CRCZombie.Generate());
                            }
                            else
                            {
                                CRCClient.Send(message);
                            }
                        }
                    }
                    else if (type == "Death" && CRCOptions.SendDeath)
                    {
                        Match  deathMatch = deathRx.Match(typeMatch.Groups[2].Value);
                        string faction    = deathMatch.Groups[1].Value;
                        string level      = deathMatch.Groups[2].Value;
                        string xrClass    = deathMatch.Groups[3].Value;
                        string section    = deathMatch.Groups[4].Value;
                        CRCOptions.GameFaction = CRCStrings.ValidateFaction(faction);
                        CRCClient.UpdateSettings();
                        if (CRCOptions.GameFaction != "actor_zombied")
                        {
                            string message = CRCStrings.DeathMessage(CRCOptions.Name, level, xrClass, section);
                            CRCClient.SendDeath(message);
                        }
                    }
                }
            }
            catch (IOException) { }
            catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException)
            {
                Disable();
                return;
            }

            // Send messages to game
            lock (sendQueue)
            {
                try
                {
                    File.AppendAllText(gamePath + CRCOptions.InPath, sendQueue.ToString(), encoding);
                    sendQueue.Clear();
                }
                catch (IOException) { }
                catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException)
                {
                    Disable();
                    return;
                }
            }
        }