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