Ban Check
#1

So I've recently started working on an old gamemode of mine, that I halted development on, and I came across one problem. When I start up SA-MP and connect to my server, the screen looks something like this...



What I'm trying to make the server do is to check a folder to see if there are any bans associated with a connecting player. If there is a ban associated then the player will be kicked and notified of why they were banned in the first place. If there aren't any bans, then the player will be let in and welcomed.

It just hangs there like that forever. Here's the code of my OnPlayerConnect which is where I believe the problem lies...

pawn Код:
public OnPlayerConnect(playerid)
{
    new banfile[64], ipstring[32], string[128];
    SendClientMessage(playerid, COLOR_DEADCONNECT, "|_Ban Check Started_|");
    SendClientMessage(playerid, COLOR_YELLOW, "Checking for bans...");
    GetPlayerIp(playerid, ipstring, sizeof(ipstring));
    format(banfile, sizeof(banfile),"SArcr/Users/Bans/%s.ban", ipstring);
    if(DOF2_FileExists(banfile))
    {
        new banmsg[128];
        if(!strcmp(DOF2_GetString(banfile, "BanName"), PlayerName(playerid), true))
        {
            SendClientMessage(playerid, COLOR_YELLOW, "====================================BANNED=====================================");
            SendClientMessage(playerid, COLOR_YELLOW, "This player name has been banned from [Sarcr]");
            format(banmsg, sizeof(banmsg), "Date of Ban: %s", dUser(PlayerName(playerid)).("BanDate"));
            SendClientMessage(playerid, COLOR_YELLOW, banmsg);
            format(banmsg, sizeof(banmsg), "Time of Ban: %s", dUser(PlayerName(playerid)).("BanTime"));
            SendClientMessage(playerid, COLOR_YELLOW, banmsg);
            format(banmsg, sizeof(banmsg), "Banned By: %s", dUser(PlayerName(playerid)).("BannedBy"));
            SendClientMessage(playerid, COLOR_YELLOW, banmsg);
            format(banmsg, sizeof(banmsg), "Banned For: %s", dUser(PlayerName(playerid)).("BanReason"));
            SendClientMessage(playerid, COLOR_YELLOW, banmsg);
            SendClientMessage(playerid, COLOR_YELLOW, "If you feel that this ban is a mistake, please make an appeal at www.sa-rcr.com");
            SendClientMessage(playerid, COLOR_YELLOW, "===============================================================================");
            Kick(playerid);
        }
        else
        {
            SendClientMessage(playerid, COLOR_YELLOW, "====================================BANNED=====================================");
            SendClientMessage(playerid, COLOR_YELLOW, "This IP Address has been banned from [Sarcr]");
            format(banmsg, sizeof(banmsg), "Date of Ban: %s", dUser(PlayerName(playerid)).("BanDate"));
            SendClientMessage(playerid, COLOR_YELLOW, banmsg);
            format(banmsg, sizeof(banmsg), "Time of Ban: %s", dUser(PlayerName(playerid)).("BanTime"));
            SendClientMessage(playerid, COLOR_YELLOW, banmsg);
            format(banmsg, sizeof(banmsg), "Banned By: %s", dUser(PlayerName(playerid)).("BannedBy"));
            SendClientMessage(playerid, COLOR_YELLOW, banmsg);
            format(banmsg, sizeof(banmsg), "Banned For: %s", dUser(PlayerName(playerid)).("BanReason"));
            SendClientMessage(playerid, COLOR_YELLOW, banmsg);
            SendClientMessage(playerid, COLOR_YELLOW, "If you feel that this ban is a mistake, please make an appeal at www.sa-rcr.com");
            SendClientMessage(playerid, COLOR_YELLOW, "===============================================================================");
            Kick(playerid);
        }
        return 1;
    }
    if(udb_Exists(PlayerName(playerid)))
    {
        if(dUserINT(PlayerName(playerid)).("Banned") == 1)
        {
            SendClientMessage(playerid, COLOR_YELLOW, "====================================BANNED=====================================");
            SendClientMessage(playerid, COLOR_YELLOW, "This player name has been banned from [Sarcr]");
            SendClientMessage(playerid, COLOR_YELLOW, "The data regarding this ban is unavailable.");
            SendClientMessage(playerid, COLOR_YELLOW, "If you feel that this is a mistake, please write an appeal at www.sa-rcr.com");
            SendClientMessage(playerid, COLOR_YELLOW, "===============================================================================");
            Kick(playerid);
        }
        ShowLoginScreen(playerid);
    }
    else if(!udb_Exists(PlayerName(playerid)))
    {
        ShowRegisterScreen(playerid);
    }
    SendClientMessage(playerid, COLOR_DEADCONNECT, "|_Ban Check Complete_|");
    SendClientMessage(playerid, COLOR_GREEN, "No Bans were found");
    new name[24], str[128];
    GetPlayerName(playerid, name, 24);
    ircSay(EchoConnection, EchoChan,str);
    format(str, 128, "%s(%d) Has Joined San Andreas Roleplay/Cops/Robbers v%s", name,playerid,sversion);
    SendClientMessageToAll(0x808080AA, str);
    printf("%s(%d) Has Joined San Andreas Roleplay/Cops/Robbers v%s (IP: %s)", str,playerid,sversion,ipstring);
    InShamal[playerid] = 0;
    SetPlayerColor(playerid,COLOR_DEADCONNECT);
    SetPlayerVirtualWorld(playerid,0);
    format(string, sizeof(string), "San Andreas Roleplay/Cops/Robbers - Script Version %s",sversion);
    SendClientMessage(playerid,COLOR_WHITE, string);
    SendClientMessage(playerid,0x87CEEBAA, "This is NOT a deathmatch server. Do not randomly kill players");
    SendClientMessage(playerid,0x87CEEBAA, "Visit our website to report bugs/suggestions/complaints etc");
    SendClientMessage(playerid,0x87CEEBAA, "There is a full list of commands/rules and other information on our website" );
    SendClientMessage(playerid,0x87CEEBAA, "Visit our website at www.sa-rcr.com");
    //little variables that I deleted just now so that you can have an easier time reading :P
    return 1;
}
Anything to note?
  • I'm using Double-O-Files 2 for any file reading type stuff.
  • Please excuse my not-so-professional-sounding self since it's been awhile (7 days short of a year to be precise).
