| | |
| | | # @change: "2013-03-20 18:00" Alee 添加DEBUG输出函数DebugLog
|
| | | # @change: "2013-09-10 20:10" Alee 函数DebugLog改用GetDebugLevel才有效
|
| | | # @change: "2014-05-16 10:30" xmnathan 增加交易所管理器接口
|
| | | # @change: "2014-08-01 15:30" xmnathan 增加天梯竞技场管理器接口
|
| | | # @change: "2014-09-22 10:00" xmnathan 增加GM工具补偿管理器接口
|
| | | # @change: "2015-01-14 00:30" hxp 增加服务器平台区服ID获取
|
| | | # @change: "2015-01-14 20:30" hxp 增加CanHappen函数
|
| | |
| | | import time
|
| | | import random
|
| | | import copy
|
| | | import urllib
|
| | | #import psyco
|
| | | #---------------------------------------------------------------------
|
| | | GameWorldData = IPY_GameServer.IPY_GameWorld()
|
| | |
| | | global GameWorldData
|
| | | return GameWorldData.GetBourseManager()
|
| | |
|
| | | ## 竞技场管理器
|
| | | # @param |
| | | # @return HightLadderMgr
|
| | | # @remarks 函数详细说明.
|
| | | def GetHightLadderMgr():
|
| | | global GameWorldData
|
| | | return GameWorldData.GetHighLadderManager()
|
| | |
|
| | | ## GM工具补偿管理器
|
| | | # @param
|
| | | # @return HightLadderMgr
|
| | |
| | | def GetPlatform():
|
| | | return ReadChConfig.GetPyMongoConfig("platform", "PlatformName")
|
| | |
|
| | | ##获得当前服务器ID
|
| | | # @param 无
|
| | | # @return
|
| | | def GetServerID():
|
| | | return ToIntDef(GetServerSID()[1:], 0)
|
| | | #===============================================================================
|
| | | # ##获得当前服务器ID
|
| | | # # @param 无
|
| | | # # @return
|
| | | # def GetServerID():
|
| | | # return ToIntDef(GetServerSID()[1:], 0)
|
| | | #===============================================================================
|
| | |
|
| | | def GetServerSID():
|
| | | ##获得当前服务器ID, 带s的
|
| | | return ReadChConfig.GetPyMongoConfig("platform", "ServerID")
|
| | | #===============================================================================
|
| | | # def GetServerSID():
|
| | | # ##获得当前服务器ID, 带s的
|
| | | # return ReadChConfig.GetPyMongoConfig("platform", "ServerID")
|
| | | #===============================================================================
|
| | |
|
| | | Def_AccID_Split_Sign = "@"
|
| | |
|
| | |
| | | mainServerID = ToIntDef(ReadChConfig.GetPyMongoConfig("platform", "%sMainServerID" % accIDPlatform), None)
|
| | | if mainServerID != None:
|
| | | return mainServerID
|
| | | return GetServerID()
|
| | | return 0
|
| | |
|
| | |
|
| | | #===============================================================================
|
| | |
| | | @param dateInfo: 运营活动表配置的日期信息, 如果是纯数字代表开服天
|
| | | @param openServerDay: 当前开服天
|
| | | '''
|
| | | if not dateInfo:
|
| | | curDateTime = datetime.datetime.today()
|
| | | return "%d-%d-%d" % (curDateTime.year, curDateTime.month, curDateTime.day)
|
| | | if dateInfo.startswith("W"):
|
| | | curDateTime = datetime.datetime.today()
|
| | | curWeekday = curDateTime.weekday() + 1
|
| | | actionWeekday = int(dateInfo[1:])
|
| | | actionDateTime = curDateTime + datetime.timedelta(days=(actionWeekday-curWeekday))
|
| | | return "%d-%d-%d" % (actionDateTime.year, actionDateTime.month, actionDateTime.day)
|
| | | if dateInfo.startswith("Mix"):
|
| | | diffDay = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_MixServerDay) + 1
|
| | | actionServerDay = int(dateInfo[3:])
|
| | |
| | | # @remarks 获得系统时间
|
| | | def GetServerTime():
|
| | | return datetime.datetime.today()
|
| | |
|
| | | def GetWeekOfYear():
|
| | | ## 一年中的第几周, 1代表第1周
|
| | | return datetime.datetime.isocalendar(datetime.datetime.today())[1]
|
| | |
|
| | | #---------------------------------------------------------------------
|
| | | ##获取2个时间之间差异的TimeDelta类实例
|
| | | # @param compareTimeStr 比较的时间字符, 如"2010-05-26 11:21:25"
|
| | |
| | | def GetDatetimeBySubDays(diffDays):
|
| | | return datetime.datetime.today() - datetime.timedelta(days = diffDays)
|
| | |
|
| | | def GetDailyDateStr():
|
| | | ## 获取日常日期 yyyy-MM-dd
|
| | | curDate = GetServerTime()
|
| | | if curDate.hour >= ShareDefine.Def_OnEventHour:
|
| | | return "%d-%s-%s" % (curDate.year, curDate.month, curDate.day)
|
| | | preDate = curDate - datetime.timedelta(days = -1) # 属于前一天
|
| | | return "%s-%s-%s" % (preDate.year, preDate.month, preDate.day)
|
| | |
|
| | | def IsCrossServer():
|
| | | ## 是否跨服服务器
|
| | | return ToIntDef(ReadChConfig.GetPyMongoConfig("Merge", "IsMergeServer"), 0)
|
| | |
| | | # @param itemList 待选列表
|
| | | # @return object
|
| | | def GetResultByRandomList(randList, defValue=None, maxRateValue=ChConfig.Def_MaxRateValue):
|
| | | rate = random.randint(0, maxRateValue)
|
| | | |
| | | if not randList:
|
| | | return defValue
|
| | | rate = random.randint(0, randList[-1][0])
|
| | | return GetResultByRiseList(randList, rate, defValue)
|
| | |
|
| | | ## 增长列表(类似饼图)从中获得指定的信息
|
| | |
| | | return smallList[1]
|
| | |
|
| | | return defValue
|
| | |
|
| | | ## 从列表中产生物品,[[权重, object], ....]
|
| | | # @param weightList 待选列表
|
| | | def GetResultByWeightList(weightList):
|
| | | randList = []
|
| | | weight = 0
|
| | | for info in weightList:
|
| | | weight += info[0]
|
| | | randList.append([weight, info[1] if len(info) == 2 else info[1:]])
|
| | | if not randList:
|
| | | return
|
| | | rate = random.randint(1, randList[-1][0])
|
| | | return GetResultByRiseList(randList, rate)
|
| | |
|
| | | ## 根据字典key获取value值
|
| | | # @return
|
| | |
| | | except:
|
| | | return inputText
|
| | |
|
| | | return inputText |
| | | return inputText
|
| | |
|
| | | def RaiseException(errorMsg, playerID=0):
|
| | | ## 处理抛出异常信息,debug下直接抛出异常报错信息,否则发送运维邮件提醒
|
| | | ErrLog(errorMsg, playerID)
|
| | | if GetGameWorld().GetDebugLevel():
|
| | | raise Exception(errorMsg)
|
| | | else:
|
| | | SendGameError("GameServerRaiseException", errorMsg)
|
| | | return
|
| | |
|
| | | def SendGameError(errType, msgInfo=""):
|
| | | ''' 向运维发送邮件,用于需要紧急处理的信息
|
| | | @param errType: 错误类型,自定义即可
|
| | | @param msgInfo: 错误信息,可选
|
| | | '''
|
| | | getUrl = ReadChConfig.GetPyMongoConfig("EventReport", "OpenStateUrl")
|
| | | groupID = ReadChConfig.GetPyMongoConfig("platform", "GroupID")
|
| | | userDBName = ReadChConfig.GetPyMongoConfig("connect", "USER_DB_NAME")
|
| | | getUrl = getUrl + "?Type=%s&groupID=%s&userDBName=%s"%(errType, groupID, userDBName)
|
| | | if msgInfo:
|
| | | getUrl = getUrl + "&MsgInfo=%s" % urllib.quote_plus(msgInfo)
|
| | | GetGameWorld().EventReport_EventReport("", "", "", "", 0, getUrl)
|
| | | return
|