void wd_testit(void) { cvar_t *cv; cv=CVAR_GET_POINTER("csguard_version"); if(cv) LOG_CONSOLE(PLID, "csguard_version found!: %d", cv); else LOG_CONSOLE(PLID, "csguard_version not found!"); }
void wd_msgid(void) { const char *msgname; int id; msgname=CMD_ARGV(1); id=GET_USER_MSG_ID(PLID, msgname, NULL); if(id) LOG_CONSOLE(PLID, "%s = %d", msgname, id); else LOG_CONSOLE(PLID, "msg not found: %s", msgname); }
void wd_msglist(void) { int i, size; const char *cp; LOG_CONSOLE(PLID, "registered user msgs:"); for(i=0; i < MAX_REG_MSGS; i++) { cp=GET_USER_MSG_NAME(PLID, i, &size); if(cp) LOG_CONSOLE(PLID, "%d %s %d", i, cp, size); } }
// Print usage for "trace" console command. void cmd_trace_usage(void) { LOG_CONSOLE(PLID, "usage: trace <command> [<arguments>]"); LOG_CONSOLE(PLID, "valid commands are:"); LOG_CONSOLE(PLID, " version - display plugin version info"); LOG_CONSOLE(PLID, " show - show currently traced api routines"); LOG_CONSOLE(PLID, " set <routine> - set tracing for given routine"); LOG_CONSOLE(PLID, " unset <routine> - unset tracing for given routine"); LOG_CONSOLE(PLID, " list dllapi - list all dllapi routines available for tracing"); LOG_CONSOLE(PLID, " list newapi - list all newapi routines available for tracing"); LOG_CONSOLE(PLID, " list engine - list all engine routines available for tracing"); LOG_CONSOLE(PLID, " list all - list dllapi, neapi, and engine"); }
bool RankSystem::loadCalc(const char* filename, char* error, size_t maxLength) { if ((MF_LoadAmxScriptEx(&calc.amx,&calc.code,filename, error, maxLength, 0)!=AMX_ERR_NONE)|| (MF_AmxAllot(&calc.amx, 8 , &calc.amxAddr1, &calc.physAddr1)!=AMX_ERR_NONE)|| (MF_AmxAllot(&calc.amx, 8 , &calc.amxAddr2, &calc.physAddr2)!=AMX_ERR_NONE)|| (MF_AmxFindPublic(&calc.amx,"get_score",&calc.func)!=AMX_ERR_NONE)){ LOG_CONSOLE( PLID, "Couldn't load plugin (file \"%s\")",filename); MF_UnloadAmxScript(&calc.amx, &calc.code); return false; } return true; }
// "trace unset" console command. void cmd_trace_unset(void) { int i, argc; const char *arg; const char *api; TRACE_RESULT ret; argc=CMD_ARGC(); if(argc < 3) { LOG_CONSOLE(PLID, "usage: trace unset <routine>"); return; } for(i=1; i < argc; i++) { arg=CMD_ARGV(i); ret=trace_setflag(&arg, mFALSE, &api); if(ret==TR_SUCCESS) LOG_MESSAGE(PLID, "Un-Tracing %s routine '%s'", api, arg); else if(ret==TR_ALREADY) LOG_CONSOLE(PLID, "Already not tracing %s routine '%s'", api, arg); else LOG_CONSOLE(PLID, "Unrecognized API routine '%s'", arg); } }
C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs) { // this function is the first function ever called by metamod in the plugin DLL. Its purpose // is for metamod to retrieve basic information about the plugin, such as its meta-interface // version, for ensuring compatibility with the current version of the running metamod. // keep track of the pointers to metamod function tables metamod gives us gpMetaUtilFuncs = pMetaUtilFuncs; *pPlugInfo = &Plugin_info; // check for interface version compatibility if (strcmp(ifvers, Plugin_info.ifvers) != 0) { int mmajor = 0, mminor = 0, pmajor = 0, pminor = 0; LOG_CONSOLE(PLID, "%s: meta-interface version mismatch (metamod: %s, %s: %s)", Plugin_info.name, ifvers, Plugin_info.name, Plugin_info.ifvers); LOG_MESSAGE(PLID, "%s: meta-interface version mismatch (metamod: %s, %s: %s)", Plugin_info.name, ifvers, Plugin_info.name, Plugin_info.ifvers); // if plugin has later interface version, it's incompatible (update metamod) sscanf (ifvers, "%d:%d", &mmajor, &mminor); sscanf (META_INTERFACE_VERSION, "%d:%d", &pmajor, &pminor); if (pmajor > mmajor || (pmajor == mmajor && pminor > mminor)) { LOG_CONSOLE(PLID, "metamod version is too old for this plugin; update metamod"); LOG_ERROR(PLID, "metamod version is too old for this plugin; update metamod"); } // if plugin has older major interface version, it's incompatible (update plugin) else if (pmajor < mmajor) { LOG_CONSOLE(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin"); LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin"); } } return TRUE; // tell metamod this plugin looks safe }
void FuncShowMaps(edict_t *pEntity) { FILE *file = NULL; const char *path = "AdminMod/maps.txt"; char fullpath[PATH_MAX]; char line[MAX_CONF_LEN]; char buf[MAX_CONF_LEN]; sup_gamedir_path(path, fullpath); file = fopen(fullpath, "r"); if(!file) { UTIL_LogPrintf("Unable to open map list file '%s': %s", fullpath, strerror(errno)); if(pEntity) CLIENT_PRINTF(pEntity, print_console, "\nUnable to load map list\n"); return; } for(int i = 1, j = 0; !feof(file); i++) { if(!fgets(line, sizeof(line), file)) { UTIL_LogPrintf("Unable to read %d line", i); if(pEntity) CLIENT_PRINTF(pEntity, print_console, "\nUnable to load map list\n"); fclose(file); break; } if(line[0] == '#' || line[0] == ';') continue; if(strnmatch(line, "//", 2)) continue; j = strlen(line) - 1; if(line[j] == '\n') line[j] = '\0'; if(!pEntity) LOG_CONSOLE(NULL, "%d) %s", i, line); else { sup_make_str(buf, sizeof(buf), "%d) %s\n", i, line); CLIENT_PRINTF(pEntity, print_console, buf); } } fclose(file); }
// "trace show" console command. void cmd_trace_show(void) { api_info_t *routine; int n=0; LOG_CONSOLE(PLID, "Tracing routines:"); for(api_info_t *routine=&dllapi_info.pfnGameInit; routine->name; routine++) { if(routine->trace==mTRUE) { LOG_CONSOLE(PLID, " %s (dllapi)", routine->name); n++; } } for(api_info_t *routine=&newapi_info.pfnOnFreeEntPrivateData; routine->name; routine++) { if(routine->trace==mTRUE) { LOG_CONSOLE(PLID, " %s (newapi)", routine->name); n++; } } for(api_info_t *routine=&engine_info.pfnPrecacheModel; routine->name; routine++) { if(routine->trace==mTRUE) { LOG_CONSOLE(PLID, " %s (engine)", routine->name); n++; } } LOG_CONSOLE(PLID, "%d routines", n); }
// "trace show" console command. void cmd_trace_show(void) { api_info_t *routine; int n=0; LOG_CONSOLE(PLID, "Tracing routines:"); for(routine=(api_info_t *) &dllapi_info; routine->name; routine++) { if(routine->trace==mTRUE) { LOG_CONSOLE(PLID, " %s (dllapi)", routine->name); n++; } } for(routine=(api_info_t *) &newapi_info; routine->name; routine++) { if(routine->trace==mTRUE) { LOG_CONSOLE(PLID, " %s (newapi)", routine->name); n++; } } for(routine=(api_info_t *) &engine_info; routine->name; routine++) { if(routine->trace==mTRUE) { LOG_CONSOLE(PLID, " %s (engine)", routine->name); n++; } } LOG_CONSOLE(PLID, "%d routines", n); }
C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { // this function is called when metamod unloads the plugin. A basic check is made in order // to prevent unloading the plugin if its processing should not be interrupted. // is metamod allowed to unload the plugin? if (now > Plugin_info.unloadable && reason != PNL_CMD_FORCED) { LOG_CONSOLE(PLID, "%s: plugin NOT detaching (can't unload plugin right now)", Plugin_info.name); LOG_ERROR(PLID, "%s: plugin NOT detaching (can't unload plugin right now)", Plugin_info.name); return FALSE; // returning FALSE prevents metamod from unloading this plugin } UserRemoveAllBots(); // Kick all bots off this server return TRUE; // returning TRUE enables metamod to unload this plugin }
// Parse "trace" console command. void svr_trace(void) { const char *cmd; cmd=CMD_ARGV(1); if(!strcasecmp(cmd, "version")) cmd_trace_version(); else if(!strcasecmp(cmd, "show")) cmd_trace_show(); else if(!strcasecmp(cmd, "set")) cmd_trace_set(); else if(!strcasecmp(cmd, "unset")) cmd_trace_unset(); else if(!strcasecmp(cmd, "list")) cmd_trace_list(); else { LOG_CONSOLE(PLID, "Unrecognized trace command: %s", cmd); cmd_trace_usage(); return; } }
C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs) { // this function is called when metamod attempts to load the plugin. Since it's the place // where we can tell if the plugin will be allowed to run or not, we wait until here to make // our initialization stuff, like registering CVARs and dedicated server commands. // are we allowed to load this plugin now? if (now > Plugin_info.loadable) { LOG_CONSOLE(PLID, "%s: plugin NOT attaching (can't load plugin right now)", Plugin_info.name); LOG_ERROR(PLID, "%s: plugin NOT attaching (can't load plugin right now)", Plugin_info.name); return FALSE; // returning FALSE prevents metamod from attaching this plugin } // keep track of the pointers to engine function tables metamod gives us gpMetaGlobals = pMGlobals; memcpy (pFunctionTable, &gMetaFunctionTable, sizeof (META_FUNCTIONS)); gpGamedllFuncs = pGamedllFuncs; return TRUE; // returning TRUE enables metamod to attach this plugin }
/************************************************************************* Process Process the frames in a video one by one. 1) FG detection 2) Blob Detection 3) Blob Tracking and Association 4) Blob Post Processing 5) Blob Analysis 6) Store the results Exceptions None *************************************************************************/ void Camera::Process(const int startFrameIndex, const int endFrameIndex) { ASSERT_TRUE ( m_initializied ); ASSERT_TRUE ( m_pTracker != NULL ); InitializeDisplayWindows( ); LOG_CONSOLE( "Start processing " + m_videoFileName ); int key, oneFrameProcess=0, frameNum; for ( frameNum = 1; m_videoCap.grab() && ( key = cvWaitKey( oneFrameProcess ? 0 : 1 ) ) != 27 && ( frameNum <= endFrameIndex || endFrameIndex < 0 ); frameNum++ ) { if ( frameNum >= startFrameIndex ) { std::cout << "frameNum: " << frameNum << '\r'; // get the video frame m_videoCap.retrieve( m_originalFrameMat ); // downscale the image if required if ( m_downScaleImage ) { cv::resize( m_originalFrameMat, m_frame, m_frame.size() ); } else { m_frame = m_originalFrameMat; } m_frameIpl = m_frame; if ( key != -1 ) { oneFrameProcess = ( key == 'r' ) ? 0 : 1; } // Process the current frame m_pTracker->Process( &m_frameIpl, m_pFGMaskIpl); m_fgMask = m_pTracker->GetFGMask(); // Process the current video frame using the blob tracker IplImage fgMaskIpl = m_fgMask; // Save Blob Information in a file for( int i = m_pTracker->GetBlobNum(); i> 0; i-- ) { CvBlob* pBlob = m_pTracker->GetBlob(i-1); ASSERT_TRUE( pBlob != NULL ); // Save blob record SaveBlobRecord( pBlob, frameNum ); } if ( m_displayIntermediateResult || m_saveIntermediateResult ) { char tempString[128]; std::string textMessage; //display intermediate result if necessary CvFont font; CvSize TextSize; cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, 0.7, 0.7, 0, 1, CV_AA ); sprintf(tempString,"frame # %d", frameNum); textMessage = tempString; cv::putText( m_originalFrameMat, textMessage, cv::Point(10,20), CV_FONT_HERSHEY_PLAIN, 1, cv::Scalar((0,255,255))); cv::putText( m_fgMask,textMessage, cv::Point(10,20), CV_FONT_HERSHEY_PLAIN, 1, cv::Scalar((0,255,255))); cv::putText( m_frame, textMessage, cv::Point(10,20), CV_FONT_HERSHEY_PLAIN, 1, cv::Scalar((0,255,255))); //drawing blobs if any with green ellipse with m_cvBlob id displayed next to it. int c = 0; // 0: g; 255: red for ( int i = m_pTracker->GetBlobNum(); i > 0; i-- ) { CvBlob* pBlob = m_pTracker->GetBlob(i-1); ASSERT_TRUE( pBlob != NULL ); cv::Point blobCorner( cvRound( pBlob->x * 256 ), cvRound( pBlob->y * 256 ) ); CvSize blobSize = cvSize( MAX( 1, cvRound( CV_BLOB_RX(pBlob) * 256 ) ), MAX( 1, cvRound( CV_BLOB_RY(pBlob) * 256 ) ) ); cv::Scalar boundingBoxColor( c, 255-c, 0 ); if ( m_pTracker->GetState( CV_BLOB_ID( pBlob ) ) != 0 ) { boundingBoxColor = cv::Scalar( 255-c, c, 0 ); } cv::ellipse( m_frame, cv::RotatedRect( cv::Point2f( pBlob->x, pBlob->y ), cv::Size2f( pBlob->w, pBlob->h ), 0 ), cv::Scalar( c, 255-c, 0 ) ); blobCorner.x >>= 8; blobCorner.y >>= 8; blobSize.width >>= 8; blobSize.height >>= 8; blobCorner.y -= blobSize.height; sprintf( tempString, "BlobId=%03d", CV_BLOB_ID(pBlob) ); cvGetTextSize( tempString, &font, &TextSize, NULL ); cv::putText( m_frame, std::string( tempString ), blobCorner, CV_FONT_HERSHEY_PLAIN, 1, cv::Scalar( 255, 255, 0, 0 ) ); } } if ( m_displayIntermediateResult ) { cv::imshow(m_videoFileName+"_FGMask", m_fgMask); cv::imshow(m_videoFileName+"_Tracking", m_frame); } if ( m_saveIntermediateResult ) { cv::Mat tmpFrame; cv::cvtColor( m_fgMask, tmpFrame, CV_GRAY2BGR ); *m_pFGAvi << tmpFrame; *m_pBTAvi << m_frame; } }
// This message gets sent when the bots are getting damaged. void BotClient_Valve_Damage(void *p, int bot_index) { //DebugOut("bot_client: BotClient_Valve_Damage()\n"); static int state = 0; // current state machine state static int damage_armor; static int damage_taken; static int damage_bits; // type of damage being done static Vector damage_origin; if (state == 0) { state++; damage_armor = *(int *) p; } else if (state == 1) { state++; damage_taken = *(int *) p; } else if (state == 2) { state++; damage_bits = *(int *) p; } else if (state == 3) { state++; damage_origin.x = *(float *) p; } else if (state == 4) { state++; damage_origin.y = *(float *) p; } else if (state == 5) { state = 0; damage_origin.z = *(float *) p; if ((damage_armor > 0) || (damage_taken > 0)) { // Damage recieved: // - when the prev node was higher (so we are sure we do FIX the correct nodes!) // we fix it (only when dist > 90) cBot *pBot = &bots[bot_index]; if (damage_bits & (DMG_FALL | DMG_CRUSH)) { LOG_CONSOLE(PLID, "realbot - fixed connection with falling."); LOG_MESSAGE(PLID, "realbot - fixed connection with falling."); if (pBot->bot_pathid > 0) { int iNode = NodeMachine.NodeFromPath(pBot->iIndex, (pBot->bot_pathid - 1)); float fDist = fabs(damage_origin.z - NodeMachine.node_vector(iNode).z); if (fDist > 90) { // we know where we came from, and we know where we went to int iNodeTo = NodeMachine.NodeFromPath(pBot->iIndex, pBot->bot_pathid); // remove connection NodeMachine.remove_neighbour_node(iNode, iNodeTo); } } } // ignore certain types of damage... if (damage_bits & IGNORE_DAMAGE) return; // depending on bot skill slow this bot down a bit pBot->f_move_speed *= (((10 - pBot->bot_skill) + 1) / 10); // if the bot doesn't have an enemy and someone is shooting at it then // turn in the attacker's direction... if (bots[bot_index].pBotEnemy == NULL) { // face the attacker... // Face danger vector pBot->vHead = damage_origin; pBot->vBody = damage_origin; // move to damage vector pBot->f_camp_time = gpGlobals->time; // stop camping pBot->iGoalNode = NodeMachine.getCloseNode(damage_origin, 150, NULL); pBot->bot_pathid = -1; ///////////// END STEFAN } } } }
// "trace version" console command. void cmd_trace_version(void) { LOG_CONSOLE(PLID, "%s v%s, %s", Plugin_info.name, Plugin_info.version, Plugin_info.date); LOG_CONSOLE(PLID, "by %s", Plugin_info.author); LOG_CONSOLE(PLID, " %s", Plugin_info.url); LOG_CONSOLE(PLID, "compiled: %s Eastern (%s)", COMPILE_TIME, OPT_TYPE); }
bool FuncIsBanned(const char *name, int &minutes) { FILE *file = NULL; const char *path = "AdminMod/banned.txt"; char fullpath[PATH_MAX]; char line[MAX_CONF_LEN]; char *banned = NULL, *date = NULL, *cur = NULL; time_t clock = time(NULL); tm *ltm = localtime(&clock); sup_gamedir_path(path, fullpath); LOG_CONSOLE(NULL, "path - %s", fullpath); file = fopen(fullpath, "r"); if(!file) { UTIL_LogPrintf("Unable to open banned list file '%s': %s", fullpath, strerror(errno)); return false; } for(int i = 1, j = 0; !feof(file); i++) { if(!fgets(line, sizeof(line), file)) { UTIL_LogPrintf("Unable to read %d line in file %s", i, fullpath); fclose(file); return false; } if(line[0] == '#' || line[0] == ';') continue; if(strnmatch(line, "//", 2)) continue; j = strlen(line) - 1; if(line[j] == '\n') line[j] = '\0'; banned = strtok(line, "\""); if(!banned) { UTIL_LogPrintf("Invalid parameters at line %d in file %s", i, fullpath); fclose(file); return false; } sup_del_quotes(banned); if(strcmp(banned, name) == 0) { minutes = 0; date = strtok(NULL, "\n"); for(USHORT k = 0; k < strlen(date); k++) if(date[k] != ' ' && date[k] != '\t') { STRNCPY(date, date + k, strlen(date)); break; } if(date[0] == '-') { fclose(file); return true; } cur = strtok(date, ":"); minutes += sup_str_to_int(cur) - ltm->tm_min; cur = strtok(NULL, " "); minutes += 60 * (sup_str_to_int(cur) - ltm->tm_hour); cur = strtok(NULL, ":"); minutes += 60 * 24 * (sup_str_to_int(cur) - ltm->tm_yday); cur = strtok(NULL, ":"); minutes += 60 * 24 * 30 * (sup_str_to_int(cur) - ltm->tm_year); fclose(file); if(minutes <= 0) { FuncRemoveFromBanned(banned); return false; } else return true; } } fclose(file); return false; }
// "trace list" console command. void cmd_trace_list(void) { mBOOL valid=mFALSE; int n, t; const char *arg; arg=CMD_ARGV(2); if(!strcasecmp(arg, "all") || !strcasecmp(arg, "dllapi")) { valid=mTRUE; n=0; t=0; LOG_CONSOLE(PLID, "DLLAPI routines:"); for(api_info_t *routine=&dllapi_info.pfnGameInit; routine->name; routine++) { LOG_CONSOLE(PLID, " %c %s", routine->trace ? '+' : ' ', routine->name); n++; if(routine->trace) t++; } LOG_CONSOLE(PLID, "%d DLLAPI routines, %d traced", n, t); } if(!strcasecmp(arg, "all") || !strcasecmp(arg, "newapi")) { valid=mTRUE; n=0; t=0; LOG_CONSOLE(PLID, "NEWAPI routines:"); for(api_info_t *routine=&newapi_info.pfnOnFreeEntPrivateData; routine->name; routine++) { LOG_CONSOLE(PLID, " %c %s", routine->trace ? '+' : ' ', routine->name); n++; if(routine->trace) t++; } LOG_CONSOLE(PLID, "%d NEWAPI routines, %d traced", n, t); } if(!strcasecmp(arg, "all") || !strcasecmp(arg, "engine")) { valid=mTRUE; n=0; t=0; LOG_CONSOLE(PLID, "Engine routines:"); for(api_info_t *routine=&engine_info.pfnPrecacheModel; routine->name; routine++) { LOG_CONSOLE(PLID, " %c %s", routine->trace ? '+' : ' ', routine->name); n++; if(routine->trace) t++; } LOG_CONSOLE(PLID, "%d Engine routines, %d traced", n, t); } if(!valid) { LOG_CONSOLE(PLID, "usage: trace list <type>"); LOG_CONSOLE(PLID, "where <type> is one of:"); LOG_CONSOLE(PLID, " dllapi - list all dllapi routines available for tracing"); LOG_CONSOLE(PLID, " newapi - list all newapi routines available for tracing"); LOG_CONSOLE(PLID, " engine - list all engine routines available for tracing"); LOG_CONSOLE(PLID, " all - list dllapi, newapi, engine"); } }
bool FuncRemoveFromBanned(const char *name) { FILE *file = NULL; const char *path = "AdminMod/banned.txt"; char fullpath[PATH_MAX]; char line[MAX_CONF_LEN]; char *banned = NULL; int offset = 0, cur = 0; sup_gamedir_path(path, fullpath); file = fopen(fullpath, "r+"); if(!file) { UTIL_LogPrintf("Unable to open banned list file '%s': %s", fullpath, strerror(errno)); return false; } for(int i = 1, j = 0; !feof(file); i++) { if(!fgets(line, sizeof(line), file)) { UTIL_LogPrintf("Unable to read %d line in file %s", i, fullpath); fclose(file); return false; } if(line[0] == '#' || line[0] == ';') continue; if(strnmatch(line, "//", 2)) continue; j = strlen(line) - 1; if(line[j] == '\n') line[j] = '\0'; offset = strlen(line); banned = strtok(line, "\""); if(!banned) { UTIL_LogPrintf("Invalid parameters at line %d in file %s", i, fullpath); fclose(file); return false; } sup_del_quotes(banned); LOG_CONSOLE(NULL, "banned - %s; list name - %s", banned, name); if(strcmp(banned, name) == 0) { LOG_CONSOLE(NULL, "size of offset - %d", offset); while(1) { if(fgets(line, sizeof(line), file) == NULL) { fseek(file, -(offset + 3), SEEK_CUR); fputs("\n", file); chsize(fileno(file), ftell(file)); fclose(file); return true; } if(feof(file)) break; LOG_CONSOLE(NULL, "read line - %s", line); cur = strlen(line); fseek(file, -(cur + offset + 3), SEEK_CUR); fputs(line, file); fseek(file, offset + 2, SEEK_CUR); } LOG_CONSOLE(NULL, "read line - %s", line); cur = strlen(line); fseek(file, -(cur + offset + 2), SEEK_CUR); fputs(line, file); chsize(fileno(file), ftell(file)); break; } } fclose(file); return true; }