From 5585fbf6960e2a939d36ff78d1a0f782f0815588 Mon Sep 17 00:00:00 2001 From: cookiecrumbs Date: Sat, 24 Nov 2012 04:02:20 +0000 Subject: Implemented script command getcharip (tid:69646) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16957 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/script.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/map') diff --git a/src/map/script.c b/src/map/script.c index 2cbb6f6b6..f06698d16 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -13,6 +13,7 @@ #include "../common/nullpo.h" #include "../common/random.h" #include "../common/showmsg.h" +#include "../common/socket.h" // usage: getcharip #include "../common/strlib.h" #include "../common/timer.h" #include "../common/utils.h" @@ -16906,6 +16907,50 @@ BUILDIN_FUNC(getargcount) { return 0; } +/** + * getcharip(//) + **/ +BUILDIN_FUNC(getcharip) +{ + struct map_session_data* sd = NULL; + int id = 0; + + /* check if a character name is specified */ + if( script_hasdata(st, 2) ) + { + if (script_isstring(st, 2)) + sd = map_nick2sd(script_getstr(st, 2)); + else if (script_isint(st, 2) || script_getnum(st, 2)) + { + id = script_getnum(st, 2); + sd = (sd = map_id2sd(id) ? map_id2sd(id) : map_charid2sd(id)); + } + } + else + sd = script_rid2sd(st); + + /* check for sd and IP */ + if (!sd || !session[sd->fd]->client_addr) + { + script_pushconststr(st, ""); + return 0; + } + + /* return the client ip_addr converted for output */ + if (sd && sd->fd && session[sd->fd]) + { + /* initiliaze */ + const char *ip_addr = NULL; + uint32 ip; + + /* set ip, ip_addr and convert to ip and push str */ + ip = session[sd->fd]->client_addr; + ip_addr = ip2str(ip, NULL); + script_pushstrcopy(st, ip_addr); + } + + return 0; +} /** * is_function() -> 1 if function exists, 0 otherwise **/ @@ -17618,6 +17663,7 @@ struct script_function buildin_func[] = { * rAthena and beyond! **/ BUILDIN_DEF(getargcount,""), + BUILDIN_DEF(getcharip,"?"), BUILDIN_DEF(is_function,"s"), BUILDIN_DEF(get_revision,""), BUILDIN_DEF(freeloop,"i"), -- cgit v1.2.3-60-g2f50