Ejemplo n.º 1
0
def processCreateRoleReq(session, msg):
    print('CreateRoleReq', msg)
    if msg.gender != Base.Gender.MALE and msg.gender != Base.Gender.FEMAIL:
        msg.gender = Base.Gender.MALE
    roleTmp = PlayerModel.Role()
    roleTmp.uid = idtool.allocUid()
    if session.isWebDebug:
        msg.name = msg.name.encode('utf-8')
    roleTmp.name = msg.name
    roleTmp.job = msg.job
    roleTmp.gender = msg.gender
    if roleTmp.gender != Base.Gender.MALE and roleTmp.gender != Base.Gender.FEMAIL:
        roleTmp.gender = Base.Gender.MALE

    if roleTmp.job < Base.Job.ZHANSHI or roleTmp.job > Base.Job.YOUXIA:
        roleTmp.job = Base.Job.ZHANSHI

    def callback(db):
        retMsg = MsgDef.CreateRoleRet()
        if db.isOk():
            retMsg.flag = True
            retMsg.uid = roleTmp.uid
            session.user.addRole(roleTmp)
        else:
            retMsg.flag = False
            retMsg.errMsg = '角色名已经存在'
        session.sendMsg(MsgDef.ServerCmd.CREATE_ROLE_RET, retMsg)
        MailModel.createMailRecrodAtFirstTime(roleTmp.uid)
        # 新增每日活动记录
        DbService.getPlayerService().createDailyLoginAct(
            session.user.accountid)
        if retMsg.flag == True:
            # 创角(old)-记录log
            LogModel.logLoginData(session.user.accountid, roleTmp.uid,
                                  roleTmp.name,
                                  LogModel.LoginOpType.CREATE_PLAYER, 0)

    mapName = 10001
    x = 27
    y = 188
    mapObj = MapMgr.getMapMgr().allocMap(mapName)
    if mapObj.cfg.reviveMap != None:
        mapName = mapObj.cfg.reviveMap.mapname
        x = mapObj.cfg.reviveMap.x
        y = mapObj.cfg.reviveMap.y

    DbService.getPlayerService().createRole(session.user, roleTmp, mapName, x,
                                            y, callback)
    return
Ejemplo n.º 2
0
    def callback(db):
        session.user = PlayerModel.User()
        session.user.username = msg.username
        reconnectUid = msg.reconnectUid
        retRole = []
        if db.result:
            accountId = long(db.result[0][0])

            def funcToClose(sessOther):
                if sessOther.user.accountid == accountId:
                    ffext.warn('check relogin accountId=%d, name=%s' %
                               (accountId, sessOther.user.username))
                    #if reconnectUid:
                    #    session.sendMsg(MsgDef.ServerCmd.ERROR_MSG, buildErrMsg(MsgDef.ClientCmd.LOGIN, Base.lang('账号在其他地方登录')))
                    #else:
                    #    sessOther.close()
                    # 登出-记录log
                    LogModel.logLoginData(accountId, 0, '',
                                          LogModel.LoginOpType.LOGOUT,
                                          LogModel.LoginReason.KICKOUT)
                    sessOther.sendMsg(MsgDef.ServerCmd.RELOGIN,
                                      MsgDef.ReLoginRet())

                    def cbClose():
                        sessOther.close()

                    ffext.timer(500, cbClose)
                    return True

            ffext.getSessionMgr().foreach_until(funcToClose)
            session.user.accountid = accountId
        else:
            session.user.accountid = idtool.allocUid()

            def cbNewUser(retNew):
                accountId = long(retNew.result[0][0])
                session.user.accountid = accountId
                ffext.dump('cbNewUser', retNew, accountId)
                # 登录(new)-记录log
                LogModel.logLoginData(accountId, 0, '',
                                      LogModel.LoginOpType.LOGIN_ACCOUNT,
                                      LogModel.LoginReason.NEW_LOGIN)
                return

            DbService.getPlayerService().createUser(msg.username, cbNewUser)
        ffext.dump('load player', db.result)
        for row in db.result:
            roleTmp = PlayerModel.Role(row)
            session.user.addRole(roleTmp)
            tmpRoleMsg = MsgDef.RoleInfo(roleTmp.uid, roleTmp.name,
                                         roleTmp.job, roleTmp.gender,
                                         roleTmp.level, roleTmp.exp)
            retRole.append(tmpRoleMsg)
        #print(session.user.accountid, session.user.username)
        ffext.checkWebDebug(session, msg, MsgDef)
        retMsg = MsgDef.UserInfoRet(ffext.getTime(), retRole)
        if reconnectUid:  #重连
            processSelectRoleReq(session, MsgDef.SelectRoleReq(reconnectUid),
                                 msg.x, msg.y)
        else:
            session.sendMsg(MsgDef.ServerCmd.USER_INFO, retMsg)
        # 登录(old)-记录log-(TODO:ip,geo信息获取接口暂缺)
        LogModel.logLoginData(session.user.accountid, 0, '',
                              LogModel.LoginOpType.LOGIN_ACCOUNT,
                              LogModel.LoginReason.OLD_LOGIN)