blob: e489a291028cf594c2e1a809bfb4f137bc95ef72 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001/* This sefun is to provide a replacement for the efuns query_ip_name() and
2 * query_ip_number().
3 * Feel free to add it to your mudlibs, if you have much code relying on that.
Zesstra7452d552020-02-04 22:21:56 +01004 *
5 * The code of the helper functions originates from the driver sources, they
6 * are kept as-is intentionally.
MG Mud User88f12472016-06-24 23:31:02 +02007 */
8
9#if ! __EFUN_DEFINED__(query_ip_name)
10
11#include <interactive_info.h>
12
Zesstra7452d552020-02-04 22:21:56 +010013// (actually not used in MG)
MG Mud User88f12472016-06-24 23:31:02 +020014private varargs string _query_ip_name(object player)
15{
16 object ob = player;
17 ob ||= efun::this_player();
18
MG Mud User88f12472016-06-24 23:31:02 +020019 return efun::interactive_info(ob, II_IP_NAME);
20}
21
Zesstra7452d552020-02-04 22:21:56 +010022private varargs string int_query_ip_number(object player)
MG Mud User88f12472016-06-24 23:31:02 +020023{
24 object ob = player;
25 ob ||= efun::this_player();
26
MG Mud User88f12472016-06-24 23:31:02 +020027 return efun::interactive_info(ob, II_IP_NUMBER);
28}
29
Zesstra7452d552020-02-04 22:21:56 +010030// First tries to get the "real" IP (instead of the proxy's one), which was
31// saved in the object by the login object. If that is unsuccessful, it falls
32// back to the driver information of the IP the interactive object is
33// connected to.
34public string query_ip_number(object ob)
MG Mud User88f12472016-06-24 23:31:02 +020035{
Zesstra7452d552020-02-04 22:21:56 +010036 ob = ob || this_player();
37 if(objectp(ob) && interactive(ob))
MG Mud User88f12472016-06-24 23:31:02 +020038 {
Zesstra7452d552020-02-04 22:21:56 +010039 string realip = ob->query_realip();
Zesstraca502032020-02-05 19:56:09 +010040 if (sizeof(realip))
Zesstra7452d552020-02-04 22:21:56 +010041 {
42 return realip;
43 }
MG Mud User88f12472016-06-24 23:31:02 +020044 }
Zesstra7452d552020-02-04 22:21:56 +010045 return int_query_ip_number(ob);
MG Mud User88f12472016-06-24 23:31:02 +020046}
47
Zesstra7452d552020-02-04 22:21:56 +010048/* Liefert zu einer gegebenen ipnum den Hostnamen.
49 * @param ipnum eine numerische ip-adresse oder ein interactive
50 * @return den Hostnamen der zu der angegebenen ip-adresse gehoert.
51 * wenn der hostname nicht bekannt ist, wird die ipadresse zurueckgegeben.
52 */
Zesstra2bffcd42020-02-04 22:17:55 +010053public string query_ip_name(string|object ob)
MG Mud User88f12472016-06-24 23:31:02 +020054{
Zesstra7452d552020-02-04 22:21:56 +010055 // First get the IP number (as string) for the object or a 0.
MG Mud User88f12472016-06-24 23:31:02 +020056 if ( !ob || objectp(ob) )
57 ob=query_ip_number(ob);
Zesstra7452d552020-02-04 22:21:56 +010058 // then get its host name from the lookup & cache daemon.
Zesstra4dbb9882019-11-26 21:26:36 +010059 return "/p/daemon/iplookup"->host(ob);
MG Mud User88f12472016-06-24 23:31:02 +020060}
61
62#endif
63