diff --git a/addons/fn_a3web.sqf b/addons/fn_a3web.sqf index b06d822..b613df7 100644 --- a/addons/fn_a3web.sqf +++ b/addons/fn_a3web.sqf @@ -1,25 +1,25 @@ [] spawn { - //if (!hasInterface) exitWith {}; - if (!isServer) exitWith {}; - //if (!isDedicated) exitWith {}; + //if (!hasInterface) exitWith {}; + if (!isServer) exitWith {}; + //if (!isDedicated) exitWith {}; - addMissionEventHandler ["ExtensionCallback", { - params ["_name", "_function", "_data"]; - if (_name isEqualTo "a3web") then - { - diag_log format ["ExtensionCallback %1, %2, %3", _name, _function, _data]; - }; - }]; + addMissionEventHandler ["ExtensionCallback", { + params ["_name", "_function", "_data"]; + if (_name isEqualTo "a3web") then + { + diag_log format ["ExtensionCallback %1, %2, %3", _name, _function, _data]; + }; + }]; - waitUntil {time > 0}; - - a3web_interval = 1; + waitUntil {time > 0}; - while {true} do { - sleep a3web_interval; - private _units = allUnits apply { - [netid _x, isPlayer _x, name _x, str (side _x), getPos _x]; - }; + a3web_interval = 1; + + while {true} do { + sleep a3web_interval; + private _units = allUnits apply { + [netid _x, isPlayer _x, name _x, str (side _x), getPos _x]; + }; "liba3web" callExtension ["http:post:/units-info", [_units]]; - }; + }; }; diff --git a/extension/liba3web.go b/extension/liba3web.go index 6017333..a9c466d 100644 --- a/extension/liba3web.go +++ b/extension/liba3web.go @@ -16,11 +16,14 @@ package main import "C" import ( + "os" "fmt" "log" "strings" "unsafe" "net/http" + "encoding/json" + "io/ioutil" ) var cb C.callbackProc @@ -45,6 +48,19 @@ func RVExtensionVersion(output *C.char, outputsize C.size_t) { defer C.free(unsafe.Pointer(version)) var size = C.min(C.strlen(version)+1, outputsize-1) C.strncpy(output, version, size) + + // Load config + const configPath string = "~/.a3web.conf" + type Config struct { + serverURL string `json:"serverURL"` + } + var config Config + + if _, err := os.Stat(configPath); err == nil { + configFile, _ := ioutil.ReadFile(configPath) + json.Unmarshal(configFile, &config) + serverURL = config.serverURL + } } // RVExtensionArgs STRING callExtension ARRAY @@ -56,8 +72,8 @@ func RVExtensionArgs(output *C.char, outputsize C.size_t, function *C.char, argv out = append(out, C.GoString(*argv)) argv = (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(argv)) + offset)) } - - go handleArgs(C.GoString(function), argc, out) + + go handleArgs(C.GoString(function), out) } // RVExtension STRING callExtension STRING @@ -71,14 +87,20 @@ func RVExtension(output *C.char, outputsize C.size_t, function *C.char) { func main() {} -func handleArgs(function string, argc C.int, argv []string) { - fns := strings.Split(strings.ToLower(function), ":") - if len(fns) == 3 && fns[0] == "http" && fns[1] == "post" { - resp, err := http.Post(serverURL + fns[2], "", strings.NewReader(argv[0])) - if err != nil { - log.Printf("Error Sending HTTP Request: %s", err) - return - } - resp.Body.Close() +func handleArgs(function string, argv []string) { + switch dispatcher := "function" + dispatcher { + case "upload_pos": + uploadUnitsInfo(argv[0]) } } + +func uploadUnitsInfo(body string) { + var endpoint string = "/units-info" + resp, err := http.Post(serverURL + endpoint, "", strings.NewReader(body)) + if err != nil { + log.Printf("Error Sending HTTP Request: %s", err) + return + } + resp.Body.Close() +} diff --git a/server-lisp/server.lisp b/server-lisp/server.lisp index bb77e6d..d61f4d1 100644 --- a/server-lisp/server.lisp +++ b/server-lisp/server.lisp @@ -82,8 +82,8 @@ (defparameter +dispatch-table+ `(("^/$" ,#'route-ok) - ("^/post-arma3-info$" ,#'route-post-arma3-info) - ("^/units-pos$" ,#'route-units-pos) + ("^/positional-info$" ,#'route-post-arma3-info) + ("^/units-info$" ,#'route-units-pos) (,(concatenate 'string "^" +static-prefix+ ".*$") ,#'serve-static-file) (nil ,#'route-not-found)))