Example #1
0
void ApoClient::_closeConnect()
{
	if (m_pconn) {
		nd_logmsg("net colsed error = %d\n", m_pconn->LastError());
		m_pconn->Close(0);
	}
}
Example #2
0
/* if server program received a signal
 * it will run here
 * so I can do some to handle error
 */
void _terminate_server(int signo)
{
	char *msg = get_signal_desc(signo);

	nd_logmsg("sigaction() -> _terminate_server() received signed %s server exit\n",msg);

	nd_instance_exit(0) ;
}
Example #3
0
int NDReportHook(int nRptType, char *szMsg,int  *retVal)
{
	char *RptTypes[] = { "Warning", "Error", "Assert" };
	if ( ( nRptType > 0 ) || ( strstr( szMsg, "HEAP CORRUPTION DETECTED" ) ) )
		nd_logmsg("%s: %s" AND RptTypes[nRptType] AND szMsg );

	retVal = 0;
	return 1;         // Allow the report to be made as usual
}
Example #4
0
void apoCli_Logout()
{
	ApoClient *apoCli = ApoClient::getInstant();
	if (apoCli)	{
		apoCli->Logout();
	}
	
	nd_logmsg("account logout\n") ;
}
Example #5
0
void ApoClient::Close()
{
	if (m_pconn)	{
		nd_logmsg(" apoClient::close() net colsed error = %d\n", m_pconn->LastError());
		m_pconn->Close(0);
	}
	DestroyConnectorObj(m_pconn);
	m_pconn = 0;
}
Example #6
0
RESULT_T apoCli_ReloginEx(const char *sessionData, int sessionSize, bool bReloginOffline)
{
	nd_logmsg("Begining to relogin!!!!!\n");
	ApoClient *apoCli = ApoClient::getInstant();
	if (!apoCli)	{
		nd_logerror("net client instant not init\n");
		return NDSYS_ERR_NOT_INIT;
	}
	if(!sessionData || sessionSize == 0) {
		nd_logerror("can not relogin , input session data is NULL \n");
		return  NDSYS_ERR_PARAM_NUMBER_ZERO ;
	}
	return apoCli->ReloginEx((void*)sessionData,sessionSize,bReloginOffline);
}
Example #7
0
bool ApoClient::openSendStreamLog()
{
	const char *pFielName = "./apoGameNetStream.data";
	int length = strlen(pFielName);
	if (m_pconn->ioctl(NDIOCTL_LOG_SEND_STRAM_FILE, (void*)pFielName, &length) == -1){
		nd_logmsg("log net message bin-data errror\n");
		return false;
	}
	else {
		//const char *p = nd_getcwd();
		//nd_logmsg("out put net stream file %s/apoGameNetStream.data\n", p);
		return true;
	}
	
}
Example #8
0
int apoCli_init(const char *workingPath, const char *logPath, const char *udid, const char *devDesc)
{
	LoginApollo::SetDeviceInfo(udid, devDesc);
	ApoClient *pInstant = ApoClient::getInstant();
	nd_logmsg("net Initilized!\n");
	if (pInstant) {
#ifdef __ND_WIN__

		char tmpBuf[1024];
		pInstant->setWorkingPath(nd_utf8_to_ndcode(workingPath, tmpBuf, sizeof(tmpBuf)));
		pInstant->setLogPath(nd_utf8_to_ndcode(logPath, tmpBuf, sizeof(tmpBuf)));
#else 
		pInstant->setWorkingPath(workingPath);
		pInstant->setLogPath(logPath);

#endif 
		return 1;
	}
	return 0;
}
Example #9
0
//return error code
int _call_message_func(struct nd_msgentry_root *root,struct nd_msg_entry_node * node, nd_usermsgbuf_t*msg, nd_netui_handle connector)
{
	int ret = 0 ;
	if (!node || !node->entry) {
		if (root->def_entry){
			ret = root->def_entry(connector->msg_caller, msg);
		}
		else{
			nd_logmsg("received message (%d,%d) UNHANDLED\n" AND msg->msg_hdr.maxid AND msg->msg_hdr.minid);
			return NDERR_UNHANDLED_MSG ;
		}
	}
	else {
		if (!node->is_script){
			ret = node->entry(connector->msg_caller, msg);
		}
		else {
			ret = root->script_entry(root->script_engine, connector->msg_caller, msg, (const char*)node->entry);
		}
	}
	return ret==-1? NDERR_USER : 0 ;
}
Example #10
0
RESULT_T ApoClient::_connectHost(const char *host, int port)
{
	if (!host || !*host){
		nd_logerror("connect to host error, input host name is NULL\n");
		return NDSYS_ERR_INVALID_INPUT;
	}	
	CHECK_CONN_VALID(m_pconn) ;
	
	if (-1 == m_pconn->Open(host, port, "tcp-connector")){
		return (RESULT_T)NDSYS_ERR_HOST_UNAVAILABLE;
	}


	int level = ndGetTimeoutVal();
	int size = sizeof(int);
	m_pconn->ioctl(NDIOCTL_SET_TIMEOUT, &level, &size);
		
	if (m_login) {
		delete m_login;
		m_login = 0;
	}
	
	if (m_sessionFile.empty()){
		m_login = new LoginApollo(m_pconn->GetHandle(),  NULL);
	}
	else {
		m_login = new LoginApollo(m_pconn->GetHandle(), m_sessionFile.c_str());
	}
	nd_assert(m_login);
	
	if (-1 == m_login->TrytoGetCryptKey()) {
		return (RESULT_T) NDERR_VERSION;
	}
	m_runningUpdate = ERUN_UP_NORMAL;
	onInit();
	nd_logmsg("connect host:%s port:%d ok\n", host, port);
	return ESERVER_ERR_SUCCESS;
}
Example #11
0
int nd_net_init(void)
{
#if !defined(ND_UNIX) 
	{
		WORD wVersionRequested = MAKEWORD(2,2);
		
		WSADATA wsaData;

 		HRESULT nRet = WSAStartup(wVersionRequested, &wsaData);

		if (0!=nRet || wsaData.wVersion != wVersionRequested)
		{	
			WSACleanup();
			return -1;
		}
	}
#else 
#endif
	
	register_connector() ;
	nd_logmsg("nd_net_init success \n") ;
	return 0 ;
}
Example #12
0
int NDInstanceBase::Create(int argc,const char *argv[])
{
	int i ;
	const char *logfileName = NULL ;
	if (m_bCreated)	{
		return 0;
	}

    system_signals_init() ;
    
	nd_arg(argc, argv);	
	
	//get config file 	
	for (i=1; i<argc; i++){
		if(0 == strcmp(argv[i],"-f" ) && i< argc-1) {
			NDInstanceBase::config_file = argv[++i] ;
		}
		else if(0== strcmp(argv[i], "-c") && i< argc-1) {
			m_config_name = argv[++i] ;
		}
		else if(0==strcmp(argv[i],"-nodev")) {
			m_un_develop = 1;
		}
		
		else if(0==strcmp(argv[i],"-log") && i<argc -1) {
			logfileName = argv[++i];
		}
		else if(0==strcmp(argv[i],"-workdir") &&i<argc -1 ) {
			nd_chdir(argv[++i]) ;
		}
		else if(0==strcmp(argv[i],"-v") || 0==strcmp(argv[i],"--version") ) {
			fprintf(stdout, "version : %s \n" , __g_version_desc) ;
			exit(0) ;
		}
		else if(0==strcmp(argv[i],"-l") || 0==strcmp(argv[i],"--rlimit") ) {
			char buf[1024] ;
			fprintf(stdout, "rlimit: \n %s\n" , get_rlimit_info(buf, sizeof(buf)) ) ;
			exit(0) ;
		}

        else if(0==strcmp(argv[i],"-pid") && i<argc -1){
            FILE *pf = fopen(argv[i+1], "w") ;
            if (pf) {
                fprintf(pf, "%d", nd_processid()) ;
                fclose(pf) ;
            }
            else {
                fprintf(stderr,"write pid error %s file not exist\n", argv[i+1]) ;
                exit(1) ;
            }
        }
	}

	if(!config_file|| !m_config_name) {
		printf("usage: -f config-file -c config-name\n press ANY key to continue\n") ;
		//getch() ;
		exit(1) ;
		//return -1 ;
	}

	if(-1==ReadConfig(m_config_name) ) {
		printf("Read config %s file error \n press ANY key to continue\n", m_config_name) ;
		//getch() ;
		exit(1) ;
	}
	
	nd_set_exit_callback(applib_exit_callback) ;

	if (m_config.i_cfg.open_dump){
#ifndef ND_UNIX
		::SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)nd_unhandler_except);
