PDA

View Full Version : Not added to mysql



Ni3ls
22nd June 2016, 16:18
Hi all,

I want to make a banlist using mysql


guidbanplayer(admin, reason, id, guid)
{
maps\mp\gametypes\_mysql::asyncQuery("INSERT INTO ban_guid_sd (guid, name, reason, admin) VALUES (" + guid + ", " + maps\mp\gametypes\_mysql::stripString(self.name) + "," + maps\mp\gametypes\_mysql::stripString(reason) + "," + maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"]) + ")");
printf("GUID ban added to database2!\n");
printf("guid "+guid+ "\n");
printf("name "+maps\mp\gametypes\_mysql::stripString(self.name)+ "\n");
printf("reason "+maps\mp\gametypes\_mysql::stripString(reason)+ "\n");
printf("admin "+maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"])+ "\n");

}
the table name is ban_guid_sd
the printf are shown correct

However, the record is not added to the table.
Im connected to the database

initMySQL(host, user, pass, db, port)
{
mysql = mysql_init();
ret = mysql_real_connect(mysql, host, user, pass, db, port);
if(!ret)
{
printf("errno=" + mysql_errno(mysql) + " error= " + mysql_error(mysql) + "\n");
mysql_close(mysql);
return undefined;
}
else
printf("Connected to database!\n");
return mysql;
}
I see the message "Connected to database"

What is wrong?

IzNoGoD
22nd June 2016, 16:46
Init your async mysql, not just your mysql.

Also: put ' around your strings.

Ni3ls
22nd June 2016, 16:57
Init your async mysql, not just your mysql.

Also: put ' around your strings.
Already done

initAsyncMySQL(host, user, pass, db, port)
{
mysql_async_initializer(host, user, pass, db, port, 4);
level.mysqlAsync = [];
thread loopAsyncMySQL();
}

And do you mean this?

maps\mp\gametypes\_mysql::asyncQuery("INSERT INTO ban_guid_sd ('guid', 'name', 'reason', 'admin') VALUES (" + guid + ", " + maps\mp\gametypes\_mysql::stripString(self.name) + "," + maps\mp\gametypes\_mysql::stripString(reason) + "," + maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"]) + ")");

IzNoGoD
22nd June 2016, 18:21
no, like this


maps\mp\gametypes\_mysql::asyncQuery("INSERT INTO ban_guid_sd (guid, name, reason, admin) VALUES ('" + guid + "', '" + maps\mp\gametypes\_mysql::stripString(self.name) + "', '" + maps\mp\gametypes\_mysql::stripString(reason) + "', '" + maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"]) + "')");

Ni3ls
22nd June 2016, 18:53
Working with iznogods fix!

Ni3ls
16th August 2016, 14:21
maps\mp\gametypes\_mysql::asyncQuery("INSERT INTO sd_bans_ip (ip, name, reason, admin) VALUES ('" + ip + "', '" + maps\mp\gametypes\_mysql::stripString(self.name) + "', '" + maps\mp\gametypes\_mysql::stripString(reason) + "', '" + maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"]) + "')");

printf("IP ban added to database sd_bans_ip!\n");
printf("ip "+ip+ "\n");
printf("name "+maps\mp\gametypes\_mysql::stripString(self.name)+ "\n");
printf("reason "+maps\mp\gametypes\_mysql::stripString(reason)+ "\n");
printf("admin "+maps\mp\gametypes\_mysql::stripString(admin.pers["loginname"])+ "\n");

It doesnt work with IP?
Everything is printed correctly.
IP in mysql is int(11)
rest are strings

Paho
16th August 2016, 15:49
I'm use varchar(16)

sql = "INSERT INTO `sd_bans_ip` (`IP`) VALUES ('" + self getIP() + "')";
mysql_query(level.mysql, sql);

Mitch
16th August 2016, 15:55
It doesnt work with IP?
Everything is printed correctly.
IP in mysql is int(11)
rest are strings
libcod processes the IP like this:

snprintf(tmp, 64, "%d.%d.%d.%d", ip_a, ip_b, ip_c, ip_d);
stackPushString(tmp);

IzNoGoD
16th August 2016, 16:41
You should use INET_ATON('" + stripstring(self getip()) + "')"

Ni3ls
17th August 2016, 08:02
You should use INET_ATON('" + stripstring(self getip()) + "')"

And how do I check if an IP is banned?

Mitch
17th August 2016, 09:06
And how do I check if an IP is banned?

When the result is 1 then the IP is banned otherwise not banned (e.g. no results).

SELECT 1 FROM bans WHERE ip = INET_ATON('" + stripstring(self getip()) + "') LIMIT 1

Edit: you can also return the fields (ip, name, reason, admin) for showing the kick message.

Ni3ls
17th August 2016, 11:01
Okay thanks. Switching the int in mysql to varchar did the trick

Ni3ls
28th August 2016, 12:27
Sorry to bump, but whats the main difference between inet_atom and storing the ip?


inet_aton() converts the Internet host address cp from the IPv4 numbers-and-dots notation into binary form (in network byte order) and stores it in the structure that inp points to. inet_aton() returns nonzero if the address is valid, zero if not.

Is there performance improvements or does it not affect ip changes?

Whiskas
28th August 2016, 13:31
Even with few manipulations (inet functions) IP is the same, but it's stored as number.

Single IP with inet_aton can be saved in database as an integer in 4 bytes.

If you would like to save an IP as varchar you would need to use varchar(15). If the charset of the text is ASCII it store 15 x 1 byte + 1 byte to save maximum length of text.

Note: Even if ip would be 1.2.3.4, varchar uses maximum size it has (16 bytes)

Conclusion: Each stored IP is 4 times larger when using varchar.

Performance? More data more reading.

If I'm wrong, correct me xD.

serthy
28th August 2016, 14:02
But I doubt it would have any noticable perfomance impact using strings over ints in CoD2

Whiskas
28th August 2016, 14:16
Yeah, guess we could count the difference in microseconds

IzNoGoD
28th August 2016, 14:54
With inet_aton it's easier to do subnet operations

Ni3ls
28th August 2016, 15:50
what kind of subnet operations?

IzNoGoD
28th August 2016, 23:02
like 1.2.3.0/24