RESULT_T ApoClient::TrytoReloginEx(void *session, size_t sessionSize) { // in login if (IsLoginOk()){ nd_logerror("already in login\n"); return ESERVER_ERR_SUCCESS; } if (-1 == _trytoOpen()) { return NDSYS_ERR_HOST_UNAVAILABLE; } //login server if (!m_login) { nd_logerror("can not login the program is not init-success or connector-to-server\n"); return NDSYS_ERR_NOT_INIT; } m_runningUpdate = ERUN_UP_STOP; int ret = m_login->ReloginEx(session,sessionSize); if (0 == ret) { RESULT_T res = EnterGame(); m_runningUpdate = ERUN_UP_NORMAL; return res; } return (RESULT_T)NDERR_LIMITED; }
int apoCli_recv(char *bufferFram, int bufsize, int timeOutMS) { ApoClient *apoCli = ApoClient::getInstant(); if (!apoCli) { return -1; } nd_handle h = apoCli->getConn(); if (!h) { nd_logerror("can not RECV data, MUST connected\n") ; return -1; } if (!apoCli->IsInConnect()) { nd_logerror("can not RECV data, MUST LOGIN \n") ; nd_object_seterror(h, NDSYS_ERR_NEED_LOGIN); return -1; } int ret = nd_connector_waitmsg(h, (nd_packetbuf_t*)bufferFram, timeOutMS); if (ret > bufsize) { nd_object_seterror(h, NDSYS_ERR_INVALID_INPUT); return -1; } else if (ret > 0) { apoCli->trytoHandle((nd_usermsgbuf_t *)bufferFram); } return ret; }
void startDialog::on_Compile_clicked() { ClearLog(); if (!loadDataBase()) { nd_logerror("load database error\n"); } if (false == compile()){ WriteLog("compile script error"); return; } WriteLog("=========compile script success===========\n"); const char *packaged_cmd = _getFromIocfg("compiled_rum_cmd"); if (packaged_cmd && *packaged_cmd) { int ret = system(packaged_cmd); if (0 != ret) { nd_logerror("run command error %s %d\n", packaged_cmd, ret); } } }
netObject ndOpenConnect(const char *host, int port) { nd_handle handle = 0 ; ndInitNet() ; handle = nd_object_create("tcp-connector" ) ; if(!handle){ nd_logerror((char*)"connect error :%s!" AND nd_last_error()) ; return NULL; } if(-1==nd_msgtable_open(handle, 16) ) { nd_object_destroy(handle, 0) ; return NULL ; } //open if(-1==nd_connector_open( handle, (char*)host, port,NULL ) ){ nd_logerror("connect error :%s!" AND nd_last_error()) ; nd_object_destroy(handle,1) ; return NULL; } nd_hook_packet((netObject) handle,(net_msg_entry )_translate_message); ndMsgfuncInit( (netObject) handle ) ; return (netObject) handle; }
//×¢²átcp udtÁ¬½ÓÆ÷ int register_connector(void) { int ret ; struct nd_handle_reginfo reginfo ; //tcp connector register reginfo.object_size = sizeof(struct nd_tcp_node ) ; reginfo.init_entry =(nd_init_func ) nd_tcpnode_init ; reginfo.close_entry = (nd_close_callback )_connector_destroy ; strcpy(reginfo.name, "tcp-connector" ) ; ret = nd_object_register(®info) ; if(-1==ret) { nd_logerror("register tcp-connector error") ; return -1 ; } //udp register reginfo.object_size = sizeof(nd_udp_node) ; reginfo.init_entry = (nd_init_func ) udp_node_init ; reginfo.close_entry = (nd_close_callback )nd_udp_close ; strcpy(reginfo.name, "udp-node" ) ; ret = nd_object_register(®info) ; if(-1==ret) { nd_logerror("register udt-connector error") ; return -1 ; } //udt connector register reginfo.object_size = sizeof(nd_udt_node) ; reginfo.init_entry = (nd_init_func ) nd_udtnode_init ; reginfo.close_entry = (nd_close_callback )_connector_destroy ; strcpy(reginfo.name, "udt-connector" ) ; ret = nd_object_register(®info) ; if(-1==ret) { nd_logerror("register udt-connector error") ; return -1 ; } //ICMP-udt connector register reginfo.object_size = sizeof(nd_udt_node) ; reginfo.init_entry = (nd_init_func ) udt_icmp_init ; reginfo.close_entry = (nd_close_callback )_connector_destroy ; strcpy(reginfo.name, "icmp-connector" ) ; ret = nd_object_register(®info) ; if(-1==ret) { nd_logerror("register udt-connector error") ; return -1 ; } return ret ; }
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); }
int ApoClient::_trytoOpen() { if (m_host.empty() || m_port == 0){ nd_logerror("connect host error adress is NULL\n"); return -1; } if (!m_pconn){ if (ESERVER_ERR_SUCCESS != Open()) { return -1; } } if (m_pconn->CheckValid()) { if (!m_login){ m_pconn->Close(1); RESULT_T res = _connectHost(m_host.c_str(), m_port); if (res == ESERVER_ERR_SUCCESS) { return 0; } m_pconn->SetLastError(res); return -1; } return 0; } if (ESERVER_ERR_SUCCESS!=_connectHost(m_host.c_str(), m_port)) { return -1; } return 0; }
RESULT_T ApoClient::CreateOnly(const char *userName, const char *passwd, int channel) { m_isRelogin = 0; if (!userName || !*userName){ nd_logerror("create account error, input account name is NULL\n"); return NDSYS_ERR_INVALID_INPUT; } // in login if (IsLoginOk()){ return NDSYS_ERR_ALREADY_LOGIN; } if (-1 == _trytoOpen()) { return NDSYS_ERR_HOST_UNAVAILABLE; } account_base_info acc; m_runningUpdate = ERUN_UP_STOP; myInitAccCreateInfo(acc, ACC_APOLLO, userName, passwd); acc.channel = channel; int ret = m_login->CreateAccount(&acc); m_runningUpdate = ERUN_UP_NORMAL; if (-1 == ret) { return (RESULT_T)m_login->GetLastError(); } return ESERVER_ERR_SUCCESS; }
int apollo_message_script_entry(void *engine, nd_handle handle, nd_usermsgbuf_t *msg, const char *script) { LogicParserEngine *scriptEngine = (LogicParserEngine *)engine; if (!scriptEngine) { NDObject *pObj = NDObject::FromHandle(handle); if (!pObj) { return -1; } scriptEngine = (LogicParserEngine *)pObj->getScriptEngine(); if (!scriptEngine) { nd_logerror("can not get role script parser\n"); return -1; } } NDIStreamMsg inmsg(msg); //call function parse_arg_list_t params; //function name params.push_back(LogicDataObj(script)); //receive message user params.push_back(LogicDataObj((void*)handle, OT_OBJ_NDHANDLE)); //message object params.push_back(LogicDataObj((void*)&inmsg, OT_OBJ_MSGSTREAM)); LogicDataObj result; scriptEngine->runScript(script, params, result); return 0; }
void startDialog::on_ExportExcel_clicked() { ClearLog(); if (false == expExcel()) { WriteLog("Export excel error"); return; } WriteLog("==========excel export success==========\n"); const char *packaged_cmd = _getFromIocfg("packeaged_rum_cmd"); if (packaged_cmd && *packaged_cmd) { char cmdbuf[1024]; const char *p = packaged_cmd; while (p && *p) { cmdbuf[0] = 0; p = ndstr_nstr_end(p, cmdbuf, ';', sizeof(cmdbuf)); if (p && *p == ';') { ++p; } if (cmdbuf[0]) { int ret = system(cmdbuf); if (0 != ret) { nd_logerror("Run command by system %s %d\n", cmdbuf, ret); break; } } } } }
int HttpConnector::Create(const char *host, int port) { if (m_conn) { nd_object_destroy(m_conn, 0) ; //DestroyConnectorObj(m_conn) ; m_conn = 0 ; } m_conn = nd_object_create("tcp-connector" ) ; if(!m_conn){ nd_logerror((char*)"connect error :%s!" , nd_last_error()) ; return -1; } ((nd_netui_handle)m_conn)->user_data =(void*) this ; int ret = nd_connector_open(m_conn,host, port, NULL); if(ret == 0 ) { m_host = host ; m_port = port ; } else { nd_object_destroy(m_conn, 0) ; m_conn = 0 ; return -1; } return 0 ; }
int nd_run_cmdline(struct nd_cmdline_root *root, int argc, const char *argv[] ) { int ret=0 ; char buf[1024] ; if (root->init_func) { if(-1==root->init_func(root, argc, argv) ) { nd_logerror("init command lient error ") ; return -1 ; } } fprintf(stdout, "%s>", root->tips ) ; fflush(stdout) ; while (root->exit_stat==0) { int read_flag = 0; if (root->update_func) { ret = root->update_func(root, 0, NULL) ; if (ret > 0) { //fprintf(stdout, "update ret =%d\n%s>",ret, root->tips ) ; fflush(stdout) ; } if(!kbhit()) { nd_sleep(50) ; continue ; } } memset(buf, 0, sizeof(buf)) ; if (root->next_cmd) { strncpy(buf, root->next_cmd, sizeof(buf)) ; read_flag = 1 ; free(root->next_cmd) ; root->next_cmd = 0; } else if(fgets( buf, sizeof(buf), stdin ) ) { read_flag = 1 ; } if (read_flag) { ret = _parse_input_and_run(root, buf) ; if(ret == -1) { fprintf(stderr, "bad command: %s\n", buf ) ; } if (root->exit_stat) { break ; } root->last_retval =ret ; fprintf(stdout, ">%s>", root->tips ) ; fflush(stdout) ; } read_flag = 0 ; } return 0; }
static struct nd_msg_entry_node *_nd_msgentry_get_node(nd_netui_handle handle, ndmsgid_t maxid, ndmsgid_t minid) { struct nd_msgentry_root *root_entry = (struct nd_msgentry_root *) nd_get_msg_hadle(handle); if(root_entry) { ndmsgid_t main_index =(ndmsgid_t) (maxid - root_entry->msgid_base ); if(main_index >= root_entry->main_num ) { nd_logerror("MAIN MESSAGE ERROR input %d limited %d\n"AND main_index AND root_entry->main_num ) ; return NULL ; } if(minid>=SUB_MSG_NUM ){ nd_logerror("MIN MESSAGE ERROR input %d limited %d\n"AND minid AND SUB_MSG_NUM ) ; return NULL; } return &(root_entry->sub_buf[main_index].msg_buf[minid]) ; } return NULL ; }
RESULT_T apoCli_open(const char *host, int port) { ApoClient *apoCli = ApoClient::getInstant(); if (!apoCli) { nd_logerror("open net, MUST INIT before open\n") ; return NDSYS_ERR_NOT_INIT; } if (!host || !*host) { nd_logerror("open net error aim address is NULL\n") ; return NDSYS_ERR_INVALID_INPUT; } RESULT_T res = apoCli->Open(host, port); nd_logdebug("open net %s code = %d\n", res ? "success":"error", res) ; return res ; }
int apoCli_fetchSessionKey(char *outbuf, int bufsize) { ApoClient *apoCli = ApoClient::getInstant(); if (!apoCli) { nd_logerror("can not fetch session key, net connector is NULL\n") ; return -1; } LoginBase *pLogin = apoCli->getLoginObj(); if (!pLogin) { nd_logerror("can not fetch session key, login manager is NULL\n") ; return -1; } if(!outbuf || bufsize == 0) { nd_logerror("can not catch ssession key, input buffer is NULL \n"); return -1 ; } return (int)pLogin->GetSessionData(outbuf, bufsize); }
RESULT_T apoCli_CreateAccount(const char *userName, const char *passwd,int channel) { ApoClient *apoCli = ApoClient::getInstant(); if (!apoCli) { return NDSYS_ERR_NOT_INIT; } RESULT_T res = apoCli->CreateAccount(userName,passwd,channel); if (res != ESERVER_ERR_SUCCESS) { apoCli->Close(); nd_logerror("account create failed code =%d\n", res) ; } return res; }
RESULT_T apoCli_LoginAccount(const char *account, const char *passwd, int accType, int channel, bool skipAuth) { ApoClient *apoCli = ApoClient::getInstant(); if (!apoCli) { return NDSYS_ERR_NOT_INIT; } RESULT_T res = apoCli->LoginAccountOneKey(account, passwd,accType,channel,skipAuth); if (res != ESERVER_ERR_SUCCESS) { apoCli->Close(); nd_logerror("login failed code =%d\n", res) ; } return res; }
static int code_convert(const char *from_charset,const char *to_charset, char *inbuf,int inlen,char *outbuf,int outlen) { iconv_t cd; //int rc; char **pin = &inbuf; char **pout = &outbuf; size_t in_buf=inlen; size_t out_buf=outlen; cd = iconv_open(to_charset,from_charset); if (cd==0) { nd_logerror("iconv_open %s\n", nd_last_error() ) ; return -1; } memset(outbuf,0,outlen); if (iconv(cd,pin,&in_buf,pout,&out_buf)==-1) { nd_logerror("iconv %s\n", nd_last_error() ) ; return -1; } iconv_close(cd); return 0; }
bool apoAttrCalcHelper::FormulaRun(const char *text, float *result) { //init vm bool ret = false; *result = 0; if (!text || !text[0]) { return true; } vm_cpu formula; char cmd_buf[1024]; vm_machine_init(&formula, m_values, m_wa_num); vm_set_echo_ins(&formula, 0); vm_set_echo_result(&formula, 0); vm_set_outfunc(NULL); vm_set_errfunc(NULL); //parse size_t size = vm_parse_expression((char*)text, cmd_buf, sizeof(cmd_buf), (vm_param_replace_func)apo_place_name_runtime, this); if (size > 0) { if (0 == vm_run_cmd(&formula, cmd_buf, size)) { *result = vm_return_val(&formula); ret = true; } else { nd_logerror("run formula %s error\n", text); } } else { nd_logerror("parse formula error %s\n", text); } return ret; }
void startDialog::on_ScriptEdit_clicked() { EditorFrame *pMain = new EditorFrame(); pMain->setHostWidget(this); pMain->setAttribute(Qt::WA_DeleteOnClose, true); if (!loadDataBase()) { nd_logerror("load database error\n"); } std::string defProj = getPathFromConfig("script_root"); if (!defProj.empty() && pMain->myInit(defProj.c_str() )) { this->setVisible(false); pMain->showMaximized(); } else { delete pMain; } }
RESULT_T apoCli_sendMsg(int messageId, void *messageBody, int bodySize) { NDOStreamMsg omsg((NDUINT16) messageId); if (messageBody && bodySize > 0) { if (-1 == omsg.WriteStream((char*)messageBody, bodySize)) { return NDSYS_ERR_INVALID_INPUT; } } ApoClient *apoCli = ApoClient::getInstant(); if (apoCli) { if (!apoCli->IsInConnect()) { nd_logerror("can not send data, MUST LOGIN \n") ; return NDSYS_ERR_NEED_LOGIN; } nd_connector_send(apoCli->getConn(), &(omsg.GetMsgAddr()->msg_hdr.packet_hdr), 0); return ESERVER_ERR_SUCCESS; } return NDSYS_ERR_NOT_INIT; }
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; }
int ipaddr_mac_cmp(const char *input_addr) { PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pAdapter = NULL; DWORD dwRetVal = 0; pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) ); ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO); dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) ; if ( dwRetVal != ERROR_SUCCESS) { free (pAdapterInfo); pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); } if((dwRetVal=GetAdaptersInfo(pAdapterInfo ,&ulOutBufLen))==NO_ERROR){ pAdapter= pAdapterInfo; while(pAdapter) { char mac_buf[128] ; char *p = mac_buf ; for(UINT i=0;i<pAdapter->AddressLength;i++) { p +=snprintf(p,128 , "%02x-" , pAdapter->Address[i]) ; } --p ; *p = 0 ; if (0==ndstricmp((char*)mac_buf,(char*) input_addr)){ return 0 ; } pAdapter=pAdapter->Next; } } else { nd_logerror("last error :%s\n" AND nd_last_error()) ; } free (pAdapterInfo); return -1; }
int ndSendAndWaitMessage(nd_handle nethandle, nd_usermsgbuf_t *sendBuf, nd_usermsgbuf_t* recvBuf, ndmsgid_t waitMaxid, ndmsgid_t waitMinid, int sendFlag, int timeout) { if (nd_connector_send(nethandle, (nd_packhdr_t*)sendBuf, sendFlag) <= 0) { nd_object_seterror(nethandle, NDERR_WRITE); nd_logerror("send data error: NDERR_WRITE\n"); return -1; } ndtime_t start_tm = nd_time(); RE_RECV: if (-1 == nd_connector_waitmsg(nethandle, (nd_packetbuf_t *)recvBuf, timeout)) { nd_object_seterror(nethandle, NDERR_TIMEOUT); nd_logerror("wait message timeout\n"); return -1; } else if (recvBuf->msg_hdr.packet_hdr.ndsys_msg){ if (-1 == nd_net_sysmsg_hander((nd_netui_handle)nethandle, (nd_sysresv_pack_t *)recvBuf)){ nd_logerror("receive system mesaage and handler error \n"); return -1; } } else if (nd_checkErrorMsg(nethandle, (struct ndMsgData*)recvBuf)) { nd_logerror("receive error message \n"); return -1; } else if (ND_USERMSG_MAXID(recvBuf) != waitMaxid || ND_USERMSG_MINID(recvBuf) != waitMinid) { if ((nd_time() - start_tm) >= timeout) { nd_object_seterror(nethandle, NDERR_TIMEOUT); nd_logerror("wait message(%d,%d) timeout\n", waitMaxid, waitMinid); return -1; } if (((nd_netui_handle)nethandle)->msg_handle) { //int ret = nd_translate_message(nethandle, (nd_packhdr_t*)recvBuf, NULL); int ret = _packet_handler((nd_netui_handle)nethandle, &recvBuf->msg_hdr.packet_hdr, NULL); if (ret == -1){ nd_logerror("wait message(%d,%d) error ,recvd(%d,%d)\n", waitMaxid, waitMinid, ND_USERMSG_MAXID(recvBuf), ND_USERMSG_MINID(recvBuf)); return ret; } } goto RE_RECV; } return 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; }
//#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; }