//------------------------------------------------------------------------------------- bool Loginapp::_createAccount(Network::Channel* pChannel, std::string& accountName, std::string& password, std::string& datas, ACCOUNT_TYPE type) { AUTO_SCOPED_PROFILE("createAccount"); ACCOUNT_TYPE oldType = type; if(!g_kbeSrvConfig.getDBMgr().account_registration_enable) { WARNING_MSG(fmt::format("Loginapp::_createAccount({}): not available!\n", accountName)); std::string retdatas = ""; Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_ACCOUNT_REGISTER_NOT_AVAILABLE; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } accountName = KBEngine::strutil::kbe_trim(accountName); password = KBEngine::strutil::kbe_trim(password); if(accountName.size() > ACCOUNT_NAME_MAX_LENGTH) { ERROR_MSG(fmt::format("Loginapp::_createAccount: accountName too big, size={}, limit={}.\n", accountName.size(), ACCOUNT_NAME_MAX_LENGTH)); return false; } if(password.size() > ACCOUNT_PASSWD_MAX_LENGTH) { ERROR_MSG(fmt::format("Loginapp::_createAccount: password too big, size={}, limit={}.\n", password.size(), ACCOUNT_PASSWD_MAX_LENGTH)); return false; } if(datas.size() > ACCOUNT_DATA_MAX_LENGTH) { ERROR_MSG(fmt::format("Loginapp::_createAccount: bindatas too big, size={}, limit={}.\n", datas.size(), ACCOUNT_DATA_MAX_LENGTH)); return false; } std::string retdatas = ""; if(shuttingdown_ != SHUTDOWN_STATE_STOP) { WARNING_MSG(fmt::format("Loginapp::_createAccount: shutting down, create {} failed!\n", accountName)); Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_IN_SHUTTINGDOWN; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.find(const_cast<std::string&>(accountName)); if(ptinfos != NULL) { WARNING_MSG(fmt::format("Loginapp::_createAccount: pendingCreateMgr has {}, request create failed!\n", accountName)); Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_BUSY; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } if(type == ACCOUNT_TYPE_SMART) { if (email_isvalid(accountName.c_str())) { type = ACCOUNT_TYPE_MAIL; } else { if(!validName(accountName)) { ERROR_MSG(fmt::format("Loginapp::_createAccount: invalid accountName({})\n", accountName)); Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } type = ACCOUNT_TYPE_NORMAL; } } else if(type == ACCOUNT_TYPE_NORMAL) { if(!validName(accountName)) { ERROR_MSG(fmt::format("Loginapp::_createAccount: invalid accountName({})\n", accountName)); Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } } else if (!email_isvalid(accountName.c_str())) { /* std::string user_name, domain_name; user_name = regex_replace(accountName, _g_mail_pattern, std::string("$1") ); domain_name = regex_replace(accountName, _g_mail_pattern, std::string("$2") ); */ WARNING_MSG(fmt::format("Loginapp::_createAccount: invalid mail={}\n", accountName)); Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME_MAIL; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } DEBUG_MSG(fmt::format("Loginapp::_createAccount: accountName={}, passwordsize={}, type={}, oldType={}.\n", accountName.c_str(), password.size(), type, oldType)); ptinfos = new PendingLoginMgr::PLInfos; ptinfos->accountName = accountName; ptinfos->password = password; ptinfos->datas = datas; ptinfos->addr = pChannel->addr(); pendingCreateMgr_.add(ptinfos); Components::COMPONENTS& cts = Components::getSingleton().getComponents(DBMGR_TYPE); Components::ComponentInfos* dbmgrinfos = NULL; if(cts.size() > 0) dbmgrinfos = &(*cts.begin()); if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0) { ERROR_MSG(fmt::format("Loginapp::_createAccount: create({}), not found dbmgr!\n", accountName)); Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_SRV_NO_READY; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } pChannel->extra(accountName); Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(DbmgrInterface::reqCreateAccount); uint8 uatype = uint8(type); (*pBundle) << accountName << password << uatype; (*pBundle).appendBlob(datas); dbmgrinfos->pChannel->send(pBundle); return true; }
//------------------------------------------------------------------------------------- bool Loginapp::_createAccount(Network::Channel* pChannel, std::string& accountName, std::string& password, std::string& datas, ACCOUNT_TYPE type) { AUTO_SCOPED_PROFILE("createAccount"); ACCOUNT_TYPE oldType = type; if(!g_kbeSrvConfig.getDBMgr().account_registration_enable) { WARNING_MSG(fmt::format("Loginapp::_createAccount({}): not available!\n", accountName)); std::string retdatas = ""; Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_ACCOUNT_REGISTER_NOT_AVAILABLE; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } accountName = KBEngine::strutil::kbe_trim(accountName); password = KBEngine::strutil::kbe_trim(password); if(accountName.size() > ACCOUNT_NAME_MAX_LENGTH) { ERROR_MSG(fmt::format("Loginapp::_createAccount: accountName too big, size={}, limit={}.\n", accountName.size(), ACCOUNT_NAME_MAX_LENGTH)); return false; } if(password.size() > ACCOUNT_PASSWD_MAX_LENGTH) { ERROR_MSG(fmt::format("Loginapp::_createAccount: password too big, size={}, limit={}.\n", password.size(), ACCOUNT_PASSWD_MAX_LENGTH)); return false; } if(datas.size() > ACCOUNT_DATA_MAX_LENGTH) { ERROR_MSG(fmt::format("Loginapp::_createAccount: bindatas too big, size={}, limit={}.\n", datas.size(), ACCOUNT_DATA_MAX_LENGTH)); return false; } std::string retdatas = ""; if(shuttingdown_ != SHUTDOWN_STATE_STOP) { WARNING_MSG(fmt::format("Loginapp::_createAccount: shutting down, create {} failed!\n", accountName)); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_IN_SHUTTINGDOWN; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.find(const_cast<std::string&>(accountName)); if(ptinfos != NULL) { WARNING_MSG(fmt::format("Loginapp::_createAccount: pendingCreateMgr has {}, request create failed!\n", accountName)); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_BUSY; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } { // 把请求交由脚本处理 SERVER_ERROR_CODE retcode = SERVER_SUCCESS; SCOPED_PROFILE(SCRIPTCALL_PROFILE); PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), const_cast<char*>("onRequestCreateAccount"), const_cast<char*>("ssy#"), accountName.c_str(), password.c_str(), datas.c_str(), datas.length()); if(pyResult != NULL) { if(PySequence_Check(pyResult) && PySequence_Size(pyResult) == 4) { char* sname; char* spassword; char *extraDatas; Py_ssize_t extraDatas_size = 0; if(PyArg_ParseTuple(pyResult, "H|s|s|y#", &retcode, &sname, &spassword, &extraDatas, &extraDatas_size) == -1) { ERROR_MSG(fmt::format("Loginapp::_createAccount: {}.onReuqestLogin, Return value error! accountName={}\n", g_kbeSrvConfig.getLoginApp().entryScriptFile, accountName)); retcode = SERVER_ERR_OP_FAILED; } else { accountName = sname; password = spassword; if (extraDatas && extraDatas_size > 0) datas.assign(extraDatas, extraDatas_size); else SCRIPT_ERROR_CHECK(); } } else { ERROR_MSG(fmt::format("Loginapp::_createAccount: {}.onReuqestLogin, Return value error, must be errorcode or tuple! accountName={}\n", g_kbeSrvConfig.getLoginApp().entryScriptFile, accountName)); retcode = SERVER_ERR_OP_FAILED; } Py_DECREF(pyResult); } else { SCRIPT_ERROR_CHECK(); retcode = SERVER_ERR_OP_FAILED; } if(retcode != SERVER_SUCCESS) { Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } else { if(accountName.size() == 0) { ERROR_MSG(fmt::format("Loginapp::_createAccount: accountName is empty!\n")); retcode = SERVER_ERR_NAME; Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } } } if(type == ACCOUNT_TYPE_SMART) { if (email_isvalid(accountName.c_str())) { type = ACCOUNT_TYPE_MAIL; } else { if(!validName(accountName)) { ERROR_MSG(fmt::format("Loginapp::_createAccount: invalid accountName({})\n", accountName)); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } type = ACCOUNT_TYPE_NORMAL; } } else if(type == ACCOUNT_TYPE_NORMAL) { if(!validName(accountName)) { ERROR_MSG(fmt::format("Loginapp::_createAccount: invalid accountName({})\n", accountName)); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } } else if (!email_isvalid(accountName.c_str())) { /* std::string user_name, domain_name; user_name = regex_replace(accountName, _g_mail_pattern, std::string("$1") ); domain_name = regex_replace(accountName, _g_mail_pattern, std::string("$2") ); */ WARNING_MSG(fmt::format("Loginapp::_createAccount: invalid mail={}\n", accountName)); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME_MAIL; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } DEBUG_MSG(fmt::format("Loginapp::_createAccount: accountName={}, passwordsize={}, type={}, oldType={}.\n", accountName.c_str(), password.size(), type, oldType)); ptinfos = new PendingLoginMgr::PLInfos; ptinfos->accountName = accountName; ptinfos->password = password; ptinfos->datas = datas; ptinfos->addr = pChannel->addr(); pendingCreateMgr_.add(ptinfos); Components::COMPONENTS& cts = Components::getSingleton().getComponents(DBMGR_TYPE); Components::ComponentInfos* dbmgrinfos = NULL; if(cts.size() > 0) dbmgrinfos = &(*cts.begin()); if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0) { ERROR_MSG(fmt::format("Loginapp::_createAccount: create({}), not found dbmgr!\n", accountName)); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_SRV_NO_READY; (*pBundle) << retcode; (*pBundle).appendBlob(retdatas); pChannel->send(pBundle); return false; } pChannel->extra(accountName); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(DbmgrInterface::reqCreateAccount); uint8 uatype = uint8(type); (*pBundle) << accountName << password << uatype; (*pBundle).appendBlob(datas); dbmgrinfos->pChannel->send(pBundle); return true; }
//------------------------------------------------------------------------------------- bool Loginapp::_createAccount(Mercury::Channel* pChannel, std::string& accountName, std::string& password, std::string& datas, ACCOUNT_TYPE type) { accountName = KBEngine::strutil::kbe_trim(accountName); password = KBEngine::strutil::kbe_trim(password); if(accountName.size() > ACCOUNT_NAME_MAX_LENGTH) { ERROR_MSG(boost::format("Loginapp::_createAccount: accountName too big, size=%1%, limit=%2%.\n") % accountName.size() % ACCOUNT_NAME_MAX_LENGTH); return false; } if(password.size() > ACCOUNT_PASSWD_MAX_LENGTH) { ERROR_MSG(boost::format("Loginapp::_createAccount: password too big, size=%1%, limit=%2%.\n") % password.size() % ACCOUNT_PASSWD_MAX_LENGTH); return false; } if(datas.size() > ACCOUNT_DATA_MAX_LENGTH) { ERROR_MSG(boost::format("Loginapp::_createAccount: bindatas too big, size=%1%, limit=%2%.\n") % datas.size() % ACCOUNT_DATA_MAX_LENGTH); return false; } std::string retdatas = ""; if(shuttingdown_) { WARNING_MSG(boost::format("Loginapp::_createAccount: shutting down, create %1% failed!\n") % accountName); Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_SHUTTINGDOWN; bundle << retcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pChannel); return false; } PendingLoginMgr::PLInfos* ptinfos = pendingCreateMgr_.find(const_cast<std::string&>(accountName)); if(ptinfos != NULL) { WARNING_MSG(boost::format("Loginapp::_createAccount: pendingCreateMgr has %1%, request create failed!\n") % accountName); Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_BUSY; bundle << retcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pChannel); return false; } if(type == ACCOUNT_TYPE_SMART) { if (email_isvalid(accountName.c_str())) { type = ACCOUNT_TYPE_MAIL; } else { if(!validName(accountName)) { ERROR_MSG(boost::format("Loginapp::_createAccount: invalid accountName(%1%)\n") % accountName); Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME; bundle << retcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pChannel); return false; } type = ACCOUNT_TYPE_NORMAL; } } else if(type == ACCOUNT_TYPE_NORMAL) { if(!validName(accountName)) { ERROR_MSG(boost::format("Loginapp::_createAccount: invalid accountName(%1%)\n") % accountName); Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME; bundle << retcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pChannel); return false; } } else if (!email_isvalid(accountName.c_str())) { /* std::string user_name, domain_name; user_name = regex_replace(accountName, _g_mail_pattern, std::string("$1") ); domain_name = regex_replace(accountName, _g_mail_pattern, std::string("$2") ); */ WARNING_MSG(boost::format("Loginapp::_createAccount: invalid mail=%1%\n") % accountName); Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_NAME_MAIL; bundle << retcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pChannel); return false; } DEBUG_MSG(boost::format("Loginapp::_createAccount: accountName=%1%, passwordsize=%2%, type=%3%.\n") % accountName.c_str() % password.size() % type); ptinfos = new PendingLoginMgr::PLInfos; ptinfos->accountName = accountName; ptinfos->password = password; ptinfos->datas = datas; ptinfos->addr = pChannel->addr(); pendingCreateMgr_.add(ptinfos); Components::COMPONENTS& cts = Components::getSingleton().getComponents(DBMGR_TYPE); Components::ComponentInfos* dbmgrinfos = NULL; if(cts.size() > 0) dbmgrinfos = &(*cts.begin()); if(dbmgrinfos == NULL || dbmgrinfos->pChannel == NULL || dbmgrinfos->cid == 0) { ERROR_MSG(boost::format("Loginapp::_createAccount: create(%1%), not found dbmgr!\n") % accountName); Mercury::Bundle bundle; bundle.newMessage(ClientInterface::onCreateAccountResult); SERVER_ERROR_CODE retcode = SERVER_ERR_SRV_NO_READY; bundle << retcode; bundle.appendBlob(retdatas); bundle.send(this->getNetworkInterface(), pChannel); return false; } pChannel->extra(accountName); Mercury::Bundle bundle; bundle.newMessage(DbmgrInterface::reqCreateAccount); uint8 uatype = uint8(type); bundle << accountName << password << uatype; bundle.appendBlob(datas); bundle.send(this->getNetworkInterface(), dbmgrinfos->pChannel); return true; }