Exemplo n.º 1
0
        public static ServerEvent Parse(string input, RefreshPacket refreshPacket)
        {
            if (refreshPacket?.PlayerName == null)
            {
                return(ServerEvent.NoRefreshFrame(input));
            }

            Func <RefreshPacket, string, ServerEvent>[] handlers =
            {
                ParsePlayerLeavesTeam,
                ParsePlayerSays,
                ParseAddressIsRequestingGame,
                ParsePlayerJoiningGame,
                ParsePlayerJoinsTeam,
                ParsePlayerKillsPlayer,
                ParsePlayerCapturesFlag,
                ParsePlayerReturnsFlag,
                ParsePlayerScoresForTeam,
                ParseNextMap,
                ParseTimeLeft,
                ParseCommandRequest,
            };

            foreach (var handler in handlers)
            {
                var result = handler(refreshPacket, input);
                if (result == null)
                {
                    continue;
                }

                if (PlayerNameMatches(result, refreshPacket.PlayerName))
                {
                    return(result);
                }
                else
                {
                    Console.WriteLine($"Tried {result.EventType} but player name doesn't match");
                }
            }

            return(ServerEvent.Unknown(input));
        }
Exemplo n.º 2
0
 private static bool PlayerNameMatches(ServerEvent parsedEvent, string[] playerNames)
 {
     return(!parsedEvent.Props.ContainsKey("name") ||
            playerNames.Contains(parsedEvent["name"]));
 }