Пример #1
0
 def LoadRoleData(roleid):
     with session_scope() as session:
         generallist = session.query(t_general).filter(
             t_general.rid == roleid).all()
         result = {}
         for general in generallist:
             result[general.id] = general
         if len(result) == 0:
             general = t_general()
             CreateGeneral(roleid, 10102, general)
             general.hp = 9999
             general.def_ = 10000
             general.atk = 9999
             DBEngine.Add(general)
             result[general.id] = general
             general = t_general()
             CreateGeneral(roleid, 10102, general)
             general.hp = 9999
             general.def_ = 10000
             general.atk = 9999
             DBEngine.Add(general)
             result[general.id] = general
             general = t_general()
             CreateGeneral(roleid, 10102, general)
             general.hp = 9999
             general.def_ = 10000
             general.atk = 9999
             DBEngine.Add(general)
             result[general.id] = general
         return result
Пример #2
0
    def LoadUserData(userid):
        # 引入合服机制, 通过判断userid的组成, 判断什么模式
        # 正常模式 userid 为整数
        # 合服模式 userid 为userid_server
        result = None
        if isinstance(userid, int) or isinstance(userid, long):     # 正常模式
            with session_scope() as session:
                result = session.query(t_role).filter(t_role.uid == userid).first()
            if result is None:
                result = t_role()
                result.uid = userid
                result.createtime = GameData.sysTickTime
                CreateRole(result)
                DBEngine.Add(result)
                DBEngine.Update(result)
            result.__server_fix = None
        else:                                                       # 合服模式
            Log.Write("LoadUserData merge tip")
            userid_a = userid.split("_")
            if len(userid_a) < 2:
                raise TypeError("Merge Mode t_role error")

            userid_fix = int(userid_a[0])
            server_fix = int(userid_a[1])
            Log.Write(userid_fix, server_fix)
            with session_scope() as session:
                result = session.query(t_role).filter(
                    and_(
                        t_role.uid == userid_fix,
                        and_(t_role.id > (1000000 * server_fix),
                            (t_role.id < (1000000 * (server_fix + 1)))
                        )
                    )
                ).first()
            if result is None:
                result = t_role()
                result.uid = userid_fix
                result.createtime = GameData.sysTickTime
                CreateRole(result, server_fix)
                DBEngine.Add(result)
                DBEngine.Update(result)
            else:
                m = re.match(r"^S(\d+)-", result.name)      # S999999-xxxx
                server_test = None
                try:
                    xxxtuple = m.groups()
                    server_test = int(xxxtuple[0])              # 服务器编号999999
                    Log.Write("[TIP]server_test", server_test)
                except:
                    pass
                if server_test != server_fix:
                    result.name = u"S%d-" % server_fix + result.name
                    Log.Write("[TIP]name", result.name)
                    DBEngine.Update(result)
            result.__server_fix = server_fix
        Log.Write("LoadUserData", userid, result.id, result.__server_fix)
        result.createtime_utc = ConvertToUTCSeconds(result.createtime)
        return result
Пример #3
0
 def On(rid, sock):
     '''
     在线
     :param rid: 角色rid
     :param sock: sockfileno
     :return:
     '''
     if not rid:
         return
     log = t_log_onoffline()
     log.rid = rid
     log.sock = sock
     DBEngine.Add(log)
Пример #4
0
 def Update(uid, uuid, server=None):
     Log.Write("t_session", uid, uuid)
     with session_scope() as session:
         result = session.query(t_session).filter(t_session.uid == uid).first()
         if result is None:
             result = t_session()
             result.uid = uid
             result.uuid = uuid
             result.server = server
             DBEngine.Add(result)
         else:
             result.uuid = uuid
             result.server = server
             DBEngine.Update(result)
Пример #5
0
 def UpdateVersion(section, ctype, version):
     with session_scope() as session:
         configFile = session.query(t_section_config).filter(
             t_section_config.section == section).filter(
                 t_section_config.ctype == ctype).first()
         if configFile != None:
             configFile.version = version  # 更新配置的版本
             DBEngine.Update(configFile)
         else:
             configFile = t_section_config()  # 添加新的配置
             configFile.section = section
             configFile.ctype = ctype
             configFile.version = version
             DBEngine.Add(configFile)
         return configFile
Пример #6
0
 def setSection(section):
     """
     设置分区
     :param section: 分区号|数字
     """
     GameConfigManager._section = section
     if not GameConfigManager._ktv.has_key("section"):  # 初始化分区
         ktv = t_ktv()
         ktv.key = "section"
         ktv.type = "int"
         ktv.value = str(section)
         GameConfigManager._ktv["section"] = ktv
         DBEngine.Add(GameConfigManager._ktv["section"])
     else:
         if int(GameConfigManager._ktv["section"].value) != int(section):
             GameConfigManager._ktv["section"].value = str(
                 section)  # 缓存跟数据库数据做映射
             DBEngine.Update(GameConfigManager._ktv["section"])  # 更新数据的数据
Пример #7
0
 def Now(c, u):
     nowLogConnections = t_log_connections()
     nowLogConnections.t = GameData.sysTickTime
     nowLogConnections.c = c
     nowLogConnections.u = u
     DBEngine.Add(nowLogConnections)