void SV_DumpBanlist_f(){ banList_t *this; time_t aclock; time(&aclock); int i, k; char *timestr; this = banlist; if(!this) return; for(i = 0, k = 0; i < current_banindex; this++, i++){ if(this->expire == (time_t)-1 || this->expire > aclock){ if(this->guid[0] == 0) { continue; } k++; if(this->expire == (time_t)-1){ timestr = "Never"; }else{ timestr = ctime(&this->expire); timestr[strlen(timestr) -1] = 0; } Plugin_Printf("%i guid8: %s; nick: %s; expire: %s; reason: %s\n", i, this->guid, this->playername, timestr, this->reason); } } Plugin_Printf("%i Active bans\n", k); }
void G_SayCensor_Init() { fileHandle_t file; int read; badwordsList_t *this; qboolean exactmatch; char buff[24]; char line[24]; char* linept; register int i=0; Plugin_FS_SV_FOpenFileRead("badwords.txt",&file); if(!file){ Plugin_Printf("Censor_Plugin: Can not open badwords.txt for reading\n"); return; } for(i = 0; ;i++){ read = Plugin_FS_ReadLine(buff,sizeof(buff),file); if(read == 0){ Plugin_Printf("%i lines parsed from badwords.txt\n",i); Plugin_FS_FCloseFile(file); return; } if(read == -1){ Plugin_Printf("Can not read from badwords.txt\n"); Plugin_FS_FCloseFile(file); return; } Q_strncpyz(line,buff,sizeof(line)); linept = line; if(*linept == '#'){ exactmatch = qtrue; linept++; }else{ exactmatch = qfalse; } this = Plugin_Malloc(sizeof(badwordsList_t)); if(this){ this->next = badwords; this->exactmatch = exactmatch; Q_strncpyz(this->word,linept,strlen(linept)); badwords = this; } } Plugin_Printf("Censor: init complete.\n"); }
PCL int OnInit(){ // Funciton called on server initiation int size; char path[512]; //char* buffer; size_t result; char basepath[512]; Plugin_Cvar_VariableString("fs_basepath", basepath, sizeof(basepath)); snprintf(path,sizeof(path),"%s/guids.txt",basepath); FILE *file = fopen( path, "r" ); if(!file) { Plugin_Printf("guids.txt does not exist in this dir: %s\n", basepath); return; } fseek(file, 0, SEEK_END); size = ftell(file); rewind(file); buffer = Plugin_Malloc(sizeof(char) * (size + 1)); if(buffer == NULL) { Plugin_Printf("Memory error\n"); return; } memset(buffer, 0, sizeof(char) * (size + 1)); result = fread (buffer,1,size,file); if(result != size) { Plugin_Printf("Reading has resulted an error\n"); return; } //Plugin_Printf("Debug from plugin %s", buffer); fclose (file); return 0; }
PCL int OnInit(){ // Funciton called on server initiation char portstr[6]; serverport = Plugin_Cvar_VariableIntegerValue("net_port"); Com_sprintf(portstr, sizeof(portstr), "%hu", serverport); Plugin_Printf("Sourcebans plugin is ready to work\n"); return 0; }
static void Cmd_UnbanPlayer_f() { char* name; if ( Plugin_Cmd_Argc() != 2) { Plugin_Printf( "Usage: unban <guid/name>\n" ); } char* handle = Plugin_Cmd_Argv(1); char* guid = IsGUID(handle); if(guid) { name = NULL; }else{ name = handle; } if(!SV_RemoveBanFromInternalList(guid, name)) { Plugin_Printf("No such ban: %s\n", handle); } }
void SV_LoadBanlist(){ time_t aclock; time(&aclock); char buf[256]; buf[0] = 0; fileHandle_t file; int read; int error; int i; Plugin_FS_SV_FOpenFileRead(banlistfile->string,&file); if(!file){ Plugin_DPrintf("SV_ReadBanlist: Can not open %s for reading\n",banlistfile->string); return; } for(i = 0, error = 0 ;error < 32 ;i++){ read = Plugin_FS_ReadLine(buf,sizeof(buf),file); if(read == 0){ Plugin_Printf("%i lines parsed from %s, %i errors occured\n",i,banlistfile->string,error); Plugin_FS_FCloseFile(file); return; } if(read == -1){ Plugin_Printf("Can not read from %s\n",banlistfile->string); Plugin_FS_FCloseFile(file); return; } if(!*buf || *buf == '/' || *buf == '\n'){ continue; } if(!SV_ParseBanlist(buf, aclock, i+1)) error++; //Executes the function given as argument in execute } Plugin_PrintWarning("More than 32 errors occured by reading from %s\n",banlistfile->string); Plugin_FS_FCloseFile(file); }
void SV_DumpBanlist_f(){ banList_t *this; time_t aclock; time(&aclock); int i, k; char *timestr; char pid[128]; char aid[128]; this = banlist; if(!this) return; for(i = 0, k = 0; i < current_banindex; this++, i++){ if(this->expire == (time_t)-1 || this->expire > aclock){ if(this->playerid == 0) { continue; } k++; if(this->expire == (time_t)-1){ timestr = "Never"; }else{ timestr = ctime(&this->expire); timestr[strlen(timestr) -1] = 0; } Plugin_SteamIDToString(this->playerid, pid, sizeof(pid)); Plugin_SteamIDToString(this->adminsteamid, aid, sizeof(aid)); Plugin_Printf("%i playerid: %s; nick: %s; adminsteamid: %s; expire: %s; reason: %s\n", i, pid, this->playername, aid, timestr, this->reason); } } Plugin_Printf("%i Active bans\n", k); }
qboolean SV_ParseBanlistLegacy(char* line, time_t aclock, int linenumber){ banList_t *this; time_t expire = 0; time_t create = 0; char reason[128]; char guid[9]; guid[8] = 0; char playername[MAX_NAME_LENGTH]; int i; char *tmp; netadr_t adr; expire = atoi(Info_ValueForKey(line, "exp")); tmp = Info_ValueForKey(line, "create"); if(tmp && tmp[0]) { create = atoi(tmp); } tmp = Info_ValueForKey(line, "netadr"); if(tmp && tmp[0]) { Plugin_NET_StringToAdr(tmp, &adr, NA_UNSPEC); }else{ memset(&adr, 0, NA_BAD); } Q_strncpyz(reason, Info_ValueForKey(line, "rsn"), sizeof(reason)); Q_strncpyz(guid, Info_ValueForKey(line, "guid"), sizeof(guid)); Q_strncpyz(playername, Info_ValueForKey(line, "nick"), sizeof(playername)); if(expire < aclock && expire != (time_t)-1) { return qtrue; } this = banlist; if(!this) return qfalse; if(guid[7]){ for(i = 0; i < current_banindex; this++, i++){ if(Q_stricmpn(this->guid, guid, 8) == 0){ Plugin_Printf("Error: This player with GUID: %s is already banned on this server (line: %d)\n",guid, linenumber); return qfalse; } } }else{ Plugin_Printf("Error: This player has no guid (line: %d)\n",linenumber); return qfalse; //Bad entry: No Id } if(!SV_OversizeBanlistAlign()) return qfalse; this = &banlist[current_banindex]; Q_strncpyz(this->guid, guid, sizeof(this->guid)); this->expire = expire; this->created = create; Q_strncpyz(this->reason, reason, sizeof(this->reason)); Q_strncpyz(this->playername, playername, sizeof(this->playername)); this->remote = adr; current_banindex++; //Rise the array index return qtrue; }
static qboolean SV_RemoveBanFromInternalList(char* guid, char* name) { banList_t *this; int i; qboolean succ = qfalse; char* banreason; char* printnick; if(name == NULL) { name = ""; } if(guid == NULL) { guid = ""; } if(guid[0] == 0 && name[0] == 0) { return qfalse; } if(guid[0] && strlen(guid) == 32) { guid += 24; } if(guid[0] && strlen(guid) != 8) { return qfalse; } this = banlist; if(!this) return qfalse; if(!SV_ReloadBanlist()) return qfalse; for(i = 0 ; i < current_banindex; this++, i++) { if(guid[0]) { if(Q_stricmpn(guid, this->guid, 8)) { continue; } }else if(name[0]){ if(Q_stricmp(name, this->playername)) { continue; } }else{ continue; } this->expire = (time_t) 0; Plugin_RemoveBanByip(&this->remote); succ = qtrue; if(!*this->reason){ banreason = "N/A"; }else{ banreason = this->reason; } if(!*this->playername){ printnick = "N/A"; }else{ printnick = this->playername; } Plugin_Printf("Removing ban for Nick: %s, GUID: %s, Banreason: %s\n", printnick, guid, banreason); Plugin_PrintAdministrativeLog("Removing ban for Nick: %s, UID: %s, Banreason: %s\n", printnick, guid, banreason); } if(succ) SV_WriteBanlist(); return succ; }
qboolean SV_ParseBanlist(char* line, time_t aclock, int linenumber){ banList_t *this; uint64_t playerid = 0; uint64_t adminsteamid = 0; time_t expire = 0; time_t create = 0; char reason[128]; char playername[MAX_NAME_LENGTH]; int i; char *tmp; netadr_t adr; playerid = Plugin_StringToSteamID(Info_ValueForKey(line, "playerid")); adminsteamid = Plugin_StringToSteamID(Info_ValueForKey(line, "asteamid")); expire = atoi(Info_ValueForKey(line, "exp")); create = atoi(Info_ValueForKey(line, "create")); tmp = Info_ValueForKey(line, "netadr"); if(tmp && tmp[0]) { Plugin_NET_StringToAdr(tmp, &adr, NA_UNSPEC); }else{ memset(&adr, 0, NA_BAD); } Q_strncpyz(reason, Info_ValueForKey(line, "rsn"), sizeof(reason)); Q_strncpyz(playername, Info_ValueForKey(line, "nick"), sizeof(playername)); if(expire < aclock && expire != (time_t)-1) { return qtrue; } this = banlist; if(!this) return qfalse; if(playerid){ for(i = 0; i < current_banindex; this++, i++){ if(this->playerid == playerid){ Plugin_SteamIDToString(playerid, tmp, sizeof(tmp)); Plugin_Printf("Error: This player with playerid: %s is already banned on this server (line: %d)\n", tmp, linenumber); return qfalse; } } }else{ Plugin_Printf("Error: This player has no id (line: %d)\n",linenumber); return qfalse; //Bad entry: No Id } if(!SV_OversizeBanlistAlign()) return qfalse; this = &banlist[current_banindex]; this->playerid = playerid; this->adminsteamid = adminsteamid; this->expire = expire; this->created = create; Q_strncpyz(this->reason, reason, sizeof(this->reason)); Q_strncpyz(this->playername, playername, sizeof(this->playername)); this->remote = adr; current_banindex++; //Rise the array index return qtrue; }
qboolean SV_RemoveBanFromInternalList(uint64_t playerid, char* name){ banList_t *this; int i; qboolean succ = qfalse; char* banreason; char* printnick; char pid[128]; if(name == NULL) { name = ""; } if(playerid == 0 && name[0] == 0) { return qfalse; } this = banlist; if(!this) return qfalse; if(!SV_ReloadBanlist()) return qfalse; for(i = 0 ; i < current_banindex; this++, i++) { if(playerid) { if(playerid != this->playerid) { continue; } }else if(name[0]){ if(Q_stricmp(name, this->playername)) { continue; } }else{ continue; } this->expire = (time_t) 0; Plugin_RemoveBanByip(&this->remote); succ = qtrue; if(!*this->reason){ banreason = "N/A"; }else{ banreason = this->reason; } if(!*this->playername){ printnick = "N/A"; }else{ printnick = this->playername; } Plugin_SteamIDToString(this->playerid, pid, sizeof(pid)); Plugin_Printf("Removing ban for Nick: %s, PlayerID: %s, Banreason: %s\n", printnick, pid, banreason); Plugin_PrintAdministrativeLog("Removing ban for Nick: %s, PlayerID: %s, Banreason: %s\n", printnick, pid, banreason); } if(succ) SV_WriteBanlist(); return succ; }
qboolean SV_AddBanToInternalList(uint64_t playerid, uint64_t adminsteamid, char* name, netadr_t* adr, time_t expire, char* banreason) { char pid[128]; time_t aclock; if(!SV_OversizeBanlistAlign()) return qfalse; time(&aclock); banList_t *this; int i; this = banlist; if(!this) return qfalse; if(playerid == 0) { return qfalse; } if(!SV_ReloadBanlist()) return qfalse; for(i = 0 ; i < current_banindex; this++, i++){ if(playerid == this->playerid) break; } if(i == current_banindex) { current_banindex++; //Rise the array index }else{ Plugin_SteamIDToString(playerid, pid, sizeof(pid)); Plugin_Printf( "Modifying banrecord for player id: %s\n", pid); Plugin_PrintAdministrativeLog( "modified banrecord of player id: %s:", pid); } this->playerid = playerid; this->adminsteamid = adminsteamid; this->expire = expire; this->created = aclock; if(adr && adr->type != NA_BAD) { this->remote = *adr; }else{ memset(&this->remote, 0, sizeof(netadr_t)); } if(banreason) Q_strncpyz(this->reason, banreason, sizeof(this->reason)); else *this->reason = 0; if(name) Q_strncpyz(this->playername, name, sizeof(this->playername)); else *this->playername = 0; SV_WriteBanlist(); return qtrue; }