Any help is greatly appreciated c:
Reply
#2

This bans system is yours?

If you like, you can use this > VBan
Reply
#3

Use print every couple of lines to debug that code and determine where it freezes. Every couple of lines put
pawn Код:
print("1");
//......
print("2");
Then tell us what line of code it stops on.
Reply
#4

So after a bit of narrowing things down, I've got it down to these lines...
pawn Код:
new banfile[64], ipstring[32], string[128];
    SendClientMessage(playerid, COLOR_DEADCONNECT, "|_Ban Check Started_|");
    SendClientMessage(playerid, COLOR_YELLOW, "Checking for bans...");
    GetPlayerIp(playerid, ipstring, sizeof(ipstring));
    format(banfile, sizeof(banfile),"SArcr/Users/Bans/%s.ban", ipstring);
It doesn't even call
pawn Код:
if(DOF2_FileExists(banfile))
:L
Reply
#5

Does the server console crash? If it does, make sure that the directory that you're trying to check exists. Sa-mp doesn't like directories that don't exist and it will crash most of the time. Make sure that you have the folder SArcr in script files, inside that has to be Users and inside that has to be Bans.
Reply
#6

The server console doesn't crash, it just shows that I've connected and it stays like that forever. I can't even send chat messages either. The directories are perfect down to every last capitalization.
Reply
#7

