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

Move players record to lua #4840

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ramon-bernardo
Copy link
Contributor

@ramon-bernardo ramon-bernardo commented Nov 17, 2024

Pull Request Prelude

Changes Proposed

  • Move players record to lua.
  • Saves the record only when the server save.
  • Remove globalevent onRecord.

Test required

  • I added a ScriptInterface to Game, but I am unsure of its limitations. It’s necessary to check whether what I’ve implemented is correct, including Game::getPlayersRecord()

Copy link
Contributor

@MillhioreBT MillhioreBT left a comment

Choose a reason for hiding this comment

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

Horrible, having to instantiate a pointer to a lua interface in the Game class just to get a variable from lua.
More code, same functionality, less efficient, harder to maintain.

First of all, it would be easier to have a method that accepts a luaState* L and use it to interact with lua.
Secondly, you can obtain the number of players with the Game.getPlayerCount method.
Thirdly you are not freeing the results table from the database when using storeQuery

@ramon-bernardo
Copy link
Contributor Author

@MillhioreBT I agree—if only we had a status server in Lua or something like an Http Client, we wouldn’t need to call Lua in Game.cpp.

  • However, I disagree regarding performance. Unlike before, where an UPDATE was performed every time a player joined, now it only occurs when save the game.

  • I didn’t recall Game.getPlayerCount(). I'll make the adjustment!

  • If I’m not mistaken, it’s no longer necessary to call result.free. This is because of the automatic cleanup we perform after every Lua call, using tfs::lua::resetScriptEnv(). However, I can add it explicitly if needed.

I’m not a fan of Game::Game() : scriptInterface("Game Interface"). If anyone has a better idea, im open to suggestions 🫤

@ranisalt
Copy link
Member

Just keep a running counter of players online that increases with a creaturescript of type login and decreases with a logout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants