Example #1
0
        public void SelectSocket_OnClientConnect(object sender, AsyncUserToken e)
        {
            DBShare.MainOutMessage("Sel连接: " + e.EndPoint.ToString());
            TSelectClient ClentSocket = new TSelectClient(e, FrmIDSoc);

            e.Tag = ClentSocket;
        }
Example #2
0
 public void SelectSocket_OnClientRead(object sender, AsyncUserToken e)
 {
     byte[] data = new byte[e.BytesReceived];
     Array.Copy(e.ReceiveBuffer, e.Offset, data, 0, e.BytesReceived);
     DBShare.MainOutMessage(System.Text.Encoding.Default.GetString(data));
     (e.Tag as TSelectClient).ExecGateBuffers(System.Text.Encoding.Default.GetString(data), e.BytesReceived);
 }
Example #3
0
 private void StartService()
 {
     try
     {
         DBShare.MainOutMessage("正在启动服务器...");
         DBShare.LoadConfig();
         ServerSocket.Start(new IPEndPoint(IPAddress.Parse("0.0.0.0"), DBShare.g_nServerPort));
         SelectSocket.Start(new IPEndPoint(IPAddress.Parse("0.0.0.0"), DBShare.g_nGatePort));
         DBShare.g_boStartService = true;
         FrmIDSoc.Invoke((MethodInvoker) delegate() { FrmIDSoc.OpenConnect(); });
         this.Invoke((MethodInvoker) delegate() { MENU_CONTROL_START.Enabled = false; });
         this.Invoke((MethodInvoker) delegate() { MENU_CONTROL_STOP.Enabled = true; });
         DBShare.MainOutMessage("数据库服务器启动成功...");
         DBShare.SendGameCenterMsg(Common.SG_STARTOK, "数据库服务器启动完成...");
     }
     catch (Exception ex)
     {
         DBShare.MainOutMessage(ex.Message);
         DBShare.g_boStartService = false;
         this.Invoke((MethodInvoker) delegate() { MENU_CONTROL_START.Enabled = true; });
         this.Invoke((MethodInvoker) delegate() { MENU_CONTROL_STOP.Enabled = false; });
         FrmIDSoc.Invoke((MethodInvoker) delegate() { FrmIDSoc.CloseConnect(); });
         SelectSocket.Shutdown();
         ServerSocket.Shutdown();
     }
 }
Example #4
0
 public void MENU_HELP_VERSIONClick(System.Object Sender, System.EventArgs _e1)
 {
     DBShare.MainOutMessage(DBShare.g_sVersion);
     DBShare.MainOutMessage(DBShare.g_sUpDateTime);
     DBShare.MainOutMessage(DBShare.g_sProgram);
     DBShare.MainOutMessage(DBShare.g_sWebSite);
 }
Example #5
0
        public void ServerSocket_OnClientConnect(object sender, AsyncUserToken e)
        {
            string      sRemoteAddress;
            TModuleInfo ModuleInfo = new TModuleInfo();

            sRemoteAddress = e.EndPoint.Address.ToString();
            DBShare.MainOutMessage("M2连接: " + e.EndPoint.ToString());
            if ((!DBShare.CheckServerIP(sRemoteAddress)))
            {
                DBShare.MainOutMessage("非法服务器连接: " + sRemoteAddress);
                e.Socket.Close();
                return;
            }
            if (!(THumDB.boDataDBReady && THumDB.boHumDBReady && DBShare.g_boStartService))
            {
                e.Socket.Close();
            }
            else
            {
                ModuleInfo.Module     = e;
                ModuleInfo.ModuleName = "游戏中心";
                ModuleInfo.Address    = string.Format("{0}:{1} → {2}:{3}", sRemoteAddress, e.EndPoint.Port, sRemoteAddress, 6000);// Format("%s:%d → %s:%d", new object[] {sRemoteAddress, Socket.RemotePort, sRemoteAddress, ServerSocket.Port});
                ModuleInfo.Buffer     = "0/0";
                ModuleInfo            = DBShare.AddModule(ModuleInfo);
            }
            TServerClient ClentSocket = new TServerClient(e, FrmIDSoc);

            e.Tag = new object[] { ClentSocket, ModuleInfo };
        }
Example #6
0
 private void StopService()
 {
     DBShare.g_boStartService = false;
     DBShare.MainOutMessage("正在停止服务器...");
     MENU_CONTROL_START.Enabled = true;
     MENU_CONTROL_STOP.Enabled  = false;
     FrmIDSoc.Invoke((MethodInvoker) delegate() { FrmIDSoc.CloseConnect(); });
     SelectSocket.Shutdown();
     ServerSocket.Shutdown();
     DBShare.MainOutMessage("服务器已停止...");
 }
Example #7
0
 public void TimerCloseTimer(object objState)
 {
     if (DBShare.g_boStartService)
     {
         DBShare.g_boStartService = false;
         DBShare.MainOutMessage("正在停止服务器...");
         this.Invoke((MethodInvoker) delegate() { MENU_CONTROL_START.Enabled = true; });
         this.Invoke((MethodInvoker) delegate() { MENU_CONTROL_STOP.Enabled = false; });
         FrmIDSoc.Invoke((MethodInvoker) delegate() { FrmIDSoc.CloseConnect(); });
     }
     TimerClose.Change(-1, -1);
     SelectSocket.Shutdown();
     ServerSocket.Shutdown();
     DBShare.MainOutMessage("服务器已停止...");
 }
