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

Add option to disable connection events on filterscript load/unload #869

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions Server/Components/Pawn/Manager/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,13 @@ void PawnManager::openAMX(PawnScript& script, bool isEntryScript)
// cache public pointers.

// Call `OnPlayerConnect` (can be after caching).
for (auto p : players->entries())
// https://github.com/openmultiplayer/open.mp/issues/807
if (isEntryScript || config->getBool("game.use_filterscript_load_events"))
{
script.Call("OnPlayerConnect", DefaultReturnValue_True, p->getID());
for (auto p : players->entries())
{
script.Call("OnPlayerConnect", DefaultReturnValue_True, p->getID());
}
}
}

Expand Down Expand Up @@ -593,40 +597,45 @@ bool PawnManager::Load(std::string const& name, bool isEntryScript)

void PawnManager::closeAMX(PawnScript& script, bool isEntryScript)
{
AMX* amx = script.GetAMX();
int idx;
bool once = true;
// Reason 4, to match fixes.inc. Why was it not 3? I don't know.
if (amx_FindPublic(amx, "OnPlayerDisconnect", &idx) == AMX_ERR_NONE)
// https://github.com/openmultiplayer/open.mp/issues/807
if (isEntryScript || config->getBool("game.use_filterscript_load_events"))
{
for (auto const p : players->entries())
AMX* amx = script.GetAMX();
int idx;
bool once = true;
// Reason 4, to match fixes.inc. Why was it not 3? I don't know.
if (amx_FindPublic(amx, "OnPlayerDisconnect", &idx) == AMX_ERR_NONE)
{
cell ret = 1;
int err = script.CallChecked(idx, ret, p->getID(), PeerDisconnectReason_ModeEnd);
switch (err)
for (auto const p : players->entries())
{
case AMX_ERR_NONE:
break;
case AMX_ERR_BOUNDS:
// Test the `OP_BOUNDS` parameter and the current index.
if (once && (*(cell*)((uintptr_t)amx->base + (((AMX_HEADER*)amx->base)->cod + amx->cip - sizeof(cell)))) == 2) // && amx->pri == 4)
cell ret = 1;
int err = script.CallChecked(idx, ret, p->getID(), PeerDisconnectReason_ModeEnd);
switch (err)
{
core->printLn(R"(
case AMX_ERR_NONE:
break;
case AMX_ERR_BOUNDS:
// Test the `OP_BOUNDS` parameter and the current index.
if (once && (*(cell*)((uintptr_t)amx->base + (((AMX_HEADER*)amx->base)->cod + amx->cip - sizeof(cell)))) == 2) // && amx->pri == 4)
{
core->printLn(R"(
Array out-of-bounds encountered during `OnPlayerDisconnect` with reason `4`
(script exit). This may be due to old code assuming the highest possible reason
is `2`.
)");
// Only show the error once, don't spam it.
once = false;
// Only show the error once, don't spam it.
once = false;
break;
}
// Fallthrough
default:
core->logLn(LogLevel::Error, "%s", aux_StrError(err));
break;
}
// Fallthrough
default:
core->logLn(LogLevel::Error, "%s", aux_StrError(err));
break;
}
}
}

if (isEntryScript)
{
script.Call("OnGameModeExit", DefaultReturnValue_False);
Expand Down
1 change: 1 addition & 0 deletions Server/Source/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static const std::map<String, ConfigStorage> Defaults {
{ "game.use_all_animations", true },
{ "game.lag_compensation_mode", LagCompMode_Enabled },
{ "game.group_player_objects", false },
{ "game.use_filterscript_load_events", true },
// logging
{ "logging.enable", true },
{ "logging.file", String("log.txt") },
Expand Down