ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py
@@ -421,6 +421,31 @@
    ## 服务器组ID,必须唯一,代表这台物理服务器
    return ToIntDef(ReadChConfig.GetPyMongoConfig("platform", "GroupID"), 0)
def GetMainServerID(serverID):
    ## 获取服务器ID所属主服ID
    ServerIDMainServerDict = IpyGameDataPY.GetConfigEx("ServerIDMainServerDict")
    if ServerIDMainServerDict == None:
        filePath = ChConfig.GetDBPath() + ("\\MixServerMap_%s.json" % GetPlatform())
        if not os.path.isfile(filePath):
            SendGameErrorEx("GetMainServerIDError", "file can not found. %s" % filePath)
        else:
            fileObj = open(filePath, 'rb')
            content = fileObj.read()
            fileObj.close()
            MixServerMapDict = eval(content)
            ServerIDMainServerDict = {}
            for mainServerIDStr, serverIDList in MixServerMapDict.items():
                mainServerID = int(mainServerIDStr)
                for sID in serverIDList:
                    ServerIDMainServerDict[sID] = mainServerID
            IpyGameDataPY.SetConfigEx("ServerIDMainServerDict", ServerIDMainServerDict)
            Log("加载 ServerIDMainServerDict=%s" % ServerIDMainServerDict)
    if not ServerIDMainServerDict:
        return serverID
    return ServerIDMainServerDict.get(serverID, serverID)
def GetPlatformServerNum(platform):
    # 获取服务器的平台编号
    platformNumDict = ReadChConfig.GetDBEvalChConfig("DBPlatformNum")
@@ -460,7 +485,7 @@
def GetPlayerServerID(curPlayer): return GetAccIDServerID(curPlayer.GetAccID())
def GetAccIDServerID(accID):
    infoList = accID.split(Def_AccID_Split_Sign)
    return 0 if len(infoList) < 3 else int(infoList[-1][1:])
    return 0 if len(infoList) < 3 else ToIntDef(infoList[-1][1:])
def GetPlayerServerSID(curPlayer):
    # 返回含s的serverID
@@ -476,6 +501,17 @@
        return mainServerID
    return 0
def CheckServerIDInList(serverID, serverIDList):
    if serverIDList == None:
        return False
    if not serverIDList:
        return True
    for serverIDInfo in serverIDList:
        if (isinstance(serverIDInfo, tuple) and serverIDInfo[0] <= serverID <= serverIDInfo[1]) \
            or (isinstance(serverIDInfo, list) and serverIDInfo[0] <= serverID <= serverIDInfo[1]) \
            or (isinstance(serverIDInfo, int) and serverIDInfo == serverID):
            return True
    return False
#===============================================================================
# ƽ̨ID = appid
@@ -563,6 +599,30 @@
    templateID = templateIDList[-1] if dayIndex >= len(templateIDList) else templateIDList[dayIndex]
    return templateID
def GetOperationActionLoopDate(startDateStr, endDateStr, curDateTime):
    ## 获取运营活动配置日期循环的具体活动时间
    # @return: 开始日期, 结束日期, 返回的日期是第x次循环
    startSplitList = startDateStr.split("_")
    loopDays = int(startSplitList[0][1:])
    startLoopDateStr = startSplitList[1]
    startLoopDateTime = ChangeStrToDatetime(startLoopDateStr, ChConfig.TYPE_Time_YmdFormat)
    endSplitList = endDateStr.split("_") # 可不配Lx_开头,防误配,做兼容
    endLoopDateStr = endSplitList[0] if len(endSplitList) == 1 else endSplitList[1]
    endLoopDateTime = ChangeStrToDatetime(endLoopDateStr, ChConfig.TYPE_Time_YmdFormat)
    if curDateTime >= startLoopDateTime:
        passDays = (curDateTime - startLoopDateTime).days
        loopTimes = passDays / loopDays + 1 # 第x次循环
        loopTimeMax = (endLoopDateTime - startLoopDateTime).days / loopDays + 1 # 最大循环次数
        loopTimes = min(loopTimes, loopTimeMax)
    else:
        loopTimes = 1 # 还未开始取第一次
    startDateTime = startLoopDateTime + datetime.timedelta((loopTimes - 1)*loopDays)
    endDateTime = startDateTime + datetime.timedelta(days=(loopDays - 1))
    return startDateTime, endDateTime, loopTimes
