예제 #1
0
        /// <summary>
        /// 获取指定的用户在线的服务器线路ID
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public static int GetUserOnlineState(string userID)
        {
            int state           = 0;
            int oldServerLineID = -1;

            lock (_RegUserIDDict)
            {
                if (!_RegUserIDDict.TryGetValue(userID, out oldServerLineID))
                {
                    oldServerLineID = -1;
                }
            }

            if (oldServerLineID <= -1)
            {
                return(state);
            }

            //判断是否服务器已经当掉
            if (LineManager.GetLineHeartState(oldServerLineID) > 0)
            {
                state = 1;
            }

            return(state);
        }
예제 #2
0
        public static void NotifyTotalOnlineNumToServer(DBManager dbMgr)
        {
            long nowTicks = DateTime.Now.Ticks / 10000L;

            if (nowTicks - OnlineUserNumMgr.LastNotifyDBTicks >= 30000L)
            {
                OnlineUserNumMgr.LastNotifyDBTicks = nowTicks;
                int totalNum = LineManager.GetTotalOnlineNum();
            }
        }
예제 #3
0
        public static void WriteTotalOnlineNumToDB(DBManager dbMgr)
        {
            DateTime dateTime = DateTime.Now;
            long     nowTicks = dateTime.Ticks / 10000L;

            if (nowTicks - OnlineUserNumMgr.LastWriteDBTicks >= 120000L)
            {
                OnlineUserNumMgr.LastWriteDBTicks = nowTicks;
                int    totalNum         = LineManager.GetTotalOnlineNum();
                string strMapOnlineInfo = LineManager.GetMapOnlineNum();
                DBWriter.AddNewOnlineNumItem(dbMgr, totalNum, dateTime, strMapOnlineInfo);
            }
        }
