/// <summary> /// 删除英雄数据 /// </summary> /// <param name="sMsg"></param> private void DeleteHeroRcd(string sMsg) { string sData; string sAccount = string.Empty; string sChrName = string.Empty; bool boCheck; int n10; int n12; HumInfo HumRecord; THumDataInfo HumanRCD; n12 = 0; sData = EncryptUnit.DeCodeString(sMsg); sData = HUtil32.GetValidStr3(sData, ref sAccount, new string[] { "/" }); sData = HUtil32.GetValidStr3(sData, ref sChrName, new string[] { "/" }); boCheck = false; try { HumRecord = DBShare.g_HumCharDB.FindObjectByChrName(sChrName); if (HumRecord != null) { //HumRecord = DBShare.g_HumCharDB.FindObjectByChrName(sChrName); if (HumRecord != null && HumRecord.boIsHero.Value) { if (DBShare.g_HumCharDB.Delete(sChrName)) { n12 = 1; } DBShare.g_nDeleteHeroCount++; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } if (n12 == 1) { try { HumanRCD = DBShare.g_HumDataDB.Get(sChrName); if (HumanRCD.Header.NameLen > 0) { if (HumanRCD.Header.NameLen > 0 && HumanRCD.Header.boIsHero) { if (DBShare.g_HumDataDB.Delete(sChrName)) { n12 = 1; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } m_DefMsg = EncryptUnit.MakeDefaultMsg(Common.DBR_DELHERORCD, n12, 0, 0, 0); SendSocket(EncryptUnit.EncodeMessage(m_DefMsg)); }
/// <summary> /// 加载英雄数据 /// </summary> /// <param name="sAccount"></param> /// <param name="sCharName"></param> /// <param name="sStr"></param> /// <param name="nCertCode"></param> /// <param name="HumanRcd"></param> /// <returns></returns> public unsafe static bool LoadHeroRcd(string sAccount, string sCharName, string sStr, int nCertCode, THumDataInfo *HumanRcd) { bool result; TDefaultMessage DefMsg; int nQueryID = 0; int nIdent = 0; int nRecog = 0; string sHumanRcdStr = string.Empty; string sDBMsg = string.Empty; string sDBCharName; nQueryID = GetQueryID(M2Share.g_Config); DefMsg = EncryptUnit.MakeDefaultMsg(Common.DB_LOADHERORCD, 0, 0, 0, 0, 0); TLoadHuman LoadHuman = new TLoadHuman(); LoadHuman.sAccount = sAccount; LoadHuman.sChrName = sCharName; LoadHuman.sUserAddr = sStr; LoadHuman.nSessionID = nCertCode; byte[] data = HUtil32.StructToBytes(LoadHuman); sDBMsg = EncryptUnit.EncodeMessage(DefMsg) + EncryptUnit.EncodeBuffer(data, Marshal.SizeOf(LoadHuman)); SendDBSockMsg(nQueryID, sDBMsg); if (GetDBSockMsg(nQueryID, ref nIdent, ref nRecog, ref sHumanRcdStr, M2Share.g_Config.dwGetDBSockMsgTime, true, "LoadHeroRcd(" + sAccount + "/" + sCharName + ")")) { result = false; if (nIdent == Common.DB_LOADHERORCD) { if (nRecog == 1) { sHumanRcdStr = HUtil32.GetValidStr3(sHumanRcdStr, ref sDBMsg, new string[] { "/" }); sDBCharName = EncryptUnit.DeCodeString(sDBMsg); if (sDBCharName == sCharName) { if (HUtil32.GetCodeMsgSize(sizeof(THumDataInfo) * 4 / 3) == sHumanRcdStr.Length) { EncryptUnit.DecodeBuffer(sHumanRcdStr, HumanRcd, sizeof(THumDataInfo)); result = true; } } else { result = false; } } else { result = false; } } else { result = false; } } else { result = false; } return(result); }
/// <summary> /// 保存人物数据 /// </summary> /// <param name="sAccount"></param> /// <param name="sCharName"></param> /// <param name="nSessionID"></param> /// <param name="HumanRcd"></param> /// <returns></returns> public unsafe static bool SaveRcd(string sAccount, string sCharName, int nSessionID, THumDataInfo HumanRcd) { bool result = false; int nQueryID = GetQueryID(M2Share.g_Config); int nIdent = 0; int nRecog = 0; string sStr = string.Empty; SendDBSockMsg(nQueryID, EncryptUnit.EncodeMessage(EncryptUnit.MakeDefaultMsg(Common.DB_SAVEHUMANRCD, nSessionID, 0, 0, 0, 0)) + EncryptUnit.EncodeString(sAccount) + "/" + EncryptUnit.EncodeString(sCharName) + "/" + EncryptUnit.EncodeBuffer(&HumanRcd, sizeof(THumDataInfo))); if (GetDBSockMsg(nQueryID, ref nIdent, ref nRecog, ref sStr, M2Share.g_Config.dwGetDBSockMsgTime, false, "SaveRcd(" + sAccount + "/" + sCharName + ")")) { if ((nIdent == Common.DBR_SAVEHUMANRCD) && (nRecog == 1)) { result = true; } } return(result); }
/// <summary> /// 新建英雄数据 /// </summary> /// <param name="sChrName"></param> /// <param name="sMsg"></param> /// <returns></returns> public static int NewHeroRcd(string sChrName, string sMsg) { int result = 0; TDefaultMessage DefMsg; int nQueryID; int nIdent = 0; int nRecog = 0; string sHumanRcdStr = string.Empty; string sDBMsg; string sDBCharName; nQueryID = GetQueryID(M2Share.g_Config); DefMsg = EncryptUnit.MakeDefaultMsg(Common.DB_NEWHERORCD, 0, 0, 0, 0, 0); sDBMsg = EncryptUnit.EncodeMessage(DefMsg) + EncryptUnit.EncodeString(sMsg); SendDBSockMsg(nQueryID, sDBMsg); if (GetDBSockMsg(nQueryID, ref nIdent, ref nRecog, ref sHumanRcdStr, M2Share.g_Config.dwGetDBSockMsgTime, true, "NewHeroRcd(" + sChrName + ")")) { result = -1; if (nIdent == Common.DB_NEWHERORCD) { sDBCharName = EncryptUnit.DeCodeString(sHumanRcdStr); if (sDBCharName == sChrName) { result = nRecog; } else { result = -1; } } else { result = -1; } } else { result = -1; } return(result); }
private unsafe void button1_Click(object sender, EventArgs e) { var saasdasdasdasd = "天魔神甲".Length; var sdasdsad = HUtil32.GetStrLength("天魔神甲"); IClientScoket socket = new IClientScoket(); socket.OnConnected += socket_OnConnected; socket.Connect("127.0.0.1", 6000); socket.ReceivedDatagram += socket_ReceivedDatagram; TLoadHuman sLoadHuman = new TLoadHuman(); sLoadHuman.sAccount = "123123"; sLoadHuman.sChrName = "阿斯顿23"; sLoadHuman.sUserAddr = "127.0.0.1"; sLoadHuman.nSessionID = 15; string sDBMsg = EncryptUnit.EncodeMessage(EncryptUnit.MakeDefaultMsg(1000, 0, 0, 0, 0, 0)) + EncryptUnit.EncodeBuffer <TLoadHuman>(sLoadHuman); socket.Send(SendDBSockMsg(0, sDBMsg)); }
/// <summary> /// 处理服务器包 /// </summary> /// <param name="Buffer"></param> /// <param name="BufLen"></param> public void ProcessServerPacket(string Buffer, int BufLen) { bool bo25 = false; int nC = 0; //string sReceiveText = string.Empty; string sC; string s1C; string s20 = string.Empty; string s24 = string.Empty; int n14; int n18; ushort wE; ushort w10; TDefaultMessage DefMsg; try { m_sQueryID = ""; m_dwKeepAliveTick = GameFramework.HUtil32.GetTickCount(); string sReceiveText = Buffer; m_sReceiveText = m_sReceiveText + sReceiveText; #if DEBUG DBShare.MainOutMessage("ServerClient.m_sReceiveText:" + m_sReceiveText); #endif while (true) { if (m_sReceiveText.IndexOf('!') <= 0) { break; } //获取一条数据放入s20 m_sReceiveText = GameFramework.HUtil32.ArrestStringEx(m_sReceiveText, "#", "!", ref s20); if (s20 != "") //如果s20不为空 { if (s20.Length > 2) //并且大于2 { s20 = GameFramework.HUtil32.GetValidStr3(s20, ref s24, new string[] { "/" }); n14 = s20.Length; if ((n14 >= Grobal2.DEFBLOCKSIZE) && (s24 != "")) { m_sQueryID = s24; wE = (ushort)(GameFramework.HUtil32.Str_ToInt(s24, 0) ^ 170); w10 = (ushort)n14; n18 = GameFramework.HUtil32.MakeLong(wE, w10); sC = EncryptUnit.EncodeBuffer(BitConverter.GetBytes(n18), 4); if (HUtil32.CompareBackLStr(s20, sC)) { ProcessServerMsg(s20, n14); bo25 = true; m_sReceiveText = ""; break; } else { m_DefMsg = EncryptUnit.MakeDefaultMsg(Common.DBR_FAIL, 0, 0, 0, 0); SendSocket(EncryptUnit.EncodeMessage(m_DefMsg)); m_sReceiveText = ""; break; } } } else { m_sReceiveText = ""; break; } } else { // 防止DBS溢出攻击 if (nC >= 1) { m_sReceiveText = ""; break; } nC++; } } m_dwCheckServerTimeMin = GameFramework.HUtil32.GetTickCount() - m_dwCheckRecviceTick; if (m_dwCheckServerTimeMin > m_dwCheckServerTimeMax) { m_dwCheckServerTimeMax = m_dwCheckServerTimeMin; } m_dwCheckRecviceTick = GameFramework.HUtil32.GetTickCount(); if (m_Module != null) { m_Module.Buffer = string.Format("{0}/{1}", m_dwCheckServerTimeMin, m_dwCheckServerTimeMax); } } catch { DBShare.MainOutMessage("[Exception] TDBSERVER::ProcessServerPacket"); } }
/// <summary> /// 保存角色数据 /// </summary> /// <param name="nRecog"></param> /// <param name="sMsg"></param> private unsafe void SaveHumanRcd(int nRecog, string sMsg) { string sChrName = string.Empty; string sUserID = string.Empty; string sHumanRCD = string.Empty; int I; int nIndex; bool bo21; TDefaultMessage DefMsg; THumDataInfo * HumanRCD; THumDataInfo HumDataInfo; sHumanRCD = HUtil32.GetValidStr3(sMsg, ref sUserID, new string[] { "/" }); sHumanRCD = HUtil32.GetValidStr3(sHumanRCD, ref sChrName, new string[] { "/" }); sUserID = EncryptUnit.DeCodeString(sUserID); sChrName = EncryptUnit.DeCodeString(sChrName); bo21 = false; HumanRCD = (THumDataInfo *)Marshal.AllocHGlobal(sizeof(THumDataInfo)); HUtil32.ZeroMemory((IntPtr)(&HumanRCD->Data), (IntPtr)sizeof(THumData)); int THumDataInfoLength = DBShare.GetCodeMsgSize(sizeof(THumDataInfo) * 4 / 3) + 1; if (sHumanRCD.Length == THumDataInfoLength) { EncryptUnit.DecodeBuffer(sHumanRCD, HumanRCD, sizeof(THumDataInfo)); } else { bo21 = true; } if (!bo21) { bo21 = true; try { HumDataInfo = DBShare.g_HumDataDB.Get(sChrName); //nIndex = DBShare.g_HumDataDB.Index(sChrName); if (HumDataInfo.Header.NameLen <= 0) { HumanRCD->Header.boDeleted = false; HumanRCD->Header.dCreateDate = DateTime.Now.ToOADate(); //sChrName.StrToSbyte(HumanRCD->Header.sName, 15,ref HumanRCD->Header.NameLen); HumanRCD->Header.sName = sChrName; HumanRCD->Header.boIsHero = false; DBShare.g_HumDataDB.Add(ref *HumanRCD); //nIndex = DBShare.g_HumDataDB.Index(sChrName); } HumDataInfo = DBShare.g_HumDataDB.Get(sChrName); if (HumDataInfo.Header.NameLen > 0) { HumanRCD->Header = HumDataInfo.Header; DBShare.g_HumDataDB.Update(sChrName, ref *HumanRCD); bo21 = false; DBShare.g_nSaveHumCount++; } } catch (Exception ex) { MessageBox.Show(ex.Message); } FrmIDSoc.SetSessionSaveRcd(sUserID); } if (!bo21) { m_DefMsg = EncryptUnit.MakeDefaultMsg(Common.DBR_SAVEHUMANRCD, 1, 0, 0, 0); SendSocket(EncryptUnit.EncodeMessage(m_DefMsg)); } else { m_DefMsg = EncryptUnit.MakeDefaultMsg(Common.DBR_LOADHUMANRCD, 0, 0, 0, 0); SendSocket(EncryptUnit.EncodeMessage(m_DefMsg)); DBShare.MainOutMessage("SaveHumanRcd Fail,UserID:sUserID,ChrName:sChrName"); } }
/// <summary> /// 载入角色记录 /// </summary> /// <param name="sMsg"></param> private unsafe void LoadHumanRcd(string sMsg) { string sHumName; string sAccount; string sIPaddr; int nSessionID; int nCheckCode; THumDataInfo HumanRCD; bool boFoundSession = false; TLoadHuman * pLoadHuman; pLoadHuman = (TLoadHuman * )Marshal.AllocHGlobal(sizeof(TLoadHuman)); EncryptUnit.DecodeBuffer(sMsg, pLoadHuman, sizeof(TLoadHuman)); sAccount = HUtil32.SBytePtrToString(pLoadHuman->sAccount, 0, 30).TrimEnd('\0'); sHumName = HUtil32.SBytePtrToString(pLoadHuman->sChrName, 0, 14).TrimEnd('\0'); sIPaddr = HUtil32.SBytePtrToString(pLoadHuman->sUserAddr, 0, 15).TrimEnd('\0'); nSessionID = pLoadHuman->nSessionID; nCheckCode = -1; if ((sAccount != "") && (sHumName != "")) { if ((FrmIDSoc.CheckSessionLoadRcd(sAccount, sIPaddr, nSessionID, ref boFoundSession))) { nCheckCode = 1; } else { if (boFoundSession) { DBShare.MainOutMessage("[非法重复请求] " + "帐号: " + sAccount + " IP: " + sIPaddr + " 标识: " + (nSessionID).ToString()); } else { DBShare.MainOutMessage("[非法请求] " + "帐号: " + sAccount + " IP: " + sIPaddr + " 标识: " + (nSessionID).ToString()); } // nCheckCode:= 1; //测试用,正常去掉 } } if (nCheckCode == 1) { try { HumanRCD = DBShare.g_HumDataDB.Get(sHumName); if (HumanRCD.Header.NameLen > 0) { if (HumanRCD.Header.NameLen < 0) { nCheckCode = -2; } } else { nCheckCode = -3; } }catch { nCheckCode = -4; } } if (nCheckCode == 1) { DBShare.g_nLoadHumCount++; m_DefMsg = EncryptUnit.MakeDefaultMsg(Common.DBR_LOADHUMANRCD, 1, 0, 0, 1); SendSocket(EncryptUnit.EncodeMessage(m_DefMsg) + EncryptUnit.EncodeString(sHumName) + '/' + EncryptUnit.EncodeBuffer(&HumanRCD, sizeof(THumDataInfo))); } else { m_DefMsg = EncryptUnit.MakeDefaultMsg(Common.DBR_LOADHUMANRCD, nCheckCode, 0, 0, 0); SendSocket(EncryptUnit.EncodeMessage(m_DefMsg)); } }
/// <summary> /// 处理服务器消息 /// </summary> /// <param name="sMsg"></param> /// <param name="nLen"></param> private void ProcessServerMsg(string sMsg, int nLen) { string sDefMsg;//消息头 string sData; TDefaultMessage DefMsg; if (nLen == Grobal2.DEFBLOCKSIZE) { sDefMsg = sMsg; sData = ""; } else { sDefMsg = sMsg.Substring(1 - 1, Grobal2.DEFBLOCKSIZE); sData = sMsg.Substring(Grobal2.DEFBLOCKSIZE + 1 - 1, sMsg.Length - Grobal2.DEFBLOCKSIZE - 6); } DefMsg = EncryptUnit.DecodeMessage(sDefMsg); DBShare.g_nWorkStatus = DefMsg.Ident; switch (DefMsg.Ident) { case Common.DB_LOADHUMANRCD: LoadHumanRcd(sData); break; case Common.DB_SAVEHUMANRCD: SaveHumanRcd(DefMsg.Recog, sData); break; case Common.DB_LOADHERORCD: // DB_SAVEHUMANRCDEX: begin // SaveHumanRcdEx(sData, DefMsg.Recog, Socket); // end; // 读取英雄数据 LoadHeroRcd(sData); break; case Common.DB_NEWHERORCD: // 新建英雄 NewHeroRcd(sData); break; case Common.DB_DELHERORCD: // 删除英雄 DeleteHeroRcd(sData); break; case Common.DB_SAVEHERORCD: // 保存英雄数据 SaveHeroRcd(DefMsg.Recog, sData); break; case Common.DB_LOADRANKING: // 排行榜 LoadRanking(sData, DefMsg); break; case Common.DB_SAVEMAGICLIST: SaveMagicList(DefMsg.Recog, sData); break; case Common.DB_SAVESTDITEMLIST: SaveStdItemList(DefMsg.Recog, sData); break; case Common.DB_CLOSESOCKET: break; case Common.DB_SENDKEEPALIVE: break; default: m_DefMsg = EncryptUnit.MakeDefaultMsg(Common.DBR_FAIL, 0, 0, 0, 0, 0); SendSocket(EncryptUnit.EncodeMessage(m_DefMsg)); break; } }
unsafe static void Main(string[] args) { int sasdasdasdasd = sizeof(TUnbindInfo);//4491 int asdasd = Marshal.SizeOf(typeof(THumDataInfo)); Console.ReadLine(); DbSession dbsession = new DbSession("MyTest"); TDefaultMessage hun = new TDefaultMessage(); int HumSize = Marshal.SizeOf(hun); TStdItem a = new TStdItem(); MyRefTest(a); // Console.WriteLine(a.Name); IClientScoket socket = new IClientScoket(); socket.OnConnected += socket_OnConnected; socket.ReceivedDatagram += socket_ReceivedDatagram; socket.Connect("127.0.0.1", 6000); TDefaultMessage DefMsg = EncryptUnit.MakeDefaultMsg(1000, 0, 0, 0, 0, 0); TLoadHuman sLoadHuman = new TLoadHuman(); int aaaaaaaaaaaa = Marshal.SizeOf(sLoadHuman); sLoadHuman.sAccount = "123123"; sLoadHuman.sChrName = "啊啊啊啊"; sLoadHuman.sUserAddr = "127.0.0.1"; sLoadHuman.nSessionID = 15; byte[] sdata = StructToBytes(sLoadHuman); string sDBMsg = EncryptUnit.EncodeMessage(DefMsg) + EncryptUnit.EncodeBuffer <TLoadHuman>(sLoadHuman); socket.Send(SendDBSockMsg(0, sDBMsg)); Console.WriteLine("ok"); Console.ReadKey(); //TStdItem a = new TStdItem(); // MyRefTest(a); // Console.WriteLine(a.Name); TUnbindInfo abc = new TUnbindInfo(); int MySize = Marshal.SizeOf(abc); HUtil32._MIN(Int32.MaxValue, 14 + (int)Math.Floor(1 / (double)6 + 2.5 * 1)); Math.Round(Math.Round((double)50 / 100, 1), 1); decimal aaaaaaaaa = Round((decimal)Round((decimal)50.0 / 100, 1) * 368, 2); //string strss= EncryptUnit.EncodeBuffer(StructToBytes(a, Marshal.SizeOf(typeof(Struct1))), Marshal.SizeOf(typeof(Struct1))); Class1 b = new Class1(); b.Id = 1; b.Name = "张三"; string strbb = EncryptUnit.EncodeBuffer(ObjectToBytes(b), 8); b.Name = "张三"; //string a = "你好吗"; //sbyte[] by = new sbyte[StringToSBytePtr(a, null, 1) + 1]; //fixed (sbyte* pb = by) //{ // StringToSBytePtr(a, pb, 1); // string b = SBytePtrToString(pb, 1, by.Length - 1); // Console.WriteLine(b); //} //int nLen = StringToIntPtrPlusLen(a, (IntPtr)0, 0); //byte[] byy = new byte[nLen + 1]; //fixed (byte* pb = byy) //{ // StringToIntPtrPlusLen(a, (IntPtr)pb, 1); // string b = IntPtrPlusLenToString((IntPtr)pb, 1); // Console.WriteLine(b); //} Test t = new Test(); t.Main(); // THumDataInfo* HumanRcd = (THumDataInfo*)Marshal.AllocHGlobal(Marshal.SizeOf(typeof(THumDataInfo))); //byte[] data=new byte[sizeof(THumDataInfo)]; //fixed (byte* pb = data) //{ // *(THumDataInfo*)pb = *HumanRcd; //} TProcessMessage msg = new TProcessMessage(); int aaaaaaaaaaa = Marshal.SizeOf(typeof(TProcessMessage)); var arrayDouble = Enumerable.Range(1, 1024) .Select(i => (int)i) .ToArray(); fixed(int *p = arrayDouble) { var array2 = ToByte <int>(p, 1); //Assert.AreEqual(arrayDouble, array2); } int[,] arr4 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }; //byte[, ,] arr = new byte[8,4,4] //{ // { // {1,2},{1,2} // }, // { // {1,2},{1,2} // } //}; byte[, ,] arr = new byte[, , ] { { { 1, 2 }, { 1, 2 } }, { { 21, 22 }, { 21, 22 } }, { { 31, 32 }, { 31, 32 } } }; string sText = "G73"; int nValNo = 0; nValNo = HUtil32.Str_ToInt(sText.Substring(1, 2), -1); byte[] buff = System.Text.Encoding.GetEncoding("gb2312").GetBytes("我是测试字符串");; string str2 = string.Empty; for (int i = 0; i < 14; i++) { str2 += String.Format("{0:X2}", buff[i]) + ","; } string aa = System.Text.Encoding.GetEncoding("gb2312").GetString(buff); Console.WriteLine(str2); Console.WriteLine(aa); //Console.WriteLine(sizeof(TStdItem)); //Console.WriteLine(Marshal, sizeof(PTDealOffInfo)); string str = string.Empty; string FColor = string.Empty; string BColor = string.Empty; string nTime = string.Empty; string sMsg = "{180,251} 3 战斗区域"; sMsg = HUtil32.ArrestStringEx(sMsg, "{", "}", ref str); str = HUtil32.GetValidStrCap(str, ref FColor, new string[] { "," }); str = HUtil32.GetValidStrCap(str, ref BColor, new string[] { "," }); str = HUtil32.GetValidStrCap(str, ref nTime, new string[] { "," }); Console.WriteLine(MakeWord((byte)255, (byte)56)); //m_CanJmpScriptLableList = new List<string>(); //string msg = @"欢迎,我能为你做点什么?\ \<买/@buy> 物品\<卖/@sell> 物品\<特修毒符/@s_repair>\<询问/@questionprize> 物品详细情况 \<离 开/@exit>\"; //GetScriptLabel(msg); //Console.WriteLine(sizeof(TClientMagic)); //Console.WriteLine(Marshal.SizeOf(typeof(TClientMagic))); //int ccc = sizeof(TClientMagic); //@@rmst //strLen = sLabel.Substring(0, sLabel.Length - 1); //s18 = sLabel.Substring(strLen.Length + 1, sLabel.Length - strLen.Length); //Console.WriteLine(m_CanJmpScriptLableList.Count); //string aaaa= sub_49ADB8("<$USERNAME>加入游戏,<$SERVERNAME>又多了一份力量!", "<$USERNAME>", "1234"); //aaaa = sub_49ADB8(aaaa, "<$SERVERNAME>", "12345"); Console.ReadKey(); }