Esempio n. 1
0
Parameter::Parameter(Node *node, const ParameterName& name, const ParameterType& type, Channel channels, ParameterDirection direction)
     : m_node(node),
       m_name(name),
       m_verboseName(""),
       m_type(type),
       m_direction(direction),
       m_connection(0),
       m_channelCount(channels),
       m_channels(new Value[channels])
{
    if (validName(name)) {
        m_name = name;
    } else {
        throw InvalidName();
    }
    
    if (channels <= 0) {
        throw InvalidName();
    }
    
    for (Channel i=0; i<m_channelCount;++i) {        
        if (m_type == kInt) {
            m_channels[i].i = 0;
        } else if (m_type == kFloat) {
            m_channels[i].f = 0;
        } else if (m_type == kString) {
            m_channels[i].s = new std::string;
        } else {
            m_channels[i].d = 0;
        }
    }
}
Esempio n. 2
0
void connect_bang(t_connect *x)
{
	int i, j;
 
	x->f_inc = 0;
	
	if (x->f_nbSelected > 0) 
	{
		for (i = 0; i < x->f_nbSelected; i++) 
		{	
			if(validName(x->f_object[i]))
			{
				x->f_object[x->f_inc++] = x->f_object[i];
			}
			
		}
		
		for(i = 1; i < x->f_inc; i++)
		{
			if (object_classname(jbox_get_object(x->f_object[i -1])) == gensym("hoa.decoder~") || object_classname(jbox_get_object(x->f_object[i -1])) == gensym("hoa.projector~"))
			{
				for(j = 0; j < x->f_output; j++)
				{
					connect_connect(x->f_patcher, x->f_object[i -1], j, x->f_object[i], j);
				}
			}
			else if (object_classname(jbox_get_object(x->f_object[i -1])) == gensym("jpatcher"))
			{
				for(j = 0; j < x->f_harmonics; j++)
				{
					connect_connect(x->f_patcher, x->f_object[i -1], j, x->f_object[i], j);
				}
			}
			else
			{
				for(j = 0; j < x->f_harmonics; j++)
				{
					connect_connect(x->f_patcher, x->f_object[i -1], j, x->f_object[i], j);
				}
			}
			
		}
		
		for(i  = 0; i < CONNECT_MAX_TAB; i++)
			x->f_object[i] = NULL;
		
		jpatcher_set_dirty(x->f_patcherview, true);
	}
	
	x->f_nbSelected = 0;
	
	color_patchline(x);
}
Esempio n. 3
0
MObject HesperisTransformCreator::create(BaseTransform * data, MObject & parentObj,
                       const std::string & nodeName)
{
    MObject otm = MObject::kNullObj;
    if(!HesperisIO::FindNamedChild(otm, nodeName, parentObj)) {
        MFnTransform ftransform;
        otm = ftransform.create(parentObj);

        std::string validName(nodeName);
        SHelper::noColon(validName);
        ftransform.setName(validName.c_str()); 
    }
    // MGlobal::displayInfo(MString("todo transform in ")+nodeName.c_str()); 
    return otm;
}
Esempio n. 4
0
int du_file(const char * pathname)
{
  struct stat st;
  struct dirent* stdir;
  char current [PATH_MAX+1];
  int size;/*count dir size*/
  DIR * dir;
  
  /*Check if the st is init*/
  assert(lstat(pathname, &st) == 0);

  /*if it is a regular file, return the size (using the opt)*/
  if(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode) ){
    return opt_apparent_size ? st.st_size : st.st_blocks;
  }
  
  /*If is a directory*/
  if(S_ISDIR(st.st_mode)){
    /*Open directory*/
    dir = opendir(pathname);
    /*add the directory size (unsing the opt)*/
    size = opt_apparent_size ? st.st_size : st.st_blocks ;
    
    while( (stdir = readdir(dir)) != NULL ){
      /*if the directory is the same or the parent ignore*/
      if(!validName(stdir->d_name)){
	continue;
      }
      /*add the path of the current dir to the given path*/
      snprintf(current,PATH_MAX,"%s/%s",pathname, stdir->d_name);
      size+= du_file(current);  
    }
    closedir(dir);
    return size;
  }

  /*4 autres type possibles*/
  printf("Warning the pathname were ignored because the type of file is not treated");
  return 0;
    
}
Esempio n. 5
0
File: Case4.c Progetto: baducki/me
int insertName(int line, int row, char *name, int menu)
{
	int valid;
	char temp[1000];
	gotoxy(line, row);
	gets(temp);

	valid = validName(temp, 2);
	if (valid != -1){
		valid = inputInfoYesOrNo(menu);
		if (valid == 0){
			strcpy(name, temp);
			return 0;
		}
		else if (valid == -1) return -2;
		gotoxy(0, 16); lineClear();
		gotoxy(0, 17); lineClear();
		gotoxy(0, 18); lineClear();
		gotoxy(0, 26); lineClear();
		gotoxy(0, 28); lineClear();
	}
	return valid;
}
Esempio n. 6
0
inline bool validName(const std::string& name)
{
	return validName(name.c_str(), name.size());
}
Esempio n. 7
0
//-------------------------------------------------------------------------------------
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;
}
Esempio n. 8
0
void WorkerThread::runUnzip() {
	emit(beginRunUnzip());
	emit(stageEvent("Extracting and merging game data"));
	
	emit(infoEvent("Unzipping original game files"));
	CZipArchive zip;
	try {
	    zip.Open(m_gameFileName.toStdString().c_str(), CZipArchive::zipOpenReadOnly);
		
		ZIP_SIZE_TYPE totalSize = 0;
		for(ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
			totalSize += zip.GetFileInfo(i)->m_uUncomprSize; // uncompressed size
			QString name = QString::fromUtf8(zip.GetFileInfo(i)->GetFileName());
			if(!validName(name)) {
				emit(errorEvent("Game pack contains illegal file names (e.g. " + name + ")"));
				emit(infoEvent("A near future release of WHDRun will fix this problem, sorry for the inconvenience"));
				m_die = true;
				return;
			}
		}
		emit(unzipTotalSize(totalSize));

		ZIP_SIZE_TYPE progress = 0;
		for(ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
			progress += zip.GetFileInfo(i)->m_uUncomprSize;
			zip.ExtractFile(i, m_tempPath.toUtf8());
			emit(unzipProgress(progress));
		}

	    zip.Close();
    } catch(CZipException ex) {
		zip.Close(CZipArchive::afAfterException);
		emit(errorEvent(QString("Error while unzipping: %1").arg((LPCTSTR)ex.GetErrorDescription())));
		m_die = true; // no need to rezip
		return;
	}

	emit(infoEvent("Collecting checksums of unmodified files"));
	emit(beginCollect());
	m_checksums.clear();
	collectFiles(m_tempPath, &m_checksums); // TODO: progress for this? (should always be quick)
	
	QString gameFileBase = QFileInfo(m_gameFileName).baseName();
	QString diffFileName = m_dataPath + "/" + gameFileBase + __WHDRun__DiffSuffix;
	if(QFileInfo(diffFileName).exists()) {
		emit(infoEvent("Merging original game files with previously modified files"));
		CZipArchive zip;
		try {
		    zip.Open(diffFileName.toUtf8(), CZipArchive::zipOpenReadOnly);

			//TODO: progress infoEvent for this? (should always be quick)
			for (ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
				zip.ExtractFile(i, m_tempPath.toUtf8());
			}

		    zip.Close();
	    } catch(CZipException ex) {
			zip.Close(CZipArchive::afAfterException);
			emit(errorEvent(QString("Error while unzipping changes: %1").arg((LPCTSTR)ex.GetErrorDescription())));
			m_die = true; // no need to rezip
			return;
		}
	}
	
	emit(endRunUnzip());
}
Esempio n. 9
0
//-------------------------------------------------------------------------------------
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;
}
Esempio n. 10
0
//-------------------------------------------------------------------------------------
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;
}