private bool AnalysisSystemMessage(Packet packet) { int dataStruct = Marshal.SizeOf(typeof(CMD_CS_MarqueeMessage)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError("CMD_CS_MarqueeMessage Data Error !"); return(true); } ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); int dataSzie = Marshal.SizeOf(typeof(CMD_CS_MarqueeMessage)); int dataCount = packet.DataSize / dataSzie; for (int i = 0; i < dataCount; i++) { byte[] tempData = listDataBuff.PopByteArray(dataSzie); CMD_CS_MarqueeMessage msg = GameConvert.ByteToStruct <CMD_CS_MarqueeMessage>(tempData); GameApp.Account.CallMarqueeMessageEvent(msg.MsgType, msg.MsgID, msg.MsgPlayCount, (float)msg.MsgInterval, msg.szMessage, msg.MsgStartTime, msg.MsgNumberID, msg.MsgPlayTime); } ByteBufferPool.DropPacket(listDataBuff); return(true); }
private bool AnalysisLogonRecord(Packet packet) { int dataStruct = Marshal.SizeOf(typeof(CMD_GH_LogonRecord)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError("LogonRecord Success Data Error CMD_GH_LogonRecord!"); return(false); } ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); int dataSzie = Marshal.SizeOf(typeof(CMD_GH_LogonRecord)); int dataCount = packet.DataSize / dataSzie; List <LogonRecordItem> logonRecordList = new List <LogonRecordItem>(); for (int i = 0; i < dataCount; i++) { byte[] tempData = listDataBuff.PopByteArray(dataSzie); CMD_GH_LogonRecord logonRecord = GameConvert.ByteToStruct <CMD_GH_LogonRecord>(tempData); LogonRecordItem logonItem = new LogonRecordItem(); logonItem.dwLogonIP = logonRecord.dwLogonIP; logonItem.dwTmlogonTime = logonRecord.dwTmlogonTime; logonRecordList.Add(logonItem); } ByteBufferPool.DropPacket(listDataBuff); GameApp.Account.CallLogonRecordEvent(logonRecordList); return(true); }
//游戏记录 private bool AnalysisGameRecord(Packet packet) { //int dataStruct = Marshal.SizeOf(typeof(CMD_GH_GameRecord)); //if (packet.DataSize < dataStruct) //{ // Debug.LogError("Game Record Data Error CMD_GH_GameRecord!"); // return false; //} List <GameRecordItem> gameRecordList = new List <GameRecordItem>(); if (packet.DataSize > 0) { ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); int dataSzie = Marshal.SizeOf(typeof(CMD_GH_GameRecord)); int dataCount = packet.DataSize / dataSzie; for (int i = 0; i < dataCount; i++) { byte[] tempData = listDataBuff.PopByteArray(dataSzie); CMD_GH_GameRecord gameRecord = GameConvert.ByteToStruct <CMD_GH_GameRecord>(tempData); GameRecordItem gameItem = new GameRecordItem(); gameItem.dwAllCount = gameRecord.dwAllCount; gameItem.dwAmount = gameRecord.dwAmount; gameItem.dwEndTime = gameRecord.dwEndTime; gameItem.dwGameKind = gameRecord.dwGameKind; gameRecordList.Add(gameItem); } ByteBufferPool.DropPacket(listDataBuff); } GameApp.Account.CallGameRecordEvent(gameRecordList); return(true); }
public byte[] ToBytes(Packet packet) { var pHead = new CMD_Head_8(); pHead.MainCmdID = (ushort)packet.MainCmd; pHead.SubCmdID = (ushort)packet.SubCmd; pHead.CheckCode = (byte)packet.CheckCode; pHead.DataSize = (ushort)(CommonDefine.TCP_HEAD_8_SIZE + packet.DataSize); pHead.MessageVer = (byte)CommonDefine.VERSION; var buffer = ByteBufferPool.PopPacket(); byte[] headBuffer = GameConvert.StructToByteArray <CMD_Head_8>(pHead); buffer.Position = 0; buffer.PushByteArray(headBuffer); if (packet.Data != null) { buffer.PushByteArray(packet.Data); } var bytes = buffer.ToByteArray(); ByteBufferPool.DropPacket(buffer); if (EnableEncrypt) { bytes = Encrypt(bytes); } return(bytes); }
private void OnQueryIndividualResp(Packet packet) { ByteBuffer buffer = ByteBufferPool.PopPacket(packet.Data); //不需要只包含用户信息的数据包 buffer.Position = Marshal.SizeOf(typeof(CMD_GP_UserIndividual)); var info = new CMD_GH_UserInformation(); info.dwLogoID = GameApp.GameData.UserInfo.HeadId; while (true) { string str = ""; ushort type = ProtoHelper.ReadDescDataString(ref buffer, ref str); if (type == 0) { break; } switch (type) { case CommonDefine.DTP_GP_UI_COMPELLATION: { info.dwName = str; break; } case CommonDefine.DTP_GP_UI_QQ: { info.dwIM = str; break; } case CommonDefine.DTP_GP_UI_USER_NOTE: { info.dwIdentification = str; break; } case CommonDefine.DTP_GP_UI_MOBILE_PHONE: { info.dwCellPhone = str; break; } } } ByteBufferPool.DropPacket(buffer); GameApp.Account.CallUserInformationEvent( info.dwName, info.dwIdentification, info.dwCellPhone, info.dwIM, info.dwLogoID); }
private void AnalysisVersionInfo(Packet packet) { ByteBuffer buffer = ByteBufferPool.PopPacket(packet.Data); //不需要只包含用户信息的数据包 byte[] descData = buffer.PopByteArray(Marshal.SizeOf(typeof(CMD_GP_ClientUpdate))); CMD_GP_ClientUpdate version = GameConvert.ByteToStruct <CMD_GP_ClientUpdate>(descData); while (true) { string str = ""; ushort type = ProtoHelper.ReadDescDataString(ref buffer, ref str); if (type == 0) { break; } switch (type) { case CommonDefine.DTP_GP_CDN: { GameApp.GameData.CDN = str; break; } case CommonDefine.DTP_GP_OFFICESITE_URL: { GameApp.GameData.OfficeSiteUrl = str; break; } case CommonDefine.DTP_GP_BACK_STORGE_URL: { GameApp.GameData.BackStorgeUrl = str; break; } case CommonDefine.DTP_GP_MODULE_INFO: { GameApp.ModuleMgr.ApplyDataFromStr(str); break; } } } ByteBufferPool.DropPacket(buffer); GameApp.Account.CallVersionInfoEvent(version.dwVersion); }
private void OnUserEnterResp(Packet packet) { int dataStruct = Marshal.SizeOf(typeof(tagUserInfoHead)); if (packet.DataSize < dataStruct) { Debug.LogWarning("data error!"); return; } tagUserInfoHead userInfo = GameConvert.ByteToStruct <tagUserInfoHead>(packet.Data); PlayerInfo player = ProtoHelper.InitPlayerInfo(userInfo); if (player.ID == GameApp.GameData.UserInfo.UserID) { GameApp.GameData.UserInfo.SetSitInfo(player.DeskNO, player.DeskStation); } ByteBuffer buffer = ByteBufferPool.PopPacket(packet.Data); buffer.Position = dataStruct; while (true) { string str = ""; ushort type = ProtoHelper.ReadDescDataString(ref buffer, ref str); if (type == 0) { break; } switch (type) { case CommonDefine.DTP_GR_NICK_NAME: { player.NickName = str; break; } } } ByteBufferPool.DropPacket(buffer); GameApp.GameSrv.AddPlayer(player); GameApp.GameSrv.CallUserEnterEvent(player); }
//修改资料 public void SendChangeUserInformation(string name, string nickName, string phone, string im, uint head, string UnderWrite) { var req = new CMD_GP_ModifyIndividual(); req.cbGender = GameApp.GameData.UserInfo.Gender; req.dwUserID = GameApp.GameData.UserInfo.UserID; req.szPassword = GameApp.GameData.Password; GameApp.GameData.TempNickName = nickName; byte[] dataBuffer = GameConvert.StructToByteArray(req); var buffer = ByteBufferPool.PopPacket(dataBuffer); if (!string.IsNullOrEmpty(nickName)) { ProtoHelper.AppendDescDataString(ref buffer, CommonDefine.DTP_GP_UI_NICKNAME, nickName /*GameApp.GameData.UserInfo.NickName*/); } //ProtoHelper.AppendDescDataString(ref buffer, CommonDefine.DTP_GP_UI_USER_NOTE, ident); if (!string.IsNullOrEmpty(name)) { ProtoHelper.AppendDescDataString(ref buffer, CommonDefine.DTP_GP_UI_COMPELLATION, name); } if (!string.IsNullOrEmpty(im)) { ProtoHelper.AppendDescDataString(ref buffer, CommonDefine.DTP_GP_UI_QQ, im); } if (!string.IsNullOrEmpty(phone)) { ProtoHelper.AppendDescDataString(ref buffer, CommonDefine.DTP_GP_UI_MOBILE_PHONE, phone); } if (!string.IsNullOrEmpty(UnderWrite)) { ProtoHelper.AppendDescDataString(ref buffer, CommonDefine.DTP_GP_UI_UNDER_WRITE, UnderWrite); } var data = buffer.ToByteArray(); ByteBufferPool.DropPacket(buffer); SendToHallSvr(MainCommand.MDM_GP_USER_SERVICE, SubCommand.SUB_GP_MODIFY_INDIVIDUAL, 0, data); }
void OnLogonSuccess(Packet packet) { int dataStruct = Marshal.SizeOf(typeof(CMD_GP_LogonSuccess)); com.QH.QPGame.GameUtils.Logger.Net.Log("logon success. size:" + packet.DataSize + "/" + dataStruct); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" CMD_GP_LogonSuccess data error!"); return; } ByteBuffer buffer = ByteBufferPool.PopPacket(packet.Data); byte[] descData = buffer.PopByteArray(Marshal.SizeOf(typeof(CMD_GP_LogonSuccess))); CMD_GP_LogonSuccess loginData = GameConvert.ByteToStruct <CMD_GP_LogonSuccess>(descData); GameApp.GameData.UserInfo = ProtoHelper.InitUserInfo(loginData); com.QH.QPGame.GameUtils.Logger.Net.Log("User:"******" Loged|Money:" + loginData.lUserScore + "|Bank:" + loginData.lUserInsure); while (true) { string str = ""; ushort type = ProtoHelper.ReadDescDataString(ref buffer, ref str); if (type == 0) { break; } switch (type) { case CommonDefine.DTP_GP_UI_UNDER_WRITE: { GameApp.GameData.UserInfo.UnderWrite = str; break; } } } ByteBufferPool.DropPacket(buffer); GameApp.Account.CallLogonSuccessEvent(); }
public bool SendData(int nChannelID, int nMainID, int nSubID, int nHandleCode, byte[] bytes) { IPC_Head_t head = new IPC_Head_t(); head.wMainCmdID = (UInt32)nMainID; head.wSubCmdID = (UInt32)nSubID; head.wHandleCode = (UInt32)nHandleCode; head.wDataSize = IPC_HEADER_LEN; if (bytes != null) { UInt32 tempDataBufferSize = (UInt32)bytes.Length; head.wDataSize += tempDataBufferSize; } ByteBuffer buffer = ByteBufferPool.PopPacket(); byte[] headBuffer = GameConvert.StructToByteArray <IPC_Head_t> (head); buffer.Position = 0; buffer.PushByteArray(headBuffer); if (bytes != null) { buffer.PushByteArray(bytes); } DATA_BUFFER sendData = new DATA_BUFFER(); sendData.buf = buffer.ToByteArray(); sendData.len = (UInt32)buffer.Length; mSendBufferQueue.Enqueue(new Send_Buffer(sendData, nChannelID)); ByteBufferPool.DropPacket(buffer); //LogUtil.Log ("IPC push messge |chan:"+nChannelID+"|main:"+nMainID+"|sub:"+nSubID+"|len:"+sendData.len); return(true); }
public static T ByteToStruct <T>(byte[] bytebuffer, int len) { ByteBuffer buffer = ByteBufferPool.PopPacket(); buffer.PushByteArray(bytebuffer, 0, len); //ByteBuffer buffer = ByteBufferPool.PopPacket(bytebuffer, len); Type t = typeof(T); object tObj = Activator.CreateInstance(t); FieldInfo[] fields = t.GetFields(); // Debug.LogWarning("class:" + t.Name); foreach (FieldInfo fieldInfo in fields) { //buffer.Position = mPointer; if (fieldInfo.FieldType.IsArray) { int cCount = GetSizeConstOfMarshal(fieldInfo); if (fieldInfo.FieldType.GetElementType() == typeof(string)) { //buffer.PopByteArray(cCount); byte[] sData = buffer.PopByteArray(cCount); string dataS = StringHelper.ByteArray2DefaultString(sData); fieldInfo.SetValue(tObj, dataS); } else if (fieldInfo.FieldType.GetElementType() == typeof(byte)) { fieldInfo.SetValue(tObj, buffer.PopByteArray(cCount)); } else if (fieldInfo.FieldType.GetElementType().IsPrimitive) { int cSize = Marshal.SizeOf(fieldInfo.FieldType.GetElementType()); Array arr = Array.CreateInstance(fieldInfo.FieldType.GetElementType(), cCount); for (int i = 0; i < cCount; i++) { ByteBuffer tempB = ByteBufferPool.PopPacket(buffer.PopByteArray(cSize)); arr.SetValue(BytesToValue(tempB, fieldInfo.FieldType.GetElementType()), i); ByteBufferPool.DropPacket(tempB); } fieldInfo.SetValue(tObj, arr); //mPointer += cCount * cSize; //throw new Exception("ByteToStruct UNKnow Type To Byte Aray Value FieldType.IsArray IsPrimitive"+fieldInfo.FieldType); } else { Type type = fieldInfo.FieldType.GetElementType(); int cSize = Marshal.SizeOf(type); Array arr = Array.CreateInstance(fieldInfo.FieldType.GetElementType(), cCount); for (int i = 0; i < cCount; i++) { var buf = buffer.PopByteArray(cSize); var param = new object[] { buf, cSize }; MethodInfo methodDefine = null; var methods = typeof(GameConvert).GetMethods(); for (int j = 0; j < methods.Length; j++) { if (methods[j].Name == "ByteToStruct" && methods[j].IsGenericMethodDefinition && methods[j].GetParameters().Length == 2) { methodDefine = methods[j]; break; } } var method = methodDefine.MakeGenericMethod(type); object val = method.Invoke(null, param); arr.SetValue(val, i); } fieldInfo.SetValue(tObj, arr); } } else { int cCount = GetSizeConstOfMarshal(fieldInfo); if (fieldInfo.FieldType == typeof(string)) { System.Text.Encoding encoding = (typeof(T).IsUnicodeClass) ? System.Text.Encoding.Unicode : System.Text.Encoding.GetEncoding("GB2312"); int totalCnt = cCount; if (typeof(T).IsUnicodeClass) { totalCnt = cCount * encoding.GetByteCount(new char[1]); } if (totalCnt > buffer.RemainLength) { totalCnt = buffer.RemainLength; } byte[] sData = buffer.PopByteArray(totalCnt); string dataS = encoding.GetString(sData); if (dataS.Length > 0) { dataS = dataS.Substring(0, dataS.IndexOf((char)0)); fieldInfo.SetValue(tObj, dataS); } } else if (fieldInfo.FieldType == typeof(byte)) { fieldInfo.SetValue(tObj, buffer.PopByte()); } else if (fieldInfo.FieldType.IsPrimitive) { fieldInfo.SetValue(tObj, BytesToValue(buffer, fieldInfo.FieldType)); } else { int classSize = Marshal.SizeOf(fieldInfo.FieldType); byte[] sData = buffer.PopByteArray(classSize); var param = new object[] { sData, classSize }; MethodInfo methodDefine = null; var methods = typeof(GameConvert).GetMethods(); for (int j = 0; j < methods.Length; j++) { if (methods[j].Name == "ByteToStruct" && methods[j].IsGenericMethodDefinition && methods[j].GetParameters().Length == 2) { methodDefine = methods[j]; break; } } var method = methodDefine.MakeGenericMethod(fieldInfo.FieldType); object val = method.Invoke(null, param); fieldInfo.SetValue(tObj, val); //cByteToStruct<T>(sData, classSize); //throw new Exception("ByteToStruct UNKnow Type To Byte Aray To Value " + fieldInfo.FieldType); } } } ByteBufferPool.DropPacket(buffer); return((T)tObj); }
public static byte[] StructToByteArray <T>(T structObject) { ByteBuffer buffer = ByteBufferPool.PopPacket(); foreach (FieldInfo fieldInfo in structObject.GetType().GetFields()) { //Debug.Log("cStructToByteArray FieldInfo:"+fieldInfo.FieldType); if (fieldInfo.FieldType.IsArray) { int cCount = GetSizeConstOfMarshal(fieldInfo); object obj = fieldInfo.GetValue(structObject); if (fieldInfo.FieldType.GetElementType() == typeof(string)) { throw new Exception("StructToByteArray UNKnow Type To Byte Aray Value " + fieldInfo.FieldType); } else if (fieldInfo.FieldType.GetElementType() == typeof(byte)) { byte[] value = (byte[])obj; buffer.PutByteArray(value); } else if (fieldInfo.FieldType.GetElementType() == typeof(UInt32)) { UInt32[] value = (UInt32[])obj; buffer.PutIntArray(value); } else { throw new Exception("StructToByteArray UNKnow Type To Byte Aray Value " + fieldInfo.FieldType); } } else { int cCount = GetSizeConstOfMarshal(fieldInfo); object obj = fieldInfo.GetValue(structObject); if (fieldInfo.FieldType == typeof(string)) { System.Text.Encoding encoding = (typeof(T).IsUnicodeClass) ? System.Text.Encoding.Unicode : System.Text.Encoding.Default; string strValue = (string)obj; if (string.IsNullOrEmpty(strValue)) { strValue = ""; } // byte[] strValueArray = StringHelper.String2UTF8ByteArray(strValue); // int len= cCount - strValueArray.Length; byte[] strValueArray = encoding.GetBytes(strValue); int len = cCount - strValueArray.Length; if (typeof(T).IsUnicodeClass) { len = cCount - strValue.Length; } buffer.PutByteArray(strValueArray); if (len > 0) { char[] temp = new char[len]; byte[] tempArray = encoding.GetBytes(temp); buffer.PutByteArray(tempArray); } //throw new Exception("StructToByteArray UNKnow Type To Byte Aray Value "+fieldInfo.FieldType); } else if (fieldInfo.FieldType == typeof(byte)) { byte value = (byte)obj; buffer.PutByte(value); } else if (fieldInfo.FieldType.IsPrimitive) { byte[] array = ValueToBytes(obj, fieldInfo.FieldType); buffer.PutByteArray(array); } else if (fieldInfo.FieldType.IsEnum) { Int32 value = (Int32)obj; byte[] array = ValueToBytes(value, typeof(Int32)); buffer.PutByteArray(array); } else if (fieldInfo.FieldType.IsValueType) { byte[] valueArray = StructToByteArray(obj); buffer.PutByteArray(valueArray); } else { throw new Exception("StructToByteArray UNKnow Type To Byte Aray Value " + fieldInfo.FieldType); } } } buffer.Position = 0; var bytes = buffer.PopByteArray(); ByteBufferPool.DropPacket(buffer); return(bytes); }
public void OnServerListResp(Packet packet) { switch (packet.SubCmd) { case SubCommand.SUB_GP_LIST_TYPE: { int dataStruct = Marshal.SizeOf(typeof(tagGameType)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameType Game List data error!"); return; } int dataSzie = Marshal.SizeOf(typeof(tagGameType)); int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempDataBB = listDataBuff.PopByteArray(dataSzie); tagGameType kindDataE = GameConvert.ByteToStruct <tagGameType>(tempDataBB); GameApp.GameListMgr.AppendTypeItem(ProtoHelper.InitGameTypeItem(kindDataE)); //Logger.Sys.Log("Append Game Type===========" + kindDataE.TypeID + " Name:" + kindDataE.TypeName); } ByteBufferPool.DropPacket(listDataBuff); return; } case SubCommand.SUB_GP_LIST_KIND: { int dataStruct = Marshal.SizeOf(typeof(tagGameKind)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameKind Game name list data error!"); return; } int dataSzie = Marshal.SizeOf(typeof(tagGameKind)); int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempDataBB = listDataBuff.PopByteArray(dataSzie); tagGameKind tempNameS = GameConvert.ByteToStruct <tagGameKind>(tempDataBB); GameApp.GameListMgr.AppendKindItem(ProtoHelper.InitGameKindItem(tempNameS)); //Logger.Sys.Log("Append Game Kind==========="+ tempNameS.KindID +" Name:"+tempNameS.KindName + " Process:"+tempNameS.ProcessName); } ByteBufferPool.DropPacket(listDataBuff); //GameApp.Account.CallGameListFinishEvent(); return; } case SubCommand.SUB_GP_LIST_NODE: { int dataStruct = Marshal.SizeOf(typeof(tagGameNode)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameNode Game List data error!"); return; } int dataSzie = Marshal.SizeOf(typeof(tagGameNode)); int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempDataBB = listDataBuff.PopByteArray(dataSzie); tagGameNode nodeDataE = GameConvert.ByteToStruct <tagGameNode>(tempDataBB); GameApp.GameListMgr.AppendNodeItem(ProtoHelper.InitGameNodeItem(nodeDataE)); } ByteBufferPool.DropPacket(listDataBuff); GameApp.Account.CallGameListFinishEvent(); return; } case SubCommand.SUB_GP_LIST_SERVER: { int dataStruct = Marshal.SizeOf(typeof(tagGameServer)); if (packet.DataSize < dataStruct) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameServer Room list data error!"); return; } uint kindID = 0; int dataSzie = Marshal.SizeOf(typeof(tagGameServer)); int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempData = listDataBuff.PopByteArray(dataSzie); tagGameServer roomInfoS = GameConvert.ByteToStruct <tagGameServer>(tempData); //Logger.Net.Log("--------------ROOM:" + roomInfoS.KindID + " " + roomInfoS.ServerID + " " + roomInfoS.ServerName+" "+roomInfoS.ServerAddr); kindID = roomInfoS.KindID; GameApp.GameListMgr.AppendRoomItem(ProtoHelper.InitGameRoomItem(roomInfoS)); /* if (GameApp.GameData.ReEnter && * GameApp.GameData.ReEnterRoomID == roomInfoS.ServerID) * { * GameApp.GameData.ReEnterNameID = roomInfoS.KindID; * if (ReconnectGameEvent != null) * { * ReconnectGameEvent(roomInfoS.ServerID, false); * } * }*/ } ByteBufferPool.DropPacket(listDataBuff); GameApp.Account.CallRoomListFinishEvent(kindID); return; } case SubCommand.SUB_CS_S_SERVER_ONLINE: { int dataSzie = Marshal.SizeOf(typeof(tagOnLineInfoServer)); if (packet.DataSize < dataSzie) { com.QH.QPGame.GameUtils.Logger.Net.LogError(" tagGameServer Room list data error! size:" + packet.DataSize); return; } int dataCount = packet.DataSize / dataSzie; ByteBuffer listDataBuff = ByteBufferPool.PopPacket(packet.Data); for (int i = 0; i < dataCount; i++) { byte[] tempDataBB = listDataBuff.PopByteArray(dataSzie); tagOnLineInfoServer OnlineDataE = GameConvert.ByteToStruct <tagOnLineInfoServer>(tempDataBB); SGameRoomItem temRoomItem = GameApp.GameListMgr.FindRoomItem((uint)OnlineDataE.wServerID); if (temRoomItem != null) { temRoomItem.UpdateOnlineCnt((uint)OnlineDataE.dwOnLineCount); } } ByteBufferPool.DropPacket(listDataBuff); GameApp.Account.CallOnlineCountEvent(); return; } } }
public void OnStatusResp(Packet packet) { switch (packet.SubCmd) { case SubCommand.SUB_GR_TABLE_INFO: { ByteBuffer buffer = ByteBufferPool.PopPacket(packet.Data); ushort cnt = buffer.PopUInt16(); for (int i = 0; i < cnt; i++) { //GameTable table = new GameTable(); byte TableLock = buffer.PopByte(); byte PlayStatus = buffer.PopByte(); SRoomDeskItem item = new SRoomDeskItem(); item.DeskID = (uint)i; item.Status = PlayStatus; SGameRoomItem room = GameApp.GameListMgr.FindRoomItem(GameApp.GameData.EnterRoomID); if (room != null) { room.Desks.Add(item); } /* table.ChairFlag = "0".PadRight((int)GameApp.GameData.EnterRoomItem.DeskPeople, '0'); * table.ChairUsedQty = 0;*/ } ByteBufferPool.DropPacket(buffer); break; } case SubCommand.SUB_GR_TABLE_STATUS: { ByteBuffer buffer = ByteBufferPool.PopPacket(packet.Data); ushort tableID = buffer.PopUInt16(); byte locked = buffer.PopByte(); byte status = buffer.PopByte(); ByteBufferPool.DropPacket(buffer); SGameRoomItem room = GameApp.GameListMgr.FindRoomItem(GameApp.GameData.EnterRoomID); if (room != null) { SRoomDeskItem item = room.Desks.Find(deskItem => deskItem.DeskID == tableID); if (item != null) { item.DeskID = (uint)tableID; item.Status = status; GameApp.GameSrv.CallDeskPlayStatuseEvent((UInt32)tableID, status); } } if (status == (byte)TableState.TB_FREE) { GameApp.GameSrv.CallGameEndedEvent(tableID); } else { Debug.Log("Game Start"); GameApp.GameSrv.CallGameStartedEvent(tableID); } break; } } }
public void ReceiveLoop() { if (mIPCBase != IntPtr.Zero) { return; } /*important!!!! * win32窗口消息队列为线程单独所有,要开线程读取,则必须在该线程创建 */ IpcWindowHandle = CreateIpcModuleEx(ref mIPCBase, ref mIPCModule); if (IpcWindowHandle == IntPtr.Zero) { Logger.Sys.LogError("call CreateIpcModuleEx failed"); return; } Logger.Sys.Log("call CreateIpcModuleEx finished, handle:" + IpcWindowHandle.ToString("X")); mInitEvent.Set(); int channel = -1; DATA_BUFFER ipcData = new DATA_BUFFER(); while (mReceiveThreadRuning) { //缓存发送,必须push到创建线程发送,这里先发送还是先接收或者一次性全发完再接收待优化 if (mSendBufferQueue.Count != 0) { IntPtr ptr = IntPtr.Zero; Send_Buffer sendData = mSendBufferQueue.Dequeue(); try { ptr = Marshal.AllocHGlobal((int)sendData.Data.len); Marshal.Copy(sendData.Data.buf, 0, ptr, (int)sendData.Data.len); SendIpcData(mIPCBase, sendData.Channel, ptr, sendData.Data.len); //LogUtil.Log ("IPC send messge |chan:"+sendData.Channel+"|len:"+sendData.Data.len); } catch (Exception e) { Logger.Sys.LogError("send data to ipc failed|msg:" + e.Message + "|source:" + e.Source + "|chan:" + sendData.Channel + "|len:" + sendData.Data.len + "|stack:" + e.StackTrace ); } finally { Marshal.FreeHGlobal(ptr); } } try { if (PeekIPCMessage(mIPCBase, ref ipcData, ref channel) != true) { Thread.Sleep(10); continue; } ByteBuffer buffer = ByteBufferPool.PopPacket(ipcData.buf, (int)ipcData.len); IPC_Head_t head = GameConvert.ByteToStruct <IPC_Head_t>(buffer.PopByteArray(IPC_HEADER_LEN)); byte[] bytes = null; if (head.wDataSize > IPC_HEADER_LEN) { bytes = buffer.PopByteArray((int)head.wDataSize - IPC_HEADER_LEN); } ByteBufferPool.DropPacket(buffer); UInt32 mainID = head.wMainCmdID; UInt32 subID = head.wSubCmdID; UInt32 code = head.wHandleCode; if (mainID == IPC_MAIN_IPC_KERNEL) { //IPC控制协议 switch (subID) { case IPC_SUB_IPC_CLIENT_CONNECT: { SendData(channel, IPC_MAIN_IPC_KERNEL, IPC_SUB_IPC_SERVER_ACCEPT, 0, null); //接受连接 OnConnect(channel); break; } case IPC_SUB_IPC_SERVER_ACCEPT: { OnConnect(channel); break; } case IPC_SUB_IPC_CLIENT_CLOSE: { OnClose(channel); ResetChannel(channel); break; } default: { //break到OnRead处理 break; } } } OnRead(channel, (int)mainID, (int)subID, (int)code, bytes); } catch (Exception e) { Logger.Sys.LogError("peek msg|msg:" + e.Message + "|source:" + e.Source + "|stack:" + e.StackTrace ); } } //貌似c#线程会被野蛮退出,走不到这里执行 DestroyIpcModuleEx(mIPCBase); IpcWindowHandle = IntPtr.Zero; mIPCBase = IntPtr.Zero; mIPCModule = IntPtr.Zero; }