summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/gokz/localdb.inc
blob: 472a1205a8e3c5670f7a3d4d9a50101d51370f19 (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
	gokz-localdb Plugin Include
	
	Website: https://bitbucket.org/kztimerglobalteam/gokz
*/

#if defined _gokz_localdb_included_
#endinput
#endif
#define _gokz_localdb_included_



// =====[ ENUMS ]=====

enum DatabaseType
{
	DatabaseType_None = -1, 
	DatabaseType_MySQL, 
	DatabaseType_SQLite
};

enum
{
	JumpstatDB_Lookup_JumpID = 0, 
	JumpstatDB_Lookup_Distance, 
	JumpstatDB_Lookup_Block
};

enum
{
	JumpstatDB_FindPlayer_SteamID32 = 0, 
	JumpstatDB_FindPlayer_Alias
};

enum
{
	JumpstatDB_Top20_JumpID = 0,
	JumpstatDB_Top20_SteamID, 
	JumpstatDB_Top20_Alias, 
	JumpstatDB_Top20_Block, 
	JumpstatDB_Top20_Distance, 
	JumpstatDB_Top20_Strafes, 
	JumpstatDB_Top20_Sync, 
	JumpstatDB_Top20_Pre, 
	JumpstatDB_Top20_Max, 
	JumpstatDB_Top20_Air
};

enum
{
	JumpstatDB_PBMenu_JumpID = 0,
	JumpstatDB_PBMenu_JumpType,
	JumpstatDB_PBMenu_Distance,
	JumpstatDB_PBMenu_Strafes,
	JumpstatDB_PBMenu_Sync,
	JumpstatDB_PBMenu_Pre,
	JumpstatDB_PBMenu_Max,
	JumpstatDB_PBMenu_Air
};

enum
{
	JumpstatDB_BlockPBMenu_JumpID = 0,
	JumpstatDB_BlockPBMenu_JumpType,
	JumpstatDB_BlockPBMenu_Block,
	JumpstatDB_BlockPBMenu_Distance,
	JumpstatDB_BlockPBMenu_Strafes,
	JumpstatDB_BlockPBMenu_Sync,
	JumpstatDB_BlockPBMenu_Pre,
	JumpstatDB_BlockPBMenu_Max,
	JumpstatDB_BlockPBMenu_Air
};

enum
{
	JumpstatDB_Cache_Distance = 0, 
	JumpstatDB_Cache_Block, 
	JumpstatDB_Cache_BlockDistance, 
	JUMPSTATDB_CACHE_COUNT
};

enum
{
	TimerSetupDB_GetVBPos_SteamID = 0, 
	TimerSetupDB_GetVBPos_MapID, 
	TimerSetupDB_GetVBPos_Course, 
	TimerSetupDB_GetVBPos_IsStart, 
	TimerSetupDB_GetVBPos_PositionX, 
	TimerSetupDB_GetVBPos_PositionY, 
	TimerSetupDB_GetVBPos_PositionZ
};

enum
{
	TimerSetupDB_GetStartPos_SteamID = 0, 
	TimerSetupDB_GetStartPos_MapID, 
	TimerSetupDB_GetStartPos_PositionX, 
	TimerSetupDB_GetStartPos_PositionY, 
	TimerSetupDB_GetStartPos_PositionZ, 
	TimerSetupDB_GetStartPos_Angle0, 
	TimerSetupDB_GetStartPos_Angle1
};

enum DBOption:
{
	DBOption_AutoLoadTimerSetup = 0, 
	DBOPTION_COUNT
};

enum
{
	DBOption_Disabled = 0, 
	DBOption_Enabled, 
	DBOPTIONBOOL_COUNT
};



// =====[ CONSTANTS ]=====

#define GOKZ_DB_JS_DISTANCE_PRECISION 10000
#define GOKZ_DB_JS_SYNC_PRECISION 100
#define GOKZ_DB_JS_PRE_PRECISION 100
#define GOKZ_DB_JS_MAX_PRECISION 100
#define GOKZ_DB_JS_AIRTIME_PRECISION 10000
#define GOKZ_DB_JS_MAX_JUMPS_PER_PLAYER 100

stock char gC_DBOptionNames[DBOPTION_COUNT][] = 
{
	"GOKZ DB - Auto Load Setup"
};

stock char gC_DBOptionDescriptions[DBOPTION_COUNT][] = 
{
	"Automatically load timer setup on map start - 0 = Disabled, 1 = Enabled"
}

stock int gI_DBOptionDefaultValues[DBOPTION_COUNT] = 
{
	DBOption_Disabled
};

stock int gI_DBOptionCounts[DBOPTION_COUNT] = 
{
	DBOPTIONBOOL_COUNT
};

stock char gC_DBOptionPhrases[DBOPTION_COUNT][] = 
{
	"Options Menu - Auto Load Timer Setup"
};



// =====[ TYPES ]=====

typeset GetVBPositionCallback
{
	function Action(int client, const float position[3], int course, bool isStart);
};

typeset GetStartPositionCallback
{
	function Action(int client, const float position[3], const float angles[3]);
};



// =====[ FORWARDS ]=====

/**
 * Called when gokz-localdb has connected to the database.
 * Use GOKZ_DB_GetDatabase to get a clone of the database handle.
 *
 * @param DBType		Database type.
 */
forward void GOKZ_DB_OnDatabaseConnect(DatabaseType DBType);

/**
 * Called when a player is ready for database interaction.
 * At this point, the player is present and updated in the "Players" table.
 *
 * @param client		Client index.
 * @param steamID		SteamID32 of the player (from GetSteamAccountID()).
 * @param cheater		Whether player is marked as a cheater in the database.
 */
forward void GOKZ_DB_OnClientSetup(int client, int steamID, bool cheater);

/**
 * Called when the current map is ready for database interaction.
 * At this point, the map is present and updated in the "Maps" table.
 *
 * @param mapID			MapID from the "Maps" table.
 */
forward void GOKZ_DB_OnMapSetup(int mapID);

/**
 * Called when a time has been inserted into the database.
 *
 * @param client			Client index.
 * @param steamID			SteamID32 of the player (from GetSteamAccountID()).
 * @param mapID				MapID from the "Maps" table.
 * @param course    		Course number e.g. 0=main, 1='bonus1' etc.
 * @param mode				Player's movement mode.
 * @param style				Player's movement style.
 * @param runTimeMS			Player's end time in milliseconds.
 * @param teleportsUsed		Number of teleports used by player.
 */
forward void GOKZ_DB_OnTimeInserted(
	int client, 
	int steamID, 
	int mapID, 
	int course, 
	int mode, 
	int style, 
	int runTimeMS, 
	int teleportsUsed);

/**
 * Called when jumpstat PB has been achieved.
 *
 * @param client		Client index.
 * @param jumptype		Type of the jump.
 * @param mode			Mode the jump was performed in.
 * @param distance		Distance jumped.
 * @param block			The size of the block jumped across.
 * @param strafes		The amount of strafes used.
 * @param sync			Keyboard/mouse synchronisation of the jump.
 * @param pre			Speed at takeoff.
 * @param max			Maximum speed during the jump.
 * @param airtime		Amount of time spend airborne.
 */
forward void GOKZ_DB_OnJumpstatPB(
	int client,
	int jumptype,
	int mode,
	float distance,
	int block,
	int strafes,
	float sync,
	float pre,
	float max,
	int airtime);


// =====[ NATIVES ]=====

/**
 * Gets a clone of the GOKZ local database handle.
 *
 * @param database		Database handle, or null if connection hasn't been made.
 */
native Database GOKZ_DB_GetDatabase();

/**
 * Gets the GOKZ local database type.
 *
 * @return				Database type.
 */
native DatabaseType GOKZ_DB_GetDatabaseType();

/**
 * Gets whether client has been set up for GOKZ Local DB.
 *
 * @param client		Client index.
 * @return				Whether GOKZ Local DB has set up the client.
 */
native bool GOKZ_DB_IsClientSetUp(int client);

/**
 * Gets whether GOKZ Local DB is set up for the current map.
 *
 * @return				Whether GOKZ Local DB has set up the current map.
 */
native bool GOKZ_DB_IsMapSetUp();

/**
 * Gets the current map's MapID as in the "Maps" table.
 *
 * @return				MapID from the "Maps" table.
 */
native int GOKZ_DB_GetCurrentMapID();

/**
 * Gets whether player is marked as a cheater in the database.
 *
 * @param client		Client index.
 * @return				Whether player is marked as a cheater in the database.
 */
native bool GOKZ_DB_IsCheater(int client);

/**
 * Sets wheter player is marked as a cheater in the database.
 *
 * @param client		Client index.
 * @param cheater		Whether to mark the player as a cheater.
 */
native void GOKZ_DB_SetCheater(int client, bool cheater);



// =====[ STOCKS ]=====

/**
 * Converts a time float (seconds) to an integer (milliseconds).
 *
 * @param time			Time in seconds.
 * @return				Time in milliseconds.
 */
stock int GOKZ_DB_TimeFloatToInt(float time)
{
	return RoundFloat(time * 1000.0);
}

/**
 * Converts a time integer (milliseconds) to a float (seconds).
 *
 * @param time			Time in milliseconds.
 * @return				Time in seconds.
 */
stock float GOKZ_DB_TimeIntToFloat(int time)
{
	return time / 1000.0;
}



// =====[ DEPENDENCY ]=====

public SharedPlugin __pl_gokz_localdb = 
{
	name = "gokz-localdb", 
	file = "gokz-localdb.smx", 
	#if defined REQUIRE_PLUGIN
	required = 1, 
	#else
	required = 0, 
	#endif
};

#if !defined REQUIRE_PLUGIN
public void __pl_gokz_localdb_SetNTVOptional()
{
	MarkNativeAsOptional("GOKZ_DB_GetDatabase");
	MarkNativeAsOptional("GOKZ_DB_GetDatabaseType");
	MarkNativeAsOptional("GOKZ_DB_IsClientSetUp");
	MarkNativeAsOptional("GOKZ_DB_IsMapSetUp");
	MarkNativeAsOptional("GOKZ_DB_GetCurrentMapID");
	MarkNativeAsOptional("GOKZ_DB_IsCheater");
	MarkNativeAsOptional("GOKZ_DB_SetCheater");
}
#endif