3647 【后端】思璞游戏SDK接入-动态字段被转化为小写问题
New file |
| | |
| | | #!/usr/bin/python
|
| | | # -*- coding: GBK -*-
|
| | | #
|
| | | #
|
| | | ##@package CommFunc.py
|
| | | # @todo: 公共调用函数集
|
| | | # @author:eggxp
|
| | | # @date 2010-01-01 00:00
|
| | | # @version 1.8
|
| | | #
|
| | | # 修改时间 修改人 修改内容
|
| | | # @change: "2010-01-19 16:35" zb 修改公共函数的一个错误,解决小喇叭输入'瞾'字会导致客户端弹框的问题
|
| | | # @change: "2010-01-29 11:45" chenxuewei 修改公共函数ReplaceBig5AppointSign(srcStr,sign,desSign)的一个错误,解决字符串srcStr最后一个字节的字符替换问题
|
| | | # @change: "2010-04-02 17:45" zb 添加公共函数ToDWORD()
|
| | | # @change: "2010-04-02 20:30" zb 将ReadBYTE()/ReadDWORD()/ReadDWORD(),改成无符号数读取
|
| | | # @change: "2010-09-27 15:55" chenxuewei 将WriteBYTE()/WriteDWORD()/WriteDWORD(),改成自动转化有无符号数写入
|
| | | #
|
| | | # @change: "2011-03-15 17:20" Alee 与GameWorld中的函数重复
|
| | | # @change: "2016-07-18 19:00" hxp 增加GetPlatformAccID
|
| | | # @change: "2017-07-04 15:00" hxp 增加获取玩家所属平台主服ID
|
| | | #
|
| | | #---------------------------------------------------------------------
|
| | | #导入
|
| | | import os
|
| | | import struct
|
| | | import string
|
| | | import math
|
| | | import datetime
|
| | | import subprocess
|
| | |
|
| | | DBConfig = __import__('Config.DBConfig')
|
| | | #---------------------------------------------------------------------
|
| | | #全局变量
|
| | |
|
| | | MODULE_NAME = "cmd_mail"
|
| | |
|
| | | VER = "2017-07-04 15:00"
|
| | |
|
| | |
|
| | | ## 用于发包,当封包是DWORD的时候
|
| | | # @param num 数字
|
| | | # @return 有符号数字
|
| | | # @remarks 函数详细说明:用于发包,当封包是DWORD的时候,转换为有符号数
|
| | | def ToDWORD( num ):
|
| | | if num >= 0:
|
| | | return num
|
| | | return num + 4294967296
|
| | |
|
| | | ## 将hex转化成二进制对应的字符串,用于发包
|
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:将hex转化成二进制对应的字符串,用于发包
|
| | | def HexToBin (hexStr):
|
| | | returnStr = ''
|
| | | hexStrLen = len(hexStr)
|
| | | for i in [j for j in range(hexStrLen) if j%2==0]:
|
| | | returnStr += chr(string.atoi(hexStr[i:i+2],16))
|
| | | return returnStr
|
| | |
|
| | | #获取异常信息#(try:...except:..GetExceptionInfo())
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def GetExceptionInfo():
|
| | | import traceback
|
| | | return traceback.format_exc()
|
| | |
|
| | |
|
| | | #执行cmd指令
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def RunCmd(curCmd):
|
| | | pipe = subprocess.Popen(['cmd', ""], shell = False,
|
| | | stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
| | | pipe.stdin.write('%s\n'%curCmd)
|
| | | pipe.stdin.close()
|
| | | retStr = pipe.stdout.read()
|
| | | retStr += pipe.stderr.read()
|
| | | print retStr
|
| | | return retStr
|
| | |
|
| | |
|
| | | #取得代码中真实的字符串(如参数srcStr是'\n',会得到回车符)
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def GetCodeStr(srcStr):
|
| | | desStr = srcStr.replace("'", "\\'")
|
| | | cmd = "desStr='" + desStr + "'"
|
| | | exec(cmd)
|
| | | return desStr |
| | |
|
| | |
|
| | | #python写文件:
|
| | | # f = file('c:\\fuck.txt', 'a')
|
| | | # f.write(mapObsData)
|
| | |
|
| | | #等待输入: raw_input()
|
| | |
|
| | | #创建Socket
|
| | | #s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
|
| | | #s.bind(('192.168.0.81', 6112))
|
| | | #s.listen(1)
|
| | |
|
| | | #获得子目录:
|
| | | #os.path.abspath
|
| | |
|
| | | #等待输入:
|
| | | #raw_input()
|
| | |
|
| | | #得到本目录:
|
| | | #os.getcwd()
|
| | |
|
| | | #得到参数:
|
| | | #os.sys.argv
|
| | |
|
| | | #得到python路径
|
| | | #os.sys.executable
|
| | |
|
| | | #运行外部文件/结束外部文件
|
| | | #processID = os.spawnl(os.P_NOWAIT, pythonPath, '-p', os.path.join(curPath, 'test.py'))
|
| | | #win32api.TerminateProcess(processID, 0)
|
| | |
|
| | |
|
| | | #python的读取/写入库
|
| | |
|
| | | #------------------------读取 |
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ReadBYTE(buf, pos):
|
| | | curValue = struct.unpack_from('B', buf, pos)
|
| | | pos += 1
|
| | | return curValue[0], pos
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ReadWORD(buf, pos):
|
| | | curValue = struct.unpack_from('H', buf, pos)
|
| | | pos += 2 |
| | | return curValue[0], pos
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ReadDWORD(buf, pos):
|
| | | curValue = struct.unpack_from('I', buf, pos) |
| | | pos += 4
|
| | | return curValue[0], pos
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ReadFloat(buf, pos):
|
| | | curValue = struct.unpack_from('f', buf, pos) |
| | | pos += 4
|
| | | return curValue[0], pos
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ReadDouble(buf, pos):
|
| | | curValue = struct.unpack_from('d', buf, pos) |
| | | pos += 8
|
| | | return curValue[0], pos
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ReadString(buf, pos, _len):
|
| | | curValue = struct.unpack_from('%ds'%_len, buf, pos)
|
| | | pos += _len |
| | | return curValue[0], pos
|
| | |
|
| | |
|
| | | #----------------------写入
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def Pack(sign, value):
|
| | | |
| | | if value < 0:
|
| | | sign = sign.lower()
|
| | | else:
|
| | | sign = sign.upper()
|
| | | |
| | | return struct.pack(sign, value)
|
| | | |
| | | |
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def WriteBYTE(buf, value):
|
| | | buf += Pack('B', value)
|
| | | return buf
|
| | |
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def WriteWORD(buf, value):
|
| | | buf += Pack('H', value)
|
| | | return buf
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def WriteDWORD(buf, value):
|
| | | buf += Pack('I', value)
|
| | | return buf
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def WriteFloat(buf, value):
|
| | | buf += struct.pack('f', value)
|
| | | return buf
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def WriteDouble(buf, value):
|
| | | buf += struct.pack('d', value)
|
| | | return buf
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def WriteString(buf, len, value):
|
| | | buf += struct.pack('%ds'%len, value)
|
| | | return buf
|
| | |
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def GetDistance(srcX, srcY, destX, destY):
|
| | | return math.sqrt(pow(srcX - destX, 2) + pow(srcY - destY, 2))
|
| | | |
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def MovePos(srcX, srcY, destX, destY, curMoveDist):
|
| | | if curMoveDist == 0:
|
| | | return srcX, srcY
|
| | | |
| | | totalDist = GetDistance(srcX, srcY, destX, destY)
|
| | | if totalDist == 0:
|
| | | return srcX, srcY
|
| | | |
| | | resultX = curMoveDist / float(totalDist) * (destX - srcX) + srcX
|
| | | resultY = curMoveDist / float(totalDist) * (destY - srcY) + srcY
|
| | | return resultX, resultY |
| | | |
| | |
|
| | | ##测试代码:
|
| | | #strs = '美香是猪'
|
| | | #buf = ''
|
| | | #buf = WriteString(buf, len(strs), strs)
|
| | | #value, pos = ReadString(buf, 0, len(strs))
|
| | | #print value
|
| | |
|
| | | #获得当前系统时间
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def GetCurrentDataTimeStr():
|
| | | curTime = datetime.datetime.today()
|
| | | curTimeStr = str(curTime)
|
| | | curTimeStr = curTimeStr.split(".")[0]
|
| | | return curTimeStr
|
| | |
|
| | |
|
| | | #字符串转换为整型, 如果不能转换, 返回默认值
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ToIntDef(input, defValue = 0):
|
| | | try:
|
| | | result = int(input)
|
| | | return result
|
| | | except ValueError:
|
| | | return defValue
|
| | | |
| | | #16进制颜色转换
|
| | | #"#FFFFFF"--"255,255,255"
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def HcToSc(h):
|
| | | h="0x"+h[1:7]
|
| | | red=string.atoi(h[:2]+h[2:4], base=16)
|
| | | green=string.atoi(h[:2]+h[4:6], base=16)
|
| | | blue=string.atoi(h[:2]+h[6:8], base=16)
|
| | | cStr=str(red)+","+str(green)+","+str(blue)
|
| | | return cStr
|
| | |
|
| | | #"255,255,255"--"#FFFFFF"
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ScToHc(s):
|
| | | red=hex(string.atoi(s.split(",")[0]))[2:]
|
| | | green=hex(string.atoi(s.split(",")[1]))[2:]
|
| | | blue=hex(string.atoi(s.split(",")[2]))[2:]
|
| | | hStr="#"+str(red+green+blue)
|
| | | return hStr
|
| | |
|
| | | #16进制转换
|
| | | #"0xFFFFFF"--"255,255,255"
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def HdToSd(h):
|
| | | red=string.atoi(h[0:2]+h[2:4], base=16)
|
| | | green=string.atoi(h[0:2]+h[4:6], base=16)
|
| | | blue=string.atoi(h[0:2]+h[6:8], base=16)
|
| | | cStr=str(red)+","+str(green)+","+str(blue)
|
| | | return cStr
|
| | |
|
| | | #"255,255,255"--"0xFFFFFF"
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def SdToHd(s):
|
| | | red=hex(string.atoi(s.split(",")[0]))[2:]
|
| | | green=hex(string.atoi(s.split(",")[1]))[2:]
|
| | | blue=hex(string.atoi(s.split(",")[2]))[2:]
|
| | | hStr="0x"+str(red+green+blue)
|
| | | return hStr
|
| | |
|
| | | #提示除零错误的EVAL
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def SafeEval(value):
|
| | | try:
|
| | | return eval(value)
|
| | | except ZeroDivisionError:
|
| | | return "Division is Zero"
|
| | |
|
| | | ##生成指定文件(如par:r'E:\开发版本\Data\logo\formName1.log')
|
| | | #def MakeAppointFile(par):
|
| | | # dir = os.path.dirname(par) # 获得文件目录
|
| | | # os.makedirs(dir) # 创建多级目录
|
| | | # file = open(os.path.basename(par),'w')
|
| | | # file.close()
|
| | | #
|
| | | ##在指定目录根据当前时间生成新目录(如par:r'E:\开发版本\Data\logo')
|
| | | #def MakeCurTimeDir(par):
|
| | | # if not os.path.exists(par): # 传进来的目录不存在
|
| | | # return
|
| | | # path=par+'\\'+str(datetime.datetime.today()).split()[0]
|
| | | # if not os.path.exists(path): # 文件夹是否存在,不存在则创建
|
| | | # os.mkdir(path) # 创建文件夹
|
| | | |
| | | #生成指定目录(如par:r'E:\开发版本\Data\logo')
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def MakeAppointDir(par):
|
| | | if not isinstance(par,str):
|
| | | return
|
| | | pathList=par.split('\\')
|
| | | path=pathList[0]
|
| | | for i in range(1,len(pathList)):
|
| | | path+='\\'+pathList[i]
|
| | | if not os.path.exists(path): # 文件夹是否存在,不存在则创建
|
| | | os.mkdir(path) # 创建文件夹
|
| | | |
| | | #生成指定文件(如par:r'E:\开发版本\Data\logo\formName1.log')
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def MakeAppointFile(par):
|
| | | if not isinstance(par,str):
|
| | | return
|
| | | pathList=par.split('\\')
|
| | | path=pathList[0]
|
| | | for i in range(1,len(pathList)):
|
| | | path+='\\'+pathList[i]
|
| | | if i==len(pathList)-1:
|
| | | file=open(path,'w')
|
| | | file.close()
|
| | | else:
|
| | | if not os.path.exists(path): # 文件夹是否存在,不存在则创建
|
| | | os.mkdir(path) # 创建文件夹
|
| | |
|
| | | #在指定目录根据当前时间生成新目录(如par:r'E:\开发版本\Data\logo')
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def MakeCurTimeDir(par):
|
| | | if not os.path.exists(par): # 传进来的目录不存在
|
| | | return
|
| | | path=par+'\\'+str(datetime.datetime.today()).split()[0]
|
| | | if not os.path.exists(path): # 文件夹是否存在,不存在则创建
|
| | | os.mkdir(path) # 创建文件夹
|
| | |
|
| | |
|
| | | #得到替换后的字符串(参数:string是需要替换的字符串;varlist为不定参,为替换内容)
|
| | | #如GetReplaceString('str%s%s','str1','str2','str3','str4'),return结果为'strstr1str2'
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def GetReplaceString(string,*varlist):
|
| | | if '%' not in string:
|
| | | return string
|
| | | repalceCount = len(varlist) # 替换次数
|
| | | newStr = string
|
| | | if '%%' in string:
|
| | | newStr = string.replace('%%','') # 去除字符串str内的'%%'
|
| | | needReplaceCount = newStr.count('%') # 字符串newStr内的'%'个数,即需要替换的次数
|
| | | if repalceCount < needReplaceCount:
|
| | | tempList = list(varlist)
|
| | | for i in range(needReplaceCount-repalceCount):
|
| | | tempList.append(0)
|
| | | replaceTuple= tuple(tempList)
|
| | | #告诉调用者,参数传少了
|
| | | return 'func:GetReplaceString();error:the parameter lack'
|
| | | # return string%replaceTuple
|
| | | |
| | | replaceTuple = tuple(varlist[:needReplaceCount])
|
| | | return string%replaceTuple
|
| | |
|
| | |
|
| | | #将unicode编码转换成中文字符(参数:"#19968"-"#40869"之间)
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def UnicodeStrToGBKStr(U_STR):#如输入"#23435",获得返回值"宋"
|
| | | import re
|
| | | RegularExpression="#[0-9]+"
|
| | | if not re.match(RegularExpression,U_STR):
|
| | | return U_STR
|
| | | UnicodeNum=int(U_STR[1:])
|
| | | CODEC="GBK"
|
| | | try:
|
| | | unicode_string=eval("u'\u%s'"%((hex(UnicodeNum))[2:]))
|
| | | GBK_str=unicode_string.encode(CODEC)
|
| | | except:
|
| | | return U_STR
|
| | | return GBK_str
|
| | | |
| | | |
| | | #用指定字符desSign替换繁体字符串srcStr的指定单字节字符sign
|
| | | ## |
| | | # @param 参数
|
| | | # @return 返回值
|
| | | # @remarks 函数详细说明:
|
| | | def ReplaceBig5AppointSign(srcStr,sign,desSign):
|
| | | |
| | | isContinue = False
|
| | | desStr = ''
|
| | | |
| | | for i in range( len(srcStr) ):
|
| | | |
| | | if isContinue:
|
| | | #如果最后两个字节刚好是一个繁体字,则倒数第二个字节时会判定,最后一个字节则在此跳过
|
| | | isContinue = False
|
| | | continue
|
| | | |
| | | #已到字符串最后一个字节,操作完跳出循环
|
| | | if i == len(srcStr)-1:
|
| | | |
| | | if srcStr[i] == sign:
|
| | | #替换
|
| | | desStr = desStr + desSign
|
| | | else:
|
| | | desStr = desStr + srcStr[i]
|
| | | |
| | | break # 跳出循环
|
| | | |
| | | if 129 <= ord(srcStr[i]) <= 254: # 判断是否在Big5高位字节范围内
|
| | | |
| | | if 64 <= ord(srcStr[i+1]) <= 126 or 161 <= ord(srcStr[i+1]) <= 254: # 判断是否Big5低位字节范围内
|
| | | isContinue = True # 下次判断高字节时,可跳过一次循环
|
| | | desStr = desStr + srcStr[i:i+2]
|
| | | else:
|
| | | #不在Big5低位字节范围内
|
| | | if srcStr[i] == sign:
|
| | | #替换
|
| | | desStr = desStr + desSign
|
| | | else:
|
| | | desStr = desStr + srcStr[i]
|
| | | else:
|
| | | #不在Big5高位字节范围内
|
| | | if srcStr[i] == sign:
|
| | | #替换
|
| | | desStr = desStr + desSign
|
| | | else:
|
| | | desStr = desStr + srcStr[i]
|
| | | |
| | | return desStr
|
| | |
|
| | |
|
| | | Def_AccID_Split_Sign = "@"
|
| | | ##玩家游戏账号格式: 平台账号@平台名@s区服ID, 平台账号可能带@,如邮箱yhlz123@qq.com@173on_lan@s519
|
| | |
|
| | | def GetPlayerMainServerID(accIDPlatform):
|
| | | # 玩家合服后所属主服ID
|
| | | # @param accIDPlatform: 玩家账号所属的平台
|
| | | # 获取平台在该服务器所对应的主服ID, 如果没有配置默认取ServerID
|
| | | key = "%sMainServerID" % accIDPlatform.lower()
|
| | | if hasattr(DBConfig, key):
|
| | | return getattr(DBConfig, key)
|
| | | if hasattr(DBConfig, "ServerID"):
|
| | | return int(getattr(DBConfig, "ServerID")[1:])
|
| | | return 0
|
| | |
|
| | | ##获取玩家所属区服ID
|
| | | def GetPlayerServerID(gameAccID):
|
| | | infoList = gameAccID.split(Def_AccID_Split_Sign)
|
| | | return 0 if len(infoList) < 3 else int(infoList[-1][1:])
|
| | |
|
| | | ##获取玩家账号所属平台
|
| | | def GetPlayerPlatform(gameAccID):
|
| | | infoList = gameAccID.split(Def_AccID_Split_Sign)
|
| | | return "" if len(infoList) < 3 else infoList[-2]
|
| | |
|
| | | ##获取平台账号
|
| | | def GetPlatformAccID(gameAccID):
|
| | | infoList = gameAccID.split(Def_AccID_Split_Sign)
|
| | | paInfoList = infoList[:-2]
|
| | | platformAccID = Def_AccID_Split_Sign.join(paInfoList)
|
| | | return platformAccID
|
| | |
|
| | | ##登录key 如思璞
|
| | | def GetLoginKey(gameAccID):
|
| | | infoList = gameAccID.split(Def_AccID_Split_Sign)
|
| | | accIDPlatform = "" if len(infoList) < 3 else infoList[-2]
|
| | | key = "%s_LoginKey" % accIDPlatform.lower()
|
| | | if hasattr(DBConfig, key):
|
| | | return getattr(DBConfig, key)
|
| | | |
| | | return ""
|
New file |
| | |
| | | #!/usr/bin/python
|
| | | # -*- coding: GBK -*-
|
| | | #-------------------------------------------------------------------------------
|
| | | #
|
| | | #-------------------------------------------------------------------------------
|
| | | #
|
| | |
|
| | | #from Common import mylog
|
| | | from DBCommon import GlobalFunctions
|
| | | import traceback
|
| | | import ConfigParser
|
| | | import os
|
| | |
|
| | | from DBCommon import error
|
| | | #mylog = __import__('Common.mylog')
|
| | | from Common import mylog
|
| | |
|
| | | #DB配置字典
|
| | | #格式:keyname:[defvalue, secionname],新增配置只要在下面字典定义中新增一行即可
|
| | | #用法,import模块后,直接DBConfig.开关名称 即可
|
| | |
|
| | | ###PyMongoDataServer.ini###
|
| | | #运维必须修改的配置项
|
| | | BaseConfig ={
|
| | | #connect section
|
| | | #"PyMongoDBPort":[16899, "connect"], #PyMongoDBServer端口 CenterGate 用的端口
|
| | | #"PyMongoDBPort_CreateRole":[16900, "connect"], #PyMongoDBServer端口 CreateRole 用的端口
|
| | | #"PyMongoDBPort_GMTool":[16901, "connect"], #PyMongoDBServer端口 GMTool 用的端口
|
| | |
|
| | | #"USER_DB_PORT":[27017, "connect"], #MongoDB端口
|
| | | "USER_DB_IP":["localhost", "connect"], #MongoDB IP
|
| | | "USER_DB_NAME":["GameUser", "connect"], #MongoDB Name# |
| | |
|
| | | #"SYS_DB_PORT":[27017, "connect"],#MongoDB端口
|
| | | "SYS_DB_IP":["localhost", "connect"], #MongoDB IP
|
| | | "SYS_DB_NAME":["GameSys", "connect"], #MongoDB Name
|
| | |
|
| | | #"LOG_DB_PORT":[27017, "connect"],#MongoDB端口
|
| | | "LOG_DB_IP":["localhost", "connect"], #MongoDB IP
|
| | | "LOG_DB_NAME":["GameLog", "connect"], #MongoDB Name |
| | |
|
| | | #platform section
|
| | | "PlatformName":["", "platform"], #ƽ̨
|
| | | "ServerID":["", "platform"], #区服ID
|
| | |
|
| | | #ID 分配服务器设置
|
| | | "UseIDDispatchServer":[0, "IDDispatch"], #启用ID分配服务器开关
|
| | | "IDDispatchServerIP":["localhost", "IDDispatch"], #ID分配服务器 域名
|
| | | "IDDispatchServerPort":[8001, "IDDispatch"], #ID分配服务器 端口
|
| | | "IDDispatchPlayeIDLimit":[100, "IDDispatch"], #PlayerID预分配数量下限
|
| | | #"IDDispatchFamilyIDLimit":[30, "IDDispatch"], #FamilyID预分配数量下限---在GameServer判断通知
|
| | |
|
| | | #账号验证
|
| | | "CheckTokenUrl":["", "CheckAccID"],
|
| | |
|
| | |
|
| | | #事件回报和定时处理
|
| | | "OpenErrLogReport":[0,"OpenErrLogReport"], #开启回报错误数量
|
| | | "PlatformName":["9377","platform"], #ZoneName |
| | | "ServerID":["s1","platform"], #OperatorID
|
| | | "AppId":["AppId1","EventReport"], #AppId
|
| | | "Key":["7ded96779343f198de9b95a05a0704c9","EventReport"], #Secret
|
| | | "SessionGUID":["sid1","EventReport"], #SessionID
|
| | | "ProductID":["pid1","EventReport"], #ProductID
|
| | | "ErrLogReportEventID":[22222,"EventReport"], #回报错误数量事件ID
|
| | | "ErrLogReportInterval":[60000,"EventReport"], #回报错误数量间隔
|
| | | "ReportUrl":["","EventReport"], # 数据汇报地址 |
| | |
|
| | | "LoginKey":["","SPGame"] # 思璞游戏登录key
|
| | | }
|
| | |
|
| | | ###config\\config.ini###
|
| | | dbconfig = {
|
| | | #auth section
|
| | | "userdb_user":['', "auth"],
|
| | | "userdb_pwd":['', 'auth'],
|
| | | "sysdb_user":['', "auth"],
|
| | | "sysdb_pwd":['', 'auth'],
|
| | | "logdb_user":['', "auth"],
|
| | | "logdb_pwd":['', 'auth'], |
| | | |
| | | #connect section
|
| | | "ConnectionQueueSize":[1, "connect"],
|
| | | "PyMongoDBPort":[16899, "connect"], #PyMongoDBServer端口 CenterGate 用的端口
|
| | | "PyMongoDBPort_CreateRole":[16900, "connect"], #PyMongoDBServer端口 CreateRole 用的端口
|
| | | "PyMongoDBPort_GMTool":[16901, "connect"], #PyMongoDBServer端口 GMTool 用的端口
|
| | | "MergePort":[16902, "connect"], #跨服接口端口
|
| | |
|
| | | "USER_DB_PORT":[27017, "connect"], #MongoDB端口
|
| | | #"USER_DB_IP":["localhost", "connect"], #MongoDB IP
|
| | | #"USER_DB_NAME":["GameUser", "connect"], #MongoDB Name
|
| | | #
|
| | | "SYS_DB_PORT":[27017, "connect"],#MongoDB端口
|
| | | #"SYS_DB_IP":["localhost", "connect"], #MongoDB IP
|
| | | #"SYS_DB_NAME":["GameSys", "connect"], #MongoDB Name
|
| | | #
|
| | | "LOG_DB_PORT":[27017, "connect"],#MongoDB端口
|
| | | #"LOG_DB_IP":["localhost", "connect"], #MongoDB IP
|
| | | #"LOG_DB_NAME":["GameLog", "connect"], #MongoDB Name
|
| | |
|
| | | #encoding
|
| | | "base64":[1, "encoding"], #是否对字符串进行BASE64编码
|
| | | "encoding":['gbk', "encoding"], #字符串编码,在base64为False时有效
|
| | |
|
| | | #merge
|
| | | "randPswLen":[8, "merge"], #合服生成随机密码长度,不得超过32
|
| | | "randPswHasDigit":[True, "merge"], #随机密码是否包含数字
|
| | | "randPswHasLowLetter":[True, "merge"], #随机密码是否包含小写字符
|
| | | "randPswHasUpperLetter":[True, "merge"], #随机密码是否包含大写字符
|
| | | "randPswHasSpecialChar":[False, "merge"], #随机密码是否包含特殊字符
|
| | |
|
| | | #config section
|
| | | "MultiThreading":[False,"config"], #主main是否开启多线程
|
| | | "checkSID":[False, "config"], #是否进行SID校验
|
| | | "TryCntOnWriteFail":[3, 'config'], #存储失败后,尝试次数, 默认3次
|
| | | "IsOpenDbSaveServer":[False, 'config'], #是否打开mongoDBSaveServer
|
| | | "maxReconnectCnt":[100, 'config'],
|
| | | "UploadSysTables":[False, "config"],
|
| | | #"MainLogPath":["D:\\ServerLog", "config"],
|
| | |
|
| | | "EventShellEnable":[False, "config"], #是否启用EventShellDLL发送流向记录 |
| | | "EventShellIP":["127.0.0.1", "config"], #事件接口服务器的IP地址 |
| | | "EventShellPort":[60000, "config"], #事件接口服务器的端口号 |
| | | "EventShellGroupID":[0,"config"], #本服务器的服务器组标识 |
| | | "EventShellServerID":[0,"config"], #本服务器的ID |
| | | "EventShellHeartInterval":[60000, "config"],#连接事件接口服务器心跳时间间隔(ms)
|
| | | "EventShellDllPath":["EventToInterfaceDll.dll", "config"],#指定事件接口服务器Dll地址
|
| | | "EventShellDllLogPath":["D:\\ServerLog", "config"],
|
| | |
|
| | | "IsOpenLogDBFileSave":[False, 'config'], #是否打开LogDB文件保存
|
| | | "LogDB_EventShell_Save":[True, 'config'], #LogDB保存通过EventShell保存(如果要使用该功能,一定要关闭IsOpenLogDBFileSave,并开启EventShellEnable和配置相关网络参数)
|
| | | "PackSave":[True, 'config'], #是否打开打包保存
|
| | | "StartProfile":[True, 'config'], #是否开启性能评测
|
| | | "ProfileThreshold":[100, 'config'], #性能阀值,默认100毫秒,超过则输出一条日志
|
| | | "ProfileQueueThresholdMax":[100, 'config'], #性能统计队列上限,超过此上限触发写一条日志
|
| | | "ProfileQueueThresholdMin":[10, 'config'], #性能统计队列下限,低于此上限触发写一条日志
|
| | |
|
| | | #env section
|
| | | "Python_Ver":["2.7.2", "environment"],
|
| | | "PyMongo_Ver":["2.5.1", "environment"],
|
| | | "MongoDB_Ver":["2.4.3", "environment"],
|
| | | "MongoDB_Bits":[64, "environment"],
|
| | |
|
| | | #InnerParam
|
| | | "PLAYERID_FEED":[10000, "InnerParam"],
|
| | | "PLAYERID_STEP":[1, 'InnerParam'],
|
| | | "LOGINDEX_FEED":[0, "InnerParam"], #tagDBMapServerInfo日志索引种子起始
|
| | | "LOGINDEX_STEP":[1, 'InnerParam'], #tagDBMapServerInfo日志索引增量
|
| | | "LOGDB_LOGINDEX_FEED":[0, 'InnerParam'],#tagDBPlayerLog日志索引种子起始
|
| | | "LOGDB_LOGINDEX_STEP":[1, 'InnerParam'],#tagDBPlayerLog日志索引增量
|
| | | "LOGDB_SvrStatus_fldIndex_FEED":[0, 'InnerParam'],#SvrStatus日志索引种子起始
|
| | | "LOGDB_SvrStatus_fldIndex_STEP":[1, 'InnerParam'],#SvrStatus日志索引增量
|
| | | "LOGDB_AccForbiddenLog_StateID_FEED":[0, 'InnerParam'], #AccForbiddenLog日志索引种子起始 |
| | | "LOGDB_AccForbiddenLog_StateID_STEP":[1, 'InnerParam'], #AccForbiddenLog日志索引增量 |
| | | "LOGDB_tagDBServerMoneyLog_LogIndex_FEED":[0, 'InnerParam'], #tagDBServerMoneyLog 日志索引种子起始
|
| | | "LOGDB_tagDBServerMoneyLog_LogIndex_STEP":[1, 'InnerParam'], #tagDBServerMoneyLog 日志索引增量
|
| | | "LOGDB_tagDBApexKickLog_KickLogIndex_FEED":[0, 'InnerParam'], #tagDBApexKickLog 日志索引种子起始
|
| | | "LOGDB_tagDBApexKickLog_KickLogIndex_STEP":[1, 'InnerParam'], #tagDBApexKickLog 日志索引增量
|
| | | "LOGDB_tagDBGateServerIP_LogIndex_FEED":[0, 'InnerParam'], #tagDBGateServerIP 日志索引种子起始
|
| | | "LOGDB_tagDBGateServerIP_LogIndex_STEP":[1, 'InnerParam'], #tagDBGateServerIP 日志索引增量
|
| | | "LOGDB_tagDBHugeTrade_TradeIndex_FEED":[0, 'InnerParam'], #tagDBHugeTrade 日志索引种子起始
|
| | | "LOGDB_tagDBHugeTrade_TradeIndex_STEP":[1, 'InnerParam'], #tagDBHugeTrade 日志索引增量
|
| | | "LOGDB_tagDBPlayerSaveCoinLog_LogIndex_FEED":[0, 'InnerParam'], #tagDBPlayerSaveCoinLog 日志索引种子起始
|
| | | "LOGDB_tagDBPlayerSaveCoinLog_LogIndex_STEP":[1, 'InnerParam'], #tagDBPlayerSaveCoinLog 日志索引增量
|
| | | "LOGDB_tagDBServerKickLog_LogIndex_FEED":[0, 'InnerParam'], #tagDBServerKickLog 日志索引种子起始
|
| | | "LOGDB_tagDBServerKickLog_LogIndex_STEP":[1, 'InnerParam'], #tagDBServerKickLog 日志索引增量
|
| | | "LOGDB_tagDBTalkTraceLog_LogIndex_FEED":[0, 'InnerParam'], #tagDBTalkTraceLog 日志索引种子起始
|
| | | "LOGDB_tagDBTalkTraceLog_LogIndex_STEP":[1, 'InnerParam'], #tagDBTalkTraceLog 日志索引增量
|
| | | "tagExpiation_ExpiationIndex_FEED":[0, 'InnerParam'], #tagExpiation 索引种子起始
|
| | | "tagExpiation_ExpiationIndex_STEP":[1, 'InnerParam'], #tagExpiation 索引增量
|
| | | "tagPetExpiation_ExpiationIndex_FEED":[0, 'InnerParam'], #tagPetExpiation 索引种子起始
|
| | | "tagPetExpiation_ExpiationIndex_STEP":[1, 'InnerParam'], #tagPetExpiation 索引增量
|
| | | "tagDBImpeach_ImpeachIndex_FEED":[0, 'InnerParam'], #tagDBImpeach 索引种子起始
|
| | | "tagDBImpeach_ImpeachIndex_STEP":[1, 'InnerParam'], #tagDBImpeach 索引增量
|
| | | "tagDBCoinChangeLog_LogIndex_FEED":[0, 'InnerParam'], #tagDBCoinChangeLog 索引种子起始
|
| | | "tagDBCoinChangeLog_LogIndex_STEP":[1, 'InnerParam'], #tagDBCoinChangeLog 索引增量
|
| | | } |
| | |
|
| | |
|
| | | def ReadCongfigValue(config, secname, keyname, defvalue):
|
| | | try:
|
| | | if config.has_option(secname, keyname):
|
| | | value = config.get(secname, keyname)
|
| | | # if type(defvalue) == str:
|
| | | # value = type(defvalue)(value)
|
| | | if type(defvalue) == bool:
|
| | | value = type(defvalue)(int(value))
|
| | | else:
|
| | | value = type(defvalue)(value)
|
| | | else:return defvalue |
| | | except:
|
| | | msg = error.formatMsg('error', error.ERROR_NO_18, 'config = %s, secname = %s, keyname = %s, defvalue = %s\n%s'%(config, secname, keyname, defvalue, traceback.format_exc()))
|
| | | mylog.error(msg)
|
| | | return None |
| | | # print value
|
| | | return value
|
| | | |
| | | def ReadDBConfig():
|
| | | try:
|
| | | self_module = __import__(__name__)
|
| | | config = ConfigParser.ConfigParser()
|
| | | |
| | | #读取数据库配置文件config\\config.ini
|
| | | config.read(os.path.join(GlobalFunctions.getAppPath(), 'config\\config.ini')) |
| | | for k, v in dbconfig.items(): |
| | | value = ReadCongfigValue(config, v[1], k, v[0])
|
| | | if value == None:return False
|
| | | setattr(self_module, k, value)
|
| | | |
| | | #读取数据库配置文件PyMongoDataServer.ini
|
| | | config.read(os.path.join(GlobalFunctions.getAppPath(), 'PyMongoDataServer.ini')) |
| | | for k, v in BaseConfig.items(): |
| | | value = ReadCongfigValue(config, v[1], k, v[0])
|
| | | if value == None:return False
|
| | | setattr(self_module, k, value)
|
| | | #动态加载有配置平台合服主服的平台主服ID
|
| | | sectionName = "platform"
|
| | | if config.has_section(sectionName):
|
| | | optionsList = config.options(sectionName)
|
| | | # 注意options 已经是小写 调用也只能用小写
|
| | | for k in optionsList:
|
| | | if "mainserverid" in k:
|
| | | value = ReadCongfigValue(config, sectionName, k, 0)
|
| | | if value:
|
| | | setattr(self_module, k, value)
|
| | | elif "loginkey" in k:
|
| | | value = ReadCongfigValue(config, sectionName, k, 0)
|
| | | if value:
|
| | | setattr(self_module, k, value)
|
| | | |
| | | #检查并解密mongodb的登录用户名和密码
|
| | | #userdb
|
| | | if not self_module.userdb_user:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_19, "user db mongodb longin user name is empty!")
|
| | | mylog.DeployError(msg, True)
|
| | | return False
|
| | | |
| | | if self_module.userdb_pwd:
|
| | | ret, self_module.userdb_pwd = GlobalFunctions.GetEncodePsw(self_module.userdb_pwd)
|
| | | if not ret:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_20, "Decrypt userdb_pwd faied.")
|
| | | mylog.DeployError(msg, True) |
| | | return False
|
| | | else:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_21, "user db mongodb longin pwd is empty!")
|
| | | mylog.DeployError(msg, True) |
| | | return False
|
| | | |
| | | #sysdb
|
| | | if not self_module.sysdb_user:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_22, "sys db mongodb longin user name is empty!")
|
| | | mylog.DeployError(msg, True)
|
| | | return False
|
| | | |
| | | if self_module.sysdb_pwd:
|
| | | ret, self_module.sysdb_pwd = GlobalFunctions.GetEncodePsw(self_module.sysdb_pwd)
|
| | | if not ret:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_23, "Decrypt sysdb_pwd faied.")
|
| | | mylog.DeployError(msg, True) |
| | | return False
|
| | | else:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_24, "sys db mongodb longin pwd is empty!")
|
| | | mylog.DeployError(msg, True) |
| | | return False
|
| | | |
| | | #logdb
|
| | | if not self_module.logdb_user:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_25, "log db mongodb longin user name is empty!")
|
| | | mylog.DeployError(msg, True) |
| | | return False
|
| | | |
| | | if self_module.logdb_pwd:
|
| | | ret, self_module.logdb_pwd = GlobalFunctions.GetEncodePsw(self_module.logdb_pwd)
|
| | | if not ret:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_26, "Decrypt logdb_pwd faied.")
|
| | | mylog.DeployError(msg, True) |
| | | return False
|
| | | else:
|
| | | msg = error.formatMsg('DeployError', error.ERROR_NO_27, "log db mongodb longin pwd is empty!") |
| | | mylog.DeployError(msg, True)
|
| | | return False |
| | | except:
|
| | | msg = error.formatMsg('error', error.ERROR_NO_28, '%s'%traceback.format_exc()) |
| | | mylog.error(msg)
|
| | | return False |
| | | return True
|
| | |
|
| | | dbconfig_init = False
|
| | |
|
| | | if not dbconfig_init:
|
| | | if not ReadDBConfig():
|
| | | msg = error.formatMsg('fatal', error.ERROR_NO_29, "Init config failed.")
|
| | | mylog.fatal(msg)
|
| | | dbconfig_init = True
|
| | | |