Ejemplo n.º 1
0
        /// <summary>
        /// 发信息给DBServer
        /// </summary>
        /// <param name="nQueryID"></param>
        /// <param name="sMsg"></param>
        public unsafe static void SendDBSockMsg(int nQueryID, string sMsg)
        {
            string sSENDMSG;
            int    nCheckCode;
            string sCheckStr = string.Empty;

            if (!DBSocketConnected())
            {
                return;
            }
            HUtil32.EnterCriticalSection(M2Share.UserDBSection);
            try
            {
                M2Share.g_Config.sDBSocketRecvText = "";
            }
            finally
            {
                HUtil32.LeaveCriticalSection(M2Share.UserDBSection);
            }
            nCheckCode = HUtil32.MakeLong(nQueryID ^ 170, sMsg.Length + 6);
            byte[] by = new byte[sizeof(int)];
            fixed(byte *pb = by)
            {
                *(int *)pb = nCheckCode;
            }

            sCheckStr = EncryptUnit.EncodeBuffer(by, by.Length);
            sSENDMSG  = "#" + nQueryID + "/" + sMsg + sCheckStr + "!";
            M2Share.g_Config.boDBSocketWorking = true;
            byte[] data = System.Text.Encoding.Default.GetBytes(sSENDMSG);
            TFrmMain.DBSocket.Send(HUtil32.StrToByte(sSENDMSG));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="sMsg"></param>
        private void SendSocket(string sMsg)
        {
            int    n10 = HUtil32.MakeLong(HUtil32.Str_ToInt(m_sQueryID, 0) ^ 170, sMsg.Length + 6);
            string s18 = EncryptUnit.EncodeBuffer(BitConverter.GetBytes(n10), 4);

            Socket.Socket.Send(System.Text.Encoding.Default.GetBytes('#' + m_sQueryID + '/' + sMsg + s18 + '!'));
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 对Byte数组加密
 /// </summary>
 /// <param name="sData">需要加密的对象</param>
 /// <param name="Size">对象大小</param>
 /// <returns></returns>
 public static string EncodeBuffer(this byte[] sData, int Size = 0)
 {
     if (Size == 0) //如果Szie参数为0,则拿字节大小即可
     {
         return(EncryptUnit.EncodeBuffer(sData, sData.Length));
     }
     else
     {
         return(EncryptUnit.EncodeBuffer(sData, Size));
     }
 }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        public unsafe static byte[] SendDBSockMsg(int nQueryID, string sMsg)
        {
            string sSENDMSG;
            int    nCheckCode;
            string sCheckStr = string.Empty;

            nCheckCode = HUtil32.MakeLong(nQueryID ^ 170, sMsg.Length + 6);
            byte[] by = new byte[sizeof(int)];
            fixed(byte *pb = by)
            {
                *(int *)pb = nCheckCode;
            }

            sCheckStr = EncryptUnit.EncodeBuffer(by, by.Length);
            sSENDMSG  = "#" + nQueryID + "/" + sMsg + sCheckStr + "!";

            byte[] data = System.Text.Encoding.Default.GetBytes(sSENDMSG);
            return(HUtil32.StrToByte(sSENDMSG));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取DBSERBER发送过来的消息
        /// </summary>
        /// <param name="nQueryID"></param>
        /// <param name="nIdent"></param>
        /// <param name="nRecog"></param>
        /// <param name="sStr"></param>
        /// <param name="dwTimeOut"></param>
        /// <param name="boLoadRcd"></param>
        /// <param name="sName"></param>
        /// <returns></returns>
        public unsafe static bool GetDBSockMsg(int nQueryID, ref int nIdent, ref int nRecog, ref string sStr, uint dwTimeOut, bool boLoadRcd, string sName)
        {
            bool            result;
            bool            boLoadDBOK;
            uint            dwTimeOutTick;
            string          s24        = string.Empty;
            string          s28        = string.Empty;
            string          s2C        = string.Empty;
            string          sCheckFlag = string.Empty;
            string          sDefMsg;
            string          s38;
            int             nLen;
            int             nCheckCode;
            TDefaultMessage DefMsg;
            byte            nCode;
            const string    sLoadDBTimeOut = "[RunDB] 读取人物数据超时...";
            const string    sSaveDBTimeOut = "[RunDB] 保存人物数据超时...";

            boLoadDBOK    = false;
            result        = false;
            dwTimeOutTick = HUtil32.GetTickCount();
            nCode         = 0;
            while (true)
            {
                if ((HUtil32.GetTickCount() - dwTimeOutTick) > dwTimeOut)//dwTimeOut--等待消息的时间
                {
                    nCode = 1;
                    break;
                }
                s24 = "";
                HUtil32.EnterCriticalSection(M2Share.UserDBSection);
                try
                {
                    if (M2Share.g_Config.sDBSocketRecvText.IndexOf("!") > 0)
                    {
                        s24 = M2Share.g_Config.sDBSocketRecvText;
                        M2Share.g_Config.sDBSocketRecvText = "";
                    }
                }
                finally
                {
                    HUtil32.LeaveCriticalSection(M2Share.UserDBSection);
                }
                if (s24 != "")
                {
                    s28 = "";
                    s24 = HUtil32.ArrestStringEx(s24, "#", "!", ref s28);
                    if (s28 != "")
                    {
                        s28  = HUtil32.GetValidStr3(s28, ref s2C, new string[] { "/" });
                        nLen = s28.Length;
                        if ((nLen >= sizeof(TDefaultMessage)) && (HUtil32.Str_ToInt(s2C, 0) == nQueryID))
                        {
                            nCheckCode = HUtil32.MakeLong(HUtil32.Str_ToInt(s2C, 0) ^ 170, nLen);
                            byte[] data = new byte[sizeof(int)];
                            fixed(byte *by = data)
                            {
                                *(int *)by = nCheckCode;
                            }

                            sCheckFlag = EncryptUnit.EncodeBuffer(data, data.Length);
                            if (HUtil32.CompareBackLStr(s28, sCheckFlag, sCheckFlag.Length))
                            {
                                if (nLen == Grobal2.DEFBLOCKSIZE)
                                {
                                    sDefMsg = s28;
                                    s38     = "";
                                }
                                else
                                {
                                    sDefMsg = s28.Substring(0, Grobal2.DEFBLOCKSIZE);
                                    s38     = s28.Substring(Grobal2.DEFBLOCKSIZE + 1 - 1, s28.Length - Grobal2.DEFBLOCKSIZE - 6);
                                }
                                DefMsg     = EncryptUnit.DecodeMessage(sDefMsg);
                                nIdent     = DefMsg.Ident;
                                nRecog     = DefMsg.Recog;
                                sStr       = s38;
                                boLoadDBOK = true;
                                result     = true;
                                break;
                            }
                        }
                        else
                        {
                            if ((nLen < Marshal.SizeOf(typeof(TDefaultMessage))))
                            {
                                nCode = 2;
                            }
                            if ((HUtil32.Str_ToInt(s2C, 0) != nQueryID))
                            {
                                nCode = 4;
                            }
                            M2Share.g_Config.nLoadDBErrorCount++;
                            break;
                        }
                    }
                    else
                    {
                        nCode = 3;
                        M2Share.g_Config.nLoadDBErrorCount++;
                        break;
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(1);
                }
            }
            if (!boLoadDBOK)
            {
                M2Share.g_nSaveRcdErrorCount++;
                if (boLoadRcd)
                {
                    M2Share.MainOutMessage(sLoadDBTimeOut + sName + " Code:" + nCode);
                }
                else
                {
                    M2Share.MainOutMessage(sSaveDBTimeOut + sName + " Code:" + nCode);
                }
            }
            else
            {
                M2Share.g_nSaveRcdErrorCount = 0;
            }
            M2Share.g_Config.boDBSocketWorking = false;
            return(result);
        }
Ejemplo n.º 8
0
        public unsafe static bool GetDBSockMsg(byte[] da, int nQueryID, ref int nIdent, ref int nRecog, ref string sStr, uint dwTimeOut, bool boLoadRcd, string sName)
        {
            bool            result;
            bool            boLoadDBOK;
            string          s24        = string.Empty;
            string          s28        = string.Empty;
            string          s2C        = string.Empty;
            string          sCheckFlag = string.Empty;
            string          sDefMsg;
            string          s38;
            int             nLen;
            int             nCheckCode;
            TDefaultMessage DefMsg;

            boLoadDBOK = false;
            result     = false;
            byte      nCode        = 0;
            const int DEFBLOCKSIZE = 32;

            while (true)
            {
                s24 = "";

                try
                {
                    fixed(byte *pb = da)
                    {
                        s24 = HUtil32.SBytePtrToString((sbyte *)pb, 0, da.Length);
                    }

                    s24 = System.Text.Encoding.Default.GetString(da);
                }
                finally
                {
                }
                if (s24 != "")
                {
                    s28 = "";
                    s24 = HUtil32.ArrestStringEx(s24, "#", "!", ref s28);
                    if (s28 != "")
                    {
                        s28  = HUtil32.GetValidStr3(s28, ref s2C, new string[] { "/" });
                        nLen = s28.Length;
                        if ((nLen >= sizeof(TDefaultMessage)) && (HUtil32.Str_ToInt(s2C, 0) == nQueryID))
                        {
                            nCheckCode = HUtil32.MakeLong(HUtil32.Str_ToInt(s2C, 0) ^ 170, nLen);
                            byte[] data = new byte[sizeof(int)];
                            fixed(byte *by = data)
                            {
                                *(int *)by = nCheckCode;
                            }

                            sCheckFlag = EncryptUnit.EncodeBuffer(data, data.Length);
                            if (HUtil32.CompareBackLStr(s28, sCheckFlag, sCheckFlag.Length))
                            {
                                if (nLen == DEFBLOCKSIZE)
                                {
                                    sDefMsg = s28;
                                    s38     = "";
                                }
                                else
                                {
                                    sDefMsg = s28.Substring(0, DEFBLOCKSIZE);
                                    s38     = s28.Substring(DEFBLOCKSIZE + 1 - 1, s28.Length - DEFBLOCKSIZE - 6);
                                }
                                DefMsg     = EncryptUnit.DecodeMessage(sDefMsg);
                                nIdent     = DefMsg.Ident;
                                nRecog     = DefMsg.Recog;
                                sStr       = s38;
                                boLoadDBOK = true;
                                result     = true;
                                break;
                            }
                        }
                        else
                        {
                            if ((nLen < Marshal.SizeOf(typeof(TDefaultMessage))))
                            {
                                nCode = 2;
                            }
                            if ((HUtil32.Str_ToInt(s2C, 0) != nQueryID))
                            {
                                nCode = 4;
                            }
                            break;
                        }
                    }
                    else
                    {
                        nCode = 3;
                        break;
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(1);
                }
            }
            if (!boLoadDBOK)
            {
                if (boLoadRcd)
                {
                    //M2Share.MainOutMessage(sLoadDBTimeOut + sName + " Code:" + (nCode).ToString());
                }
                else
                {
                    //M2Share.MainOutMessage(sSaveDBTimeOut + sName + " Code:" + (nCode).ToString());
                }
            }
            else
            {
            }
            return(result);
        }
Ejemplo n.º 9
0
        unsafe static void Main(string[] args)
        {
            GameBaseTest g1 = new GameBaseTest();
            int          n1 = g1.Parse(g1.GameConfig);

            Console.WriteLine(n1);
            Console.ReadKey();
            return;

            GameBaseTest g = new GameBaseTest();

            g.test();
            Thread.Sleep(1000);
            g = new GameBaseTest();
            g.test();
            Console.ReadKey();
            return;

            Console.Write(int.MaxValue);
            Console.ReadKey();
            return;

            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();
        }
Ejemplo n.º 10
0
        /// <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");
            }
        }
Ejemplo n.º 11
0
        /// <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));
            }
        }
Ejemplo n.º 12
0
        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));
        }