Initial commit
This commit is contained in:
544
scripting/towerdefense/database/general.sp
Normal file
544
scripting/towerdefense/database/general.sp
Normal file
@@ -0,0 +1,544 @@
|
||||
#pragma semicolon 1
|
||||
|
||||
#include <sourcemod>
|
||||
|
||||
#if defined INFO_INCLUDES
|
||||
#include "../info/constants.sp"
|
||||
#include "../info/enums.sp"
|
||||
#include "../info/variables.sp"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Database Connection Callback
|
||||
*/
|
||||
public void ConnectToDB(Database db, const char[] error, any data) {
|
||||
if (!db || error[0]) {
|
||||
LogError("Database failure: %s", error);
|
||||
SetFailState("OnDatabaseConnectionResult: %s", error);
|
||||
} else {
|
||||
g_hDatabase = db;
|
||||
}
|
||||
}
|
||||
|
||||
/*======================================
|
||||
= Data Functions =
|
||||
======================================*/
|
||||
|
||||
/**
|
||||
* Starts to load all data from the database, calls Database_OnDataLoaded() when finished.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_LoadData() {
|
||||
Database_LoadTowers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads towers to its map.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_LoadTowers() {
|
||||
char sQuery[512];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `tower`.`tower_id`, `level`, `tower`.`name`, `class`, `price`, `teleport_tower`, `damagetype`, `description`, `metal`, `weapon_id`, `attack`, `rotate`, `pitch`, `damage`, `attackspeed`, `area` " ...
|
||||
"FROM `tower` " ...
|
||||
"INNER JOIN `map` " ...
|
||||
"ON (`map`.`map_id` = %d) " ...
|
||||
"INNER JOIN `towerlevel` " ...
|
||||
"ON (`tower`.`tower_id` = `towerlevel`.`tower_id`) " ...
|
||||
"ORDER BY `tower`.`name` ASC, `level` ASC",
|
||||
g_iServerMap);
|
||||
|
||||
g_hDatabase.Query(Database_OnLoadTowers, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnLoadTowers(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_LoadTowers > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
int iTowerId = 0, iTowerLevel = 0;
|
||||
char sKey[64], sBuffer[128];
|
||||
|
||||
// Level Name Class Price Location Damagetype Description Metal WeaponId AttackPrimary AttackSecondary Rotate Pitch Damage Attackspeed Area
|
||||
// 1 EngineerTower Engineer 500 666 -626 -2 0 0 0 Melee ... 1000 1 1 0 0 45 1.0 1.0 1.0
|
||||
|
||||
while (SQL_FetchRow(hResult)) {
|
||||
iTowerId = SQL_FetchInt(hResult, 0) - 1;
|
||||
iTowerLevel = SQL_FetchInt(hResult, 1);
|
||||
|
||||
// Save data only once
|
||||
if (iTowerLevel == 1) {
|
||||
// Save tower name
|
||||
Format(sKey, sizeof(sKey), "%d_name", iTowerId);
|
||||
SQL_FetchString(hResult, 2, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapTowers, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save tower class
|
||||
Format(sKey, sizeof(sKey), "%d_class", iTowerId);
|
||||
SQL_FetchString(hResult, 3, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapTowers, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save tower price
|
||||
Format(sKey, sizeof(sKey), "%d_price", iTowerId);
|
||||
SetTrieValue(g_hMapTowers, sKey, SQL_FetchInt(hResult, 4));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 4));
|
||||
|
||||
// Save tower location
|
||||
Format(sKey, sizeof(sKey), "%d_location", iTowerId);
|
||||
SQL_FetchString(hResult, 5, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapTowers, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save tower damagetype
|
||||
Format(sKey, sizeof(sKey), "%d_damagetype", iTowerId);
|
||||
SQL_FetchString(hResult, 6, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapTowers, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save tower description
|
||||
Format(sKey, sizeof(sKey), "%d_description", iTowerId);
|
||||
SQL_FetchString(hResult, 7, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapTowers, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
}
|
||||
|
||||
// PrintToServer("Level %d:", iTowerLevel);
|
||||
|
||||
// Save tower level metal
|
||||
Format(sKey, sizeof(sKey), "%d_%d_metal", iTowerId, iTowerLevel);
|
||||
SetTrieValue(g_hMapTowers, sKey, SQL_FetchInt(hResult, 8));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 8));
|
||||
|
||||
// Save tower level weapon index
|
||||
Format(sKey, sizeof(sKey), "%d_%d_weapon", iTowerId, iTowerLevel);
|
||||
SetTrieValue(g_hMapTowers, sKey, SQL_FetchInt(hResult, 9));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 9));
|
||||
|
||||
// Save tower level attack mode
|
||||
Format(sKey, sizeof(sKey), "%d_%d_attack", iTowerId, iTowerLevel);
|
||||
SQL_FetchString(hResult, 10, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapTowers, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save tower level rotate
|
||||
Format(sKey, sizeof(sKey), "%d_%d_rotate", iTowerId, iTowerLevel);
|
||||
SetTrieValue(g_hMapTowers, sKey, SQL_FetchInt(hResult, 11));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 11));
|
||||
|
||||
// Save tower level pitch
|
||||
Format(sKey, sizeof(sKey), "%d_%d_pitch", iTowerId, iTowerLevel);
|
||||
SetTrieValue(g_hMapTowers, sKey, SQL_FetchInt(hResult, 12));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 12));
|
||||
|
||||
// Save tower level damage
|
||||
Format(sKey, sizeof(sKey), "%d_%d_damage", iTowerId, iTowerLevel);
|
||||
SetTrieValue(g_hMapTowers, sKey, SQL_FetchFloat(hResult, 13));
|
||||
|
||||
// PrintToServer("%s => %f", sKey, SQL_FetchFloat(hResult, 13));
|
||||
|
||||
// Save tower level attackspeed
|
||||
Format(sKey, sizeof(sKey), "%d_%d_attackspeed", iTowerId, iTowerLevel);
|
||||
SetTrieValue(g_hMapTowers, sKey, SQL_FetchFloat(hResult, 14));
|
||||
|
||||
// PrintToServer("%s => %f", sKey, SQL_FetchFloat(hResult, 14));
|
||||
|
||||
// Save tower level area
|
||||
Format(sKey, sizeof(sKey), "%d_%d_area", iTowerId, iTowerLevel);
|
||||
SetTrieValue(g_hMapTowers, sKey, SQL_FetchFloat(hResult, 15));
|
||||
|
||||
// PrintToServer("%s => %f", sKey, SQL_FetchFloat(hResult, 15));
|
||||
}
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
|
||||
Database_LoadWeapons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads weapons to its map.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_LoadWeapons() {
|
||||
char sQuery[256];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `name`, `index`, (`slot` - 1), `level`, (`quality` - 1), `classname`, `attributes`, (`preserve_attributes` - 1) " ...
|
||||
"FROM `weapon` " ...
|
||||
"ORDER BY `weapon_id` ASC");
|
||||
|
||||
g_hDatabase.Query(Database_OnLoadWeapons, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnLoadWeapons(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_LoadWeapons > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
int iWeaponId = 1;
|
||||
char sKey[64], sBuffer[128];
|
||||
|
||||
// Name Index Slot Level Quality Classname Attributes Preserve
|
||||
// Wrench 7 2 1 0 tf_weapon_wrench 1
|
||||
|
||||
while (SQL_FetchRow(hResult)) {
|
||||
// Save weapon name
|
||||
Format(sKey, sizeof(sKey), "%d_name", iWeaponId);
|
||||
SQL_FetchString(hResult, 0, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapWeapons, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save weapon index
|
||||
Format(sKey, sizeof(sKey), "%d_index", iWeaponId);
|
||||
SetTrieValue(g_hMapWeapons, sKey, SQL_FetchInt(hResult, 1));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 1));
|
||||
|
||||
// Save weapon slot
|
||||
Format(sKey, sizeof(sKey), "%d_slot", iWeaponId);
|
||||
SetTrieValue(g_hMapWeapons, sKey, SQL_FetchInt(hResult, 2));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 2));
|
||||
|
||||
// Save weapon level
|
||||
Format(sKey, sizeof(sKey), "%d_level", iWeaponId);
|
||||
SetTrieValue(g_hMapWeapons, sKey, SQL_FetchInt(hResult, 3));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 3));
|
||||
|
||||
// Save weapon quality
|
||||
Format(sKey, sizeof(sKey), "%d_quality", iWeaponId);
|
||||
SetTrieValue(g_hMapWeapons, sKey, SQL_FetchInt(hResult, 4));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 4));
|
||||
|
||||
// Save weapon classname
|
||||
Format(sKey, sizeof(sKey), "%d_classname", iWeaponId);
|
||||
SQL_FetchString(hResult, 5, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapWeapons, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save weapon attributes
|
||||
Format(sKey, sizeof(sKey), "%d_attributes", iWeaponId);
|
||||
SQL_FetchString(hResult, 6, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapWeapons, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save weapon preserve attributes
|
||||
Format(sKey, sizeof(sKey), "%d_preserve_attributes", iWeaponId);
|
||||
SetTrieValue(g_hMapWeapons, sKey, SQL_FetchInt(hResult, 7));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 7));
|
||||
|
||||
iWeaponId++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
|
||||
Database_LoadWaves();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads waves to its map.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_LoadWaves() {
|
||||
char sQuery[512];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `wavetype`, `wave`.`name`, `class`, `quantity`, `health`, IF(`wavetype` & (SELECT `bit_value` FROM `wavetype` WHERE `wavetype`.`type` = 'air'), `teleport_air`, `teleport_ground`) " ...
|
||||
"FROM `wave` " ...
|
||||
"INNER JOIN `map` " ...
|
||||
"ON (`map`.`map_id` = %d) " ...
|
||||
"WHERE `wave_id` >= `wave_start` AND `wave_id` <= `wave_end` " ...
|
||||
"ORDER BY `wave_id` ASC",
|
||||
g_iServerMap);
|
||||
|
||||
g_hDatabase.Query(Database_OnLoadWaves, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnLoadWaves(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_LoadWaves > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
int iWaveId = 0;
|
||||
char sKey[64], sBuffer[128];
|
||||
|
||||
iMaxWaves = 0;
|
||||
|
||||
// Type Name Class Quantiy Health Location
|
||||
// 0 WeakScout Scout 4 125 560 -1795 -78 0 90 0
|
||||
|
||||
while (SQL_FetchRow(hResult)) {
|
||||
// Save wave type
|
||||
Format(sKey, sizeof(sKey), "%d_type", iWaveId);
|
||||
SetTrieValue(g_hMapWaves, sKey, SQL_FetchInt(hResult, 0));
|
||||
|
||||
if (iWaveId == 0) {
|
||||
g_iNextWaveType = SQL_FetchInt(hResult, 0);
|
||||
}
|
||||
|
||||
// Save wave name
|
||||
Format(sKey, sizeof(sKey), "%d_name", iWaveId);
|
||||
SQL_FetchString(hResult, 1, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapWaves, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save wave class
|
||||
Format(sKey, sizeof(sKey), "%d_class", iWaveId);
|
||||
SQL_FetchString(hResult, 2, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapWaves, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save wave quantity
|
||||
Format(sKey, sizeof(sKey), "%d_quantity", iWaveId);
|
||||
SetTrieValue(g_hMapWaves, sKey, SQL_FetchInt(hResult, 3));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 3));
|
||||
|
||||
// Save wave health
|
||||
Format(sKey, sizeof(sKey), "%d_health", iWaveId);
|
||||
SetTrieValue(g_hMapWaves, sKey, SQL_FetchInt(hResult, 4));
|
||||
|
||||
// PrintToServer("%s => %d", sKey, SQL_FetchInt(hResult, 4));
|
||||
|
||||
// Save wave location
|
||||
Format(sKey, sizeof(sKey), "%d_location", iWaveId);
|
||||
SQL_FetchString(hResult, 5, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapWaves, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
iWaveId++;
|
||||
iMaxWaves++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
|
||||
Database_LoadAirWaveSpawn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the spawn location of air waves (for anti-air towers).
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_LoadAirWaveSpawn() {
|
||||
char sQuery[512];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `teleport_air` " ...
|
||||
"FROM `map` " ...
|
||||
"WHERE (`map_id` = %d)",
|
||||
g_iServerMap);
|
||||
|
||||
g_hDatabase.Query(Database_OnLoadAirWaveSpawn, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnLoadAirWaveSpawn(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_LoadAirWaveSpawn > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
SQL_FetchRow(hResult);
|
||||
|
||||
SQL_FetchString(hResult, 0, g_sAirWaveSpawn, sizeof(g_sAirWaveSpawn));
|
||||
|
||||
char sLocationParts[6][16];
|
||||
ExplodeString(g_sAirWaveSpawn, " ", sLocationParts, sizeof(sLocationParts), sizeof(sLocationParts[]));
|
||||
|
||||
g_fAirWaveSpawn[0] = StringToFloat(sLocationParts[0]);
|
||||
g_fAirWaveSpawn[1] = StringToFloat(sLocationParts[1]);
|
||||
g_fAirWaveSpawn[2] = StringToFloat(sLocationParts[2]);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
|
||||
Database_LoadMetalpacks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads metalpacks to its map.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_LoadMetalpacks() {
|
||||
char sQuery[256];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `type`, `metal`, `location` " ...
|
||||
"FROM `metalpack` " ...
|
||||
"INNER JOIN `metalpacktype` " ...
|
||||
"ON (`metalpack`.`metalpacktype_id` = `metalpacktype`.`metalpacktype_id`) " ...
|
||||
"WHERE `map_id` = %d " ...
|
||||
"ORDER BY `metalpack_id` ASC",
|
||||
g_iServerMap);
|
||||
|
||||
g_hDatabase.Query(Database_OnLoadMetalpacks, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnLoadMetalpacks(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_LoadMetalpacks > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
int iMetalpackId = 0;
|
||||
char sKey[64], sBuffer[128];
|
||||
|
||||
// Type Metal Location
|
||||
// start 400 1100 -1200 -90
|
||||
|
||||
while (SQL_FetchRow(hResult)) {
|
||||
// Save metalpack type
|
||||
Format(sKey, sizeof(sKey), "%d_type", iMetalpackId);
|
||||
SQL_FetchString(hResult, 0, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapMetalpacks, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save metalpack metal
|
||||
Format(sKey, sizeof(sKey), "%d_metal", iMetalpackId);
|
||||
SetTrieValue(g_hMapMetalpacks, sKey, SQL_FetchInt(hResult, 1));
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
// Save metalpack location
|
||||
Format(sKey, sizeof(sKey), "%d_location", iMetalpackId);
|
||||
SQL_FetchString(hResult, 2, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMapMetalpacks, sKey, sBuffer);
|
||||
|
||||
// PrintToServer("%s => %s", sKey, sBuffer);
|
||||
|
||||
iMetalpackId++;
|
||||
}
|
||||
|
||||
// Save metalpack quantity
|
||||
SetTrieValue(g_hMapMetalpacks, "quantity", iMetalpackId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
|
||||
Database_LoadMultipliersTypes();
|
||||
|
||||
}
|
||||
|
||||
stock void Database_LoadMultipliersTypes() {
|
||||
char sQuery[512];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery), "SELECT type FROM multipliertype ORDER BY `multipliertype_id` ASC", g_iServerMap);
|
||||
|
||||
g_hDatabase.Query(Database_OnLoadMultipliersTypes, sQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Multiplier Types
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
public void Database_OnLoadMultipliersTypes(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_LoadMaxWaves > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
// type
|
||||
// bullet
|
||||
int iMultiplierTypeId = 1;
|
||||
while (SQL_FetchRow(hResult)) {
|
||||
char sKey[64], sBuffer[128];
|
||||
|
||||
// Save type
|
||||
Format(sKey, sizeof(sKey), "%d_type", iMultiplierTypeId);
|
||||
SQL_FetchString(hResult, 0, sBuffer, sizeof(sBuffer));
|
||||
SetTrieString(g_hMultiplierType, sKey, sBuffer);
|
||||
|
||||
iMultiplierTypeId++;
|
||||
}
|
||||
}
|
||||
|
||||
Database_LoadMultipliers();
|
||||
}
|
||||
|
||||
stock void Database_LoadMultipliers() {
|
||||
char sQuery[512];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery), "SELECT price,increase FROM `multiplier` WHERE map_id=%d ORDER BY `multipliertype_id` ASC", g_iServerMap);
|
||||
|
||||
g_hDatabase.Query(Database_OnLoadMultipliers, sQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Multipliers
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
public void Database_OnLoadMultipliers(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_LoadMaxWaves > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
// multipliertype_id price increase
|
||||
// 1 1000 1000
|
||||
|
||||
iMaxMultiplierTypes = 0;
|
||||
int iMultiplierTypeId = 1;
|
||||
|
||||
while (SQL_FetchRow(hResult)) {
|
||||
char sKey[64];
|
||||
|
||||
// Save price
|
||||
Format(sKey, sizeof(sKey), "%d_price", iMultiplierTypeId);
|
||||
SetTrieValue(g_hMultiplier, sKey, SQL_FetchInt(hResult, 0));
|
||||
|
||||
// Save increase
|
||||
Format(sKey, sizeof(sKey), "%d_increase", iMultiplierTypeId);
|
||||
SetTrieValue(g_hMultiplier, sKey, SQL_FetchInt(hResult, 1));
|
||||
|
||||
iMultiplierTypeId++;
|
||||
iMaxMultiplierTypes++;
|
||||
}
|
||||
}
|
||||
|
||||
Database_OnDataLoaded();
|
||||
}
|
550
scripting/towerdefense/database/player.sp
Normal file
550
scripting/towerdefense/database/player.sp
Normal file
@@ -0,0 +1,550 @@
|
||||
#pragma semicolon 1
|
||||
|
||||
#include <sourcemod>
|
||||
|
||||
#if defined INFO_INCLUDES
|
||||
#include "../info/constants.sp"
|
||||
#include "../info/enums.sp"
|
||||
#include "../info/variables.sp"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Checks if a player already exists.
|
||||
*
|
||||
* @param iUserId The user id on server (unique on server).
|
||||
* @param iClient The client.
|
||||
* @param sCommunityId The clients 64-bit steam id (community id).
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_CheckPlayer(int iUserId, int iClient, const char[] sCommunityId) {
|
||||
if (!IsDefender(iClient)) {
|
||||
return;
|
||||
}
|
||||
|
||||
char sQuery[192];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `player_id` " ...
|
||||
"FROM `player` " ...
|
||||
"WHERE `player`.`steamid64` = '%s' " ...
|
||||
"LIMIT 1",
|
||||
sCommunityId);
|
||||
|
||||
g_hDatabase.Query(Database_OnCheckPlayer, sQuery, iUserId);
|
||||
}
|
||||
|
||||
public void Database_OnCheckPlayer(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_CheckPlayer > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult) == 0) {
|
||||
// No player found, add it
|
||||
Database_AddPlayer(iUserId);
|
||||
} else {
|
||||
SQL_FetchRow(hResult);
|
||||
|
||||
Player_USetValue(iUserId, PLAYER_DATABASE_ID, SQL_FetchInt(hResult, 0));
|
||||
|
||||
Database_UpdatePlayer(iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player.
|
||||
*
|
||||
* @param iUserId The user id on server (unique on server).
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_AddPlayer(int iUserId) {
|
||||
char sQuery[256];
|
||||
char sSteamId[32];
|
||||
char sPlayerNameSave[MAX_NAME_LENGTH * 2 + 1];
|
||||
char sPlayerIp[16];
|
||||
char sPlayerIpSave[33];
|
||||
|
||||
int iClient = GetClientOfUserId(iUserId);
|
||||
|
||||
SQL_EscapeString(g_hDatabase, GetClientNameShort(iClient), sPlayerNameSave, sizeof(sPlayerNameSave));
|
||||
|
||||
Player_UGetString(iUserId, PLAYER_COMMUNITY_ID, sSteamId, sizeof(sSteamId));
|
||||
|
||||
Player_UGetString(iUserId, PLAYER_IP_ADDRESS, sPlayerIp, sizeof(sPlayerIp));
|
||||
SQL_EscapeString(g_hDatabase, sPlayerIp, sPlayerIpSave, sizeof(sPlayerIpSave));
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"INSERT INTO `player` (`name`,`steamid64`,`ip`,`first_server`) " ...
|
||||
"VALUES ('%s', '%s', '%s', %d)",
|
||||
sPlayerNameSave, sSteamId, sPlayerIpSave, g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnAddPlayer_1, sQuery, iUserId);
|
||||
}
|
||||
|
||||
public void Database_OnAddPlayer_1(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_AddPlayer > Error: %s", sError);
|
||||
} else {
|
||||
char sQuery[32];
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery), "SELECT LAST_INSERT_ID()");
|
||||
|
||||
g_hDatabase.Query(Database_OnAddPlayer_2, sQuery, iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Database_OnAddPlayer_2(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_AddPlayer > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
char sSteamId[32];
|
||||
Player_UGetString(iUserId, PLAYER_COMMUNITY_ID, sSteamId, sizeof(sSteamId));
|
||||
|
||||
Log(TDLogLevel_Info, "Added player %N to database (%s)", GetClientOfUserId(iUserId), sSteamId);
|
||||
|
||||
SQL_FetchRow(hResult);
|
||||
|
||||
Player_USetValue(iUserId, PLAYER_DATABASE_ID, SQL_FetchInt(hResult, 0));
|
||||
|
||||
Database_UpdatePlayer(iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a servers info.
|
||||
*
|
||||
* @param iUserId The user id on server (unique on server).
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_UpdatePlayer(int iUserId) {
|
||||
char sQuery[512];
|
||||
|
||||
char sPlayerNameSave[MAX_NAME_LENGTH * 2 + 1];
|
||||
|
||||
int iClient = GetClientOfUserId(iUserId);
|
||||
|
||||
SQL_EscapeString(g_hDatabase, GetClientNameShort(iClient), sPlayerNameSave, sizeof(sPlayerNameSave));
|
||||
|
||||
char sPlayerIp[16];
|
||||
char sPlayerIpSave[33];
|
||||
|
||||
Player_UGetString(iUserId, PLAYER_IP_ADDRESS, sPlayerIp, sizeof(sPlayerIp));
|
||||
SQL_EscapeString(g_hDatabase, sPlayerIp, sPlayerIpSave, sizeof(sPlayerIpSave));
|
||||
|
||||
int iPlayerId;
|
||||
Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `player` " ...
|
||||
"SET `name` = '%s', " ...
|
||||
"`ip` = '%s', " ...
|
||||
"`last_server` = %d, " ...
|
||||
"`current_server` = %d " ...
|
||||
"WHERE `player_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
sPlayerNameSave, sPlayerIpSave, g_iServerId, g_iServerId, iPlayerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdatePlayer_1, sQuery, iUserId);
|
||||
}
|
||||
|
||||
public void Database_OnUpdatePlayer_1(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdatePlayer > Error: %s", sError);
|
||||
} else {
|
||||
char sQuery[512];
|
||||
|
||||
int iPlayerId;
|
||||
Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"INSERT IGNORE INTO `player_stats` (`player_id`, `map_id`, `first_connect`, `last_connect`, `last_disconnect`) " ...
|
||||
"VALUES (%d, " ...
|
||||
"(SELECT `map_id` " ...
|
||||
"FROM `server` " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1), " ...
|
||||
"UTC_TIMESTAMP(), UTC_TIMESTAMP(), UTC_TIMESTAMP())",
|
||||
iPlayerId, g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdatePlayer_2, sQuery, iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Database_OnUpdatePlayer_2(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdatePlayer > Error: %s", sError);
|
||||
} else {
|
||||
char sQuery[128];
|
||||
|
||||
int iPlayerId;
|
||||
Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `steamid64` " ...
|
||||
"FROM `player` " ...
|
||||
"WHERE `player_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
iPlayerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdatePlayer_3, sQuery, iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Database_OnUpdatePlayer_3(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdatePlayer > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
char sQuery[128];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `server` " ...
|
||||
"SET `players` = `players` + 1 " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdatePlayer_4, sQuery, iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Database_OnUpdatePlayer_4(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdatePlayer > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
SQL_FetchRow(hResult);
|
||||
|
||||
char sSteamId[32];
|
||||
SQL_FetchString(hResult, 0, sSteamId, sizeof(sSteamId));
|
||||
|
||||
Log(TDLogLevel_Info, "Updated player %N in database (%s)", GetClientOfUserId(iUserId), sSteamId);
|
||||
|
||||
Database_CheckPlayerBanned(iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player's banned.
|
||||
*
|
||||
* @param iUserId The user id on server (unique on server).
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_CheckPlayerBanned(int iUserId) {
|
||||
char sQuery[128];
|
||||
|
||||
int iPlayerId;
|
||||
Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `player_ban` " ...
|
||||
"SET `active` = 'not active' " ...
|
||||
"WHERE `player_id` = %d AND `expire` <= UTC_TIMESTAMP()",
|
||||
iPlayerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnCheckPlayerBanned_1, sQuery, iUserId);
|
||||
}
|
||||
|
||||
public void Database_OnCheckPlayerBanned_1(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_CheckPlayerBanned > Error: %s", sError);
|
||||
} else {
|
||||
char sQuery[512];
|
||||
|
||||
int iPlayerId;
|
||||
Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `reason`, CONCAT(`expire`, ' ', 'UTC') " ...
|
||||
"FROM `player_ban` " ...
|
||||
"WHERE `player_id` = %d AND `active` = 'active' AND `expire` " ...
|
||||
"IN (SELECT MAX(`expire`) " ...
|
||||
"FROM `player_ban` " ...
|
||||
"WHERE `player_id` = %d) " ...
|
||||
"LIMIT 1",
|
||||
iPlayerId, iPlayerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnCheckPlayerBanned_2, sQuery, iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Database_OnCheckPlayerBanned_2(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_CheckPlayerBanned > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
bool bDontProceed = false;
|
||||
|
||||
int iClient = GetClientOfUserId(iUserId);
|
||||
|
||||
SQL_FetchRow(hResult);
|
||||
|
||||
char sReason[256], sExpire[32];
|
||||
|
||||
SQL_FetchString(hResult, 0, sReason, sizeof(sReason));
|
||||
SQL_FetchString(hResult, 1, sExpire, sizeof(sExpire));
|
||||
|
||||
if (strlen(sReason) > 0) {
|
||||
KickClient(iClient, "You have been banned from TF2 Tower Defense until %s! Reason: %s", sExpire, sReason);
|
||||
bDontProceed = true;
|
||||
} else {
|
||||
KickClient(iClient, "You have been banned from TF2 Tower Defense until %s!", sExpire);
|
||||
bDontProceed = true;
|
||||
}
|
||||
|
||||
if (!bDontProceed) {
|
||||
Database_CheckPlayerImmunity(iUserId);
|
||||
}
|
||||
} else {
|
||||
Database_CheckPlayerImmunity(iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a players immunity level.
|
||||
*
|
||||
* @param iUserId The user id on server (unique on server).
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_CheckPlayerImmunity(int iUserId) {
|
||||
char sQuery[512];
|
||||
|
||||
int iPlayerId;
|
||||
Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `immunity` " ...
|
||||
"FROM `player_immunity` " ...
|
||||
"WHERE `player_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
iPlayerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnCheckPlayerImmunity, sQuery, iUserId);
|
||||
}
|
||||
|
||||
public void Database_OnCheckPlayerImmunity(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_CheckPlayerImmunity > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
int iClient = GetClientOfUserId(iUserId);
|
||||
|
||||
SQL_FetchRow(hResult);
|
||||
int iImmunity = SQL_FetchInt(hResult, 0);
|
||||
|
||||
if (iImmunity >= 99 && GetUserAdmin(iClient) == INVALID_ADMIN_ID) {
|
||||
AdminId iAdmin = CreateAdmin("Admin");
|
||||
|
||||
SetAdminFlag(iAdmin, Admin_Root, true);
|
||||
SetUserAdmin(iClient, iAdmin);
|
||||
}
|
||||
|
||||
Player_USetValue(iUserId, PLAYER_IMMUNITY, iImmunity);
|
||||
} else {
|
||||
Player_USetValue(iUserId, PLAYER_IMMUNITY, 0);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a disconnect client things.
|
||||
*
|
||||
* @param iUserId The user id on server (unique on server).
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_UpdatePlayerDisconnect(int iUserId) {
|
||||
char sQuery[128];
|
||||
|
||||
int iPlayerId;
|
||||
Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `player` " ...
|
||||
"SET `current_server` = NULL " ...
|
||||
"WHERE `player_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
iPlayerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdatePlayerDisconnect_1, sQuery, iUserId);
|
||||
}
|
||||
|
||||
public void Database_OnUpdatePlayerDisconnect_1(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdatePlayerDisconnect > Error: %s", sError);
|
||||
} else {
|
||||
char sQuery[128];
|
||||
|
||||
int iPlayerId;
|
||||
Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `player_stats` " ...
|
||||
"SET `last_disconnect` = UTC_TIMESTAMP() " ...
|
||||
"WHERE `player_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
iPlayerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdatePlayerDisconnect_2, sQuery, iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Database_OnUpdatePlayerDisconnect_2(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdatePlayerDisconnect > Error: %s", sError);
|
||||
} else {
|
||||
char sQuery[128];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `server` " ...
|
||||
"SET `players` = `players` - 1 " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdatePlayerDisconnect_3, sQuery, iUserId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Database_OnUpdatePlayerDisconnect_3(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdatePlayerDisconnect > Error: %s", sError);
|
||||
} else {
|
||||
// Get Saved Player Info
|
||||
int iKills, iAssists, iDeaths, iDamage, iObjects_Built, iTowers_Bought, iMetal_Pick, iMetal_Drop, iWaves_Played, iWaves_Reached, iRounds_Played, iRounds_Won, iPlayTime, iPlayerId;
|
||||
|
||||
if (!Player_UGetValue(iUserId, PLAYER_KILLS, iKills))
|
||||
iKills = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_ASSISTS, iAssists))
|
||||
iAssists = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_DEATHS, iDeaths))
|
||||
iDeaths = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_DAMAGE, iDamage))
|
||||
iDamage = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_OBJECTS_BUILT, iObjects_Built))
|
||||
iObjects_Built = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_TOWERS_BOUGHT, iTowers_Bought))
|
||||
iTowers_Bought = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_METAL_PICK, iMetal_Pick))
|
||||
iMetal_Pick = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_METAL_DROP, iMetal_Drop))
|
||||
iMetal_Drop = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_WAVES_PLAYED, iWaves_Played))
|
||||
iWaves_Played = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_WAVE_REACHED, iWaves_Reached))
|
||||
iWaves_Reached = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_ROUNDS_PLAYED, iRounds_Played))
|
||||
iRounds_Played = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_ROUNDS_WON, iRounds_Won))
|
||||
iRounds_Won = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_PLAYTIME, iPlayTime))
|
||||
iPlayTime = 0;
|
||||
if (!Player_UGetValue(iUserId, PLAYER_DATABASE_ID, iPlayerId))
|
||||
iPlayerId = 0;
|
||||
|
||||
// Update Player info based on saved info
|
||||
char sQuery[1024];
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `player_stats` " ...
|
||||
"SET `kills` = kills + %d, `assists` = assists + %d, `deaths` = deaths + %d, `damage` = damage + %d, " ...
|
||||
"`objects_built` = objects_built + %d, `towers_bought` = towers_bought + %d, `metal_pick` = metal_pick + %d, " ...
|
||||
"`metal_drop` = metal_drop + %d, `waves_played` = waves_played + %d, `wave_reached` = IF(wave_reached < %d, wave_reached = %d, wave_reached), " ...
|
||||
"`rounds_played` = rounds_played + %d, `rounds_won` = rounds_won + %d, `playtime` = playtime + %d " ...
|
||||
"WHERE `player_id` = %d AND map_id = %d",
|
||||
iKills, iAssists, iDeaths, iDamage, iObjects_Built, iTowers_Bought, iMetal_Pick, iMetal_Drop, iWaves_Played, iWaves_Reached, iWaves_Reached, iRounds_Played, iRounds_Won, iPlayTime, iPlayerId, g_iServerMap);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdatePlayerDisconnect_4, sQuery, iUserId);
|
||||
|
||||
// Reset Values
|
||||
Player_USetValue(iUserId, PLAYER_KILLS, 0);
|
||||
Player_USetValue(iUserId, PLAYER_ASSISTS, 0);
|
||||
Player_USetValue(iUserId, PLAYER_DEATHS, 0);
|
||||
Player_USetValue(iUserId, PLAYER_DAMAGE, 0);
|
||||
Player_USetValue(iUserId, PLAYER_OBJECTS_BUILT, 0);
|
||||
Player_USetValue(iUserId, PLAYER_TOWERS_BOUGHT, 0);
|
||||
Player_USetValue(iUserId, PLAYER_METAL_PICK, 0);
|
||||
Player_USetValue(iUserId, PLAYER_METAL_DROP, 0);
|
||||
Player_USetValue(iUserId, PLAYER_WAVES_PLAYED, 0);
|
||||
Player_USetValue(iUserId, PLAYER_WAVES_PLAYED, 0);
|
||||
Player_USetValue(iUserId, PLAYER_ROUNDS_WON, 0);
|
||||
Player_USetValue(iUserId, PLAYER_PLAYTIME, 0);
|
||||
Player_USetValue(iUserId, PLAYER_DATABASE_ID, 0);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Database_OnUpdatePlayerDisconnect_4(Handle hDriver, Handle hResult, const char[] sError, any iUserId) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdatePlayerDisconnect > Error: %s", sError);
|
||||
} else {
|
||||
char sSteamId[32];
|
||||
Player_UGetString(iUserId, PLAYER_COMMUNITY_ID, sSteamId, sizeof(sSteamId));
|
||||
|
||||
Log(TDLogLevel_Info, "Updated disconnected player in database (%s)", sSteamId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
494
scripting/towerdefense/database/server.sp
Normal file
494
scripting/towerdefense/database/server.sp
Normal file
@@ -0,0 +1,494 @@
|
||||
#pragma semicolon 1
|
||||
|
||||
#include <sourcemod>
|
||||
|
||||
#if defined INFO_INCLUDES
|
||||
#include "../info/constants.sp"
|
||||
#include "../info/enums.sp"
|
||||
#include "../info/variables.sp"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Checks if a server does already exist.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_CheckServer() {
|
||||
char sQuery[128];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `server_id` " ...
|
||||
"FROM `server` " ...
|
||||
"WHERE `ip` = '%s' AND `port` = %d " ...
|
||||
"LIMIT 1",
|
||||
g_sServerIp, g_iServerPort);
|
||||
|
||||
g_hDatabase.Query(Database_OnCheckServer, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnCheckServer(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_CheckServer > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult) == 0) {
|
||||
// No server found, add it
|
||||
|
||||
Database_AddServer();
|
||||
} else {
|
||||
SQL_FetchRow(hResult);
|
||||
|
||||
g_iServerId = SQL_FetchInt(hResult, 0);
|
||||
|
||||
Database_UpdateServer();
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a server.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_AddServer() {
|
||||
char sQuery[256];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"INSERT INTO `server` (`ip`, `port`, `created`, `updated`) " ...
|
||||
"VALUES ('%s', %d, UTC_TIMESTAMP(), UTC_TIMESTAMP())",
|
||||
g_sServerIp, g_iServerPort);
|
||||
|
||||
g_hDatabase.Query(Database_OnAddServer, sQuery, 0);
|
||||
}
|
||||
|
||||
public void Database_OnAddServer(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_AddServer > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
char sQuery[256];
|
||||
|
||||
if (iData == 0) {
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `server_id` " ...
|
||||
"FROM `server` " ...
|
||||
"WHERE `ip` = '%s' AND `port` = %d " ...
|
||||
"LIMIT 1",
|
||||
g_sServerIp, g_iServerPort);
|
||||
|
||||
g_hDatabase.Query(Database_OnAddServer, sQuery, 1);
|
||||
} else if (iData == 1) {
|
||||
SQL_FetchRow(hResult);
|
||||
g_iServerId = SQL_FetchInt(hResult, 0);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"INSERT INTO `server_stats` (`server_id`) " ...
|
||||
"VALUES (%d)",
|
||||
g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnAddServer, sQuery, 2);
|
||||
} else if (iData == 2) {
|
||||
Log(TDLogLevel_Info, "Added server to database (%s:%d)", g_sServerIp, g_iServerPort);
|
||||
|
||||
Database_UpdateServer();
|
||||
}
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
stock void Database_UpdateServerPlayerCount() {
|
||||
char sQuery[512];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `server` " ...
|
||||
"SET `players` = %d " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
GetRealClientCount(), g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdateServerPlayerCount, sQuery, 0);
|
||||
}
|
||||
|
||||
public void Database_OnUpdateServerPlayerCount(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdateServer > Error: %s", sError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a servers info.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_UpdateServer() {
|
||||
char sQuery[512];
|
||||
|
||||
char sServerName[128], sServerNameSave[256];
|
||||
|
||||
GetConVarString(FindConVar("hostname"), sServerName, sizeof(sServerName));
|
||||
SQL_EscapeString(g_hDatabase, sServerName, sServerNameSave, sizeof(sServerNameSave));
|
||||
|
||||
char sPassword[32], sPasswordSave[64];
|
||||
GetConVarString(FindConVar("sv_password"), sPassword, sizeof(sPassword));
|
||||
SQL_EscapeString(g_hDatabase, sPassword, sPasswordSave, sizeof(sPasswordSave));
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `server` " ...
|
||||
"SET `name` = '%s', " ...
|
||||
"`version` = '%s', " ...
|
||||
"`password` = '%s', " ...
|
||||
"`players` = %d, " ...
|
||||
"`updated` = UTC_TIMESTAMP() " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
sServerNameSave, PLUGIN_VERSION, sPasswordSave, GetRealClientCount(), g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdateServer, sQuery, 0);
|
||||
}
|
||||
|
||||
public void Database_OnUpdateServer(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_UpdateServer > Error: %s", sError);
|
||||
} else {
|
||||
char sQuery[256];
|
||||
char sCurrentMap[PLATFORM_MAX_PATH];
|
||||
GetCurrentMap(sCurrentMap, sizeof(sCurrentMap));
|
||||
|
||||
if (iData == 0) {
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `map_id`, `respawn_wave_time` " ...
|
||||
"FROM `map` " ...
|
||||
"WHERE `name` = '%s' " ...
|
||||
"LIMIT 1",
|
||||
sCurrentMap);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdateServer, sQuery, 1);
|
||||
} else if (iData == 1) {
|
||||
if (SQL_GetRowCount(hResult) == 0) {
|
||||
Log(TDLogLevel_Error, "Map \"%s\" is not supported, thus Tower Defense has been disabled.", sCurrentMap);
|
||||
|
||||
g_bEnabled = false;
|
||||
UpdateGameDescription();
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SQL_FetchRow(hResult);
|
||||
|
||||
g_iServerMap = SQL_FetchInt(hResult, 0);
|
||||
g_iRespawnWaveTime = SQL_FetchInt(hResult, 1);
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `server` " ...
|
||||
"SET `map_id` = %d " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
g_iServerMap, g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnUpdateServer, sQuery, 2);
|
||||
} else if (iData == 2) {
|
||||
Log(TDLogLevel_Info, "Updated server in database (%s:%d)", g_sServerIp, g_iServerPort);
|
||||
|
||||
g_bConfigsExecuted = true;
|
||||
|
||||
Database_CheckServerSettings();
|
||||
}
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the servers settings.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_CheckServerSettings() {
|
||||
char sQuery[256];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `lockable`, `loglevel`, `logtype` " ...
|
||||
"FROM `server` " ...
|
||||
"INNER JOIN `server_settings` " ...
|
||||
"ON (`server`.`server_settings_id` = `server_settings`.`server_settings_id`) " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnCheckServerSettings, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnCheckServerSettings(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_CheckServerSettings > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult)) {
|
||||
SQL_FetchRow(hResult);
|
||||
|
||||
char sLockable[32];
|
||||
SQL_FetchString(hResult, 0, sLockable, sizeof(sLockable));
|
||||
|
||||
if (StrEqual(sLockable, "not lockable")) {
|
||||
g_bLockable = false;
|
||||
} else if (StrEqual(sLockable, "lockable")) {
|
||||
g_bLockable = true;
|
||||
}
|
||||
|
||||
char sLogLevel[32];
|
||||
SQL_FetchString(hResult, 1, sLogLevel, sizeof(sLogLevel));
|
||||
|
||||
TDLogLevel iLogLevel;
|
||||
|
||||
if (StrEqual(sLogLevel, "None")) {
|
||||
iLogLevel = TDLogLevel_None;
|
||||
} else if (StrEqual(sLogLevel, "Error")) {
|
||||
iLogLevel = TDLogLevel_Error;
|
||||
} else if (StrEqual(sLogLevel, "Warning")) {
|
||||
iLogLevel = TDLogLevel_Warning;
|
||||
} else if (StrEqual(sLogLevel, "Info")) {
|
||||
iLogLevel = TDLogLevel_Info;
|
||||
} else if (StrEqual(sLogLevel, "Debug")) {
|
||||
iLogLevel = TDLogLevel_Debug;
|
||||
} else if (StrEqual(sLogLevel, "Trace")) {
|
||||
iLogLevel = TDLogLevel_Trace;
|
||||
}
|
||||
|
||||
char sLogType[32];
|
||||
SQL_FetchString(hResult, 2, sLogType, sizeof(sLogType));
|
||||
|
||||
TDLogType iLogType;
|
||||
|
||||
if (StrEqual(sLogType, "File")) {
|
||||
iLogType = TDLogType_File;
|
||||
} else if (StrEqual(sLogType, "Console")) {
|
||||
iLogType = TDLogType_Console;
|
||||
} else if (StrEqual(sLogType, "File and console")) {
|
||||
iLogType = TDLogType_FileAndConsole;
|
||||
}
|
||||
|
||||
Log_Initialize(iLogLevel, iLogType);
|
||||
|
||||
Database_CheckServerConfig();
|
||||
Database_CheckServerStats();
|
||||
} else {
|
||||
Database_CheckServerConfig();
|
||||
Database_CheckServerStats();
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the servers config.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_CheckServerConfig() {
|
||||
char sQuery[512];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT CONCAT(`variable`, ' \"', `value`, '\"') " ...
|
||||
"FROM `config` " ...
|
||||
"INNER JOIN `server` " ...
|
||||
"ON (`server_id` = %d) " ...
|
||||
"INNER JOIN `server_settings` " ...
|
||||
"ON (`server`.`server_settings_id` = `server_settings`.`server_settings_id`) " ...
|
||||
"WHERE `config_id` >= `config_start` AND `config_id` <= `config_end` " ...
|
||||
"ORDER BY `config_id` ASC",
|
||||
g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnCheckServerConfig, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnCheckServerConfig(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_CheckServerConfig > Error: %s", sError);
|
||||
} else {
|
||||
char sCommand[260];
|
||||
|
||||
while (SQL_FetchRow(hResult)) {
|
||||
SQL_FetchString(hResult, 0, sCommand, sizeof(sCommand));
|
||||
|
||||
ServerCommand("%s", sCommand);
|
||||
}
|
||||
|
||||
Database_OnServerChecked();
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the servers password in the database.
|
||||
*
|
||||
* @param sPassword The password to set.
|
||||
* @param bReloadMap Reload map afterwards.
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_SetServerPassword(const char[] sPassword, bool bReloadMap) {
|
||||
char sQuery[128];
|
||||
|
||||
char sPasswordSave[64];
|
||||
SQL_EscapeString(g_hDatabase, sPassword, sPasswordSave, sizeof(sPasswordSave));
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `server` " ...
|
||||
"SET `password` = '%s' " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
sPasswordSave, g_iServerId);
|
||||
|
||||
DataPack hPack = new DataPack();
|
||||
|
||||
hPack.WriteCell(bReloadMap ? 1 : 0);
|
||||
hPack.WriteString(sPassword);
|
||||
|
||||
g_hDatabase.Query(Database_OnSetServerPassword, sQuery, hPack);
|
||||
}
|
||||
|
||||
public void Database_OnSetServerPassword(Handle hDriver, Handle hResult, const char[] sError, DataPack hPack) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_SetServerPassword > Error: %s", sError);
|
||||
} else {
|
||||
ResetPack(hPack);
|
||||
|
||||
bool bReloadMap = (hPack.ReadCell() == 0 ? false : true);
|
||||
|
||||
char sPassword[32];
|
||||
hPack.ReadString(sPassword, sizeof(sPassword));
|
||||
|
||||
Log(TDLogLevel_Debug, "Set server password to \"%s\"", sPassword);
|
||||
|
||||
if (bReloadMap) {
|
||||
ReloadMap();
|
||||
}
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if server stats does already exist.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
|
||||
stock void Database_CheckServerStats() {
|
||||
char sQuery[128];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"SELECT `playtime` " ...
|
||||
"FROM `server_stats` " ...
|
||||
"WHERE `server_id` = %d " ...
|
||||
"LIMIT 1",
|
||||
g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnCheckServerStats, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnCheckServerStats(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_CheckServerStats > Error: %s", sError);
|
||||
} else if (SQL_GetRowCount(hResult) == 0) {
|
||||
// No server found, add it
|
||||
|
||||
Database_AddServerStats();
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
stock void Database_AddServerStats() {
|
||||
char sQuery[256];
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"INSERT INTO `server_stats` (`server_id`) " ...
|
||||
"VALUES (%d)",
|
||||
g_iServerId);
|
||||
|
||||
g_hDatabase.Query(Database_OnAddServerStats, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnAddServerStats(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_AddServerStats > Error: %s", sError);
|
||||
} else {
|
||||
Log(TDLogLevel_Info, "Added server stats (%i)", g_iServerId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
stock void Database_ServerStatsUpdate() {
|
||||
char sQuery[1024];
|
||||
|
||||
int iConnections, iRounds_Played, iRounds_Won, iPlaytime;
|
||||
|
||||
if (!Server_UGetValue(g_iServerId, SERVER_CONNECTIONS, iConnections))
|
||||
iConnections = 0;
|
||||
if (!Server_UGetValue(g_iServerId, SERVER_ROUNDS_PLAYED, iRounds_Played))
|
||||
iRounds_Played = 0;
|
||||
if (!Server_UGetValue(g_iServerId, SERVER_ROUNDS_WON, iRounds_Won))
|
||||
iRounds_Won = 0;
|
||||
if (!Server_UGetValue(g_iServerId, SERVER_PLAYTIME, iPlaytime))
|
||||
iRounds_Won = 0;
|
||||
|
||||
g_hDatabase.Format(sQuery, sizeof(sQuery),
|
||||
"UPDATE `server_stats` " ...
|
||||
"SET `connections` = connections + %d, `rounds_played` = rounds_played + %d, `rounds_won` = rounds_won + %d, `playtime` = playtime + %d " ...
|
||||
"WHERE `server_id` = %d",
|
||||
iConnections, iRounds_Played, iRounds_Won, iPlaytime, g_iServerId);
|
||||
|
||||
Server_USetValue(g_iServerId, SERVER_CONNECTIONS, 0);
|
||||
Server_USetValue(g_iServerId, SERVER_ROUNDS_PLAYED, 0);
|
||||
Server_USetValue(g_iServerId, SERVER_ROUNDS_WON, 0);
|
||||
Server_USetValue(g_iServerId, SERVER_PLAYTIME, 0);
|
||||
|
||||
g_hDatabase.Query(Database_OnServerStatsUpdate, sQuery);
|
||||
}
|
||||
|
||||
public void Database_OnServerStatsUpdate(Handle hDriver, Handle hResult, const char[] sError, any iData) {
|
||||
if (hResult == null) {
|
||||
Log(TDLogLevel_Error, "Query failed at Database_ServerStatsUpdate > Error: %s", sError);
|
||||
} else {
|
||||
Log(TDLogLevel_Info, "Updated server stats in database (%i)", g_iServerId);
|
||||
}
|
||||
|
||||
if (hResult != null) {
|
||||
CloseHandle(hResult);
|
||||
hResult = null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user