saving ip in mysql database -
swredder - 12.05.2010
Hello, I've been having a very irritating problem for a few days now.
I'm using the incognito mysql plugin to store IP addresses in a database (together with username, etc).
It works perfectly to store the username, reason etc into the database, but the IP address is not giving the right result.
I have two files, a filterscript and an .inc file.
Filterscript:
Код:
new
PIP[16],
giveid,
hour,
minute,
second,
year,
month,
day;
GetPlayerIp(giveid, PIP, sizeof(PIP));
gettime(hour, minute, second);
getdate(year, month, day);
gSQL_BanUser(PlayerName(giveid), PlayerName(playerid), params[idx], PIP, hour, minute, second, day, month, year);
Include
Код:
stock gSQL_BanUser(nickname[], Admin[], Reason[], IP[], hour, minute, second, day, month, year)
{
new
sTmp[256],
sqlcmd[256+128];
strcat(sqlcmd, "INSERT INTO `" #MYSQL_DB "`.`" #MYSQL_BAN_TABLE "` (",sizeof(sqlcmd));
strcat(sqlcmd,"`Name` ,`Admin`,`Reason`,`IP`,`TIME`,`DATE`)",sizeof(sqlcmd));
format(sTmp, sizeof(sTmp), "INSERT INTO Banlijst(Name, Admin, Reason,IP,Time,Date) VALUES ('%s' , '%s', '%s', '%s', '%d:%d:%d', '%d.%d.%d')", nickname, Admin, Reason,IP, hour, minute, second, day, month, year);
strcat(sqlcmd, sTmp,sizeof(sqlcmd));
if(samp_mysql_query(sTmp)) {
sTmp[0]='\0';
format(sTmp, sizeof(sTmp), "User %s banned!", nickname);
Log(sTmp);
}
return 1;
}
The output:
I really hope someone knows how to fix this.
Re: saving ip in mysql database -
Kyosaur - 12.05.2010
Is the field type for IP set to varchar with a length of 16 or greater ?
Re: saving ip in mysql database -
swredder - 12.05.2010
i didnt copied the full command by accident:
Код:
COMMAND:ban(playerid,params[]) {
if(PlayerInfo[playerid][AdminLevel] >= g_Level[lban]) {
new pip[16],
giveid,
msg[128];
if (sscanf(params, "uz",giveid,msg)) {
return SendClientFormatMessage(playerid,COLOR_SYSTEM,"%s: /ban [Player / ID] [Reason (optional)]",GetLanguageString(GetPlayerLanguageID(playerid),"txt_icommands"));
}
else if(!IsPlayerConnected(giveid)) {
return SendClientLanguageMessage(playerid,COLOR_RED2,"txt_InvalidID");
}
else if(giveid==playerid) {
return SendClientLanguageMessage(playerid,COLOR_RED,"txt_selfslct");
}
else {
if(PlayerInfo[playerid][AdminLevel]>PlayerInfo[giveid][AdminLevel]){
new TheBannedPlayer[MAX_PLAYER_NAME];
GetPlayerName(giveid,TheBannedPlayer,sizeof(TheBannedPlayer));
SetPlayerPos(giveid,2746.9270,-2092.9146,26.35164);
SetPlayerCameraPos(giveid,2748.8640,-2093.9651,25.2624);
SetPlayerCameraLookAt(giveid,2740.6001,-2089.9341,27.6800);
SetPlayerFacingAngle(giveid, 61.4775);
SendClientLanguageMessage(giveid,COLOR_RED2,"txt_ban1",msg[0] ? msg : ("<No reason>"));
CreateClientLanguageMessages("txt_ban2",TheBannedPlayer,giveid,PlayerName(playerid),msg[0] ? msg : ("<No reason>"));
SendAdminCommand(COLOR_YELLOW);
WriteLog(clearlog,LanguageString(ServerLanguage()));
#if defined MYSQL
tmpp = strtok(params, idx);
GetPlayerName(giveid, pidName, sizeof(pidName));
GetPlayerName(playerid, AdminName, sizeof(AdminName));
GetPlayerIp(giveid,pip,sizeof(pip));
gettime(hour2, minute2, second2);
getdate(year2, month2, day2);
GetPlayerName(giveid, pidName, sizeof(pidName));
GetPlayerName(playerid, AdminName, sizeof(AdminName));
gSQL_BanUser(PlayerName(giveid),PlayerName(playerid),params[idx],pip[15], hour2, minute2, second2, day2, month2, year2);
#else
dUserSetINT(TheBannedPlayer).("Trusted",-1); // Remove from Trusted
#endif
return BanEx2(giveid,13);
}
else {
SendClientLanguageMessage(playerid,COLOR_RED,"txt_ban3");
return SendClientLanguageMessage(giveid,COLOR_RED2,"txt_ban4",PlayerName(playerid));
}
}
}
else {
SendClientLanguageMessage(playerid,COLOR_LIGHTBLUE,"txt_error404");
}
return 1;
}