Example #1
0
        private static void OnTopicChange(object sender, TopicChangeEventArgs e)
        {
            string message = CRCStrings.Localize("client_topic_change") + e.NewTopic;

            CRCDisplay.AddInformation(message);
            CRCGame.AddInformation(message);
        }
Example #2
0
        public OptionsForm()
        {
            InitializeComponent();
            Text                         = CRCStrings.Localize("options_title");
            buttonOK.Text                = CRCStrings.Localize("options_ok");
            buttonCancel.Text            = CRCStrings.Localize("options_cancel");
            tabControl1.TabPages[0].Text = CRCStrings.Localize("options_tab_client");
            tabControl1.TabPages[1].Text = CRCStrings.Localize("options_tab_game");

            labelLanguage.Text            = CRCStrings.Localize("options_language");
            labelChannel.Text             = CRCStrings.Localize("options_channel");
            radioButtonFactionAuto.Text   = CRCStrings.Localize("options_auto_faction");
            radioButtonFactionManual.Text = CRCStrings.Localize("options_manual_faction");
            labelName.Text            = CRCStrings.Localize("options_name");
            buttonRandom.Text         = CRCStrings.Localize("options_name_random");
            checkBoxTimestamps.Text   = CRCStrings.Localize("options_timestamps");
            checkBoxDeathSend.Text    = CRCStrings.Localize("options_send_deaths");
            checkBoxDeathReceive.Text = CRCStrings.Localize("options_receive_deaths");
            labelDeathInterval.Text   = CRCStrings.Localize("options_death_interval");
            labelDeathSeconds.Text    = CRCStrings.Localize("crc_seconds");

            labelNewsDuration.Text = CRCStrings.Localize("options_news_duration");
            labelNewsSeconds.Text  = CRCStrings.Localize("crc_seconds");
            labelChatKey.Text      = CRCStrings.Localize("options_chat_key");
            buttonChatKey.Text     = CRCStrings.Localize("options_chat_key_change");
            checkBoxNewsSound.Text = CRCStrings.Localize("options_news_sound");
            checkBoxCloseChat.Text = CRCStrings.Localize("options_close_chat");
        }
Example #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);
            }
        }
Example #4
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;
            }
        }
 public ClientDisplay()
 {
     InitializeComponent();
     Text               = CRCStrings.Localize("crc_name") + " " + Application.ProductVersion;
     buttonSend.Text    = CRCStrings.Localize("display_send");
     buttonOptions.Text = CRCStrings.Localize("display_options");
 }
Example #6
0
        private static string GetMetadata(string message, out string fakeNick, out string faction)
        {
            Match metaMatch = metaRx.Match(message);

            if (metaMatch.Success)
            {
                Match deathMatch = deathRx.Match(metaMatch.Groups[1].Value);
                if (deathMatch.Success)
                {
                    fakeNick = deathMatch.Groups[1].Value;
                    faction  = CRCStrings.ValidateFaction(deathMatch.Groups[2].Value);
                    return(metaMatch.Groups[2].Value);
                }
                else
                {
                    fakeNick = null;
                    faction  = CRCStrings.ValidateFaction(metaMatch.Groups[1].Value);
                    return(metaMatch.Groups[2].Value);
                }
            }
            else
            {
                fakeNick = null;
                faction  = "actor_stalker";
                return(message);
            }
        }
 public KeyPromptForm()
 {
     InitializeComponent();
     labelHelp.Text  = CRCStrings.Localize("keyprompt_help") + "\r\n\r\n";
     labelError.Text = CRCStrings.Localize("keyprompt_error");
     labelError.Hide();
 }
Example #8
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);
        }
Example #9
0
 private static void OnConnected(object sender, EventArgs e)
 {
     Users.Clear();
     crcNicks.Clear();
     lastName    = CRCOptions.Name;
     lastChannel = CRCOptions.ChannelProxy();
     lastFaction = CRCOptions.GetFaction();
     client.Login(CRCOptions.Name, CRCStrings.Localize("crc_name") + " " + Application.ProductVersion);
     client.RfcJoin(CRCOptions.ChannelProxy());
 }
Example #10
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);
     }
 }
Example #11
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);
        }
        private void ClientDisplay_Load(object sender, EventArgs e)
        {
            mainFont = richTextBoxMessages.Font;
            boldFont = new Font(mainFont, FontStyle.Bold);
            timeFont = new Font("Courier New", mainFont.SizeInPoints, FontStyle.Regular);
            if (CRCOptions.DisplaySize != new Size(0, 0))
            {
                Location = CRCOptions.DisplayLocation;
                Size     = CRCOptions.DisplaySize;
            }

            AddInformation(CRCStrings.Localize("display_connecting"));
        }
