A small guide on how to extend the WoodMiniWebServer using the DSO interface

The basis of the DSO interface

; Basically, the following function is the basis for the expansion of this server:
Func _DirectServerOutput($input, $file)
    $str = StringTrimLeft($input, StringLen("directserveroutput="))
    Switch $str
    Case 'of0'
        If StringInStr(FileGetAttrib(@ScriptDir&'/'&$file), "D") THen Return _DSO_Dir($file&'/')
        Return _Get($file)
    EndSwitch
EndFunc

; You can have multipule DSOs per server.
; The server comes with 1 DSO built-in: The Directory Browser (code 'of0')
; You can see it in action at:
; http://<your server ip>/?directserveroutput=of0

Example of using the DSO interface:

; To insert a new DSO, you basically have to put a new Case statement in _DirectServerOutput's Switch.
; For example, let's say I want to have insert a game server.
; I'll give it a DSO id of game1.

;;Edited _DirectServerOutput function:
Func _DirectServerOutput($input, $file)
    $str = StringTrimLeft($input, StringLen("directserveroutput="))
    Switch $str
    Case 'of0'
        If StringInStr(FileGetAttrib(@ScriptDir&'/'&$file), "D") THen Return _DSO_Dir($file&'/')
        Return _Get($file)
    Case 'game1'
        Return _Game1Server($file)
    EndSwitch
EndFunc

;;And I'll write the _Game1Server function as well:
;;(Obviously I can't put a real game server here, let's have a fake one:)
Func _Game1Server($file)
    ;;If no input, return default webpage.
    If $file = "\" or $file = "/" or $file = "" Then Return '<a href="http://'&$IP&':'&$PORT&'/fight/Imp/50/20?directserveroutput=game1">Click here for a sample fake battle</a>'

    ;;Got Input:
    $file = _DSO_ProcessString($file) ;;A very useful function for DSOs. Cleans up the input for you.
    If $file[1] = "fight" Then
        _DSO_SetMIMEType(_GetFileType("html")) ;;Set the MIME to html (because we are going to output a html file.)
        $html = "<html>"
        $html &= "<title>A Demo DSO game for Wood's General Server</title>"
        $html &= "<body>"
        $html &= "<h2>You are fighting a "&$file[2]&"</h2>"
        $html &= "<h3>It's HP: "&$file[3]&"</h3>"
        $html &= "<h3>Your HP: "&$file[4]&"</h3>"
        $html &= "<a href='http://"&$IP&":"&$PORT&"/fight/"&$file[2]&"/"&$file[3]&"/"&$file[4]-5&"?directserveroutput=game1'>Let it attack you.</a>"
        $html &= "<br>"
        $html &= "<a href='http://"&$IP&":"&$PORT&"/fight/"&$file[2]&"/"&$file[3]-5&"/"&$file[4]&"?directserveroutput=game1'>You attack it.</a>"
        $html &= "</body>"
        $html &= "</html>"
        Return $html
    EndIf
EndFunc

; If you don't want to edit the code, you can see a working example under the DSO directory.
; Once you have done this, you can test it out!
; Point your web-browser to:
; http://<your server ip>/?directserveroutput=game1

; Start - Functions

Useful functions for DSO programmers

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions that are useful for DSO programmers: ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_DSO_SetMIMEType($mime)    ;;Sets the MIME type of your return data.
_GetFileType($extention)   ;;Returns a MIME type based on the extention.
_DSO_ProcessString($input) ;;Cleans up input and returns it as an array, $a[0] being number of array indexes.