void Cvar_Search_f (void) { cvar_t *var; if (Cmd_Argc() != 2) { Com_Printf("Usage: cvarsearch <variable>\n"); return; } for (var = cvar_vars; var; var = var->next) { if (Q_strisub(var->name, Cmd_Argv(1))) { if (Q_stricmp(var->string, var->resetString)) { Com_Printf(S_COLOR_YELLOW "%s " S_COLOR_WHITE "'%s" S_COLOR_WHITE "' [default='" S_COLOR_CYAN "%s" S_COLOR_WHITE "']\n", var->name, var->string, var->resetString); } else { Com_Printf(S_COLOR_YELLOW "%s " S_COLOR_WHITE "'%s" S_COLOR_WHITE "'\n", var->name, var->string); } } } }
/* ================== SV_GetPlayerByHandle Returns the player with player id or name from Cmd_Argv(1) ================== */ static client_t *SV_GetPlayerByHandle(void) { char *s; char name[64]; int count = 0; int i, idnum; client_t *cl; client_t *matches[MAX_CLIENTS]; // make sure server is running if (!com_sv_running->integer) { return NULL; } if (Cmd_Argc() < 2) { Com_Printf("No client specified\n"); return NULL; } s = Cmd_Argv(1); // check whether this is a numeric player handle for (i = 0; s[i] >= '0' && s[i] <= '9'; i++); if (!s[i]) { // numeric player handle given as input idnum = atoi(s); if ((idnum < 0) || (idnum >= sv_maxclients->integer)) { Com_Printf("Bad client slot: %i\n", idnum); return NULL; } cl = &svs.clients[idnum]; if (!cl->state) { Com_Printf("Client in slot %i is not connected\n", idnum); return NULL; } return cl; } else { // full/partial player name given as input for (i = 0; i < sv_maxclients->integer ; i++) { cl = &svs.clients[i]; // client is not connected if (!cl->state) { continue; } strcpy(name, cl->name); Q_CleanStr(name); // check for exact match if (!Q_stricmp(name,s)) { matches[0] = &svs.clients[i]; count = 1; break; } // check for substring match if (Q_strisub(name, s)) { matches[count] = &svs.clients[i]; count++; } } if (count == 0) { // no match found for the given input string Com_Printf("No client found matching %s\n", s); return NULL; } else if (count > 1) { // multiple matches found for the given string Com_Printf("Multiple clients found matching %s:\n", s); for (i = 0; i < count; i++) { cl = matches[i]; strcpy(name, cl->name); Com_Printf(" %2d: [%s]\n", (int)(cl - svs.clients), name); } return NULL; } // found just 1 match return matches[0]; } }
///////////////////////////////////////////////////////////////////// // Name : SV_GetMapSoundingLike // Description : Retrieve a full map name given a substring of it // Author : Fenix, p5yc0runn3r ///////////////////////////////////////////////////////////////////// static char *SV_GetMapSoundingLike(const char *s) { int i, mapcount; int len = 0, count = 0; char *matches[MAX_MAPLIST_SIZE]; char *searchmap; static char maplist[MAX_MAPLIST_STRING]; // [BUGFIX]: instead of iterating through all the maps matching both full and // partial name, search just for the exact map name and return it if the match is found Com_sprintf(maplist, sizeof(maplist), "maps/%s.bsp", s); if (FS_ReadFile(maplist, NULL) > 0) { Com_sprintf(maplist, sizeof(maplist), "%s", s); return maplist; // @p5yc0runn3r: Return static string } // We didn't found an exact name match. Keep iterating through all the // available maps matching partial substrings if (!(mapcount = FS_GetFileList("maps", ".bsp", maplist, sizeof(maplist)))) { Com_Printf("Unable to retrieve map list\n"); return NULL; } for (searchmap = maplist, i = 0; i < mapcount && count < MAX_MAPLIST_SIZE; i++, searchmap += len + 1) { len = strlen(searchmap); SV_StripExtension(searchmap, searchmap); // Check for substring match if (Q_strisub(searchmap, s)) { matches[count] = searchmap; count++; } } // One match = one map, found match. if (count == 1) return matches[0]; // @p5yc0runn3r: matches points to static string, safe to return. if (count > 1) { // Multiple matches found for the given map name Com_Printf("Multiple maps found matching '%s':\n", s); // Sorting the short map list alphabetically qsort(matches, count, sizeof(char *), SV_SortMaps); for (i = 0; i < count; i++) { // Printing a short map list so the user can retry with a more specific name Com_Printf(" %2d: [%s]\n", i + 1, matches[i]); } if (count >= MAX_MAPLIST_SIZE) { // Tell the user that there are actually more // maps matching the given substring, although // we are not displaying them.... Com_Printf("...and more\n"); } return NULL; } // No match found for the given map name input Com_Printf("No map found matching '%s'\n", s); return NULL; }