Jump to content
  • 0

Question

Posted

Ok, so simply saying I would like to add an IP checker for Battlegrounds (the one already included in rAthena's SVN) to prevent people from dual clienting while using battlegrounds. I know it should be a simple code but I got no clue on how to start writing it(or even write it fully for that matter) and I'm guessing that script would be general and can be implemented in any event/npc/map?

Thank you ~

11 answers to this question

Recommended Posts

Posted

The most practical way I can think of is making all the registration NPCs call an IP check function, which would do something like this:

// callfunc "Check_IP","<map_name>";
function    script    Check_IP    {

   // Get list of accounts with attached character's IP address.
   set .@size, query_sql("SELECT `account_id` FROM `login` WHERE `last_ip` = '"+getcharip()+"'",.@aid);

   // Passed check if only the attached player is returned.
   if (.@size < 2) return;

   // Check all online characters using the IP address if they're on the given map.
   set .@self, getcharid(3);
   for(set .@i,0; .@i<.@size; set .@i,.@i+1) {
       if (attachrid(.@aid[.@i])) {
           if (strcharinfo(3) == getarg(0)) {
               set .@name$, strcharinfo(0);
               attachrid(.@self);
               mes "Character "+.@name$+" is already logged into Battlegrounds with your IP.";
               close;
           }
       }
   }
   attachrid(.@self);

   // Passed check.
   return;
}

Note that you can't do an SQL query on `last_map` since that field doesn't update in real time.

  • 0
Posted
making all the registration NPCs call an IP check function

Edit: Ah, after looking at the scripts, it looks like this is more complicated than I'd thought. There's no way (with scripts, at least) to obtain lists of players in an area, as all the waitingrooms are on the same map.

An easy alternative is to check when a player warps to bat_room if a dual-client is on any Battlegrounds map (either a match or bat_room), and kick them appropriately. That script you would only need to add once:

-    script    BG_Check_IP    -1,{
OnInit:
   setmapflag "bat_room", mf_loadevent;
   end;

// Trigger when a player enters a map with "loadevent" mapflag.
OnPCLoadMapEvent:

   // Only run for map "bat_room".
   if (strcharinfo(3) != "bat_room") end;

   // Get list of accounts with attached character's IP address.
   set .@size, query_sql("SELECT `account_id` FROM `login` WHERE `last_ip` = '"+getcharip()+"'",.@aid);

   // Passed check if only the attached player is returned.
   if (.@size < 2) end;

   // Check all online characters using the IP address if they are on a Battlegrounds map.
   set .@self, getcharid(3);
   for(set .@i,0; .@i<.@size; set .@i,.@i+1) {
       if (.@aid[.@i] == .@self)
           continue;
       if (attachrid(.@aid[.@i])) {
           if (compare(strcharinfo(3),"bat_")) {
               set .@name$, strcharinfo(0);
               attachrid(.@self);
               message strcharinfo(0),"Character "+.@name$+" is already logged into Battlegrounds with your IP.";
               sleep2 2000;
               warp "SavePoint",0,0;
               end;
           }
       }
   }

   // Passed check.
   end;
}

Posted

The most practical way I can think of is making all the registration NPCs call an IP check function, which would do something like this:

// callfunc "Check_IP","<map_name>";
function	script	Check_IP	{

// Get list of accounts with attached character's IP address.
set .@size, query_sql("SELECT `account_id` FROM `login` WHERE `last_ip` = '"+getcharip()+"'",.@aid);

// Passed check if only the attached player is returned.
if (.@size < 2) return;

// Check all online characters using the IP address if they're on the given map.
set .@self, getcharid(3);
for(set .@i,0; .@i<.@size; set .@i,.@i+1) {
	if (attachrid(.@aid[.@i])) {
		if (strcharinfo(3) == getarg(0)) {
			set .@name$, strcharinfo(0);
			attachrid(.@self);
			mes "Character "+.@name$+" is already logged into Battlegrounds with your IP.";
			close;
		}
	}
}
attachrid(.@self);

// Passed check.
return;
}

Note that you can't do an SQL query on `last_map` since that field doesn't update in real time.

Appreciate your help Euphy, thank you very much!

To add the script, should i add it like a normal custom script? or does it have any special way of adding it.

Posted

Add it like you would any other script.

Hey Euphy, Would I need to restart the server? I just loaded the script and tried KVM BG, i could dual client, It didnt tell me that my character is logged in from another IP.

Posted
making all the registration NPCs call an IP check function

Edit: Ah, after looking at the scripts, it looks like this is more complicated than I'd thought. There's no way (with scripts, at least) to obtain lists of players in an area, as all the waitingrooms are on the same map.

An easy alternative is to check when a player warps to bat_room if a dual-client is on any Battlegrounds map (either a match or bat_room), and kick them appropriately. That script you would only need to add once:

-	script	BG_Check_IP	-1,{
OnInit:
setmapflag "bat_room", mf_loadevent;
end;

// Trigger when a player enters a map with "loadevent" mapflag.
OnPCLoadMapEvent:

// Only run for map "bat_room".
if (strcharinfo(3) != "bat_room") end;

// Get list of accounts with attached character's IP address.
set .@size, query_sql("SELECT `account_id` FROM `login` WHERE `last_ip` = '"+getcharip()+"'",.@aid);

// Passed check if only the attached player is returned.
if (.@size < 2) end;

// Check all online characters using the IP address if they are on a Battlegrounds map.
set .@self, getcharid(3);
for(set .@i,0; .@i<.@size; set .@i,.@i+1) {
	if (.@aid[.@i] == .@self)
		continue;
	if (attachrid(.@aid[.@i])) {
		if (compare(strcharinfo(3),"bat_")) {
			set .@name$, strcharinfo(0);
			attachrid(.@self);
			message strcharinfo(0),"Character "+.@name$+" is already logged into Battlegrounds with your IP.";
			sleep2 2000;
			warp "SavePoint",0,0;
			end;
		}
	}
}

// Passed check.
end;
}

It works great! Appreciate the help! Thank you again Euphy !

Posted
OnInit:
    setmapflag "bat_room", mf_loadevent;
    end;

// Trigger when a player enters a map with "loadevent" mapflag.
OnPCLoadMapEvent:

    // Only run for map "bat_room".
    if (strcharinfo(3) != "bat_room") end;

    // Get list of accounts with attached character's IP address.
    set .@size, query_sql("SELECT `account_id` FROM `login` WHERE `last_ip` = '"+getcharip()+"'",.@aid);

    // Passed check if only the attached player is returned.
    if (.@size < 2) end;

    // Check all online characters using the IP address if they are on a Battlegrounds map.
    set .@self, getcharid(3);
    for(set .@i,0; .@i<.@size; set .@i,.@i+1) {
        if (.@aid[.@i] == .@self)
            continue;
        if (attachrid(.@aid[.@i])) {
            if (compare(strcharinfo(3),"bat_")) {
                set .@name$, strcharinfo(0);
                attachrid(.@self);
                message strcharinfo(0),"Character "+.@name$+" is already logged into Battlegrounds with your IP.";
                sleep2 2000;
                warp "SavePoint",0,0;
                end;
            }
        }
    }

    // Passed check.
    end;
}

 

I tried this script and change "bat_room" to "guild_vs2" but after I reload/load it, It doesn't work ~ 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...