Example #13
0
        private static void ChangeNick(List <string> args, ICRCSendable output)
        {
            string nick   = args[0].Replace(' ', '_');
            string result = CRCStrings.ValidateNick(nick);

            if (result != null)
            {
                output.AddError(result);
            }
            else
            {
                CRCClient.ChangeNick(nick);
            }
        }
Example #14
0
 public UpdateForm(bool gamedataRequired, string releaseNotes)
 {
     InitializeComponent();
     labelDescription.Text = CRCStrings.Localize("update_description");
     if (gamedataRequired)
     {
         labelGamedata.Text = CRCStrings.Localize("update_gamedata");
     }
     else
     {
         labelGamedata.Text = "";
     }
     labelReleaseNotes.Text   = CRCStrings.Localize("update_notes");
     buttonDownload.Text      = CRCStrings.Localize("update_download");
     buttonClose.Text         = CRCStrings.Localize("update_close");
     webBrowser1.DocumentText = lineBreakRx.Replace(releaseNotes, new MatchEvaluator(addBr));
 }
Example #15
0
        public static bool Load()
        {
            try
            {
                Language = (string)registry.GetValue("Language", null);
                Channel  = (string)registry.GetValue("Channel", null);
                if (Language == null)
                {
                    using (LanguagePrompt languagePrompt = new LanguagePrompt())
                    {
                        languagePrompt.ShowDialog();
                        Language = languagePrompt.Result;
                    }
                }
                if (Channel == null)
                {
                    Channel = defaultChannel[Language];
                }

                DisplayLocation = new Point((int)registry.GetValue("DisplayLocationX", 0),
                                            (int)registry.GetValue("DisplayLocationY", 0));
                DisplaySize = new Size((int)registry.GetValue("DisplayWidth", 0),
                                       (int)registry.GetValue("DisplayHeight", 0));

                AutoFaction    = Convert.ToBoolean((string)registry.GetValue("AutoFaction", "True"));
                GameFaction    = (string)registry.GetValue("GameFaction", "actor_stalker");
                ManualFaction  = (string)registry.GetValue("ManualFaction", "actor_stalker");
                Name           = (string)registry.GetValue("Name", CRCStrings.RandomIrcName(GetFaction()));
                SendDeath      = Convert.ToBoolean((string)registry.GetValue("SendDeath", "True"));
                ReceiveDeath   = Convert.ToBoolean((string)registry.GetValue("ReceiveDeath", "True"));
                DeathInterval  = (int)registry.GetValue("DeathInterval", 0);
                ShowTimestamps = Convert.ToBoolean((string)registry.GetValue("ShowTimestamps", "True"));

                NewsDuration = (int)registry.GetValue("NewsDuration", 10);
                ChatKey      = (string)registry.GetValue("ChatKey", "RETURN");
                NewsSound    = Convert.ToBoolean((string)registry.GetValue("NewsSound", "True"));
                CloseChat    = Convert.ToBoolean((string)registry.GetValue("CloseChat", "True"));

                Save();
                return(true);
            }
            catch (Exception ex) when(ex is SecurityException || ex is UnauthorizedAccessException)
            {
                return(false);
            }
        }
Example #16
0
        private static void OnCtcpReply(object sender, CtcpEventArgs e)
        {
            string from = e.Data.Nick;

            switch (e.CtcpCommand.ToUpper())
            {
            case "CLIENTINFO":
                if (e.CtcpParameter.Contains("FACTION"))
                {
                    crcNicks[from] = "actor_stalker";
                    client.SendMessage(SendType.CtcpRequest, from, "FACTION");
                }
                break;

            case "FACTION":
                crcNicks[from] = CRCStrings.ValidateFaction(e.CtcpParameter);
                break;
            }
        }
Example #17
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
        }
Example #18
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);
     }
 }
Example #19
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();
     }
 }
Example #20
0
        public static async Task <bool> CheckUpdate()
        {
            UpdateChecker updateChecker = new UpdateChecker("TKGP", "Chernobyl-Relay-Chat");
            UpdateType    updateType;

            try
            {
                updateType = await updateChecker.CheckUpdate();
            }
            catch (RateLimitExceededException)
            {
                return(false);
            }
            // If it got past the first one this is probably just a temporary issue
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                {
                    return(ex is HttpRequestException);
                });
                return(false);
            }
            if (updateType != UpdateType.None)
            {
                string releaseNotes = await updateChecker.RenderReleaseNotes();

                SystemSounds.Asterisk.Play();
                CRCGame.OnUpdate(CRCStrings.Localize("update_notice"));
                using (UpdateForm updateForm = new UpdateForm((updateType == UpdateType.Major || updateType == UpdateType.Minor), releaseNotes))
                {
                    DialogResult dialogResult = updateForm.ShowDialog();
                    if (dialogResult == DialogResult.OK)
                    {
                        updateChecker.DownloadAsset("Chernobyl-Relay-Chat.zip");
                    }
                }
                return(true);
            }
            return(false);
        }
