static BrrageMsg GetMsgType(string[] msgType) { BrrageMsg brrageMsg = new BrrageMsg(); foreach (string keyValueTemp in msgType) { string[] keyValue = Regex.Split(keyValueTemp, "@=", RegexOptions.IgnoreCase); if (keyValue.Length >= 2) { string key = keyValue[0]; string[] textArr = new string[keyValue.Length - 1]; Array.Copy(keyValue, 1, textArr, 0, keyValue.Length - 1); string value = String.Join("@", textArr); if (key == "nn") { brrageMsg.Name = value; } if ((key == "txt")) { brrageMsg.Txt = value; } } } return(brrageMsg); }
static void ShowMsg(string msg) { msg = FIX_TAIL + msg; string[] chatmsgArray = Regex.Split(msg, "type@=", RegexOptions.IgnoreCase); FIX_TAIL = chatmsgArray[chatmsgArray.Length - 1]; //截取最后的丢弃数据,放在下个包的开头,防止数据丢失 string[] newChatmsgArrayArr = new string[chatmsgArray.Length - 1]; Array.Copy(chatmsgArray, 0, newChatmsgArrayArr, 0, chatmsgArray.Length - 1); foreach (string t in newChatmsgArrayArr) { string[] msgType = t.Split('/'); if (msgType.Length >= 2) { string type = msgType[0]; if (type == "chatmsg") { BrrageMsg brrageMsg = GetMsgType(msgType); string result = String.Format("[{0}]: {1}", brrageMsg.Name, brrageMsg.Txt); Console.WriteLine(result); } } } }