diff options
author | cookiecrumbs <cookiecrumbs@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-11-24 04:02:20 +0000 |
---|---|---|
committer | cookiecrumbs <cookiecrumbs@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-11-24 04:02:20 +0000 |
commit | 5585fbf6960e2a939d36ff78d1a0f782f0815588 (patch) | |
tree | 02be264e10e932a30c9398ced7284716e3f5362d | |
parent | 12ca79c53b53d2d394a79306598397ee62ce9fc7 (diff) | |
download | hercules-5585fbf6960e2a939d36ff78d1a0f782f0815588.tar.gz hercules-5585fbf6960e2a939d36ff78d1a0f782f0815588.tar.bz2 hercules-5585fbf6960e2a939d36ff78d1a0f782f0815588.tar.xz hercules-5585fbf6960e2a939d36ff78d1a0f782f0815588.zip |
Implemented script command getcharip (tid:69646)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16957 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r-- | src/map/script.c | 46 |
1 files changed, 46 insertions, 0 deletions
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" @@ -16907,6 +16908,50 @@ BUILDIN_FUNC(getargcount) { return 0; } /** + * getcharip(<account ID>/<character ID>/<character name>) + **/ +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(<function name>) -> 1 if function exists, 0 otherwise **/ BUILDIN_FUNC(is_function) { @@ -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"), |