PDA

View Full Version : Ban Time Please Help


Brokenbreaken
26/02/2013, 05:35 PM
I have such code.

#include <a_samp>

#define MaximalPlayers 500
#define DatabaseFile "Server.db"
#define C_RED "{FF0000}"
#define COLOR_WHITE 0xFFFFFFFF

new DB:Database;
new DBResult:DatabaseResult;
new PlayerName[MaximalPlayers][30];
new PlayerIp[MaximalPlayers][30];

main()
{
return 1;
}

public OnGameModeInit()
{
AddPlayerClass(0,0,0,0,0,0,0,0,0,0,0);
Database = db_open(DatabaseFile);
DatabaseResult = db_query(Database,"CREATE TABLE IF NOT EXISTS Bans (PlayerIp TEXT(30),PlayerBannedTime INTEGER(30),PlayerBannedAdministratorName TEXT(30),PlayerBannedReason TEXT(30),PlayerBannedDate TEXT(30))");
db_free_result(DatabaseResult);
return 1;
}

public OnGameModeExit()
{
db_close(Database);
return 1;
}

public OnPlayerConnect(playerid)
{
new String[200];
GetPlayerName(playerid,PlayerName[playerid],30);
GetPlayerIp(playerid,PlayerIp[playerid],30);
BanPlayer(playerid,3,-1,"For nothing.");
format(String,200,"SELECT * FROM Bans WHERE PlayerIp = '%s'",PlayerName[playerid],PlayerIp[playerid]);
DatabaseResult = db_query(Database,String);
if(db_num_rows(DatabaseResult))
{
db_get_field_assoc(DatabaseResult,"PlayerBannedTime",String,30);
if(strval(String) >= gettime())
{
SendClientMessage(playerid,COLOR_WHITE,">> "C_RED"You are banned from this server.");
format(String,200,">> "C_RED"Remeining time it \"%s\".",ConvertSeconds(strval(String)));
db_get_field_assoc(DatabaseResult,"PlayerBannedAdministratorName",String,30);
format(String,200,">> "C_RED"Administrator which gave ban it \"%s\".",String);
SendClientMessage(playerid,COLOR_WHITE,String);
db_get_field_assoc(DatabaseResult,"PlayerBannedReason",String,30);
format(String,200,">> "C_RED"Reason of ban is \"%s\".",String);
SendClientMessage(playerid,COLOR_WHITE,String);
db_get_field_assoc(DatabaseResult,"PlayerBannedDate",String,30);
format(String,200,">> "C_RED"Date of getting ban it \"%s\".",String);
SendClientMessage(playerid,COLOR_WHITE,String);
Kick(playerid);
}
}
db_free_result(DatabaseResult);
return 1;
}

stock BanPlayer(PlayerId,Days,AdministratorId,Reason[])
{
new String[200];
new Year;
new Month;
new Day;
getdate(Year,Month,Day);
new Hour;
new Minute;
new Second;
gettime(Hour,Minute,Second);
format(String,200,"%02d.%02d.%02d %02d:%02d:%02d",Day,Month,Year,Hour,Minute,Second);
format(String,200,"INSERT INTO Bans (PlayerIp,PlayerBannedTime,PlayerBannedAdministrat orName,PlayerBannedReason,PlayerBannedDate) VALUES ('%s','%d','%s','%s','%s')",PlayerIp[PlayerId],gettime() + Days * 60 * 60 * 24,PlayerName[AdministratorId],Reason,String);
DatabaseResult = db_query(Database,String);
db_free_result(DatabaseResult);
if(IsPlayerConnected(AdministratorId)) format(String,200,">> "C_RED"Player %s (%d) has been banned by administator %s (%d). Reason: %s",PlayerName[PlayerId],PlayerId,PlayerName[AdministratorId],AdministratorId,Reason);
if(!IsPlayerConnected(AdministratorId)) format(String,200,">> "C_RED"Player %s (%d) has been banned. Reason: %s",PlayerName[PlayerId],PlayerId,Reason);
SendClientMessageToAll(COLOR_WHITE,String);
Kick(PlayerId);
return 1;
}

ConvertSeconds(Seconds)
{
new String[200];
new Minutes;
new Hours;
new Days;
if(Seconds > 59)
{
Minutes = Seconds / 60;
Seconds = Seconds - Minutes * 60;
}
if(Minutes > 59)
{
Hours = Minutes / 60;
Minutes = Minutes - Hours * 60;
}
if(Hours > 23)
{
Days = Hours / 24;
Hours = Hours - Days * 24;
}
format(String,200,"%d days, %d hours, %d minutes, %d seconds",Days,Hours,Minutes,Seconds);
return String;
}

If i join to server i dont be banned (Look OnPlayerConnected - BanPlayer(playerid,3,-1,"For nothing.");
How to fix it?

Brokenbreaken
26/02/2013, 07:28 PM
Ok i found problem.

//OnPlayerConnect
print("ss");
BanPlayer(playerid,3,-1,"nnc");
print("ss");

In console:

ss


And this function:

stock BanPlayer(PlayerId,Days,AdministratorId,Reason[])
{
new String[200];
new Year;
new Month;
new Day;
getdate(Year,Month,Day);
new Hour;
new Minute;
new Second;
gettime(Hour,Minute,Second);
format(String,200,"%02d.%02d.%02d %02d:%02d:%02d",Day,Month,Year,Hour,Minute,Second);
format(String,200,"INSERT INTO Bans (PlayerIp,PlayerBannedTime,PlayerBannedAdministrat orName,PlayerBannedReason,PlayerBannedDate) VALUES('%s','%d','%s','%s','%s')",PlayerIp[PlayerId],gettime() + Days * 60 * 60 * 24,PlayerName[AdministratorId],Reason,String);
DatabaseResult = db_query(Database,String);
db_free_result(DatabaseResult);
if(IsPlayerConnected(AdministratorId)) format(String,200,">> "C_RED"Player %s (%d) has been banned by administator %s (%d). Reason: %s",PlayerName[PlayerId],PlayerId,PlayerName[AdministratorId],AdministratorId,Reason);
if(!IsPlayerConnected(AdministratorId)) format(String,200,">> "C_RED"Player %s (%d) has been banned. Reason: %s",PlayerName[PlayerId],PlayerId,Reason);
SendClientMessageToAll(COLOR_WHITE,String);
Kick(PlayerId);
return 1;
}

Any idea?