diff --git a/README.md b/README.md index 03f1c2d..ebed5a6 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Start CMD and install the [Insurgency Server](https://developer.valvesoftware.co Download and unpack [Sourcemod](http://www.sourcemod.net/downloads.php), after unpacking, there should be two directories, *addons* and *cfg*. Execute *build.sh* with the addons dir as argument. Download and unpack the extensions [json](https://github.com/FAUSheppy/sm-json) and and move all files into the *scriping/include/* directory. -Download and upack the [system2](https://forums.alliedmods.net/showthread.php?t=146019), follow the instructions there to install it. +Download and upack the [system2](https://forums.alliedmods.net/showthread.php?t=146019) and and move all files into the *scriping/include/* and *extensions* directory respectively. ./build.sh /path/to/addons/dir/ diff --git a/extensions/system2.ext.dll b/extensions/system2.ext.dll new file mode 100644 index 0000000..118bdf3 Binary files /dev/null and b/extensions/system2.ext.dll differ diff --git a/extensions/system2.ext.so b/extensions/system2.ext.so new file mode 100644 index 0000000..9dad877 Binary files /dev/null and b/extensions/system2.ext.so differ diff --git a/scripting/Interfaces.sp b/scripting/Interfaces.sp index 90aaa87..15eff3c 100644 --- a/scripting/Interfaces.sp +++ b/scripting/Interfaces.sp @@ -3,45 +3,91 @@ #include #include #include +#include +#include #define DEFAULT_LEN 64 #define SNAME_LEN 256 #define ACTIVE_CLIENTS_LENGTH 8192 -public void SmartClientName(const client, char[] buf, buflen){ - new String:name[DEFAULT_LEN]; - if(IsClientConnected(client)){ - GetClientName(client, name, DEFAULT_LEN); - } -} + public void HttpResponseCallback(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method) { + } -public void SmartClientID(int client, char[] buf, int buflen){ - if(IsClientConnected(client)){ - GetClientAuthId(client, AuthId_SteamID64, buf, DEFAULT_LEN, true); - } +public void SubmittViaHTTP(char[] jsonString){ + System2HTTPRequest httpRequest = new System2HTTPRequest(HttpResponseCallback, "http://localhost:5000/single-event"); + httpRequest.SetHeader("Content-Type", "application/json"); + httpRequest.SetData(jsonString); + httpRequest.POST(); } public void SubmittEventActiveClients(){ - //new String:str_tmp[ACTIVE_CLIENTS_LENGTH]; + + /* primary json */ + JSON_Object obj = new JSON_Object(); + obj.SetString("etype", "active_players"); + obj.SetInt("timestamp", GetTime()); + + /* generate players */ + JSON_Array players = new JSON_Array(); + for(new i = 1; i <= MaxClients;i++){ - new String:strCliID[DEFAULT_LEN]; - new String:strCliName[DEFAULT_LEN]; - SmartClientID(i, strCliID, DEFAULT_LEN); - SmartClientName(i, strCliName, DEFAULT_LEN); - // strCliID, strCliName, GetClientTeam(i)); + if(!IsClientConnected(i)){ + continue; + } + + JSON_Object player = new JSON_Object(); + + new String:clientId[DEFAULT_LEN]; + new String:clientName[DEFAULT_LEN]; + GetClientAuthId(i, AuthId_SteamID64, clientId, DEFAULT_LEN, true); + GetClientName(i, clientName, DEFAULT_LEN); + + player.SetString("id", clientId) + player.SetString("name", clientName) + player.SetInt("team", GetClientTeam(i)) + players.PushObject(player) } - // return json + + /* add players array to primary object */ + obj.SetObject("players", players); + + char output[2048]; + obj.Encode(output, sizeof(output)); + SubmittViaHTTP(output) } public void SubmittEventMapInformation(){ new String:mapname[DEFAULT_LEN]; GetCurrentMap(mapname, sizeof(mapname)); + + JSON_Object obj = new JSON_Object(); + obj.SetString("etype", "map"); + obj.SetInt("timestamp", GetTime()); + obj.SetString("map", mapname); + + char output[2048]; + obj.Encode(output, sizeof(output)); + SubmittViaHTTP(output) } public void SubmittEventWinnerTeam(int team_id){ + + JSON_Object obj = new JSON_Object(); + obj.SetString("etype", "map"); + obj.SetInt("timestamp", GetTime()); + obj.SetInt("winnerTeam", team_id); + char output[2048]; + obj.Encode(output, sizeof(output)); + SubmittViaHTTP(output) } public void SubmittEventRoundEnd(){ + JSON_Object obj = new JSON_Object(); + obj.SetString("etype", "round_end"); + obj.SetInt("timestamp", GetTime()); + char output[2048]; + obj.Encode(output, sizeof(output)); + SubmittViaHTTP(output) } \ No newline at end of file