예제 #1
0
        public void CheckKillRegex_KillMessageWithPenetratedAsInput_ExpectedCorrectConstructionOfObject()
        {
            String input = "\"Hu3bl<2><STEAM_1:1:10481859><TERRORIST>\" [-608 2439 -210] killed \"Invict0<6><STEAM_1:0:1234567><CT>\" [-722 2424 -125] with \"glock\" (penetrated)";

            var             regex           = new KillRegex();
            AbstractMessage abstractMessage = regex.Parse(input);

            Assert.NotNull(abstractMessage);
            var killMessage = (KillMessage)abstractMessage;

            Assert.Equal("Hu3bl", killMessage.UserName);
            Assert.Equal("2", killMessage.UserID);
            Assert.Equal("STEAM_1:1:10481859", killMessage.UserSteamID);
            Assert.Equal("TERRORIST", killMessage.UserTeam);
            Assert.Equal(-608, killMessage.UserPosX);
            Assert.Equal(2439, killMessage.UserPosY);
            Assert.Equal(-210, killMessage.UserPosZ);
            Assert.Equal("Invict0", killMessage.KilledUserName);
            Assert.Equal("6", killMessage.KilledUserID);
            Assert.Equal("STEAM_1:0:1234567", killMessage.KilledUserSteamID);
            Assert.Equal("CT", killMessage.KilledUserTeam);
            Assert.Equal(-722, killMessage.KilledUserPosX);
            Assert.Equal(2424, killMessage.KilledUserPosY);
            Assert.Equal(-125, killMessage.KilledUserPosZ);
            Assert.Equal("glock", killMessage.Weapon);
            Assert.False(killMessage.IsHeadshot);
            Assert.True(killMessage.IsPenetrated);
        }
예제 #2
0
파일: IRC.cs 프로젝트: TheDireMaster/fCraft
        static IRCMessageType GetMessageType([NotNull] string rawline, [NotNull] string actualBotNick)
        {
            if (rawline == null)
            {
                throw new ArgumentNullException("rawline");
            }
            if (actualBotNick == null)
            {
                throw new ArgumentNullException("actualBotNick");
            }

            Match found = ReplyCodeRegex.Match(rawline);

            if (found.Success)
            {
                string       code      = found.Groups[1].Value;
                IRCReplyCode replycode = (IRCReplyCode)int.Parse(code);

                // check if this replycode is known in the RFC
                if (Array.IndexOf(ReplyCodes, replycode) == -1)
                {
                    return(IRCMessageType.Unknown);
                }

                switch (replycode)
                {
                case IRCReplyCode.Welcome:
                case IRCReplyCode.YourHost:
                case IRCReplyCode.Created:
                case IRCReplyCode.MyInfo:
                case IRCReplyCode.Bounce:
                    return(IRCMessageType.Login);

                case IRCReplyCode.LuserClient:
                case IRCReplyCode.LuserOp:
                case IRCReplyCode.LuserUnknown:
                case IRCReplyCode.LuserMe:
                case IRCReplyCode.LuserChannels:
                    return(IRCMessageType.Info);

                case IRCReplyCode.MotdStart:
                case IRCReplyCode.Motd:
                case IRCReplyCode.EndOfMotd:
                    return(IRCMessageType.Motd);

                case IRCReplyCode.NamesReply:
                case IRCReplyCode.EndOfNames:
                    return(IRCMessageType.Name);

                case IRCReplyCode.WhoReply:
                case IRCReplyCode.EndOfWho:
                    return(IRCMessageType.Who);

                case IRCReplyCode.ListStart:
                case IRCReplyCode.List:
                case IRCReplyCode.ListEnd:
                    return(IRCMessageType.List);

                case IRCReplyCode.BanList:
                case IRCReplyCode.EndOfBanList:
                    return(IRCMessageType.BanList);

                case IRCReplyCode.Topic:
                case IRCReplyCode.TopicSetBy:
                case IRCReplyCode.NoTopic:
                    return(IRCMessageType.Topic);

                case IRCReplyCode.WhoIsUser:
                case IRCReplyCode.WhoIsServer:
                case IRCReplyCode.WhoIsOperator:
                case IRCReplyCode.WhoIsIdle:
                case IRCReplyCode.WhoIsChannels:
                case IRCReplyCode.EndOfWhoIs:
                    return(IRCMessageType.WhoIs);

                case IRCReplyCode.WhoWasUser:
                case IRCReplyCode.EndOfWhoWas:
                    return(IRCMessageType.WhoWas);

                case IRCReplyCode.UserModeIs:
                    return(IRCMessageType.UserMode);

                case IRCReplyCode.ChannelModeIs:
                    return(IRCMessageType.ChannelMode);

                default:
                    if (((int)replycode >= 400) &&
                        ((int)replycode <= 599))
                    {
                        return(IRCMessageType.ErrorMessage);
                    }
                    else
                    {
                        return(IRCMessageType.Unknown);
                    }
                }
            }

            found = PingRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.Ping);
            }

            found = ErrorRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.Error);
            }

            found = ActionRegex.Match(rawline);
            if (found.Success)
            {
                switch (found.Groups[1].Value)
                {
                case "#":
                case "!":
                case "&":
                case "+":
                    return(IRCMessageType.ChannelAction);

                default:
                    return(IRCMessageType.QueryAction);
                }
            }

            found = CtcpRequestRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.CtcpRequest);
            }

            found = MessageRegex.Match(rawline);
            if (found.Success)
            {
                switch (found.Groups[1].Value)
                {
                case "#":
                case "!":
                case "&":
                case "+":
                    return(IRCMessageType.ChannelMessage);

                default:
                    return(IRCMessageType.QueryMessage);
                }
            }

            found = CtcpReplyRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.CtcpReply);
            }

            found = NoticeRegex.Match(rawline);
            if (found.Success)
            {
                switch (found.Groups[1].Value)
                {
                case "#":
                case "!":
                case "&":
                case "+":
                    return(IRCMessageType.ChannelNotice);

                default:
                    return(IRCMessageType.QueryNotice);
                }
            }

            found = InviteRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.Invite);
            }

            found = JoinRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.Join);
            }

            found = TopicRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.TopicChange);
            }

            found = NickRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.NickChange);
            }

            found = KickRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.Kick);
            }

            found = PartRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.Part);
            }

            found = ModeRegex.Match(rawline);
            if (found.Success)
            {
                if (found.Groups[1].Value == actualBotNick)
                {
                    return(IRCMessageType.UserModeChange);
                }
                else
                {
                    return(IRCMessageType.ChannelModeChange);
                }
            }

            found = QuitRegex.Match(rawline);
            if (found.Success)
            {
                return(IRCMessageType.Quit);
            }

            found = KillRegex.Match(rawline);
            return(found.Success ? IRCMessageType.Kill : IRCMessageType.Unknown);
        }