Example #1
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 #2
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;
                }
            }
        }