コード例 #1
0
        private string ProcessReply(string input)
        {
            Match match = Interpreter.REGEX_REPLY_PACKET.Match(input);

            if (string.IsNullOrEmpty(this.reply))
            {
                return(input.Replace(match.Value, string.Empty));
            }

            string[]    pair        = this.reply.Split(',');
            PacketEntry replyPacket = this._interpreter.GetPacket(pair[0].Trim(), pair[1].Trim());

            string template = match.Groups[2].Value.Replace("[packet_cls_name]", replyPacket.ClsName());

            template = template.Replace("[packet_func_name]", replyPacket.FuncName());

            string splitChar = match.Groups[1].Value;

            splitChar = splitChar == "\\n" ? Environment.NewLine : splitChar;

            StringBuilder sb      = new StringBuilder();
            string        content = this.ProcessFields(template, null);

            if (replyPacket.dto != null)
            {
                content += splitChar;
            }
            sb.Append(content);

            if (replyPacket.dto != null)
            {
                content = this.ProcessFields(template, replyPacket.dto.allFields);
                int c2 = replyPacket.dto.conditions.Count;
                if (c2 > 0)
                {
                    content += splitChar;
                }
                sb.Append(content);

                for (int j = 0; j < c2; j++)
                {
                    content = this.ProcessFields(template, replyPacket.dto.conditions[j].allFields);
                    if (j != c2 - 1)
                    {
                        content += splitChar;
                    }
                    sb.Append(content);
                }
            }

            input = input.Replace(match.Value, sb.ToString());
            return(input);
        }
コード例 #2
0
ファイル: Interpreter.cs プロジェクト: niuniuzhu/RC
        public void Parse(string text)
        {
            this.ParseInternalStructs();

            XML     xml      = new XML(text);
            XMLList dtoNodes = xml.Elements("structs")[0].Elements();

            foreach (XML dtoNode in dtoNodes)              //parse structs
            {
                if (!this.CreateStruct(ushort.Parse(dtoNode.GetAttribute("id")), dtoNode.GetAttribute("name"), false, out DTOEntry dto))
                {
                    this.ParseField(dto, dtoNode, dtoNodes);
                }
            }
            XMLList moduleNodes = xml.Elements("modules")[0].Elements();

            foreach (XML moduleNode in moduleNodes)               //parse modules
            {
                ModuleEntry module = new ModuleEntry();
                module.id  = moduleNode.GetAttribute("id");
                module.key = moduleNode.GetAttribute("key");
                this._modules.Add(module);

                XMLList packetNodes = moduleNode.Elements();
                foreach (XML packetNode in packetNodes)                   //parse packets
                {
                    PacketEntry packet = new PacketEntry(this, module);
                    packet.id  = packetNode.GetAttribute("cmd");
                    packet.key = packetNode.GetAttribute("key");
                    packet.dto = this.FindDTO(packetNode.GetAttribute("struct"));
                    if (packetNode.HasAttribute("reply"))
                    {
                        packet.reply = packetNode.GetAttribute("reply");
                    }
                    module.packets.Add(packet);
                }
            }
        }