-
Notifications
You must be signed in to change notification settings - Fork 177
Begin to break into modules #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v1.x
Are you sure you want to change the base?
Changes from 7 commits
9a11fa3
4f6185b
b886d9a
567c2c9
5ea54da
26bb09f
b8afb5e
48a8d29
096c528
e0f0669
05df755
10b7cce
379878d
4647e67
02c2fc2
1cb2fa4
35c5d38
0adf6e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||||
#if defined _sbpp_core_included | ||||||||||
#endinput | ||||||||||
#endif | ||||||||||
#define _sbpp_core_included | ||||||||||
|
||||||||||
#define SBPP_VERSION "1.7.0:1049" | ||||||||||
|
||||||||||
#define SBPP_LogMsg( LogToFile( szLog, | ||||||||||
#define SBPP_LogIssue( LogToFile( szIssues, | ||||||||||
|
||||||||||
stock char szLog[PLATFORM_MAX_PATH], szIssues[PLATFORM_MAX_PATH], PREFIX[] = "\x04[SourceBans++]\x01 "; | ||||||||||
|
||||||||||
stock void SBPP_Core_Init () | ||||||||||
{ | ||||||||||
BuildPath( Path_SM, szLog, sizeof szLog, "logs/sbpp.log" ); | ||||||||||
BuildPath( Path_SM, szIssues, sizeof szIssues, "logs/sbpp.issues.log" ); | ||||||||||
TheByKotik marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would change the name to
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the errors are logged by sourcemod itself, most often there will be exactly problems there like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. Sorry for that. |
||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
#if defined _sbpp_sql_included | ||
#endinput | ||
#endif | ||
#define _sbpp_sql_included | ||
|
||
#include <sbpp/core.sp> | ||
|
||
#define SBPP_SQL_Init() SBPP_SQL_Init( DoNothing ) /* This something like function overloading. For now, we can't set default parameter-function. */ | ||
#define SBPP_SQL_Reconnect() SBPP_SQL_Reconnect( DoNothing ) /* This something like function overloading. For now, we can't set default parameter-function. */ | ||
|
||
enum { /* States */ | ||
SBPP_SQL_State_None = 0, | ||
SBPP_SQL_State_Connecting = 1 << 0, | ||
SBPP_SQL_State_Wait = 1 << 1, | ||
SBPP_SQL_State_Connected = 1 << 2, } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation seems to be all over the place with this enum |
||
|
||
forward Action _SBPP_SQL_Find (Database &db, int &iState); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, indentation. |
||
forward void _SBPP_SQL_Close (); | ||
forward void _SBPP_SQL_Release (const Database db); | ||
|
||
typedef ConnectCallback = function void (const bool bSuccessful); | ||
|
||
stock Database g_dbSQL; | ||
stock static int s_iState; | ||
stock static bool s_bIgnoreForward; | ||
stock static ConnectCallback s_fnCallback; /* For now, Database.Connect() can't have function as pass data. */ | ||
stock static char s_szPrevError[PLATFORM_MAX_PATH]; | ||
stock static Handle s_hSBPP_SQL_Find, s_hSBPP_SQL_Close, s_hSBPP_SQL_Release; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the case here for defining symbol usage as stock? Also, this seems like a UB. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand your question correctly, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if they include that file, will it ever be not used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone forgets to call |
||
|
||
stock void SBPP_SQL_Init (const ConnectCallback fnCallback) | ||
{ | ||
LoadTranslations( "sbpp.sql.phrases.txt" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems unnecessary to add a separate translation file for one phrase, this would do better added into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I planned that this module will be included not only in sbpp_main. Therefore, it would be nonsensical to add a dependency on sbpp_main translations, it is desirable that each plugin can work absolutely independently. |
||
s_hSBPP_SQL_Find = CreateGlobalForward( "_SBPP_SQL_Find", ET_Hook, Param_CellByRef, Param_CellByRef ); | ||
s_hSBPP_SQL_Close = CreateGlobalForward( "_SBPP_SQL_Close", ET_Ignore ); | ||
s_hSBPP_SQL_Release = CreateGlobalForward( "_SBPP_SQL_Release", ET_Ignore, Param_Cell ); | ||
s_fnCallback = fnCallback; | ||
SBPP_SQL_Find(); | ||
} | ||
|
||
stock void SBPP_SQL_Reconnect (const ConnectCallback fnCallback) | ||
{ | ||
if ( s_iState != SBPP_SQL_State_Connecting && s_iState != SBPP_SQL_State_Wait ) | ||
{ | ||
s_bIgnoreForward = true; | ||
Call_StartForward( s_hSBPP_SQL_Close ); | ||
Call_Finish(); | ||
s_bIgnoreForward = false; | ||
delete g_dbSQL; | ||
s_fnCallback = fnCallback; | ||
SBPP_SQL_Connect(); | ||
} | ||
} | ||
|
||
stock static void SBPP_SQL_Find () | ||
{ | ||
int iState; | ||
Database db; | ||
s_bIgnoreForward = true; | ||
Call_StartForward( s_hSBPP_SQL_Find ); | ||
Call_PushCellRef( db ); | ||
Call_PushCellRef( iState ); | ||
Call_Finish(); | ||
s_bIgnoreForward = false; | ||
switch ( iState ) | ||
{ | ||
case SBPP_SQL_State_None: | ||
{ | ||
SBPP_SQL_Connect(); | ||
} | ||
case SBPP_SQL_State_Connecting: | ||
{ | ||
s_iState = SBPP_SQL_State_Wait; | ||
CreateTimer( 15.0, CheckWait, _ ); | ||
} | ||
case SBPP_SQL_State_Connected: | ||
{ | ||
_SBPP_SQL_Release( db ); | ||
} | ||
} | ||
} | ||
|
||
stock static void SBPP_SQL_Connect () | ||
{ | ||
s_iState = SBPP_SQL_State_Connecting; | ||
Database.Connect( SBPP_SQL_Connect_Callback, "sourcebans" ); | ||
} | ||
|
||
stock static void SBPP_SQL_Connect_Callback (const Database db, const char[] szError, const any aData) | ||
{ | ||
bool bSuccessful; | ||
if ( db ) | ||
{ | ||
g_dbSQL = db; | ||
g_dbSQL.SetCharset( "utf8" ); | ||
rumblefrog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s_bIgnoreForward = true; | ||
Call_StartForward( s_hSBPP_SQL_Release ); | ||
Call_PushCell( g_dbSQL ); | ||
Call_Finish(); | ||
s_bIgnoreForward = false; | ||
bSuccessful = true; | ||
if ( s_szPrevError[0] ) | ||
{ | ||
SBPP_LogMsg( "%t", "Successful reconnect" ); | ||
s_szPrevError = ""; | ||
} | ||
} | ||
else if ( szError[0] ) | ||
{ | ||
s_iState = SBPP_SQL_State_None; | ||
if ( strcmp( s_szPrevError, szError ) ) | ||
{ | ||
SBPP_LogMsg( szError ); | ||
strcopy( s_szPrevError, sizeof s_szPrevError, szError ); | ||
} | ||
} | ||
s_iState = SBPP_SQL_State_Connected; | ||
CallCallback( bSuccessful ); | ||
} | ||
|
||
stock static void CallCallback (const bool bSuccessful) | ||
{ | ||
if ( s_fnCallback != DoNothing ) | ||
{ | ||
Call_StartFunction( null, s_fnCallback ); | ||
Call_PushCell( bSuccessful ); | ||
Call_Finish(); | ||
s_fnCallback = DoNothing; | ||
} | ||
} | ||
|
||
stock static Action CheckWait (Handle tTimer) | ||
{ | ||
if ( s_iState == SBPP_SQL_State_Wait ) | ||
{ | ||
SBPP_SQL_Find(); | ||
} | ||
return Plugin_Stop; | ||
} | ||
|
||
public Action _SBPP_SQL_Find (Database &db, int &iState) | ||
{ | ||
if ( !s_bIgnoreForward ) | ||
{ | ||
if ( g_dbSQL ) | ||
{ | ||
db = g_dbSQL; | ||
iState = SBPP_SQL_State_Connected; | ||
return Plugin_Stop; | ||
} | ||
if ( s_iState == SBPP_SQL_State_Connecting ) | ||
{ | ||
iState = SBPP_SQL_State_Connecting; | ||
return Plugin_Stop; | ||
} | ||
} | ||
return Plugin_Continue; | ||
} | ||
|
||
public void _SBPP_SQL_Close () | ||
{ | ||
if ( !s_bIgnoreForward ) | ||
{ | ||
delete g_dbSQL; | ||
s_iState = SBPP_SQL_State_Wait; | ||
CreateTimer( 15.0, CheckWait, _ ); | ||
} | ||
} | ||
|
||
public void _SBPP_SQL_Release (const Database db) | ||
{ | ||
if ( !s_bIgnoreForward ) | ||
{ | ||
g_dbSQL = view_as<Database>( CloneHandle( db ) ); | ||
s_iState = SBPP_SQL_State_Connected; | ||
CallCallback( true ); | ||
} | ||
} | ||
|
||
stock void DoNothing (const bool bSuccessful) {} |
Uh oh!
There was an error while loading. Please reload this page.