Example #8
0
 public void FormCreate(System.Object Sender, System.EventArgs _e1)
 {
     DBShare.Initialization();
     DBShare.MainOutMessage("正在启动数据库服务器...");
     FrmIDSoc = new TFrmIDSoc(this);
     FrmIDSoc.Show();
     FrmIDSoc.Hide();
     ModuleGrid.AllowUserToAddRows = false;
     ModuleGrid.RowHeadersVisible  = false;
     ModuleGrid.ReadOnly           = true;
     ModuleGrid.Columns.Add("MKMC", "模块名称");
     ModuleGrid.Columns.Add("LJDZ", "连接地址");
     ModuleGrid.Columns.Add("SJTX", "数据通讯");
     ModuleGrid.Columns[0].Width    = 80;
     ModuleGrid.Columns[1].Width    = 468 - 80 * 2;
     ModuleGrid.Columns[2].Width    = 80;
     ModuleGrid.SelectionMode       = DataGridViewSelectionMode.FullRowSelect;
     ModuleGrid.MultiSelect         = false;
     ModuleGrid.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
     ModuleGrid.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
     ModuleGrid.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
     ModuleGrid.RowTemplate.Height  = 18;
     ModuleGrid.Rows.Add(5);
     //M2套接字
     ServerSocket = new IServerSocket(1000, Int16.MaxValue);
     ServerSocket.OnClientConnect     += ServerSocket_OnClientConnect;
     ServerSocket.OnClientDisconnect  += ServerSocket_OnClientDisconnect;
     ServerSocket.OnClientError       += ServerSocket_OnClientError;
     ServerSocket.OnClientRead        += ServerSocket_OnClientRead;
     ServerSocket.OnDataSendCompleted += ServerSocket_OnDataSendCompleted;
     //选择服务器套接字
     SelectSocket = new IServerSocket(1000, Int16.MaxValue);
     SelectSocket.OnClientConnect     += SelectSocket_OnClientConnect;
     SelectSocket.OnClientDisconnect  += SelectSocket_OnClientDisconnect;
     SelectSocket.OnClientError       += SelectSocket_OnClientError;
     SelectSocket.OnClientRead        += SelectSocket_OnClientRead;
     SelectSocket.OnDataSendCompleted += SelectSocket_OnDataSendCompleted;
     ServerSocket.Init();
     SelectSocket.Init();
     CheckBoxShowMainLogMsg.Checked = DBShare.g_boShowLogMsg;
     //Units.Main.RankingThread = new TRankingThread(true);
     //Units.Main.RankingThread.Resume();
     DBShare.SendGameCenterMsg(Common.SG_STARTNOW, "正在启动数据库服务器...");
     TimerMain  = new System.Threading.Timer(TimerMainTimer, null, 0, 1);
     TimerStart = new System.Threading.Timer(TimerStartTimer, null, -1, -1);
     TimerClose = new System.Threading.Timer(TimerCloseTimer, null, -1, -1);
     TimerStart.Change(0, 1000);
 }
Example #9
0
        /// <summary>
        /// 显示窗体上网格信息
        /// </summary>
        private void ShowModule()
        {
            int         I;
            TModuleInfo ModuleInfo;

            try
            {
                if ((GameFramework.HUtil32.GetTickCount() - DBShare.g_dwShowModuleTick) > 2000)
                {
                    DBShare.g_dwShowModuleTick = GameFramework.HUtil32.GetTickCount();
                    ModuleGrid.RowCount        = HUtil32._MAX(DBShare.g_ModuleList.Count + 1, 5);
                    for (I = 0; I < ModuleGrid.RowCount; I++)
                    {
                        if (I < DBShare.g_ModuleList.Count)
                        {
                            ModuleInfo = DBShare.g_ModuleList[I];
                            ModuleGrid.Invoke((MethodInvoker) delegate()
                            {
                                ModuleGrid.Rows[I].Cells[0].Value = ModuleInfo.ModuleName;
                                ModuleGrid.Rows[I].Cells[1].Value = ModuleInfo.Address;
                                ModuleGrid.Rows[I].Cells[2].Value = ModuleInfo.Buffer;
                            });
                        }
                        else
                        {
                            ModuleGrid.Invoke((MethodInvoker) delegate()
                            {
                                ModuleGrid.Rows[I].Cells[0].Value = "";
                                ModuleGrid.Rows[I].Cells[1].Value = "";
                                ModuleGrid.Rows[I].Cells[2].Value = "";
                            });
                        }
                    }
                }
            }
            catch
            {
                DBShare.MainOutMessage("[Exception] ShowModule");
            }
        }
Example #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");
            }
        }
Example #11
0
        /// <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");
            }
        }
Example #12
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));
            }
        }
Example #13
0
 public void SelectSocket_OnClientDisconnect(object sender, AsyncUserToken e)
 {
     DBShare.MainOutMessage("Sel断开: " + e.EndPoint.ToString());
 }
Example #14
0
 public void C1Click(System.Object Sender, System.EventArgs _e1)
 {
     DBShare.LoadChrNameList("DenyChrName.txt");
     DBShare.LoadAICharNameList("AICharName.txt");
     DBShare.MainOutMessage("角色过滤列表加载完成");
 }
Example #15
0
 public void G1Click(System.Object Sender, System.EventArgs _e1)
 {
     DBShare.LoadGateID();
     DBShare.LoadIPTable();
     DBShare.MainOutMessage("网关设置加载完成");
 }