Skip to content
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

Begin to break into modules #625

Open
wants to merge 18 commits into
base: v1.x
Choose a base branch
from

Conversation

TheByKotik
Copy link
Contributor

@TheByKotik TheByKotik commented Oct 15, 2019

Motivation and Context

Begin to break into modules for preventing duplication of code.
Also resolve #464.

How Has This Been Tested?

I tested it in different situations.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

Comment on lines 11 to 15
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, }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation seems to be all over the place with this enum

SBPP_SQL_State_Wait = 1 << 1,
SBPP_SQL_State_Connected = 1 << 2, }

forward Action _SBPP_SQL_Find (Database &db, int &iState);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, indentation.

Comment on lines 23 to 28
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;
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand your question correctly, stock is not include if never used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if they include that file, will it ever be not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone forgets to call SBPP_SQL_Init().

@TheByKotik
Copy link
Contributor Author

I'm think build failed because don't set include dir (spcomp flag -i).

#undef REQUIRE_PLUGIN
#include <sourcebanspp>
#include <sourcebanspp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

@TheByKotik
Copy link
Contributor Author

Build fixed but It's not quite include. It's something like a module.

@CrazyHackGUT
Copy link
Contributor

One connection for all plugins can be implemented too easy, if plugins will be connect to DB in single-thread.

https://sm.alliedmods.net/new-api/dbi/SQL_Connect
persistent argument.

@TheByKotik
Copy link
Contributor Author

One connection for all plugins can be implemented too easy, if plugins will be connect to DB in single-thread.

https://sm.alliedmods.net/new-api/dbi/SQL_Connect
persistent argument.

If i remember correctly, this function called from main game thread and should have caused a lag.

@CrazyHackGUT
Copy link
Contributor

When you starts plugin - what's the difference? Few people launch plugins when people play. These peoples should understand any risks related with starting plugin in the middle of the game.

Yes, you remember correctly. This function really causes the lag.

@TheByKotik
Copy link
Contributor Author

When you starts plugin - what's the difference? Few people launch plugins when people play. These peoples should understand any risks related with starting plugin in the middle of the game.

Yes, you remember correctly. This function really causes the lag.

You are certainly right, loading plugins often causes lags.

However, connection to database can occur at different times, including during important game events, if, for example, something happened with db / db server.

Just as I mentioned above, this is something like a module that is designed to stop duplication of code from plugin to plugin.

@TheByKotik TheByKotik mentioned this pull request Oct 19, 2019
7 tasks
@TheByKotik TheByKotik mentioned this pull request Oct 30, 2019
7 tasks

stock void SBPP_SQL_Init (const ConnectCallback fnCallback)
{
LoadTranslations( "sbpp.sql.phrases.txt" );
Copy link
Contributor

Choose a reason for hiding this comment

The 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 sbpp_main.phrases.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 sbpp_main.phrases.txt

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.

game/addons/sourcemod/scripting/sbpp/core.sp Outdated Show resolved Hide resolved
Comment on lines 15 to 16
BuildPath( Path_SM, szLog, sizeof szLog, "logs/sbpp.log" );
BuildPath( Path_SM, szIssues, sizeof szIssues, "logs/sbpp.issues.log" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would change the name to sbpp.error.log

Suggested change
BuildPath( Path_SM, szLog, sizeof szLog, "logs/sbpp.log" );
BuildPath( Path_SM, szIssues, sizeof szIssues, "logs/sbpp.issues.log" );
BuildPath( Path_SM, szLog, sizeof szLog, "logs/sbpp.log" );
BuildPath( Path_SM, szIssues, sizeof szIssues, "logs/sbpp.error.log" );

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 can't connect to or can't find file.
My english is not perfect, but they should be called as issues in this case, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error is the more universally adapted name, especially when it comes to logs and log levels. My intention behind that change is to make the naming more inline with SM and the other software stack that is needed to run SBPP (e.g nginx / Apache, PHP, etc) since they all use error logs and not issue logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed. (Absolute forgot about string)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed. Sorry for that.

@TheByKotik TheByKotik changed the title Use one database connection Begin to break into modules Mar 27, 2020
Replaced static function variable to DataPack to store callbacks.
Renamed `Issues` log to `Error`.
Fixed `sbpp` dir permisson.
Fixed tabulation.
Changed ConnectCallback signature.
Clean-up static forwards params.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Optimization] Single database handle for all SB plugins
6 participants