def GetOperationActionDateStr(ipyData):
    ## 获取运营活动对应日期,存数字代表开服天配置,需要转化为对应的日期
    curDateTime = datetime.datetime.today()
@@ -574,7 +634,7 @@
        endDateStr = "%d-%d-%d" % (curDateTime.year, curDateTime.month, curDateTime.day)
        
    # 日期直接返回
    if startDateStr.count("-") == 2 and "W" not in startDateStr:
    if startDateStr.count("-") == 2 and "W" not in startDateStr and not startDateStr.startswith("L"):
        return startDateStr, endDateStr
    
    # 开服天
@@ -621,7 +681,10 @@
            # 只配置结束日期的时候可能导致开始日期计算出来比结束日期还大,即当前时间超过结束日期,且 配置还存在的情况
            if startDateTime > endDateTime:
                startDateTime = endDateTime # 反正都无法开启,随便给个日期,不超过结束日期即可
    # 按日期循环
    elif startDateStr.startswith("L"):
        startDateTime, endDateTime, _ = GetOperationActionLoopDate(startDateStr, endDateStr, curDateTime)
    # 默认
    else:
        startDateTime = curDateTime
@@ -700,6 +763,15 @@
    return pastTimeDelta.days * 24 * 60 * 60 + pastTimeDelta.seconds
#---------------------------------------------------------------------
def GetDiff_Day(timeA , timeB):
    ## 获取 timeA - timeB 相差的日期天数
    dateTimeA = ChangeTimeNumToDatetime(timeA)
    dateTimeA = datetime.datetime(dateTimeA.year, dateTimeA.month, dateTimeA.day, 0, 0, 0)
    dateTimeB = ChangeTimeNumToDatetime(timeB)
    dateTimeB = datetime.datetime(dateTimeB.year, dateTimeB.month, dateTimeB.day, 0, 0, 0)
    return (dateTimeA - dateTimeB).days
##设置世界服务器字典
# @param key 字典值
# @param tick 时间戳
@@ -995,6 +1067,28 @@
    
    return fullName
def MergeItemList(itemList):
    ## 合并物品列表,将相同物品数量合并
    itemDict = {}
    for itemInfo in itemList:
        if len(itemInfo) == 3:
            itemID, itemCount, isAuctionItem = itemInfo
        elif len(itemInfo) == 2:
            itemID, itemCount = itemInfo
            isAuctionItem = None
        else:
            continue
        key = (itemID, isAuctionItem)
        itemDict[key] = itemDict.get(key, 0) + itemCount
    mItemList = []
    for key, itemCount in itemDict.items():
        itemID, isAuctionItem = key
        if isAuctionItem == None:
            mItemList.append([itemID, itemCount])
        else:
            mItemList.append([itemID, itemCount, isAuctionItem])
    return mItemList
## 从列表中产生物品,[[几率,object], ....],万分率
#  @param itemList 待选列表
@@ -1223,6 +1317,14 @@
        SendGameError("GameServerRaiseException", errorMsg)
    return
def SendGameErrorEx(errType, msgInfo="", playerID=0):
    ErrLog("SendGameErrorEx: %s -> %s" % (errType, msgInfo), playerID)
    if GetGameWorld().GetDebugLevel():
        raise Exception("%s -> %s" % (errType, msgInfo))
    else:
        SendGameError(errType, msgInfo)
    return
def SendGameError(errType, msgInfo=""):
    ''' 向运维发送邮件,用于需要紧急处理的信息
    @param errType: 错误类型,自定义即可