Note that file- and directory names are case sensitive on Linux systems (doesn't matter in Windows).
Reply
#8

I've been looking at it and I still can't figure out why nothing will work. And thanks for the tip Vince.

***EDIT***
I'll try using VBan and see how that goes. Thanks for the help everyone
Reply
#9

I'm pretty sure that I'm bumping this but I found the lines directly associated with my problem.
pawn Код:
else if(udb_Exists(PlayerName(playerid)))
    {
        if(dUserINT(PlayerName(playerid)).("Banned") == 1)
        {
            SendClientMessage(playerid, COLOR_YELLOW, "===================================[BANNED]====================================");
            SendClientMessage(playerid, COLOR_YELLOW, "This player name has been banned from [Sarcr]");
            SendClientMessage(playerid, COLOR_YELLOW, "The data regarding this ban is unavailable.");
            SendClientMessage(playerid, COLOR_YELLOW, "If you feel that this is a mistake, please write an appeal at www.sa-rcr.com");
            SendClientMessage(playerid, COLOR_YELLOW, "===============================================================================");
            Kick(playerid);
        }
        ShowLoginScreen(playerid);
        return 1;
    }
    else if(!udb_Exists(PlayerName(playerid)))
    {
        ShowRegisterScreen(playerid);
        return 1;
    }
Those lines from my OnPlayerConnect that cause the freeze (neither the console, nor the game freeze/crash/etc. [the gamemode just won't continue to load anything after saying that a ban check was started]). When "ignored" (not sure how to say it but when you do the /* and */) the script works, but I'm unable to log in and I'm not able to use the chat or any commands. According to my OnPlayerText, chat isn't blocked whether one is logged in or not. Currently, I'm making a /login command and a /register command to check and make sure that the login and register functions are working.
Reply
#10

Maybe, your script is having trouble connecting to the database to check the bans?
Reply
#11

Quote:
Originally Posted by Oscii
View Post
Maybe, your script is having trouble connecting to the database to check the bans?
You could be right, but from what I can remember, I didn't really change any coding in those lines much other than setting it up so that it would show the Login and Register dialog box based on whether the user was registered or not.
Reply
#12

Bump.
Reply
#13

Well i have had that problem when it hangs on connect while checking the players bantime and it had to do with Kick(playerid); bug. Comment it off once. I aint saying that is the problem but its worth a try.
Reply
#14

Quote:
Originally Posted by nickdodd25
View Post
Well i have had that problem when it hangs on connect while checking the players bantime and it had to do with Kick(playerid); bug. Comment it off once. I aint saying that is the problem but its worth a try.
Just tried that, commented out all of the 'Kicks' and it was still hanging there forever. I'm pretty sure that it has more to do with these lines:
pawn Code:
else if(udb_Exists(PlayerName(playerid)))
    {
        if(dUserINT(PlayerName(playerid)).("Banned") == 1)
        {
            SendClientMessage(playerid, COLOR_YELLOW, "===================================[BANNED]====================================");
            SendClientMessage(playerid, COLOR_YELLOW, "This player name has been banned from [Sarcr]");
            SendClientMessage(playerid, COLOR_YELLOW, "The data regarding this ban is unavailable.");
            SendClientMessage(playerid, COLOR_YELLOW, "If you feel that this is a mistake, please write an appeal at www.sa-rcr.com");
            SendClientMessage(playerid, COLOR_YELLOW, "===============================================================================");
            Kick(playerid);
        }
        ShowLoginScreen(playerid);
        return 1;
    }
    else if(!udb_Exists(PlayerName(playerid)))
    {
        ShowRegisterScreen(playerid);
        return 1;
    }
If I comment out those lines, then I'm able to spawn but any other command aside from SA-MPs native commands, don't work.
Reply
#15

Quote:
Originally Posted by PCheriyan007
View Post
Just tried that, commented out all of the 'Kicks' and it was still hanging there forever. I'm pretty sure that it has more to do with these lines:
pawn Code:
else if(udb_Exists(PlayerName(playerid)))
    {
        if(dUserINT(PlayerName(playerid)).("Banned") == 1)
        {
            SendClientMessage(playerid, COLOR_YELLOW, "===================================[BANNED]====================================");
            SendClientMessage(playerid, COLOR_YELLOW, "This player name has been banned from [Sarcr]");
            SendClientMessage(playerid, COLOR_YELLOW, "The data regarding this ban is unavailable.");
            SendClientMessage(playerid, COLOR_YELLOW, "If you feel that this is a mistake, please write an appeal at www.sa-rcr.com");
            SendClientMessage(playerid, COLOR_YELLOW, "===============================================================================");
            Kick(playerid);
        }
        ShowLoginScreen(playerid);
        return 1;
    }
    else if(!udb_Exists(PlayerName(playerid)))
    {
        ShowRegisterScreen(playerid);
        return 1;
    }
If I comment out those lines, then I'm able to spawn but any other command aside from SA-MPs native commands, don't work.
Guess your best bet is use Print("Debug"); between every line on that part and see where it stops. Could have somthing to do with your file system. I only know how to use y_ini so far not double-o-files.
Also show us
pawn Code:
ShowLoginScreen(playerid);
Mabe its somthing in that.
Reply
#16

Quote:
Originally Posted by nickdodd25
View Post
Guess your best bet is use Print("Debug"); between every line on that part and see where it stops. Could have somthing to do with your file system. I only know how to use y_ini so far not double-o-files.
Also show us
pawn Code:
ShowLoginScreen(playerid);
Mabe its somthing in that.
pawn Code:
stock ShowLoginScreen(playerid)
{
    new string[128];
    format(string, sizeof(string), "Welcome back %s\nBefore playing you must login\nEnter your password below and click login",PlayerName(playerid));
    ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login required",string,"Login","Cancel");
}

stock ShowRegisterScreen(playerid)
{
    new string[128];
    format(string, sizeof(string), "Welcome to the server %s\nThis server requires you to register an account before playing",PlayerName(playerid));
    ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Registration",string,"Register","Cancel");
}
Reply
#17

Okay, the server is fixed, thank you all for your assistance.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)