public static void Run() { lock (_lock_session) { foreach (GameSession session in m_DicSession.Values) { byte[] retData = session.m_GamePack.GetData(); if (retData != null) { PackIn packin = new PackIn(retData); ushort tag = packin.ReadUInt16(); switch (tag) { case PacketProtoco.C_LOGINGAME: { packin.ReadUInt32(); int _key = 0, _key2 = 0; GenerateKey.GenerateKey_(ref _key, ref _key2); //取封包帐号- 发给dbserver byte[] bAccount = packin.ReadBuff(16); String account = Coding.GetDefauleCoding().GetString(bAccount); GameBase.Network.Internal.QueryRole query = new GameBase.Network.Internal.QueryRole(session.gameid, _key, _key2, bAccount); mTcpClient.SendData(query.GetBuffer()); Log.Instance().WriteLog("帐号登录!" + account); break; } } } } } }
public void Create(byte[] msg) { PackIn inpack = new PackIn(msg); mParam = inpack.ReadUInt16(); gameid = inpack.ReadUInt32(); key = inpack.ReadInt32(); key2 = inpack.ReadInt32(); account = inpack.ReadBuff(16); }
public void ProcessNetData(byte[] data) { byte[] dedata = new byte[data.Length]; Buffer.BlockCopy(data, 0, dedata, 0, data.Length); m_stream.Write(dedata, 0, dedata.Length); PackIn packin = new PackIn(m_stream.GetBuffer()); int nCurPos = 0; //记录当前流位置 while (true) { ushort tag = packin.ReadUInt16(); nCurPos += sizeof(ushort); if (tag != DEFAULT_TAG) { continue; } int nLen = packin.ReadUInt16(); nCurPos += sizeof(ushort); // //预留4字节 packin.ReadUInt32(); nCurPos += sizeof(uint); // //读取消息消耗时间 packin.ReadInt32(); nCurPos += sizeof(int); packin.ReadInt32(); nCurPos += sizeof(int); if (nLen > m_stream.Length - nCurPos) //封包不是完整的 { if (m_stream.Length == dedata.Length) //非法封包 { m_stream.SetLength(0); return; } break; } nCurPos += nLen; byte[] reData = packin.ReadBuff(nLen); if (reData == null || reData.Length == 0) { break; } m_ListData.Enqueue(reData); if (nCurPos == m_stream.Length) { break; } } int rema_Len = (int)m_stream.Length - nCurPos; if (rema_Len > 0) { dedata = new byte[rema_Len]; Buffer.BlockCopy(m_stream.GetBuffer(), nCurPos, dedata, 0, rema_Len); } m_stream.SetLength(0); if (rema_Len > 0) { m_stream.Write(dedata, 0, dedata.Length); } return; }