-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalAPI.sp
More file actions
122 lines (88 loc) · 3.22 KB
/
GlobalAPI.sp
File metadata and controls
122 lines (88 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// ====================== DEFINITIONS ======================== //
#define DATA_DIR "data/GlobalAPI"
// =========================================================== //
#include <sourcemod>
#include <SteamWorks>
#include <GlobalAPI>
#include <GlobalAPI/request>
// ====================== FORMATTING ========================= //
#pragma dynamic 131072
#pragma newdecls required
// ====================== VARIABLES ========================== //
bool gB_IsInit = false;
bool gB_usingAPIKey = false;
char gC_apiKey[GlobalAPI_Max_APIKey_Length];
char gC_baseUrl[GlobalAPI_Max_BaseUrl_Length];
char gC_MetamodVersion[32];
char gC_SourcemodVersion[32];
char gC_mapName[64];
char gC_mapPath[PLATFORM_MAX_PATH];
int gI_mapFilesize = -1;
// ======================= INCLUDES ========================== //
#include "GlobalAPI/api/convars.sp"
#include "GlobalAPI/api/natives.sp"
#include "GlobalAPI/api/forwards.sp"
#include "GlobalAPI/misc.sp"
#include "GlobalAPI/commands.sp"
#include "GlobalAPI/http/get.sp"
#include "GlobalAPI/http/post.sp"
#include "GlobalAPI/http/forwards.sp"
// ====================== PLUGIN INFO ======================== //
public Plugin myinfo =
{
name = "GlobalAPI",
author = "The KZ Global Team",
description = GlobalAPI_Plugin_Desc,
version = GlobalAPI_Plugin_Version,
url = GlobalAPI_Plugin_Url
};
// ======================= MAIN CODE ========================= //
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
RegPluginLibrary("GlobalAPI");
CreateConvars();
CreateNatives();
CreateForwards();
CreateCommands();
char dataDir[PLATFORM_MAX_PATH];
BuildPath(Path_SM, dataDir, sizeof(dataDir), "%s", DATA_DIR);
TryCreateDirectory(dataDir);
// TODO: Create empty apikey file?
}
public void OnPluginStart()
{
ConVar metamodCvar = FindConVar("metamod_version");
metamodCvar.GetString(gC_MetamodVersion, sizeof(gC_MetamodVersion));
ConVar sourcemodCvar = FindConVar("sourcemod_Version");
sourcemodCvar.GetString(gC_SourcemodVersion, sizeof(gC_SourcemodVersion));
gB_usingAPIKey = ReadAPIKey();
AutoExecConfig(true, "globalapi-convars");
}
public void OnMapStart()
{
GetMapDisplay(gC_mapName, sizeof(gC_mapName));
GetMapFullPath(gC_mapPath, sizeof(gC_mapPath));
gI_mapFilesize = FileSize(gC_mapPath);
}
public void OnConfigsExecuted()
{
Initialize();
}
public void GlobalAPI_OnRequestStarted(Handle request, GlobalAPIRequestData hData)
{
char requestUrl[GlobalAPI_Max_BaseUrl_Length];
hData.GetString("url", requestUrl, sizeof(requestUrl));
GlobalAPI_DebugMessage("HTTP Request to \"%s\" started!", requestUrl);
}
public void GlobalAPI_OnRequestFailed(Handle request, GlobalAPIRequestData hData)
{
char requestUrl[GlobalAPI_Max_BaseUrl_Length];
hData.GetString("url", requestUrl, sizeof(requestUrl));
GlobalAPI_DebugMessage("HTTP Request to \"%s\" failed! - Status: %d", requestUrl, hData.Status);
}
public void GlobalAPI_OnRequestFinished(Handle request, GlobalAPIRequestData hData)
{
char requestUrl[GlobalAPI_Max_BaseUrl_Length];
hData.GetString("url", requestUrl, sizeof(requestUrl));
GlobalAPI_DebugMessage("HTTP Request to \"%s\" completed! - Status: %d", requestUrl, hData.Status);
}