Ban system -
JessThompson - 01.12.2015
So this is my ban system now. But I would like to change it to a new on where it grabs from another table how would i do this.
Here is the query under onplayerconnect
Код:
mysql_format(mysql, query, sizeof(query),"SELECT `Pass`, `ID` FROM `players` WHERE `User` = '%e' LIMIT 1", GetUserName(playerid));
mysql_tquery(mysql, query, "SQL_Account_Check", "i", playerid);
here is the thread
Код:
forward SQL_Account_BanCheck(playerid);
public SQL_Account_BanCheck(playerid)
{
new string[70];
if(Player[playerid][AccountLocked])
{
format(string, sizeof(string), "Your account has been locked. Please head to ---");
if(Player[playerid][AccountBanned])
{
format(string, sizeof(string), "Your account is banned. Banning administrator: %s", Player[playerid][BanningAdmin]);
SendClientMessage(playerid, COLOR_ERROR, string);
format(string, sizeof(string), "Banning reason: %s", Player[playerid][BannedReason]);
SendClientMessage(playerid, COLOR_ERROR, string);
}
SendClientMessage(playerid, COLOR_ERROR, string);
SetTimerEx("KickPlayer", 1000, false, "i", playerid);
}
else if(!Player[playerid][AccountLocked])
{
TogglePlayerSpectating(playerid, false);
SetSpawnInfo(playerid, 0, Player[playerid][SkinID], SERVER_SPAWN_X, SERVER_SPAWN_Y, SERVER_SPAWN_Z, SERVER_SPAWN_A, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SetCameraBehindPlayer(playerid);
}
return true;
}
here is the table i would like it to grab from
it currently grabs from the players table but I would like it to grab the ban information from the BannedGameAccounts table
Re: Ban system -
JessThompson - 02.12.2015
help please
Re: Ban system -
Golimad - 02.12.2015
you have to change FROM `players` to FROM `BannedGameAccounts`
and fetch what you need
Re: Ban system -
PinkFloydLover - 02.12.2015
You need to re write your banning system i'm afraid, you don't need to store any of that information on the server when you have it saved in your database
why not simply just have under OnPlayerConnect:
pawn Код:
mysql_format(mysql, query, sizeof(query),"SELECT * FROM `BannedGameAccounts` WHERE `Username` = '%e' LIMIT 1", GetUserName(playerid));
mysql_tquery(mysql, query, "BanCheck", "i", playerid);
// somewhere else
forward BanCheck(playerid);
public BanCheck(playerid) {
new rows = cache_get_row_count(mysql);
if(rows) { //player is banned
Kick(playerid);
}
return 1;
}
then you can just read the data from the fields and display the ban message
Re: Ban system -
JessThompson - 02.12.2015
okay i did this
Код:
forward BanCheck(playerid);
public BanCheck(playerid) {
new rows = cache_get_row_count(mysql);
if(rows) { //player is banned
Kick(playerid);
}
else
{
TogglePlayerSpectating(playerid, false);
SetSpawnInfo(playerid, 0, Player[playerid][SkinID], SERVER_SPAWN_X, SERVER_SPAWN_Y, SERVER_SPAWN_Z, SERVER_SPAWN_A, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SetCameraBehindPlayer(playerid);
}
return 1;
}
but it spawns you in without logging in,
here is my onplayerconnect
Код:
public OnPlayerConnect(playerid)
{
new query[120];
mysql_format(mysql, query, sizeof(query),"SELECT `Pass`, `ID` FROM `players` WHERE `User` = '%e' LIMIT 1", GetUserName(playerid));
mysql_tquery(mysql, query, "SQL_Account_Check", "i", playerid);
mysql_format(mysql, query, sizeof(query),"SELECT * FROM `BannedGameAccounts` WHERE `Username` = '%e' LIMIT 1", GetUserName(playerid));
mysql_tquery(mysql, query, "BanCheck", "i", playerid);
TogglePlayerSpectating(playerid, true);
FixCameraPos(playerid);
#if defined SQL_OnPlayerConnect
return SQL_OnPlayerConnect(playerid);
#else
return false;
#endif
}
Re: Ban system -
JessThompson - 02.12.2015
okay i did this
Код:
forward BanCheck(playerid);
public BanCheck(playerid) {
new rows = cache_get_row_count(mysql);
if(rows) { //player is banned
Kick(playerid);
}
else
{
TogglePlayerSpectating(playerid, false);
SetSpawnInfo(playerid, 0, Player[playerid][SkinID], SERVER_SPAWN_X, SERVER_SPAWN_Y, SERVER_SPAWN_Z, SERVER_SPAWN_A, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
SetCameraBehindPlayer(playerid);
}
return 1;
}
but it spawns you in without logging in,
here is my onplayerconnect
Код:
public OnPlayerConnect(playerid)
{
new query[120];
mysql_format(mysql, query, sizeof(query),"SELECT `Pass`, `ID` FROM `players` WHERE `User` = '%e' LIMIT 1", GetUserName(playerid));
mysql_tquery(mysql, query, "SQL_Account_Check", "i", playerid);
mysql_format(mysql, query, sizeof(query),"SELECT * FROM `BannedGameAccounts` WHERE `Username` = '%e' LIMIT 1", GetUserName(playerid));
mysql_tquery(mysql, query, "BanCheck", "i", playerid);
TogglePlayerSpectating(playerid, true);
FixCameraPos(playerid);
#if defined SQL_OnPlayerConnect
return SQL_OnPlayerConnect(playerid);
#else
return false;
#endif
}
Re: Ban system -
PinkFloydLover - 02.12.2015
You need to spawn the player once he has logged in, not once he has been cleared from the ban check, you should spawn the player under the 'SQL_Account_Check' callback, ofcourse only after the player has logged in successfully.
Re: Ban system -
JessThompson - 02.12.2015
I tried it again but it did not work
here is my onplayerconnect
Код:
public OnPlayerConnect(playerid)
{
new query[120];
mysql_format(mysql, query, sizeof(query),"SELECT `Pass`, `ID` FROM `players` WHERE `User` = '%e' LIMIT 1", GetUserName(playerid));
mysql_tquery(mysql, query, "SQL_Account_Check", "i", playerid);
TogglePlayerSpectating(playerid, true);
FixCameraPos(playerid);
#if defined SQL_OnPlayerConnect
return SQL_OnPlayerConnect(playerid);
#else
return false;
#endif
}
here is the SQL_Account_Check fuction
Код:
public SQL_Account_Check(playerid)
{
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows)
{
cache_get_field_content(0, "Pass", Player[playerid][Pass], mysql, 129);
Player[playerid][ID] = cache_get_field_content_int(0, "ID");
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Authenticate", "{FFFFFF}Your account already exists. Please\nauthenticate by typing your password below.", "Login", "Quit");
FixCameraPos(playerid);
LoginTimer[playerid] = SetTimerEx("PendingLogin", 1000, true, "i", playerid);
LoginTimeLeft[playerid] = 30;
}
else ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registration", "{FFFFFF}Your account does not exist. Please register below\nbefore playing so your statistics save.", "Next", "Quit");
FixCameraPos(playerid);
return true;
}
here is the dialog login response
Код:
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
WP_Hash(hpass, 129, inputtext);
if(!strcmp(hpass, Player[playerid][Pass]))
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `User` = '%e' LIMIT 1", GetUserName(playerid)); // limit result to 1
mysql_tquery(mysql, query, "SQL_Account_Load", "i", playerid);
SetTimerEx("SQL_Account_BanCheck", 1000, false, "i", playerid);
KillTimer(LoginTimer[playerid]);
TextDrawShowForPlayer(playerid, ClockTD);
StartLevelingTimer(playerid);
LoginAttempt[playerid] = 0;
Logged[playerid] = true;
}
else
{
if(LoginAttempt[playerid] >= 2)
{
SetTimerEx("KickPlayer", 1000, false, "i", playerid);
SendClientMessage(playerid, COLOR_ERROR, "Too many failed login attempts!");
Logged[playerid] = false;
LoginAttempt[playerid] = 0;
}
LoginAttempt[playerid] ++;
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Authenticate", "{FFFFFF}Your account already exists. Please\nauthenticate by typing your password below.\n\nYou have entered a {F05151}incorrect{FFFFFF} password!", "Login", "Quit");
}
}
if you could show me how i would do it that would be great
Re: Ban system -
JessThompson - 02.12.2015
@PinkFloydLover or anyone else
Re: Ban system -
JessThompson - 02.12.2015
Can anyone help me with this.

+rep