void BattleReport::addReport( UInt32 id, std::vector<UInt8>& v ) { FastMutex::ScopedLock lk(_mutex); _reports[id] = v; char path[1024], path2[1024]; sprintf(path, "%s%u/%u", /*cfg.reportPath.c_str()*/ _type ? cfg.reportPath1.c_str() : cfg.reportPath0.c_str(), id / 100000, (id / 1000) % 100); sprintf(path2, "%s/%u.dat", path, id); File rfile(path); rfile.createDirectories(); FILE * f = fopen(path2, "wb"); if(f == NULL) return; fwrite(&v[0], 1, v.size(), f); fclose(f); if( _type == 0 ) { if(id >static_cast<UInt32>(lastMaxId0)) DB1().PushUpdateData("update reportid set maxid = %d where type = %d", id,_type); lastMaxId0 = id; } else { if(id >static_cast<UInt32>(lastMaxId1)) DB1().PushUpdateData("update reportid set maxid = %d where type = %d", id,_type); lastMaxId1 = id; } RptLife rptLife = {id, TimeUtil::Now()}; _rptLife.insert(rptLife); travelRptLife(); }
int traverse_modules(module_t *mod,int postorder,void (*mod_fcn)(module_t *), void (*f_fcn)(function_t *)) { module_t *modls; module_t *next; function_t *f; DB1(30,"{traverse_modules(,%d,,)\n",postorder); modls = mod; while (modls != NULL) { if (!postorder && (mod_fcn != NULL)) (*mod_fcn)(modls); f = T_FCNLS(modls); if (f_fcn != NULL) while (f != NULL) { (*f_fcn)(f); f = T_NEXT(f); } next = T_NEXT(modls); if (postorder && (mod_fcn != NULL)) (*mod_fcn)(modls); modls = next; } DB1(40,"}traverse_modules(,%d,,)\n",postorder); return 0; }
void traverse_stmtls(statement_t *stmtls,int postorder, void (*f) (statement_t *),void (*e) (expr_t *), void (*d) (symboltable_t *)) { statement_t *next; DB1(50,"{traverse_stmtls(,%d,,,)\n",postorder); for (; stmtls != NULL; stmtls = next) { next = T_NEXT(stmtls); traverse_stmt(stmtls,postorder,f,e,d); } DB1(55,"}returning from traverse_stmtls(,%d,,,)\n",postorder); }
void traverse_exprls(expr_t *exprls,int postorder,void (*e) (expr_t *)) { expr_t *next; DB1(70,"{traverse_exprls(,%d,);\n",postorder); if (e == NULL) { DB1(75,"}returning from traverse_exprls(,%d,);\n",postorder); return; } for (; exprls != NULL; exprls = next) { next = T_NEXT(exprls); traverse_expr(exprls,postorder,e); } DB1(75,"}returning from traverse_exprls(,%d,);\n",postorder); }
static void traverse_loop(loop_t *loop,int postorder,void (*f) (statement_t *), void (*e) (expr_t *),void (*d) (symboltable_t *)) { DB1(80,"traverse_loop(,%d,,,);\n",postorder); if (loop == NULL) { INT_FATAL(NULL,"Null loop in traverse_loop()"); } switch (T_TYPE(loop)) { case L_DO: if (e != NULL) { (*e)(T_IVAR(loop)); (*e)(T_START(loop)); (*e)(T_STOP(loop)); if (T_STEP(loop) != NULL) { (*e)(T_STEP(loop)); } } traverse_stmtls(T_BODY(loop),postorder,f,e,d); break; case L_WHILE_DO: case L_REPEAT_UNTIL: if (e != NULL) { (*e)(T_LOOPCOND(loop)); } traverse_stmtls(T_BODY(loop),postorder,f,e,d); break; default: INT_FATAL(NULL, "Bad looptype (%d) in traverse_loop()",T_TYPE(loop)); } #ifdef DEBUG fflush(stdout); #endif }
complex LoopToolsWrapper::PV_B1p(const double mu2, const double p2, const double m02, const double m12) const { setmudim(mu2); std::complex<double> B1pval = DB1(p2, m02, m12); return complex( B1pval.real(), B1pval.imag(), false ); }
void RoomBattle::GiveClanBattleAward() { //发公会战结果奖励 std::vector<UInt8> vecWinForce; std::vector<UInt8> vecFailForce; GetWinForce(vecWinForce,vecFailForce); //胜者发奖励 ClanBattleRoom* room = Battle::clanBattleRoomManager.GetBattleRoom(roomId); if( room == NULL) return; std::map<UInt8,UInt8> force2captureCityNum; for( auto it = vecWinForce.begin(); it != vecWinForce.end(); ++it ) { UInt32 forceId = (*it); std::vector<UInt32> vecClans = room->GetAllyClans(forceId); if( vecClans.empty() ) continue; for( auto iter = vecClans.begin(); iter != vecClans.end(); ++iter) { UInt32 clanId = (*iter); GObject::Clan* clan = GObject::globalClan[clanId]; if( clan == NULL ) { continue; } clan->SetClanFame(clan->GetClanFame()+100); DB1().PushUpdateData(" update `clan` set 'clanFame' = %u where `clanId` = %u",clan->GetClanFame(),clanId); } } }
void test1(void) { char tmpStr[65536]; printf("Connecting with no ADB defaults...\n"); ADB DB1(DBName, DBUser, DBPass, DBHost); printf("Inserting a record...\n"); sprintf(tmpStr, "INSERT INTO %s VALUES (0, 'Char Test', 'varchar test', 123456789012345, 54321, 'Big Blob Test', '1999-10-22', '11:26:34', '19990130123456', NULL)", DBTable); DB1.dbcmd(tmpStr); printf("Performing a query...\n"); DB1.query("select * from %s", DBTable); printf("The query returned %ld rows. Getting the first one.\n", DB1.rowCount); if (DB1.rowCount) DB1.getrow(); printf("Performing another query...\n"); DB1.query("select * from %s order by InternalID desc", DBTable); printf("The query returned %ld rows. Getting 2 of them...\n", DB1.rowCount); if (DB1.rowCount) { int tmpCount = 0; while (DB1.getrow()) { tmpCount++; if (tmpCount > 1) break; } } printf("Performing another query...\n"); DB1.query("select varcharfield, InternalID, blobfield from %s order by InternalID desc", DBTable); printf("The query returned %ld rows. Getting them...\n", DB1.rowCount); if (DB1.rowCount) { int tmpCount = 0; while (DB1.getrow()) { printf("Row %d: Column 0 -> '%s', Column 1 -> '%s'\n", tmpCount, DB1.curRow[0], DB1.curRow[1] ); printf("Row %d: Column 'InternalID' -> '%s', Column 'blobfield' -> '%s'\n", tmpCount, DB1.curRow["InternalID"], DB1.curRow["blobfield"] ); tmpCount++; // if (tmpCount > 1) break; } } printf("Escaping a string...\n"); sprintf(tmpStr, "Test quotes = ' ' ''', test backslashes \\, test percents %%"); printf("Source: '%s'\nEscaped: '%s'\n", tmpStr, DB1.escapeString(tmpStr)); printf("Deleting all rows...\n"); }
static void traverse_nloop(nloop_t *nloop,int postorder, void (*f) (statement_t *),void (*e) (expr_t *), void (*d) (symboltable_t *)) { DB1(80,"traverse_nloop(,%d,,,);\n",postorder); if (nloop == NULL) { INT_FATAL(NULL, "Null loop in traverse_nloop()"); } traverse_stmtls(T_NLOOP_BODY(nloop),postorder,f,e,d); }
static void traverse_region(region_t *region,int postorder, void (*f) (statement_t *),void (*e) (expr_t *), void (*d) (symboltable_t *)) { DB1(80,"traverse_region(,%d,,,);\n",postorder); if (region == NULL) { INT_FATAL(NULL, "Null region in traverse_region()"); } if (e) (*e)(T_MASK_EXPR(region)); traverse_stmtls(T_BODY(region),postorder,f,e,d); }
void traverse_expr(expr_t *expr,int postorder,void (*e) (expr_t *)) { DB1(70,"traverse_expr(,%d,);\n",postorder); if ((expr == NULL) || (e == NULL)) { return; } if (!postorder) (*e)(expr); traverse_exprls(T_OPLS(expr),postorder,e); if (postorder) (*e)(expr); }
static void traverse_if(if_t *ifstmt,int postorder,void (*f) (statement_t *), void (*e) (expr_t *),void (*d) (symboltable_t *)) { DB1(80,"{traverse_if(,%d,,,);\n",postorder); if (ifstmt == NULL) { INT_FATAL(NULL, "Null ifstmt in traverse_if()"); } if (e != NULL) { (*e)(T_IFCOND(ifstmt)); } traverse_stmtls(T_THEN(ifstmt),postorder,f,e,d); traverse_stmtls(T_ELSE(ifstmt),postorder,f,e,d); DB0(85,"}returning from traverse_if();\n"); }
void test3(void) { printf("\nCreating an ADBList...\n"); ADBList DB1(DBTable, DBName, DBUser, DBPass, DBHost); ADBList DB2(DBTable, DBName, DBUser, DBPass, DBHost); DB1.setEncryptedColumn("blobfield"); DB2.setEncryptedColumn("blobfield"); DB1.getList(); for (long liNo = DB1.first(); liNo != 0; liNo = DB1.next()) { printf("Got row %ld from the list...blobfield = '%s'\n", liNo, DB1.getStr("blobfield")); } DB2.getList("order by InternalID desc"); for (long liNo = DB1.first(); liNo != 0; liNo = DB1.next()) { printf("Descending - Got row %ld from the list...blobfield = '%s'\n", liNo, DB1.getStr("blobfield")); } }
void test2(void) { printf("\nCreating an ADBTable...\n"); ADBTable DB1(DBTable, DBName, DBUser, DBPass, DBHost); DB1.setEncryptedColumn("blobfield"); DB1.get(1); DB1.clearData(); DB1.setValue("blobfield", "This is a test blob field with 'quoted' text"); DB1.ins(); DB1.clearData(); DB1.setValue("blobfield", "This is a test blob field with 'quoted' text"); DB1.ins(); DB1.setValue("blobfield", "This is an update test"); DB1.upd(); DB1.del(); }
void traverse_stmt_g(statement_t *stmt,void (*pre_s) (statement_t *), void (*post_s) (statement_t *),void (*e) (expr_t *), void (*d) (symboltable_t *)) { DB0(60,"traverse_stmt_g(,,,,)\n"); if (stmt == NULL) { return; } if (pre_s) (*pre_s)(stmt); switch (T_TYPE(stmt)) { case S_NULL: case S_EXIT: case S_END: case S_HALT: case S_CONTINUE: case S_ZPROF: /* MDD */ break; case S_WRAP: case S_REFLECT: traverse_wrap_g(T_WRAP(stmt), pre_s, post_s, e, d); break; case S_COMM: traverse_comm_g(T_COMM(stmt), pre_s, post_s, e, d); break; case S_REGION_SCOPE: RMSPushScope(T_REGION(stmt)); traverse_region_g(T_REGION(stmt),pre_s,post_s,e,d); RMSPopScope(T_REGION(stmt)); break; case S_MLOOP: traverse_mloop_g(T_MLOOP(stmt),pre_s,post_s,e,d); break; case S_NLOOP: traverse_nloop_g(T_NLOOP(stmt),pre_s,post_s,e,d); break; case S_COMPOUND: case S_MSCAN: if (d != NULL) (*d)(T_CMPD_DECL(stmt)); traverse_stmtls_g(T_CMPD_STLS(stmt),pre_s,post_s,e,d); break; case S_EXPR: if (e != NULL) (*e)(T_EXPR(stmt)); break; case S_IF: traverse_if_g(T_IF(stmt),pre_s,post_s,e,d); break; case S_LOOP: traverse_loop_g(T_LOOP(stmt),pre_s,post_s,e,d); break; case S_RETURN: if (e != NULL && T_RETURN(stmt) != NULL) (*e)(T_RETURN(stmt)); break; case S_IO: if (e != NULL) (*e)(IO_EXPR1(T_IO(stmt))); break; default: DB1(70,"Type of structure == %d\n",ST_TYPE(stmt)); INT_FATAL(stmt, "Bad statementtype (%d) in traverse_stmt_g()",T_TYPE(stmt)); } if (post_s) (*post_s)(stmt); }
void BattleReport::init() { try { UInt32 maxid = 0; std::string sql = "SELECT maxid from reportid where type = 0"; if(_type) sql = "SELECT maxid from reportid where type = 1"; std::unique_ptr<DB::DBExecutor> execu(DB::gObjectDBConnectionMgr->GetExecutor()); if (execu.get() != NULL && execu->isConnected()) { GData::DBReportId dbexp; if(execu->Prepare(sql.c_str(), dbexp) == DB::DB_OK) { if(execu->Next() == DB::DB_OK) { maxid = dbexp.id; } else { DB1().PushUpdateData("insert into reportid values(0,%d)",_type); } } if (maxid > 0) { if(!_type) { lastMaxId0 = maxid; IDGenerator::gBattleOidGenerator0.Init(maxid); } else { lastMaxId1 = maxid; IDGenerator::gBattleOidGenerator1.Init(maxid); } return; } } DirectoryIterator dirit(_type ? cfg.reportPath1 : cfg.reportPath0); DirectoryIterator end; while (dirit != end) { DirectoryIterator dirit2(dirit.path().toString()); while (dirit2 != end) { DirectoryIterator dirit3(dirit2.path().toString()); while (dirit3 != end) { UInt32 id = atoi(dirit3.path().getBaseName().c_str()); if(id > 0) { if(id > maxid) maxid = id; //_reports[id].clear(); _reports.insert(std::make_pair(id, std::vector<UInt8>())); } ++dirit3; } ++dirit2; } ++dirit; } if(!_type) IDGenerator::gBattleOidGenerator0.Init(maxid); else IDGenerator::gBattleOidGenerator1.Init(maxid); } catch(...) { return; } }