예제 #4
0
        /// <summary>
        /// 添加GM命令消息
        /// </summary>
        /// <param name="serverLineID"></param>
        /// <param name="gmCmd"></param>
        public static void AddGMCmdChatMsg(int serverLineID, string gmCmd)
        {
            string          chatMsg  = string.Format("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}", 0, "", 0, "", 0, gmCmd, 0, 0, serverLineID);
            List <LineItem> itemList = LineManager.GetLineItemList();

            if (null != itemList)
            {
                for (int i = 0; i < itemList.Count; i++)
                {
                    if (itemList[i].LineID == serverLineID)
                    {
                        continue;
                    }

                    ChatMsgManager.AddChatMsg(itemList[i].LineID, chatMsg);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 添加用户ID到字典中
        /// </summary>
        /// <param name="roleID"></param>
        public static bool RegisterUserID(string userID, int serverLineID, int state)
        {
            bool ret = true;

            lock (_RegUserIDDict)
            {
                int oldServerLineID = -1;
                if (state <= 0) //注销, 下边代码加入限制,防止错误的注销,导致的重复登录。
                {
                    //注册前先判断是否已经存在
                    if (_RegUserIDDict.TryGetValue(userID, out oldServerLineID))
                    {
                        //判断是否服务器ID是否相同
                        if (oldServerLineID == serverLineID)
                        {
                            _RegUserIDDict.Remove(userID);
                        }
                    }
                }
                else //注册
                {
                    //注册前先判断是否已经存在
                    if (_RegUserIDDict.TryGetValue(userID, out oldServerLineID))
                    {
                        //判断是否服务器已经当掉
                        if (LineManager.GetLineHeartState(oldServerLineID) > 0)
                        {
                            ret = false; //已经在线
                        }
                        else
                        {
                            _RegUserIDDict[userID] = serverLineID;
                        }
                    }
                    else
                    {
                        _RegUserIDDict[userID] = serverLineID;
                    }
                }
            }

            return(ret);
        }
예제 #6
0
        /// <summary>
        /// 将当前的在线人数写入通知统计服务器
        /// </summary>
        /// <param name="dbMgr"></param>
        public static void NotifyTotalOnlineNumToServer(DBManager dbMgr)
        {
            DateTime dateTime = DateTime.Now;
            long     nowTicks = dateTime.Ticks / 10000;

            if (nowTicks - LastNotifyDBTicks < (30L * 1000L))
            {
                return;
            }

            LastNotifyDBTicks = nowTicks;

            //获取所有线路总的在线人数
            int totalNum = LineManager.GetTotalOnlineNum();

            //GameDBManager.DBEventsWriter.CacheRecentonline(-1,
            //    GameDBManager.ZoneID,
            //    totalNum,
            //    dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
        }
예제 #7
0
        /// <summary>
        /// 将当前的在线人数写入数据库中
        /// </summary>
        /// <param name="dbMgr"></param>
        public static void WriteTotalOnlineNumToDB(DBManager dbMgr)
        {
            DateTime dateTime = DateTime.Now;
            long     nowTicks = dateTime.Ticks / 10000;

            if (nowTicks - LastWriteDBTicks < (2L * 60L * 1000L))
            {
                return;
            }

            LastWriteDBTicks = nowTicks;

            //获取所有线路总的在线人数
            int    totalNum         = LineManager.GetTotalOnlineNum();
            String strMapOnlineInfo = LineManager.GetMapOnlineNum();

            //添加一个新的在线人数记录
            DBWriter.AddNewOnlineNumItem(dbMgr, totalNum, dateTime, strMapOnlineInfo);

            //GameDBManager.DBEventsWriter.CacheOnlineuer(-1,
            //    GameDBManager.ZoneID,
            //    totalNum,
            //    dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
        }
예제 #8
0
        public static void ScanLastGroup(DBManager dbMgr)
        {
            long nowTicks = DateTime.Now.Ticks / 10000L;

            if (nowTicks - GiftCodeNewManager.LastScanTicks >= 10000L)
            {
                GiftCodeNewManager.LastScanTicks = nowTicks;
                List <LineItem> itemList = LineManager.GetLineItemList();
                if (itemList != null && itemList.Count != 0)
                {
                    bool bExistLocalServer = false;
                    for (int i = 0; i < itemList.Count; i++)
                    {
                        if (itemList[i].LineID > 0 && (itemList[i].LineID < 9000 || itemList[i].LineID == GameDBManager.ZoneID))
                        {
                            bExistLocalServer = true;
                            break;
                        }
                    }
                    if (bExistLocalServer)
                    {
                        List <GiftCodeAwardData> groupList = DBQuery.ScanNewGiftCodeFromTable(dbMgr);
                        if (groupList != null && groupList.Count != 0)
                        {
                            string        nowtime  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            List <string> GiftData = new List <string>();
                            foreach (GiftCodeAwardData item in groupList)
                            {
                                if (item.RoleID > 0 && !string.IsNullOrEmpty(item.UserId) && !string.IsNullOrEmpty(item.GiftId) && !string.IsNullOrEmpty(item.CodeNo))
                                {
                                    bool isSucc = DBWriter.UpdateGiftCodeState(dbMgr, item.Dbid, 1, nowtime);
                                    if (isSucc)
                                    {
                                        string szCmd = string.Format("{0},{1},{2},{3}", new object[]
                                        {
                                            item.UserId,
                                            item.RoleID,
                                            item.GiftId,
                                            item.CodeNo
                                        });
                                        GiftData.Add(szCmd);
                                    }
                                }
                                else
                                {
                                    LogManager.WriteLog(LogTypes.Error, string.Format("[GiftCodeNew]数据表t_giftcode相关配置DBID:{0},RoleId:{1},UserId:{2}错误!", item.Dbid, item.RoleID, item.UserId), null, true);
                                }
                            }
                            if (GiftData.Count > 0)
                            {
                                string szCmds    = string.Join("#", GiftData);
                                string gmCmdData = string.Format("-giftcodecmd {0}", szCmds);
                                ChatMsgManager.AddGMCmdChatMsgToOneClient(gmCmdData);
                            }
                            groupList.Clear();
                            GiftData.Clear();
                        }
                    }
                }
            }
        }
예제 #9
0
 public static void ScanGMMsgToGameServer(DBManager dbMgr)
 {
     try
     {
         long nowTicks = DateTime.Now.Ticks / 10000L;
         if (nowTicks - ChatMsgManager.LastScanInputGMMsgTicks >= 10000L)
         {
             ChatMsgManager.LastScanInputGMMsgTicks = nowTicks;
             List <string> msgList = new List <string>();
             DBQuery.ScanGMMsgFromTable(dbMgr, msgList);
             bool reloadConfig             = false;
             bool reloadGameserverLineList = false;
             bool reloadGMail = false;
             for (int i = 0; i < msgList.Count; i++)
             {
                 string msg = msgList[i].Replace(":", ":");
                 if (msg.IndexOf("-config ") >= 0)
                 {
                     reloadConfig = true;
                     string[] fields = msg.Trim().Split(new char[]
                     {
                         ' '
                     });
                     if (fields.Count <string>() == 3)
                     {
                         string paramName  = fields[1];
                         string paramValue = fields[2];
                         DBWriter.UpdateGameConfig(dbMgr, paramName, paramValue);
                     }
                 }
                 else if (msg == "-reload kuafu")
                 {
                     reloadGameserverLineList = true;
                 }
                 else if (msg == "-reloadall")
                 {
                     try
                     {
                         AssemblyPatchManager.getInstance().InitConfig();
                     }
                     catch (Exception ex)
                     {
                         LogManager.WriteException(ex.ToString());
                     }
                 }
                 if (msg.IndexOf("-resetgmail") >= 0)
                 {
                     reloadGMail = true;
                 }
                 if (msg.IndexOf("-outrank") >= 0)
                 {
                     GameDBManager.RankCacheMgr.PrintfRankData();
                 }
                 ChatMsgManager.AddGMCmdChatMsg(-1, msg);
             }
             if (reloadConfig)
             {
                 GameDBManager.GameConfigMgr.LoadGameConfigFromDB(dbMgr);
             }
             if (reloadGameserverLineList)
             {
                 LineManager.LoadConfig();
             }
             if (reloadGMail)
             {
                 GroupMailManager.ResetData();
             }
         }
     }
     catch (Exception)
     {
         LogManager.WriteLog(LogTypes.Error, string.Format("扫描GM命令表时发生了错误", new object[0]), null, true);
     }
 }
예제 #10
0
        public void HandleDeleteRole(DBUserInfo dbUserInfo, DBRoleInfo dbRoleInfo)
        {
            DBManager dbMgr  = DBManager.getInstance();
            string    userID = dbUserInfo.UserID;
            int       roleID = dbRoleInfo.RoleID;

            lock (dbUserInfo)
            {
                if (dbRoleInfo.Faction > 0 && dbRoleInfo.BHZhiWu == 1)
                {
                    int  nRoleID = -1;
                    bool bGoOn   = false;
                    List <BangHuiMemberData>  bangHuiMemberDataList  = DBQuery.GetBangHuiMemberDataList(dbMgr, dbRoleInfo.Faction);
                    List <BangHuiMgrItemData> bangHuiMgrItemDataList = DBQuery.GetBangHuiMgrItemItemDataList(dbMgr, dbRoleInfo.Faction);
                    if (bangHuiMemberDataList != null && bangHuiMemberDataList.Count > 0)
                    {
                        if (bangHuiMgrItemDataList != null)
                        {
                            nRoleID = Global.GetDBRoleInfoByZhiWu(bangHuiMgrItemDataList, 2);
                            if (nRoleID <= 0)
                            {
                                nRoleID = Global.GetDBRoleInfoByZhiWu(bangHuiMgrItemDataList, 3);
                                if (nRoleID <= 0)
                                {
                                    nRoleID = Global.GetDBRoleInfoByZhiWu(bangHuiMgrItemDataList, 4);
                                    if (nRoleID <= 0)
                                    {
                                        bGoOn = true;
                                    }
                                }
                            }
                        }
                        if (bGoOn)
                        {
                            for (int i = 0; i < bangHuiMemberDataList.Count; i++)
                            {
                                if (bangHuiMemberDataList[i].RoleID != roleID)
                                {
                                    nRoleID = bangHuiMemberDataList[i].RoleID;
                                    break;
                                }
                            }
                        }
                        if (nRoleID > 0)
                        {
                            lock (Global.BangHuiMutex)
                            {
                                DBRoleInfo dbRole = dbMgr.GetDBRoleInfo(ref nRoleID);
                                if (dbRole != null)
                                {
                                    if (dbRole.Faction == dbRoleInfo.Faction)
                                    {
                                        dbRole.BHZhiWu = 1;
                                        DBWriter.UpdateBangHuiMemberZhiWu(dbMgr, dbRole.Faction, nRoleID, 1);
                                        DBWriter.UpdateBangHuiRoleID(dbMgr, nRoleID, dbRole.Faction);
                                        int    serverLineID = dbRoleInfo.ServerLineID;
                                        string strCmdData   = string.Format("0::0::0:-chbhzhiwu {0} {1} {2} {3}:0:0:-1", new object[]
                                        {
                                            dbRoleInfo.Faction,
                                            nRoleID,
                                            1,
                                            dbRoleInfo.RoleID
                                        });
                                        List <LineItem> itemList = LineManager.GetLineItemList();
                                        if (null != itemList)
                                        {
                                            for (int i = 0; i < itemList.Count; i++)
                                            {
                                                if (itemList[i].LineID != serverLineID)
                                                {
                                                    ChatMsgManager.AddChatMsg(itemList[i].LineID, strCmdData);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        BangHuiDestroyMgr.ClearBangHuiLingDi(dbMgr, dbRoleInfo.Faction);
                    }
                    else
                    {
                        BangHuiDestroyMgr.DoDestroyBangHui(dbMgr, dbRoleInfo.Faction);
                    }
                }
                dbRoleInfo.Faction  = 0;
                dbRoleInfo.BHName   = "";
                dbRoleInfo.BHZhiWu  = 0;
                dbRoleInfo.BangGong = 0;
                DBWriter.UpdateRoleBangHuiInfo(dbMgr, dbRoleInfo.RoleID, dbRoleInfo.Faction, dbRoleInfo.BHName, 0);
                int index = dbUserInfo.ListRoleIDs.IndexOf(roleID);
                if (index >= 0 && index < dbUserInfo.ListRoleIDs.Count)
                {
                    dbUserInfo.ListRoleIDs.RemoveAt(index);
                    dbUserInfo.ListRoleSexes.RemoveAt(index);
                    dbUserInfo.ListRoleOccups.RemoveAt(index);
                    dbUserInfo.ListRoleNames.RemoveAt(index);
                    dbUserInfo.ListRoleLevels.RemoveAt(index);
                    dbUserInfo.ListRoleZoneIDs.RemoveAt(index);
                    dbUserInfo.ListRoleChangeLifeCount.RemoveAt(index);
                    dbUserInfo.ListRolePreRemoveTime.RemoveAt(index);
                }
            }
        }