#else
		enable_core_dump() ;
#endif
	}
	size_t max_connector = m_config.l_cfg.max_connect ;
	if ( max_connector > get_maxopen_fd() ) {
		size_t new_fd_num = set_maxopen_fd(max_connector) ;
		nd_logmsg("set max connect %d real max connect =%d\n",m_config.l_cfg.max_connect, (int) new_fd_num);
	}
	
	if(logfileName && logfileName[0]) {
		strncpy(m_config.i_cfg.log_file, logfileName, sizeof(m_config.i_cfg.log_file)) ;
	}
	if (m_config.i_cfg.log_file[0]){
		set_log_file(m_config.i_cfg.log_file) ;
		if (m_config.i_cfg.log_file_size > 0) {
			nd_setlog_maxsize(m_config.i_cfg.log_file_size) ;
		}
		nd_setlog_func(nd_default_filelog) ;
	}

	if (m_config.i_cfg.callstack_file[0]){
		if(CALLSTACK_INIT(m_config.i_cfg.callstack_file)==-1) {
			nd_logfatal("create map file %s error!\n" AND m_config.i_cfg.callstack_file) ;
			return -1 ;
		}
	}

	nd_net_set_crypt((nd_netcrypt)nd_TEAencrypt, (nd_netcrypt)nd_TEAdecrypt, sizeof(tea_v)) ;
	
