2018-09-09 16:01:29 +00:00
|
|
|
/*
|
|
|
|
* Irresistible Gaming (c) 2018
|
2018-12-12 08:21:57 +00:00
|
|
|
* Developed by Lorenc
|
2018-09-09 16:01:29 +00:00
|
|
|
* Module: servervars.inc
|
|
|
|
* Purpose: savable server variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined __irresistible_servervars
|
|
|
|
#define __irresistible_servervars
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ** Includes ** */
|
|
|
|
#include < YSI\y_hooks >
|
|
|
|
|
2018-10-25 17:58:12 +00:00
|
|
|
/* ** Macros ** */
|
|
|
|
#define GetServerVariableInt GetGVarInt
|
2018-10-31 08:01:35 +00:00
|
|
|
#define GetServerVariableFloat GetGVarFloat
|
2019-01-02 05:32:59 +00:00
|
|
|
#define GetServerVariableString GetGVarString
|
2018-10-25 17:58:12 +00:00
|
|
|
|
|
|
|
#define UpdateServerVariableString(%0,%1) \
|
2019-01-02 05:32:59 +00:00
|
|
|
(UpdateServerVariable(%0, .string_value = (%1), .type = GLOBAL_VARTYPE_STRING))
|
2018-10-25 17:58:12 +00:00
|
|
|
|
|
|
|
#define UpdateServerVariableInt(%0,%1) \
|
2019-01-02 05:32:59 +00:00
|
|
|
(UpdateServerVariable(%0, .int_value = (%1), .type = GLOBAL_VARTYPE_INT))
|
2018-10-25 17:58:12 +00:00
|
|
|
|
2018-10-31 08:01:35 +00:00
|
|
|
#define UpdateServerVariableFloat(%0,%1) \
|
2019-01-02 05:32:59 +00:00
|
|
|
(UpdateServerVariable(%0, .float_value = (%1), .type = GLOBAL_VARTYPE_FLOAT))
|
|
|
|
|
|
|
|
#define IsValidServerVariable(%0) \
|
|
|
|
(GetGVarType(%0) != GLOBAL_VARTYPE_NONE)
|
2018-10-31 08:01:35 +00:00
|
|
|
|
2018-09-09 16:01:29 +00:00
|
|
|
/* ** Hooks ** */
|
2019-01-02 05:32:59 +00:00
|
|
|
hook OnGameModeInit( ) {
|
2018-09-09 16:01:29 +00:00
|
|
|
mysql_function_query( dbHandle, "SELECT * FROM `SERVER`", true, "OnLoadServerVariables", "" );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ** Functions ** */
|
|
|
|
thread OnLoadServerVariables( )
|
|
|
|
{
|
|
|
|
new
|
2019-01-02 05:32:59 +00:00
|
|
|
rows = cache_get_row_count( );
|
|
|
|
|
2018-09-09 16:01:29 +00:00
|
|
|
if ( rows )
|
|
|
|
{
|
2019-01-02 05:32:59 +00:00
|
|
|
new variable_name[ 64 ];
|
|
|
|
new string_value[ 256 ];
|
|
|
|
|
|
|
|
for ( new i = 0; i < rows; i ++ )
|
2018-09-09 16:01:29 +00:00
|
|
|
{
|
2019-01-02 05:32:59 +00:00
|
|
|
new
|
|
|
|
variable_type = cache_get_field_content_int( i, "TYPE", dbHandle );
|
|
|
|
|
|
|
|
cache_get_field_content( i, "NAME", variable_name );
|
2018-09-09 16:01:29 +00:00
|
|
|
|
2019-01-02 05:32:59 +00:00
|
|
|
switch ( variable_type )
|
2018-09-09 16:01:29 +00:00
|
|
|
{
|
2019-01-02 05:32:59 +00:00
|
|
|
case GLOBAL_VARTYPE_INT: SetGVarInt( variable_name, cache_get_field_content_int( i, "INT_VAL", dbHandle ) );
|
|
|
|
case GLOBAL_VARTYPE_STRING: cache_get_field_content( i, "STRING_VAL", string_value ), SetGVarString( variable_name, string_value );
|
|
|
|
case GLOBAL_VARTYPE_FLOAT: SetGVarFloat( variable_name, cache_get_field_content_float( i, "FLOAT_VAL", dbHandle ) );
|
2018-09-09 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-02 05:32:59 +00:00
|
|
|
return printf( "[SERVER] %d server variables have been loaded.", rows ), 1;
|
2018-09-09 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2019-01-02 05:32:59 +00:00
|
|
|
stock UpdateServerVariable( const variable_name[ 64 ], int_value = 0, Float: float_value = 0.0, string_value[ 128 ] = '\0', type = GLOBAL_VARTYPE_INT )
|
2018-09-09 16:01:29 +00:00
|
|
|
{
|
|
|
|
static
|
2019-01-02 05:32:59 +00:00
|
|
|
query[ 256 ];
|
2018-09-09 16:01:29 +00:00
|
|
|
|
2019-01-02 05:32:59 +00:00
|
|
|
switch ( type )
|
2018-09-09 16:01:29 +00:00
|
|
|
{
|
2019-01-02 05:32:59 +00:00
|
|
|
case GLOBAL_VARTYPE_INT: {
|
|
|
|
mysql_format( dbHandle, query, sizeof ( query ), "UPDATE `SERVER` SET `INT_VAL`=%d WHERE `NAME`='%e'", int_value, variable_name );
|
|
|
|
SetGVarInt( variable_name, int_value );
|
|
|
|
}
|
|
|
|
case GLOBAL_VARTYPE_STRING: {
|
|
|
|
mysql_format( dbHandle, query, sizeof ( query ), "UPDATE `SERVER` SET `STRING_VAL`='%e' WHERE `NAME`='%e'", string_value, variable_name );
|
|
|
|
SetGVarString( variable_name, string_value );
|
|
|
|
}
|
|
|
|
case GLOBAL_VARTYPE_FLOAT: {
|
|
|
|
mysql_format( dbHandle, query, sizeof ( query ), "UPDATE `SERVER` SET `FLOAT_VAL`=%f WHERE `NAME`='%e'", float_value, variable_name );
|
|
|
|
SetGVarFloat( variable_name, float_value );
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return; // prevent a query from being fired
|
|
|
|
}
|
2018-09-09 16:01:29 +00:00
|
|
|
}
|
2019-01-02 05:32:59 +00:00
|
|
|
mysql_single_query( query );
|
2018-09-09 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2019-01-02 05:32:59 +00:00
|
|
|
stock AddServerVariable( const variable_name[ 64 ], const value[ 128 ], type )
|
2018-09-09 16:01:29 +00:00
|
|
|
{
|
2019-01-02 05:32:59 +00:00
|
|
|
static
|
|
|
|
query[ 300 ];
|
|
|
|
|
|
|
|
switch ( type )
|
2018-09-09 16:01:29 +00:00
|
|
|
{
|
2019-01-02 05:32:59 +00:00
|
|
|
case GLOBAL_VARTYPE_INT: {
|
|
|
|
mysql_format( dbHandle, query, sizeof ( query ), "INSERT IGNORE INTO `SERVER`(`NAME`,`INT_VAL`,`TYPE`) VALUES ('%e',%d,%d)", variable_name, strval( value ), type );
|
|
|
|
}
|
|
|
|
case GLOBAL_VARTYPE_STRING: {
|
|
|
|
mysql_format( dbHandle, query, sizeof ( query ), "INSERT IGNORE INTO `SERVER`(`NAME`,`STRING_VAL`,`TYPE`) VALUES ('%e','%e',%d)", variable_name, value, type );
|
|
|
|
}
|
|
|
|
case GLOBAL_VARTYPE_FLOAT: {
|
|
|
|
mysql_format( dbHandle, query, sizeof ( query ), "INSERT IGNORE INTO `SERVER`(`NAME`,`FLOAT_VAL`,`TYPE`) VALUES ('%e',%f,%d)", variable_name, floatstr( value ), type );
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return; // prevent a query from being fired
|
|
|
|
}
|
2018-09-09 16:01:29 +00:00
|
|
|
}
|
2019-01-02 05:32:59 +00:00
|
|
|
mysql_single_query( query );
|
2018-09-09 16:01:29 +00:00
|
|
|
}
|