int cmdTotalsCalculate( int usrid, dbUserMainPtr mainp ) { int a, b, num, population; int *buffer; dbMainPlanetDef planetd; dbMainEmpireDef empired; dbUserFleetPtr fleetd; memset( mainp->totalbuilding, 0, CMD_BLDG_NUMUSED*sizeof(int64_t) ); memset( mainp->totalunit, 0, CMD_UNIT_NUMUSED*sizeof(int64_t) ); if( ( num = dbUserPlanetListIndices( usrid, &buffer ) ) < 0 ) return 0; population = 0; for( a = 0 ; a < num ; a++ ) { dbMapRetrievePlanet( buffer[a], &planetd ); population += planetd.population; for( b = 0 ; b < CMD_BLDG_NUMUSED ; b++ ) mainp->totalbuilding[b] += planetd.building[b]; for( b = 0 ; b < CMD_UNIT_NUMUSED ; b++ ) mainp->totalunit[b] += planetd.unit[b]; if( ( planetd.flags & CMD_PLANET_FLAGS_PORTAL ) ) mainp->totalbuilding[CMD_BLDG_NUMUSED]++; if( ( b = artefactPrecense( &planetd ) ) < 0 ) continue; if( dbEmpireGetInfo( mainp->empire, &empired ) < 0 ) continue; empired.artefacts |= 1 << b; dbEmpireSetInfo( mainp->empire, &empired ); } mainp->planets = num; mainp->ressource[CMD_RESSOURCE_POPULATION] = (int64_t)population; free( buffer ); if( ( num = dbUserFleetList( usrid, &fleetd ) ) < 0 ) return 0; for( a = 0 ; a < num ; a++ ) { for( b = 0 ; b < CMD_UNIT_NUMUSED ; b++ ) mainp->totalunit[b] += fleetd[a].unit[b]; } free( fleetd ); return 1; }
//Ok, so here goes nothing... void iohtmlFunc_ajax( ReplyDataPtr cnt ) { #if IRCBOT_SUPPORT ConfigArrayPtr settings[2]; #endif int a, c, id, numbuild; int64_t b; int64_t bsums[CMD_BLDG_NUMUSED+1]; int64_t usums[CMD_UNIT_NUMUSED]; const char *typestring, *idstring, *refer; char CHECKER[256]; char timebuf[512]; dbMainEmpireDef empired; dbBuildPtr build; dbUserMainDef maind; proginfoDef pinfod; urlinfoPtr urlp; cpuInfo cpuinfo; time_t tint; struct sysinfo sysinfod; refer = idstring = typestring = NULL; cpuGetInfo( &cpuinfo ); getsys_infos( &pinfod ); if( sysinfo(&sysinfod) != 0 ) { critical( "Failure getting system infomation... Critical failure." ); sysconfig.shutdown = true; return; } idstring = iohtmlVarsFind( cnt, "id" ); typestring = iohtmlVarsFind( cnt, "typ" ); refer = iohtmlHeaderFind(cnt, "Referer"); if( ( id = iohtmlIdentify( cnt, 2 ) ) >= 0 ) { if( dbUserMainRetrieve( id, &maind ) < 0 ) goto BAILAJAX; else if( dbEmpireGetInfo( maind.empire, &empired ) < 0 ) goto BAILAJAX; } if( ( typestring ) && ( refer ) ) { urlp = parse_url(refer); refer = urlp->path; httpString( cnt, "<?xml version=\"1.0\"?>" ); httpPrintf( cnt, "<xml>" ); //Begin XML generation, we only make one request now... so we have to structure carefully! if( !strcmp(typestring,"ticker") ) { //Send basic tick info, and check if user is loged in. httpPrintf( cnt, "<pass>%d</pass>", ( id != -1 ) ? ( ( bitflag( ((cnt->session)->dbuser)->flags, CMD_USER_FLAGS_ACTIVATED ) ) ? true : false ) : false ); if( refer ) httpPrintf( cnt, "<page>%s</page>", refer ); httpPrintf( cnt, "<u_online>%d</u_online><u_activated>%d</u_activated>", dbRegisteredInfo[DB_TOTALS_USERS_ONLINE], dbRegisteredInfo[DB_TOTALS_USERS_ACTIVATED] ); httpPrintf( cnt, "<time><next>%d</next><week>%d</week><year>%d</year></time>", (int)fmax( 0.0, ( ticks.next - time(0) ) ), ticks.number % 52, ticks.number / 52 ); if( !strcmp(refer,"status") ) { snprintf( CHECKER, sizeof(CHECKER), "%lu bytes ( %5.1f mb )", pinfod.stvsize, pinfod.stvsize / megabyte ); httpString( cnt, "<general>" ); httpPrintf( cnt, "<servpriority>%ld</servpriority>", pinfod.stpriority ); httpPrintf( cnt, "<servthreads>%ld</servthreads>", pinfod.threads ); httpString( cnt, "</general>" ); httpString( cnt, "<memory>" ); httpPrintf( cnt, "<memused>%s</memused>", CHECKER ); httpPrintf( cnt, "<memavbytes>%ld bytes</memavbytes>", sysinfod.freeram ); httpPrintf( cnt, "<memavmeg>( %4.1f mb )</memavmeg>", (sysinfod.freeram / megabyte ) ); httpPrintf( cnt, "<totalswapbytes>%ld bytes</totalswapbytes>", sysinfod.totalswap ); httpPrintf( cnt, "<totalswapmeg>( %5.1f mb )</totalswapmeg>", (sysinfod.totalswap / megabyte ) ); httpPrintf( cnt, "<freeswapbytes>%ld bytes</freeswapbytes>", sysinfod.freeswap ); httpPrintf( cnt, "<freeswapmeg>( %5.1f mb )</freeswapmeg>", (sysinfod.freeswap / megabyte ) ); httpPrintf( cnt, "<bufferbytes>%ld bytes</bufferbytes>", sysinfod.bufferram ); httpPrintf( cnt, "<bufermeg>( %5.1f mb )</bufermeg>", (sysinfod.bufferram / megabyte ) ); httpPrintf( cnt, "<sharedbytes>%ld bytes</sharedbytes>", sysinfod.sharedram ); httpPrintf( cnt, "<sharedmeg>( %5.1f mb )</sharedmeg>", (sysinfod.sharedram / megabyte ) ); time( &tint ); strftime(timebuf,512,"%a, %d %b %G %T %Z", localtime( &tint ) ); httpPrintf( cnt, "<timeserver>%s</timeserver>", timebuf ); strftime(timebuf,512,"%a, %d %b %G %T %Z", gmtime( &tint ) ); httpPrintf( cnt, "<timegmt>%s</timegmt>", timebuf ); httpPrintf( cnt, "<strss>%lu pages</strss>", pinfod.strss ); httpPrintf( cnt, "</memory>" ); httpString( cnt, "<cpu>" ); httpPrintf( cnt, "<cpuprocs>%d</cpuprocs>", sysinfod.procs ); httpPrintf( cnt, "<cpuloads>%f (1 min) - %f (5 mins) - %f (15 mins)</cpuloads>",pinfod.loadavg[0],pinfod.loadavg[1],pinfod.loadavg[2]); httpPrintf( cnt, "<cputotal>%.3f %%</cputotal>", pinfod.userload + pinfod.kernelload ); httpPrintf( cnt, "<cpukernel>%.3f %%</cpukernel>", pinfod.kernelload ); httpPrintf( cnt, "<cpuuser>%.3f %%</cpuuser>", pinfod.userload ); httpString( cnt, "</cpu>" ); #if IRCBOT_SUPPORT if( sysconfig.irc_enabled ) { if( irc_is_connected(sysconfig.irc_session) ) { settings[0] = GetSetting( "IRC Host" ); settings[1] = GetSetting( "IRC Channel" ); snprintf( CHECKER, sizeof(CHECKER), "Enabled (Host:%s, Channel:%s)", settings[0]->string_value, settings[1]->string_value ); } else { snprintf( CHECKER, sizeof(CHECKER), "%s", "Enabled but not connected" ); } } else { snprintf( CHECKER, sizeof(CHECKER), "%s", "Disabled"); } httpPrintf( cnt, "<botstatus>%s</botstatus>", CHECKER ); #endif //End Status block -- Start user block } if( id < 0 ) goto ENDXML; a = dbUserNewsGetFlags( id ); //OK, so they are loged in... time to send some info. Lets start with the header. =) httpString( cnt, "<header>" ); httpPrintf( cnt, "<networth>%lld</networth>", (long long)maind.networth ); httpString( cnt, "<notification>" ); httpPrintf( cnt, "<mail>%d</mail>", ( a & CMD_NEWS_FLAGS_MAIL ) ? true : false ); httpPrintf( cnt, "<build>%d</build>", ( a & CMD_NEWS_FLAGS_BUILD ) ? true : false ); httpPrintf( cnt, "<aid>%d</aid>", ( a & CMD_NEWS_FLAGS_AID ) ? true : false ); httpPrintf( cnt, "<fleet>%d</fleet>", ( a & CMD_NEWS_FLAGS_ATTACK ) ? 1 : ( ( a & CMD_NEWS_FLAGS_FLEET ) ? 2 : false ) ); httpString( cnt, "</notification>" ); httpString( cnt, "<ressources>" ); for( a = 0 ; a < CMD_RESSOURCE_NUMUSED ; a++ ) { snprintf( CHECKER, sizeof(CHECKER),"%s",cmdRessourceName[a]); for(b = 0; CHECKER[b]; b++){ CHECKER[b] = tolower(CHECKER[b]); } httpPrintf( cnt, "<%s>%lld</%s>", CHECKER, (long long)maind.ressource[a], CHECKER ); } httpPrintf( cnt, "<population>%lld</population>", (long long)maind.ressource[CMD_RESSOURCE_POPULATION] ); httpString( cnt, "</ressources>" ); httpString( cnt, "</header>" ); httpPrintf( cnt, "<%s>", refer ); //End Header block -- Start HQ block if( !strcmp(refer,"hq") ) { httpString( cnt, "<readiness>" ); for( a = 0 ; a < CMD_READY_NUMUSED ; a++ ) { httpPrintf( cnt, "<%sready>%d</%sready>", cmdReadyName[a], maind.readiness[a] >> 16, cmdReadyName[a] ); } httpString( cnt, "</readiness>" ); httpPrintf( cnt, "<planets>%d</planets>", maind.planets ); //End HQ block -- Start Council block } else if( !strcmp(refer,"council") ) {