private bool OnClientData(TCPClientState state, byte[] buf) { if (state.conncode == null) { int cmd = 0; byte[] data = m_protocol.ParseCmd(buf, ref cmd); if (cmd != (int)Protocol.CMD.C2S_HANDSHAKE || data == null || data.Length == 0) { return(false); } string xml = System.Text.UTF8Encoding.UTF8.GetString(data); try { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNode node = doc.SelectSingleNode("//param"); string param = ""; XmlNode tmpnode = node.SelectSingleNode("name"); if (tmpnode != null) { param += tmpnode.InnerText; } tmpnode = node.SelectSingleNode("mac"); if (tmpnode != null) { param += "|" + tmpnode.InnerText; } XmlNode pwdnode = node.SelectSingleNode("pwd"); string pwd = ""; if (pwdnode != null) { pwd = pwdnode.InnerText; } XmlNode codenode = node.SelectSingleNode("code"); string code = ""; if (codenode != null) { code = codenode.InnerText; } node.ParentNode.RemoveChild(node); state.conncode = ConnCode.GetCode(state, param, code, pwd, doc.InnerXml); state.WriteData(m_protocol.S2C_Handshake(state.conncode)); Logger.Trace("Client Connect code=" + state.conncode); } catch (Exception e) { Logger.Trace("xml=" + xml); Logger.Trace(e); return(false); } } else { if (state.PeerTcpClient != null) { try { state.PeerTcpClient.WriteData(buf); } catch (Exception e) { Logger.Trace(e); } } } return(true); }