// 	if (g_base_inst==NULL){
// 		g_base_inst = this ;
// 	}

	OnCreate();

	m_bCreated = 1;
	return 0 ;

}
Example #13
0
void apoCli_destroy()
{
	ApoClient::destroyInstant();
	nd_logmsg("net Destroyed!\n");
}
Example #14
0
//#include <QProcess>
bool startDialog::expExcel()
{
    WriteLog("==============Begin export excel===============");

    DBLDatabase::destroy_Instant();
	const char *exp_cmd = _getFromIocfg("game_data_export_cmd");
	
	std::string stdstr_excel_path = _getFromIocfg("excel_data_in_path");
	std::string stdstr_text_path = _getFromIocfg("text_data_out_path");
	std::string stdstr_package_file = _getFromIocfg("game_data_package_file");
	std::string stdstr_excel_list = _getFromIocfg("game_data_listfile");

	const char *excel_path = stdstr_excel_path.c_str();
	const char *text_path = stdstr_text_path.c_str();
	const char *package_file = stdstr_package_file.c_str();
	const char *excel_list = stdstr_excel_list.c_str(); 

    char exp_cmdbuf[1024];

	if (!exp_cmd || !excel_path || !text_path || !package_file){
		WriteLog("export excel error : on read config file\n");
		return false;
	}

	WorkingPathSwitchHelper __pathHelper(m_projectPath.c_str());


	const char *encodeName = getGameDateEncodeType();
	const char *inputCode = encodeName;
#ifdef WIN32
	snprintf(exp_cmdbuf, sizeof(exp_cmdbuf), " %s %s %s %s %s ", exp_cmd, excel_list, excel_path, text_path, encodeName);
#else
	snprintf(exp_cmdbuf, sizeof(exp_cmdbuf), "sh %s %s %s %s %s ", exp_cmd, excel_list, excel_path, text_path, encodeName);
#endif
	
	int ret = ::system(exp_cmdbuf);	
    if (0 != ret)	{
		nd_logerror("[%s] run export shell %s\nerror: %s \n",nd_getcwd(), exp_cmdbuf,nd_last_error());
        return false;
	}

    WriteLog("===============export excel to text file  success =========");


	//get byte order  
	int orderType = ND_L_ENDIAN;
	const char *orderName = apoEditorSetting::getInstant()->getValueFromSetting("bin_data_byte_order");
	if (orderName) {
		orderType = atoi(orderName);
	}

	//DUMP FOR WINDOWS only
#ifdef WIN32
	do 	{
		std::string strWinPack = package_file;
		strWinPack += ".gbk";

		DBLDatabase dbwin;
		if (0 != dbwin.LoadFromText(text_path, excel_list, inputCode, "gbk")) {
			nd_logerror("can not read from text gbk\n");
			return false;
		}
		if (0 != dbwin.Dump(strWinPack.c_str(), "gamedbGBK", orderType)) {
			nd_logmsg("EXPORT game data for windows error\n");
		}
		dbwin.Destroy();

	} while (0);
#endif

	DBLDatabase dbtmp;
	if (0 != dbtmp.LoadFromText(text_path, excel_list, inputCode, encodeName)) {
		nd_logerror("load data from text file error");
		return false;
	}
	if (0 == dbtmp.Dump(package_file, "gamedatadb", orderType)) {
		nd_logmsg("package game data SUCCESS!!\n");
		WriteLog("==========write excel to bin-stream success ===========\n");
	}
	else{
		nd_logerror("write excel to bin-stream FAILED");
	}

	//before run test need load dbl
    DBLDatabase *pdbl = DBLDatabase::get_Instant();
    if (pdbl){
        if (0 != pdbl->LoadBinStream(package_file)) {
            WriteLog("load data from bin-stream error ");
            dbtmp.Destroy();
            DBLDatabase::destroy_Instant();
            return false;
        }
    }
    if (!(*pdbl == dbtmp)){
        nd_logmsg("test data load error , read from text and stream-bin not match!!!!");
        dbtmp.Destroy();
        DBLDatabase::destroy_Instant();
        return false ;
    }

	const char *exp_luapath = _getFromIocfg("lua_data_out_path");
	if (exp_luapath && *exp_luapath ) {
		if (!expLua(exp_luapath, dbtmp)) {
			nd_logmsg("export lua error");
			dbtmp.Destroy();
			DBLDatabase::destroy_Instant();
			return false;
		}
	}

    dbtmp.Destroy();

	std::string strOutTextPath = text_path;
	strOutTextPath += "/test_outputData";
	nd_mkdir(strOutTextPath.c_str());
    if (0 != pdbl->TestOutput(strOutTextPath.c_str())) {
        nd_logmsg("dump from bin-stream to text file error\n");
        DBLDatabase::destroy_Instant();
        return false;
    }

    DBLDatabase::destroy_Instant();
    return true;
}
Example #15
0
bool startDialog::compileScript(const char *scriptFile, const char *editorWorkingPath)
{
	ndxml_root xmlScript;
	ndxml_initroot(&xmlScript);
	if (-1 == ndxml_load_ex(scriptFile, &xmlScript, apoEditorSetting::getInstant()->m_encodeName.c_str())) {
		return false;
	}
	const char*inFile = scriptFile;

	const char *outFile = getScriptSetting(&xmlScript, "out_file");
	if (!outFile){
		nd_logerror("compile %s error !!!\nMaybe file is destroyed\n", scriptFile);
		return false;
	}
	//get out file absolute path 
	std::string curPath = nd_getcwd();
	char outFilePath[ND_FILE_PATH_SIZE];

	if (!nd_getpath(scriptFile, outFilePath, sizeof(outFilePath))) {
		nd_logerror("get out file path error 1\n");
		return false;
	}
	if (-1 == nd_chdir(outFilePath)) {
		nd_logerror("get script file-path error 2\n");
		return false;
	}

	if (!nd_absolute_filename(outFile, outFilePath, sizeof(outFilePath))) {
		nd_logerror("get out file path error 3\n");
		nd_chdir(curPath.c_str());
		return false;
	}
	nd_chdir(curPath.c_str());
	outFile = outFilePath;
	// ---end get out file absolute path


	int outEncode = getScriptExpEncodeType(&xmlScript);
	bool withDebug = getScriptExpDebugInfo(&xmlScript);
	//std::string outPath = outFile;
	ndxml_destroy(&xmlScript);

	//outFile = outPath.c_str();

	int orderType = ND_L_ENDIAN;
	const char *orderName = apoEditorSetting::getInstant()->getValueFromSetting("bin_data_byte_order");
	if (orderName) {
		orderType = atoi(orderName);
	}

	LogicCompiler &lgcompile= *LogicCompiler::get_Instant();

	if (!lgcompile.compileXml(inFile, outFile, outEncode, withDebug, orderType)) {

		const char *pFunc = lgcompile.m_cur_function.c_str();
		const char *pStep = lgcompile.m_cur_step.c_str();
		char func_name[256];
		char step_name[256];
		if (outEncode == E_SRC_CODE_GBK) {
			pFunc = nd_gbk_to_utf8(pFunc, func_name, sizeof(func_name));
			pStep = nd_gbk_to_utf8(pStep, step_name, sizeof(step_name));
		}
		nd_logerror("compile error file %s, function %s, step %s , stepindex %d\n",
			lgcompile.m_cur_file.c_str(), pFunc, pStep, lgcompile.m_cur_node_index);

		return false;
	}

	nd_logmsg("!!!!!!!!!!COMPILE %s success !!!!!!!!!!!\n begining run script...\n", scriptFile);

	ClientMsgHandler::ApoConnectScriptOwner apoOwner;
	
	LogicEngineRoot *scriptRoot = LogicEngineRoot::get_Instant();
	nd_assert(scriptRoot);
	scriptRoot->setOutPutEncode(E_SRC_CODE_UTF_8);

	scriptRoot->setPrint(ND_LOG_WRAPPER_PRINT(startDialog), NULL);
	scriptRoot->getGlobalParser().setSimulate(true);
	//scriptRoot->getGlobalParser().setOwner(&apoOwner);

	if (0 != scriptRoot->LoadScript(outFile, &scriptRoot->getGlobalParser())){
		WriteLog("load script error n");
		LogicEngineRoot::destroy_Instant();
		return false;
	}

	WriteLog("start run script...\n");
	scriptRoot->setDftScriptModule(scriptRoot->getMainModuleName());
	if (0 != scriptRoot->test()){
		WriteLog("run script error\n");

		const char *curErrNode = scriptRoot->getGlobalParser().getLastErrorNode();
		if (curErrNode && *curErrNode) {
			showScriptError(scriptFile, curErrNode,editorWorkingPath);
		}

		LogicEngineRoot::destroy_Instant();
		return false;
	}

	LogicEngineRoot::destroy_Instant();
	nd_logmsg("!!!!!!!!!!!!!!!!!!!SCRIPT %s SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",scriptFile);
	return true;
}