Exemplo n.º 1
0
        public LogEvent UnsafeParse(string s)
        {
            str = s;
            strLen = s.Length;
            if (strLen < 25) {
                return null;
            }

            pos = 25;

            CheckPrefix();
            CheckPrefixNumbers();
            GetDate();

            LogEvent log = null;

            IDictionary<string, string> dict = ReadOptionsBackwards();

            switch (str[pos]) {
            case '"':
                pos++;
                ReadPlayer();
                pos++;

                if (Require("attacked ")) {
                    Player player = GetPlayer();
                    ReadPlayer();
                    if (Require(" with ")) {
                        log = new PlayerAttack(dateTime, player, GetPlayer(), ReadValue());
                        log.Options = dict;
                        OnPlayerAttack(log as PlayerAttack);
                    }
                } else if (Require("say ")) {
                    log = new PlayerSay(dateTime, GetPlayer(), ReadValue());
                    log.Options = dict;
                    OnPlayerSay(log as PlayerSay);
                } else if (Require("say_team ")) {
                    log = new PlayerSayTeam(dateTime, GetPlayer(), ReadValue());
                    log.Options = dict;
                    OnPlayerSayTeam(log as PlayerSayTeam);
                } else if (Require("STEAM USERID validated")) {
                    log = new PlayerValidate(dateTime, GetPlayer());
                    log.Options = dict;
                    OnPlayerValidate(log as PlayerValidate);
                } else if (Require("triggered ")) {
                    Player player = GetPlayer();
                    string trigger = ReadString();

                    if (Require(" against ")) {
                        ReadPlayer();
                        Player target = GetPlayer();
                        log = new PlayerTriggerAgainst(dateTime, player, trigger, target);
                        log.Options = dict;
                        OnPlayerTriggerAgainst(log as PlayerTriggerAgainst);
                    } else  {
                        log = new PlayerTrigger(dateTime, player, trigger);
                        log.Options = dict;
                        OnPlayerTrigger(log as PlayerTrigger);
                    }
                } else if (Require("killed ")) {
                    Player player = GetPlayer();
                    ReadPlayer();
                    if (Require(" with ")) {
                        log = new PlayerAttack(dateTime, player, GetPlayer(), ReadValue());
                        log.Options = dict;
                        OnPlayerKill(log as PlayerKill);
                    }

                } else if (Require("joined team ")) {
                    log = new PlayerJoinTeam(dateTime, GetPlayer(), ReadValue());
                    log.Options = dict;
                    OnPlayerJoinTeam(log as PlayerJoinTeam);
                } else if (Require("entered the game")) {
                    log = new PlayerEnterGame(dateTime, GetPlayer());
                    log.Options = dict;
                    OnPlayerEnterGame(log as PlayerEnterGame);
                } else if (Require("disconnected")) {
                    log = new PlayerDisconnect(dateTime, GetPlayer());
                    log.Options = dict;
                    OnPlayerDisconnect(log as PlayerDisconnect);
                } else if (Require("changed name to ")) {
                    log = new PlayerNameChange(dateTime, GetPlayer(), ReadValue());
                    log.Options = dict;
                    OnPlayerNameChange(log as PlayerNameChange);
                } else if (Require("connected, address ")) {
                    log = new PlayerConnect(dateTime, GetPlayer(), ReadValue());
                    log.Options = dict;
                    OnPlayerConnect(log as PlayerConnect);
                } else if (Require("committed suicide with ")) {
                    log = new PlayerSuicide(dateTime, GetPlayer(), ReadValue());
                    log.Options = dict;
                    OnPlayerSuicide(log as PlayerSuicide);
                }
                break;
            case 'S':
                if (Require("Server cvars start")) {
                    log = new ServerCVarsStart(dateTime);
                    log.Options = dict;
                    OnServerCVarsStart(log as ServerCVarsStart);
                } else if (Require("Server cvars end")) {
                    log = new ServerCVarsEnd(dateTime);
                    log.Options = dict;
                    OnServerCVarsEnd(log as ServerCVarsEnd);
                } else if (Require("Server cvar ")) {
                    string cvar = ReadString();
                    if (Require(" = ")) {
                        log = new ServerCVarSet(dateTime, cvar, ReadValue());
                        log.Options = dict;
                        OnServerCVarSet(log as ServerCVarSet);
                    }
                } else if (Require("Started map ")) {
                    log = new ServerStartMap(dateTime, ReadValue());
                    log.Options = dict;
                    OnServerStartMap(log as ServerStartMap);
                }
            break;
            case 'T':
                if (Require("Team ")) { // triggered
                    string team = ReadString();
                    if (Require(" triggered ")) {
                        log = new TeamTrigger(dateTime, team, ReadValue());
                        log.Options = dict;
                        OnTeamTrigger(log as TeamTrigger);
                    }
                }
            break;
            case 'W':
                if (Require("World triggered ")) {
                    log = new WorldTrigger(dateTime, ReadValue());
                    log.Options = dict;
                    OnWorldTrigger(log as WorldTrigger);
                }
                break;
            case 'L':
                if (Require("Log file closed")) {
                    log = new LogFileClose(dateTime);
                    log.Options = dict;
                    OnLogFileClose(log as LogFileClose);
                } else if (Require("Log file started")) {
                    log = new LogFileStart(dateTime);
                    log.Options = dict;
                    OnLogFileStarted(log as LogFileStart);
                }
                break;
            case '[':
                break;
            case 'K':
                if (Require("Kick: ")) {
                    // TODO: implement this?
                    // Problem: double \" in argument
                }
                break;
            case 'B':
                if (Require("Bad Rcon: ")) {
                    // TODO: implement this
                    // Problem: imba amount of \"
                }
                break;
            default:
                break;
            }

            // No need for option checking
            if (log == null) {
                return null;
            }

            if (--pos != endpos) {
                throw new Exception();
            }

            OnLogEvent(log);

            return log;
        }
Exemplo n.º 2
0
 protected void OnPlayerEnterGame(PlayerEnterGame playerEnterGame)
 {
     if (PlayerEnterGame != null) {
         PlayerEnterGame(playerEnterGame);
     }
 }