backIndex

Xelagot action script

Events: DNSLookup

Refer to Events for general information about events.

Version 3.421 introduces the possiblility to do a dns lookup, sending either a dotted IP to retrieve a hostname (or a list of hostnames), or a hostname to retrieve an IP (or a list of IPs). To retrieve the asynchronous answer from the dns server, this event handler must be installed. In the event handler, you must test whether the target is defined or not, and exit if it is not:
IfTargetUndefined Escape

The statements to do a dns lookup are:
DNSLookup &p
DNSLookup &p $msg
DNSLookup $ip
DNSLookup $ip $msg
Of course, &p must be a 'real' person and contain a valid IP. $ip may contain either a valid dotted IP (like "123.10.98.33") or a hostname (like "www.microsoft.com"). An optional message $msg can be attached to this request, it can be retrieved in the event handler and can be used, for example, to identify the reply.

To test whether a person has an IP, retrieve it and test for non-emptyness, for example:
GetAddress $a &p
IfString $a <> "" DNSLookup &p

Installer:

OnDNSLookupEvent <eventlabel>
Event type: 10300
is triggered when a dnsLookup requested by the script returns an answer.

Specific statements (must be inside the event handler):

GetEventType %a stores the event type code in variable %a
GetEventResult %a stores the event result code in variable %a. 0 means success, other positive codes are equivalent to the Windows Winsock error codes, -1 signifies there has been a background exception.
GetEventAddress $ip If you sent a dotted IP, it will be returned here. If you sent a hostname, this will be the requested IP, if one is found, or it will be empty if none is found. If more than one result exists, the first one will be stored here.
GetEventHost $host If you sent a host name, it will be returned here. If you sent a dotted IP, this will be the resulting hostname, if one is found, or empty if none is found. If more than one result exists, the first one will be stored here.
GetEventAnswers /s_myList
GetEventAnswers $a
If there are no answers, /s_myList and $a will be empty, otherwise /s_myList will contain a list of answers (host names or dotted IPs). In the most common case of one answer, /s_myList will contain one line and $a will contain the answer, which will be identical to the one retrieved in GetEventHost or GetEventIP, depending on the request. In the case of more than one answer, /s_myList will have more lines, and $a will have a comma-separated list of answers.
GetMessage $msg Retrieves the same message that was sent with the request, if any.

Here follows an example to test this event handler and the corresponding statements. It requires a bot with Eject rights. It sends the bot's chat to the user interface only, so it is safe to use. When a person enters (OnAvatarAddEvent), it's IP address is checked. If the IP is defined, a dns lookup is called. Just in case the IP is not defined, Identify &p is called, which will trigger an OnAddressEvent when the IP is recovered from the world server (it does nothing if the IP was already known); in the OnAddressEvent handler the dns lookup is called, so it is either called in OnAvatarAddEvent or in OnAddressEvent. When the dns lookup is called, the session number of the avatar is passed on as a message string $s; this allows you to recover the original person later on in the OnDnsLookupEvent.

[Head]
Type=Script
Version=2.0

[Settings]
Origin=0.000n 0.000w 0.00a 0.0
Run

[Script]

OnAvatarAddEvent Add
OnAddressEvent IP
OnDNSLookupEvent DNS
Label Loop
  Goto Loop
End

Event Add
  SecretConcat "Got ADD"
  GetAvatarPerson &p
  Identify &p
  GetAddress $a &p
  GetSession %s &p
  $s = %s
  IfString $a <> "" DNSLookup &p $s
EndEvent

Event IP
  SecretConcat "got IP"
  IfTargetUndefined Escape
  GetTargetPerson &p
  GetSession %s &p
  $s = %s
  DNSLookup &p $s
EndEvent

Event DNS
  SecretConcat "Got DNS"
  GetEventResult %r
  GetEventAddress $i
  GetEventHost $h
  GetEventAnswers $a
  GetMessage $s
  %s = $s
  SecretConcat "result " %r ", " $i & = " $h " (" $a ")"
  IfGetPresentSession &p %s
  Else Escape
  GetName $n &p
  IfString $a = "" $a = "not available"
  SecretConcat "The IP of " $n " is " $i ", the hostname(s) is/are " $a
EndEvent

Note that as from version 3.421, whenever a bot receives an IP address from the server (whether automatically or through a script request), a dns lookup is always done by the bot. Nevertheless, a script should call dnsLookup explicitely: if the person's hostname is already known, the bot will trigger an OnDNSLookupEvent as if it had queried the dns server. One can, of course, always test if the bot already knows the hostname of a person:

  GetHost $h &p
  IfString $h <> "" SecretConcat "I have the hostname"
  Else SecretConcat "I do not have the hostname"

See here for statements GetHost and GetHosts.

Notice also the difference in behaviour of OnAddressEvent and OnDNSLookupEvent:



backIndex