Jump to content
×
×
  • Create New...

Server Command - Get IP


Recommended Posts

M2 Download Center

Download Here ( Internal )

Hi,

In this thread i'll show you how to display the IPs that can be found in the log database at our case loginlog2.ip is
in a dotted-quad representation as 123.456.789.123.

Those IPs are inserted into the loginlog2 table after being converted with the INET_ATON() to numeric values.

Example:

SELECT INET_ATON(192.168.1.1);

   
is 3232235777. How does this came up?

It's simple:

192*256³ + 168*256² + 1*256 + 1 =
221225472 + 11010048 + 256 + 1 = 3232235777

So to reverse it we'll use this

SELECT INET_NTOA(3232235777);

   
Which gives us this: 192.168.1.1
 

 

So let's implement this to our gm commands...

 

First navigate to game/src/

 

and open the file cmd.cpp

 

find this:

ACMD(do_block_chat);

and add after that this:

ACMD(do_get_ip);

after that find this:

{ "block_chat",		do_block_chat,		0,			POS_DEAD,	GM_PLAYER	},

and add after that this:

{ "get_ip",	do_get_ip,	0,	POS_DEAD,	GM_IMPLEMENTOR },

We're done here!

 

Next, open cmd_gm.cpp

 

and add this event:

 

Spoiler
ACMD(do_get_ip)
{
	char arg1[256], arg2[256], szQuery[1024], szQuery_[1024];
	int limit = 0;

	two_arguments(argument, arg1, sizeof(arg1), arg2, sizeof(arg2));
	
    if (!*arg1)
    {
        ch->ChatPacket(CHAT_TYPE_INFO, "Wrong syntax, use: /get_ip <char name> [< LIMIT >]");
        return;
    }

	if (*arg2)
		str_to_number(limit, arg2);
	else
		limit = 0;	
	
	snprintf(szQuery, sizeof(szQuery),"SELECT id FROM player.player WHERE name = '%s'", arg1);
	std::auto_ptr<SQLMsg> msg(DBManager::instance().DirectQuery(szQuery));
	
	if (msg->Get()->uiNumRows == 0)
	{
        ch->ChatPacket(CHAT_TYPE_INFO, "The character doesn't exist!");
        return;
	}

	MYSQL_ROW row = mysql_fetch_row(msg->Get()->pSQLResult);
	
	if(limit == 0){
		snprintf(szQuery_, sizeof(szQuery_),"SELECT INET_NTOA(ip) AS connect_ip FROM log.loginlog2 WHERE pid = %s", row[0]);
	}else if(limit > 0){
		snprintf(szQuery_, sizeof(szQuery_),"SELECT INET_NTOA(ip) AS connect_ip FROM log.loginlog2 WHERE pid = %s LIMIT %d", row[0], limit);
	}
	std::auto_ptr<SQLMsg> msg_(DBManager::instance().DirectQuery(szQuery_));
	
	if (msg_->Get()->uiNumRows == 0)
	{
        ch->ChatPacket(CHAT_TYPE_INFO, "The character has never connected to the game!");
        return;
	}
	ch->ChatPacket(CHAT_TYPE_INFO, "The ips from the character %s is:",arg1);

	while(MYSQL_ROW row1 = mysql_fetch_row(msg_->Get()->pSQLResult)) {
		ch->ChatPacket(CHAT_TYPE_INFO, "%s", row1[0]);
	}
}

 

So simply in game write /get_ip char_name [limit]

 

the [limit] is optional,it can show you how many ip you selected.

For example:

 

/get_ip Test 50

 

this command will show you 50 ip login records from the character Test

 

if you have any questions feel free to ask :)

  • Love 13
Link to comment
  • 1 year later...
  • Premium

Hi, sorry for refresh old theme, but u have a mistake in your code.

Wrong code:

{ "get_ip", do_get_ip,  0,  POS_DEAD,   GM_IMPLEMENTOR } 

 Right code:

{ "get_ip", do_get_ip,  0,  POS_DEAD,   GM_IMPLEMENTOR }, 

Just a little mistake. :)

  • Love 2

 

 

Link to comment
  • Premium

Hi, sorry for refresh old theme, but u have a mistake in your code.

Wrong code:

{ "get_ip", do_get_ip,  0,  POS_DEAD,   GM_IMPLEMENTOR } 

 Right code:

{ "get_ip", do_get_ip,  0,  POS_DEAD,   GM_IMPLEMENTOR }, 

Just a little mistake. :)

 

 

Just a comma can change life and functions of the code :o This is why I keep away from c++

Link to comment

... that happens on most if not all programming languages Adrian. Syntax matters, because it's parsed by something that needs to distinguish different parts of your code. In this case, the comma is simply a way of separating elements. Nothing to be scared of.

 

Ontopic: It's cool, but what if the player database is not called player or the log database is not called log?

Link to comment
  • 9 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.