Example #21
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

#if !DEBUG
            // Prevent multiple instances
            if (!mutex.WaitOne(TimeSpan.FromSeconds(0), false))
            {
                return;
            }
#endif

            CRCStrings.Load();
            bool optionsLoaded = CRCOptions.Load();
            if (!optionsLoaded)
            {
                // No point localizing this since localization may not even be loaded
                MessageBox.Show("CRC was unable to access the registry, which is needed to preserve settings.\r\n"
                                + "Please try running the application As Administrator.\r\n\r\n"
                                + "CRC не смог получить доступ к реестру, который необходим для сохранения настроек.\r\n"
                                + "Попробуйте запустить приложение с правами администратора.",
                                CRCStrings.Localize("crc_name"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (CRCUpdate.CheckFirstUpdate())
            {
                return;
            }

            displayThread = new Thread(CRCDisplay.Start);
            displayThread.Start();
            clientThread = new Thread(CRCClient.Start);
            clientThread.Start();

            clientThread.Join();
            displayThread.Join();
            CRCOptions.Save();
        }
Example #22
0
        // Note to self: prereleases are ignored

        public static bool CheckFirstUpdate()
        {
            UpdateChecker updateChecker = new UpdateChecker("TKGP", "Chernobyl-Relay-Chat");
            UpdateType    updateType;

            try
            {
                updateType = updateChecker.CheckUpdate().Result;
            }
            catch (RateLimitExceededException)
            {
                return(false);
            }
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                {
                    return(ex is HttpRequestException);
                });
                MessageBox.Show(CRCStrings.Localize("update_failed"), CRCStrings.Localize("crc_name"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(true);
            }
            if (updateType != UpdateType.None)
            {
                string releaseNotes = updateChecker.RenderReleaseNotes().Result;
                SystemSounds.Asterisk.Play();
                using (UpdateForm updateForm = new UpdateForm((updateType == UpdateType.Major || updateType == UpdateType.Minor), releaseNotes))
                {
                    DialogResult dialogResult = updateForm.ShowDialog();
                    if (dialogResult == DialogResult.OK)
                    {
                        updateChecker.DownloadAsset("Chernobyl-Relay-Chat.zip");
                    }
                }
                return(true);
            }
            return(false);
        }
Example #23
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string name   = textBoxName.Text.Replace(' ', '_');
            string result = CRCStrings.ValidateNick(name);

            if (result != null)
            {
                MessageBox.Show(result, CRCStrings.Localize("crc_error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string lang = indexToLanguage[comboBoxLanguage.SelectedIndex];

            if (lang != CRCOptions.Language)
            {
                CRCOptions.Language = lang;
                MessageBox.Show(CRCStrings.Localize("options_language_restart"), CRCStrings.Localize("crc_name"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            CRCOptions.Channel        = indexToChannel[comboBoxChannel.SelectedIndex];
            CRCOptions.AutoFaction    = radioButtonFactionAuto.Checked;
            CRCOptions.ManualFaction  = indexToFaction[comboBoxFaction.SelectedIndex];
            CRCOptions.Name           = name;
            CRCOptions.ShowTimestamps = checkBoxTimestamps.Checked;
            CRCOptions.SendDeath      = checkBoxDeathSend.Checked;
            CRCOptions.ReceiveDeath   = checkBoxDeathReceive.Checked;
            CRCOptions.DeathInterval  = (int)numericUpDownDeath.Value;

            CRCOptions.NewsDuration = (int)numericUpDownNewsDuration.Value;
            CRCOptions.ChatKey      = textBoxChatKey.Text;
            CRCOptions.NewsSound    = checkBoxNewsSound.Checked;
            CRCOptions.CloseChat    = checkBoxCloseChat.Checked;

            CRCOptions.Save();
            CRCClient.UpdateSettings();
            CRCGame.UpdateSettings();
            this.Close();
        }
Example #24
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();
        }
Example #25
0
 private static void Disable()
 {
     disable = true;
     MessageBox.Show(CRCStrings.Localize("game_file_error"), CRCStrings.Localize("crc_name"), MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
Example #26
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;
                }
            }
        }
Example #27
0
        private void buttonRandom_Click(object sender, EventArgs e)
        {
            string faction = radioButtonFactionAuto.Checked ? CRCOptions.GameFaction : indexToFaction[comboBoxFaction.SelectedIndex];

            textBoxName.Text = CRCStrings.RandomIrcName(faction);
        }