make server variables module more easy to use
This commit is contained in:
parent
22bf77c441
commit
0532bf946a
@ -15,19 +15,22 @@
|
||||
/* ** Macros ** */
|
||||
#define GetServerVariableInt GetGVarInt
|
||||
#define GetServerVariableFloat GetGVarFloat
|
||||
#define GetServerVariableString GetGVarString
|
||||
|
||||
#define UpdateServerVariableString(%0,%1) \
|
||||
(UpdateServerVariable(%0, 0, 0, %1, GLOBAL_VARTYPE_STRING))
|
||||
(UpdateServerVariable(%0, .string_value = (%1), .type = GLOBAL_VARTYPE_STRING))
|
||||
|
||||
#define UpdateServerVariableInt(%0,%1) \
|
||||
(UpdateServerVariable(%0, %1, 0, "", GLOBAL_VARTYPE_INT))
|
||||
(UpdateServerVariable(%0, .int_value = (%1), .type = GLOBAL_VARTYPE_INT))
|
||||
|
||||
#define UpdateServerVariableFloat(%0,%1) \
|
||||
(UpdateServerVariable(%0, 0, %1, "", GLOBAL_VARTYPE_FLOAT))
|
||||
(UpdateServerVariable(%0, .float_value = (%1), .type = GLOBAL_VARTYPE_FLOAT))
|
||||
|
||||
#define IsValidServerVariable(%0) \
|
||||
(GetGVarType(%0) != GLOBAL_VARTYPE_NONE)
|
||||
|
||||
/* ** Hooks ** */
|
||||
hook OnGameModeInit( )
|
||||
{
|
||||
hook OnGameModeInit( ) {
|
||||
mysql_function_query( dbHandle, "SELECT * FROM `SERVER`", true, "OnLoadServerVariables", "" );
|
||||
return 1;
|
||||
}
|
||||
@ -36,62 +39,76 @@ hook OnGameModeInit( )
|
||||
thread OnLoadServerVariables( )
|
||||
{
|
||||
new
|
||||
rows, fields, i = -1,
|
||||
Field[ 30 ],
|
||||
szName[ 64 ],
|
||||
iValue,
|
||||
Float: fValue,
|
||||
iType
|
||||
;
|
||||
rows = cache_get_row_count( );
|
||||
|
||||
cache_get_data( rows, fields );
|
||||
if ( rows )
|
||||
{
|
||||
while( ++i < rows )
|
||||
{
|
||||
cache_get_field_content( i, "NAME", szName );
|
||||
cache_get_field_content( i, "STRING_VAL", szBigString );
|
||||
cache_get_field_content( i, "INT_VAL", Field ), iValue = strval( Field );
|
||||
cache_get_field_content( i, "FLOAT_VAL", Field ), fValue = floatstr( Field );
|
||||
cache_get_field_content( i, "TYPE", Field ), iType = strval( Field );
|
||||
new variable_name[ 64 ];
|
||||
new string_value[ 256 ];
|
||||
|
||||
switch( iType )
|
||||
for ( new i = 0; i < rows; i ++ )
|
||||
{
|
||||
new
|
||||
variable_type = cache_get_field_content_int( i, "TYPE", dbHandle );
|
||||
|
||||
cache_get_field_content( i, "NAME", variable_name );
|
||||
|
||||
switch ( variable_type )
|
||||
{
|
||||
case GLOBAL_VARTYPE_INT: SetGVarInt( szName, iValue );
|
||||
case GLOBAL_VARTYPE_STRING: SetGVarString( szName, szBigString );
|
||||
case GLOBAL_VARTYPE_FLOAT: SetGVarFloat( szName, fValue );
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
printf( "[SERVER] %d server variables have been loaded.", rows );
|
||||
return 1;
|
||||
return printf( "[SERVER] %d server variables have been loaded.", rows ), 1;
|
||||
}
|
||||
|
||||
stock UpdateServerVariable( szName[ 64 ], intVal, Float: floatVal, stringVal[ 128 ], type )
|
||||
stock UpdateServerVariable( const variable_name[ 64 ], int_value = 0, Float: float_value = 0.0, string_value[ 128 ] = '\0', type = GLOBAL_VARTYPE_INT )
|
||||
{
|
||||
static
|
||||
szString[ 256 ];
|
||||
query[ 256 ];
|
||||
|
||||
switch( type )
|
||||
switch ( type )
|
||||
{
|
||||
case GLOBAL_VARTYPE_INT: format( szString, 128, "UPDATE `SERVER` SET `INT_VAL`=%d WHERE `NAME`='%s'", intVal, mysql_escape( szName ) ), SetGVarInt( szName, intVal );
|
||||
case GLOBAL_VARTYPE_STRING: format( szString, 256, "UPDATE `SERVER` SET `STRING_VAL`='%s' WHERE `NAME`='%s'", mysql_escape( stringVal ), mysql_escape( szName ) ), SetGVarString( szName, stringVal );
|
||||
case GLOBAL_VARTYPE_FLOAT: format( szString, 128, "UPDATE `SERVER` SET `FLOAT_VAL`=%f WHERE `NAME`='%s'", floatVal, mysql_escape( szName ) ), SetGVarFloat( szName, floatVal );
|
||||
default: return;
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
mysql_single_query( szString );
|
||||
mysql_single_query( query );
|
||||
}
|
||||
|
||||
stock AddServerVariable( szName[ 64 ], szValue[ 128 ], type )
|
||||
stock AddServerVariable( const variable_name[ 64 ], const value[ 128 ], type )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case GLOBAL_VARTYPE_INT: format( szLargeString, 164, "INSERT IGNORE INTO `SERVER`(`NAME`,`INT_VAL`,`TYPE`) VALUES ('%s',%d,%d)", mysql_escape( szName ), strval( szValue ), type );
|
||||
case GLOBAL_VARTYPE_STRING: format( szLargeString, 296, "INSERT IGNORE INTO `SERVER`(`NAME`,`STRING_VAL`,`TYPE`) VALUES ('%s','%s',%d)", mysql_escape( szName ), mysql_escape( szValue ), type );
|
||||
case GLOBAL_VARTYPE_FLOAT: format( szLargeString, 164, "INSERT IGNORE INTO `SERVER`(`NAME`,`FLOAT_VAL`,`TYPE`) VALUES ('%s',%f,%d)", mysql_escape( szName ), floatstr( szValue ), type );
|
||||
default: return;
|
||||
}
|
||||
static
|
||||
query[ 300 ];
|
||||
|
||||
mysql_single_query( szLargeString );
|
||||
switch ( type )
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
mysql_single_query( query );
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
//#pragma option -d3
|
||||
#pragma dynamic 7200000
|
||||
|
||||
// #define DEBUG_MODE
|
||||
#define DEBUG_MODE
|
||||
|
||||
#if defined DEBUG_MODE
|
||||
#pragma option -d3
|
||||
@ -429,9 +429,9 @@ public OnPlayerConnect( playerid )
|
||||
SendClientMessage( playerid, 0xa9c4e4ff, "{FF0000}[WARNING]{a9c4e4} The concept in this server and GTA in general may be considered explicit material." );
|
||||
SendClientMessage( playerid, 0xa9c4e4ff, "{FF0000}[INFO]{a9c4e4} The server is currently operating on version " # FILE_BUILD "." );
|
||||
|
||||
if ( GetGVarType( "connectsong" ) != GLOBAL_VARTYPE_NONE )
|
||||
if ( IsValidServerVariable( "connectsong" ) )
|
||||
{
|
||||
GetGVarString( "connectsong", szNormalString );
|
||||
GetServerVariableString( "connectsong", szNormalString );
|
||||
PlayAudioStreamForPlayer( playerid, szNormalString );
|
||||
}
|
||||
return 1;
|
||||
@ -1848,7 +1848,7 @@ CMD:eventbank( playerid, params[ ] )
|
||||
{
|
||||
GivePlayerCash( playerid, -iAmount );
|
||||
p_AntiSpammyTS[ playerid ] = g_iTime + 15;
|
||||
UpdateServerVariable( "eventbank", GetGVarInt( "eventbank" ) + iAmount, 0.0, "", GLOBAL_VARTYPE_INT );
|
||||
UpdateServerVariableInt( "eventbank", GetGVarInt( "eventbank" ) + iAmount );
|
||||
SendGlobalMessage( playerid, ""COL_GOLD"[EVENT BANK]"COL_WHITE" Thanks for donating %s to the event bank, %s!", cash_format( iAmount ), ReturnPlayerName( playerid ) );
|
||||
}
|
||||
}
|
||||
@ -1861,7 +1861,7 @@ CMD:eventbank( playerid, params[ ] )
|
||||
else
|
||||
{
|
||||
GivePlayerCash( playerid, iAmount );
|
||||
UpdateServerVariable( "eventbank", GetGVarInt( "eventbank" ) - iAmount, 0.0, "", GLOBAL_VARTYPE_INT );
|
||||
UpdateServerVariableInt( "eventbank", GetGVarInt( "eventbank" ) - iAmount );
|
||||
SendGlobalMessage( -1, ""COL_GOLD"[EVENT BANK]"COL_WHITE" %s(%d) has withdrawn %s from the event bank!", ReturnPlayerName( playerid ), playerid, cash_format( iAmount ) );
|
||||
}
|
||||
}
|
||||
@ -5628,7 +5628,7 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
|
||||
|
||||
p_ArmyBanned{ playerid } = 0;
|
||||
GivePlayerCash( playerid, -750000 );
|
||||
UpdateServerVariable( "eventbank", GetGVarInt( "eventbank" ) + 250000, 0.0, "", GLOBAL_VARTYPE_INT );
|
||||
UpdateServerVariableInt( "eventbank", GetGVarInt( "eventbank" ) + 250000 );
|
||||
|
||||
format( szNormalString, sizeof( szNormalString ), "UPDATE `USERS` SET `ARMY_BAN`=0 WHERE ID=%d", p_AccountID[ playerid ] );
|
||||
mysql_single_query( szNormalString );
|
||||
@ -5645,7 +5645,7 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
|
||||
|
||||
p_CopBanned{ playerid } = 0;
|
||||
GivePlayerCash( playerid, -500000 );
|
||||
UpdateServerVariable( "eventbank", GetGVarInt( "eventbank" ) + 170000, 0.0, "", GLOBAL_VARTYPE_INT );
|
||||
UpdateServerVariable( "eventbank", GetGVarInt( "eventbank" ) + 170000, .type = GLOBAL_VARTYPE_INT );
|
||||
|
||||
format( szNormalString, sizeof( szNormalString ), "UPDATE `USERS` SET `COP_BAN`=0 WHERE ID=%d", p_AccountID[ playerid ] );
|
||||
mysql_single_query( szNormalString );
|
||||
|
Loading…
Reference in New Issue
Block a user