2.4 HOOKS definition

2.4 HOOKS definition

HOOKS defines commands that the game server will accept from the outside, regardless of the state of the client (in-game player or not). Each command you specify in the HOOKS line will be associated to an event defined by you. Then, in the event code, it will be up to you what to process and what to output.

Syntax:

[ HOOKS hookID=eventName, … ]

 

  • The function handling the event can have input parameters which will be specified by the user in the URL used for the call. The programmer may read the input parameters also via the input() set.
  • Any output can be done via the Print instruction.
  • The hook will be activated by opening the game’s URL and using the cmd parameter with the specified hook ID. So you activate your event by opening an URL like this:
  • http://localhost:8080/dimx/servlet/multiplayer?game=1&cmd=hookID&param1=foobar

 

2.4.1 Example

In the following example, we define a hook.

  • We want to enable a way to peek into the game and quickly locate objects and characters, even when we are not connected.
  • We want that, when the server receives the command: findobj on the game’s URL, the event doFindObj() is triggered and, after getting the name of the object we are searching for, it outputs the results of the search in a plain text format.
  • The name of the object we are searching for will be specified in the obj parameter.

 

GUIHOOKS findobj=doFindObj  ‘ when you receive ‘findobj’ call doFindObj()

 

EVENTS

Function doFindObj(obj) ‘we expect a parameter named obj

‘obj = input(“obj”)

‘Print “input: ” + input + “<br>”

‘Print “obj: ” + obj + “<br>”

‘Print “Searching: ” + obj + “<br>”

Dim c

For Each c In getItemsIn($WORLD)

If InStr(c.name,obj)

found=1

Print $AGENT,”<LI>” + c.name + ” is in: ” + c.container.name

End_If

Next

For Each c In getCharactersIn($WORLD)

If InStr(c.name,obj)

found=1

Print $AGENT,”<LI>” + c.name + ” is in: ” + c.container.name

End_If

Next

If Not(found)

Print “Not found: ‘” + obj + “‘”

End_If

End_Function

END_EVENTS

 

The command must be specified in the game’s URL by using the cmd parameter. So you activate this hook by opening an URL like this:

http://localhost:8080/dimx/servlet/multiplayer?game=1&cmd=findobj&obj=spell

 

By opening the above URL you will get the result.

 

It should be now easy to understand that this can be used to integrate your game with any web based application.
Security notice: Be aware that when using HOOKS you open a breach into your game. While ordinary dimensioneX commands require that the user is connected or that he specifies the admin password, any request calling your hook event will be accepted by the game server. The task of checking who is performing the request, from what site/application, or how often is completely up to the programmer.

2.5 PANEL definition
2.3 GUI section

Leave a Reply

Your email address will not be published. Required fields are marked *