PDA

View Full Version : Help with IP select CoD2



caldas
14th August 2020, 01:58
Hello,

I would like some help. I don't understand much about scripts in cod2, so I've been trying to study and learn more and more. If you can help me, I will be very grateful.

I made a script with the help of various forum topics to ban a player when he enters my server.



Player_OnConnect()
{
self thread CheckIp();
}
CheckIp()
{
maps\mp\gametypes\_mysql::asyncQuery("SELECT `ip` FROM `ip` WHERE `ip` = '" + self getIP() + "'", ::processKickIp);
}

processKickIp(rows, args)
{
player_ip = self getIP();
if (isDefined(rows) && isDefined(rows[0]))
{
ip = rows;
for (i = 0; i < ip.size; i++)
{
if (player_ip == ip[i]["ip"])
{
username = self.name;
userid = self getEntityNumber();
kick2(userid, "- Player banned.");
sendgameservercommand(-1, "h \"console: " + username + " ^7kicked per banned IP \"");
printf(username + " kicked per banned IP: " + ip[i]["ip"] + "\n");
break;
}
}
}
}

I call this function in _menus, OnMenuResponse() method:


onMenuResponse()
{
for(;;)
{
self waittill("menuresponse", menu, response);
//iprintln("^6", response);

if (menu == game["menu_serverinfo"]) {
self thread maps\pam\pzt::Player_OnConnect();
}
...

However, while the map is running and if I add an IP to the database during the map, after kicking the player he can still reconnect and play, until the map is finished.

Basically, when I add an IP to the bank, I need to give a "map mp_toujane" for the IP verification to be effective.

Can anyone help?

maxdamage99
14th August 2020, 06:54
need see


maps\mp\gametypes\_mysql::asyncQuery

bcs


processKickIp(rows, args)

maybe callback function dont get any object to yourself in "self", maybe some args wrong
try use printf() to debug: is defined self, args, rows etc?

maybe the function itself is never called at all, because it is not very good to consider opening some menu (like a first menu for player) as a "connection", you can use the event onPlayerConnect, connected or put this


checkIP()

in
"codecallback_playerConnect()"
after
"waittill("connected")"

IzNoGoD
14th August 2020, 13:21
1. Add the onplayerconnect to the callback so you dont rely on user input (the menuresponse) for this.

2. The second part of your script does not know which thing "self" is. I guess you havent run this with developer enabled?

3. printf is your friend. Print everything that you are not 100% sure has the correct value. Kick/ban yourself to simulate.

caldas
14th August 2020, 16:42
1. Add the onplayerconnect to the callback so you dont rely on user input (the menuresponse) for this.

2. The second part of your script does not know which thing "self" is. I guess you havent run this with developer enabled?

3. printf is your friend. Print everything that you are not 100% sure has the correct value. Kick/ban yourself to simulate.

I may be wrong, but is Callback_PlayerConnect called every time a round is started, or not?

Because, when I put a method at this level, every time he starts a round (sd), he executes what is there after waittill ("connected") and not only when the player connects to the server.

My scripts are configured inside a zPAM207.

Thanks for understanding, I will try to run and return with information.

Thank you.

IzNoGoD
15th August 2020, 10:14
Save something to player.pers[array]. That does not get reset on round restart.



onplayerconnect()
{
if(!isDefined(self.pers["connected"]))
{
self.pers["connected"] = true;
self thread dobancheck();
}
}

caldas
15th August 2020, 17:28
@IzNoGoD


Save something to player.pers[array]. That does not get reset on round restart.



onplayerconnect()
{
if(!isDefined(self.pers["connected"]))
{
self.pers["connected"] = true;
self thread dobancheck();
}
}


Thank you very much. Its worked.

Now, when I try to use kick2, the console returns me with a Segmentation fault.



CheckIp()
{
row = maps\mp\gametypes\_mysql::query("SELECT ip FROM ip WHERE ip = '" + self getIP() + "'");

if (isDefined(row) && isDefined(row[0]) && isDefined(row[0]["ip"]))
{
id = self getEntityNumber();
name = self.name;
sendgameservercommand(-1, "h \"console: " + name + " ^7kicked per banned IP \"");
kick2(id, "Player banned.");
}
}


./cod2.sh: line 8: 4682 Segmentation fault LD_LIBRARY_PATH=. LD_PRELOAD=$PWD/libcod2_1_3.so ./cod2_lnxded +set fs_basepath "/home/cod2-28962" +set fs_homepath "/home/cod2-28962" +set pb_sv_homepath "/home/cod2-28962/pb" +set com_hunkMegs 512 +set net_ip 10.158.0.5 +set net_port 28962 +set sv_maxclients 64 +set developer 1 +set sv_punkbuster 0 +set sv_cracked 1 +set rcon_password "x" +set sv_privatePassword "caldaslindo" +exec x.cfg

I tried with developer 1/2/0. With kick(id) works perfectly.

dmesg


[408566.147065] cod2_lnxded[4682]: segfault at c ip 00000000080f6e16 sp 00000000ffd01320 error 4 in cod2_lnxded[8048000+135000]
[408566.158927] Code: e5 57 56 83 ec 30 8b 45 08 89 c2 69 d2 30 02 00 00 b8 00 64 71 08 01 d0 89 45 f4 8b 45 f4 8b 80 58 01 00 00 89 45 f0 8b 45 f0 <8b> 40 0c 25 00 00 80 00 85 c0 75 09 c7 45 ec 00 00 00 00 eb 69 8b


-----------------------------------

FIXED WITH WAIT



CheckIp()
{
row = maps\mp\gametypes\_mysql::query("SELECT ip FROM ip WHERE ip = '" + self getIP() + "'");

if (isDefined(row) && isDefined(row[0]) && isDefined(row[0]["ip"]))
{
wait 1;
kick2(self getEntityNumber(), "Player banned.");
}
}

maxdamage99
17th August 2020, 06:35
1. Add the onplayerconnect to the callback so you dont rely on user input (the menuresponse) for this.

2. The second part of your script does not know which thing "self" is. I guess you havent run this with developer enabled?

3. printf is your friend. Print everything that you are not 100% sure has the correct value. Kick/ban yourself to simulate.

ty for the translation into real english :D