Format

Topic(href,href_list[],hsrc)

When

Called when a player connects to a world with a “connection topic” or when the player runs a hyperlink in the current world by clicking one embedded in text or generated by the link() instruction.

Args

  • href: The topic text (everything after the ’?’ in the full href).
  • href_list: List of key/value pairs in href (produced from params2list(href)).
  • hsrc: The object referenced by the “src” parameter in href or null if none.

Default action

Call the hsrc object’s own Topic() proc.

The following example uses a very simple href value.

mob/Login()
  src << "Click <a href=?source>here</a> to download the source code."
  return ..()
 
client/Topic(href)
  if(href == "source")
    usr << file("world.dm")
    usr << file("world.rsc")
  else ..()

Be sure to call the default handler unless you want to prevent rerouting of topics to other objects.

Danger

Always validate the input in Topic() calls to make sure it’s correct and the query you’re recieving is legitimate. For security reasons, you will probably want to control which objects a player has access to, since a player could spoof a topic link containing any arbitrary object reference. (Never trust those sneaky players!)

The next example demonstrates an href that gets handled by another object. This is how you would normally want to do things. It is best not to override client/Topic() (as in the example above) unless you need to intervene in the low-level details of routing the request to the right object.

You specify the object that will handle the request by using a parameter called “src”.

mob/Login()
   src << "Click <a href='?src=\ref[src];action=startgame'>here</a> to start."
   return ..()
 
mob/Topic(href,href_list[])
   switch(href_list["action"])
      if("startgame")
         usr << "Starting game..."
      else
         return ..()

Although it is slightly more complex, the use of the parameter list allows you to easily include extra data and new functionality. Just remember that the data in the list is always stored as text, so if you are expecting a number or an object, you must convert it yourself (with text2num(), locate(), or whatever).

See also