Skip to content

Commit

Permalink
fix: prevent bugs in transfer coins (opentibiabr#714)
Browse files Browse the repository at this point in the history
Added:
• New method to lua from source;
• Delay in parseTransferCoins.
  • Loading branch information
carlospess0a authored Feb 12, 2023
1 parent ecc0642 commit 6b69b23
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ function parseTransferCoins(playerId, msg)
return false
end

if player:isUIExhausted(2000) then
return addPlayerEvent(sendStoreError, 250, playerId, GameStore.StoreErrors.STORE_ERROR_TRANSFER, "You are exhausted.")
end

player:updateUIExhausted()
local reciver = msg:getString()
local amount = msg:getU32()

Expand Down
28 changes: 28 additions & 0 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3207,3 +3207,31 @@ int PlayerFunctions::luaPlayerGetFaction(lua_State* L) {
lua_pushnumber(L, player->getFaction());
return 1;
}

int PlayerFunctions::luaPlayerIsUIExhausted(lua_State *L) {
// player:isUIExhausted()
Player* player = getUserdata<Player>(L, 1);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
pushBoolean(L, false);
return 0;
}

uint16_t time = getNumber<uint16_t>(L, 2);
pushBoolean(L, player->isUIExhausted(time));
return 1;
}

int PlayerFunctions::luaPlayerUpdateUIExhausted(lua_State *L) {
// player:updateUIExhausted(exhaustionTime = 250)
Player* player = getUserdata<Player>(L, 1);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
pushBoolean(L, false);
return 0;
}

player->updateUIExhausted();
pushBoolean(L, true);
return 1;
}
4 changes: 4 additions & 0 deletions src/lua/functions/creatures/player/player_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ class PlayerFunctions final : LuaScriptInterface {

registerMethod(L, "Player", "getForgeSlivers", PlayerFunctions::luaPlayerGetForgeSlivers);
registerMethod(L, "Player", "getForgeCores", PlayerFunctions::luaPlayerGetForgeCores);
registerMethod(L, "Player", "isUIExhausted", PlayerFunctions::luaPlayerIsUIExhausted);
registerMethod(L, "Player", "updateUIExhausted", PlayerFunctions::luaPlayerUpdateUIExhausted);

registerMethod(L, "Player", "setFaction", PlayerFunctions::luaPlayerSetFaction);
registerMethod(L, "Player", "getFaction", PlayerFunctions::luaPlayerGetFaction);
Expand Down Expand Up @@ -560,6 +562,8 @@ class PlayerFunctions final : LuaScriptInterface {

static int luaPlayerGetForgeSlivers(lua_State* L);
static int luaPlayerGetForgeCores(lua_State* L);
static int luaPlayerIsUIExhausted(lua_State* L);
static int luaPlayerUpdateUIExhausted(lua_State* L);

static int luaPlayerSetFaction(lua_State* L);
static int luaPlayerGetFaction(lua_State* L);
Expand Down

0 comments on commit 6b69b23

Please sign in to comment.