Beispiel #1
0
void SV_WriteBanlist(){

    banList_t *this;
    time_t aclock;
    time(&aclock);
    fileHandle_t file;
    char infostring[1024];
    char buf[1024];
    int i;


    file = Plugin_FS_SV_FOpenFileWrite(va("%s.tmp", banlistfile->string));
    if(!file){
        Plugin_PrintError("SV_WriteBanlist: Can not open %s for writing\n",banlistfile->string);
        return;
    }

    this = banlist;
    if(!this)
        return;

    for(i = 0 ; i < current_banindex; this++, i++){

        if(this->expire == (time_t)-1 || this->expire > aclock){

            *infostring = 0;
            if(this->playerid == 0)
            {
                continue;
            }
            Plugin_SteamIDToString(this->playerid, buf, sizeof(buf));
            Info_SetValueForKey(infostring, "playerid", buf);
            Plugin_SteamIDToString(this->adminsteamid, buf, sizeof(buf));
            Info_SetValueForKey(infostring, "asteamid", buf);
            Info_SetValueForKey(infostring, "nick", this->playername);
            Info_SetValueForKey(infostring, "rsn", this->reason);
            Info_SetValueForKey(infostring, "exp", va("%i", (int)this->expire));
            Info_SetValueForKey(infostring, "create", va("%i", (int)this->created));
            if(this->remote.type > NA_BAD)
            {
              Info_SetValueForKey(infostring, "netadr", Plugin_NET_AdrToStringShortMT(&this->remote, buf, sizeof(buf)));
            }
            Q_strcat(infostring, sizeof(infostring), "\\\n");
            Plugin_FS_Write(infostring,strlen(infostring),file);
        }
    }
    Plugin_FS_FCloseFile(file);
    Plugin_FS_SV_HomeCopyFile(va("%s.tmp", banlistfile->string) ,banlistfile->string);
//    FS_SV_Rename(va("%s.tmp", banlist->string),banlist->string);
}
Beispiel #2
0
int SV_InitBanlist(){

    banlistfile = Plugin_Cvar_RegisterString("banlist_filename", "banlist_v2.dat", CVAR_INIT, "Name of the file which holds the banlist");
    current_banlist_size = BANLIST_DEFAULT_SIZE;
    current_banindex = 0;
    banlist = realloc(NULL, current_banlist_size);//Test for NULL ?
    if(banlist){
        SV_LoadBanlist();
    }else{
        Plugin_PrintError("Failed to allocate memory for the banlist. Banlist is disabled\n");
        return -1;
    }
    Plugin_AddCommand("dumpbanlist", SV_DumpBanlist_f, 30);
    return 0;
}
qboolean SV_OversizeBanlistAlign(){

    banList_t *new_blist;
    int newSize;

    if(current_banlist_size <= (current_banindex + 1) * sizeof(banList_t)){//Memory extension
        newSize = current_banlist_size + current_banlist_size / 4;
        new_blist = realloc(banlist, newSize);
        if(new_blist){
            banlist = new_blist;
            current_banlist_size = newSize;

        }else{
            Plugin_PrintError("Could not allocate enougth memory to extend the size of banlist. Failed to add new bans\n");
            return qfalse;
        }
    }
    return qtrue;
}