コード例 #1
0
ファイル: login.py プロジェクト: hw233/lolita_son
def loginToServer_275(key, dynamicId, request_proto):
    argument = netutil.c2s_buf2data("C2S_LOGIN", request_proto)
    username = argument['account']
    password = argument['pwd']
    log.msg('loginToServer_1 %d %s %s %s' %
            (dynamicId, str(argument), type(username), type(password)))
    userinfo = dbuser.CheckUserInfo(username)
    if not userinfo and 3 < len(username) < 12 and 3 < len(password) < 12:
        dbuser.creatUserInfo(username, password, helper.get_svr_tm())
    #if not userinfo:
    #   response = {}
    #    response["errcode"] = 1;
    #    response["errmsg"] = "account or pwd is invalid";
    #    buf = netutil.s2c_data2buf("S2C_LOGIN",response)
    #    GlobalObject().root.callChild("net","pushObject",ProtocolDesc.S2C_LOGIN,buf, [dynamicId]);
    #    return
    oldUser = UsersManager().getUserByUsername(username)
    u = oldUser
    if oldUser:
        log.msg('loginToServer_1 relogin %d %s %s' %
                (dynamicId, str(oldUser.dynamicId), username))
        if oldUser.dynamicId != dynamicId:
            response = {}
            buf = netutil.s2c_data2buf("S2C_LOGIN_RELOGIN", response)
            GlobalObject().root.callChild("net", "pushObject",
                                          ProtocolDesc.S2C_LOGIN_RELOGIN, buf,
                                          [dynamicId])
            GlobalObject().root.callChild("net", "loseConnect",
                                          oldUser.dynamicId)

            GlobalObject().root.callChild("chat", 10, dynamicId, u.characterId)
            GlobalObject().root.callChild("combat", 10, dynamicId,
                                          u.characterId)
            ####
            scene = u.getSceneNode()
            if scene:
                GlobalObject().root.callChild(scene, 10, dynamicId,
                                              u.characterId)

            node = u.getNode()
            if node:
                GlobalObject().root.callChild(node, 10, dynamicId,
                                              u.characterId)
            ####

        oldUser.dynamicId = dynamicId
        response = {}
        response["flag"] = 1
        buf = netutil.s2c_data2buf("S2C_LOGIN_OK", response)
        GlobalObject().root.callChild("net", "pushObject",
                                      ProtocolDesc.S2C_LOGIN_OK, buf,
                                      [dynamicId])
    else:
        u = User(username, password, dynamicId)
        if not u.CheckEffective():
            response = {}
            response["errcode"] = 2
            response["errmsg"] = "account is banned"
            buf = netutil.s2c_data2buf("S2C_LOGIN", response)
            GlobalObject().root.callChild("net", "pushObject",
                                          ProtocolDesc.S2C_LOGIN, buf,
                                          [dynamicId])
            return
        log.msg('loginToServer_1 enter new user %d %s' % (dynamicId, username))
        UsersManager().addUser(u)
        response = {}
        response["flag"] = 0
        buf = netutil.s2c_data2buf("S2C_LOGIN_OK", response)
        GlobalObject().root.callChild("net", "pushObject",
                                      ProtocolDesc.S2C_LOGIN_OK, buf,
                                      [dynamicId])
        if u.characterId == 0:
            u.creatNewCharacter("character_%d" % (u.id), 0, 101,
                                helper.get_svr_tm(), 1003, 10, 10)
        else:
            u.getCharacterInfo()
    u.loginOutCharacter()
    response = {}
    roleinfo = {
        "rid": u.characterId,
        "shape": u.shape,
        "cls": 0,
        "grade": 0,
        "desc": "",
        "flag": 0,
        "newtm": 0,
        "theme": 0,
        "name": u.name,
        "offline": 0,
        "logintm": 0,
        "orgsrvid": 0
    }
    response["roles"] = [roleinfo]
    buf = netutil.s2c_data2buf("S2C_LOGIN_ROLEINFO", response)
    GlobalObject().root.callChild("net", "pushObject",
                                  ProtocolDesc.S2C_LOGIN_ROLEINFO, buf,
                                  [dynamicId])
    return