Add ServerJoin lua hook, which gets called when client joins a server (listen server hosts joining their server also count)

This commit is contained in:
indev authored and Alug committed 2024-07-10 19:09:08 +02:00
1 parent 3c70963f56
commit 630d910a9e
3 files changed
+39 -1

No files matched your search

+2
View File
@@ -2748,6 +2748,8 @@ static void CL_ConnectToServer(void)
DEBFILE(va("Synchronisation Finished\n"));
displayplayers[0] = consoleplayer;
LUAh_ServerJoin();
}
#ifndef NONET
+4 -1
View File
@@ -55,6 +55,7 @@ enum hook {
hook_PlayerCmd, //SRB2KART
hook_IntermissionThinker, //SRB2KART
hook_VoteThinker, //SRB2KART
hook_ServerJoin, // SRB2KART - Saturn 32p
hook_MAX // last hook
};
@@ -106,8 +107,10 @@ boolean LUAh_PlayerSpin(player_t *player, mobj_t *inflictor, mobj_t *source); //
boolean LUAh_PlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_ExplodePlayer. Allows Lua to execute code and/or overwrite its behavior.
boolean LUAh_PlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Hook for K_SquishPlayer. Allows Lua to execute code and/or overwrite its behavior.
void LUAh_ServerJoin(void); // SRB2KART - Saturn 32p: called by client when joining a server, allows lua to load any sort of config file
boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd); // Allows to write to player cmd before the game does anything with them.
void LUAh_IntermissionThinker(void); // Hook for Y_Ticker
void LUAh_VoteThinker(void); // Hook for Y_VoteTicker
#define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink
#define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink
+33
View File
@@ -68,6 +68,7 @@ const char *const hookNames[hook_MAX+1] = {
"PlayerCmd",
"IntermissionThinker",
"VoteThinker",
"ServerJoin",
NULL
};
@@ -219,6 +220,7 @@ static int lib_addHook(lua_State *L)
case hook_PlayerSpin:
case hook_PlayerExplode:
case hook_PlayerSquish:
case hook_ServerJoin:
default:
lastp = &roothook;
break;
@@ -1869,3 +1871,34 @@ boolean LUAh_PlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source)
lua_settop(gL, 0);
return hooked;
}
void LUAh_ServerJoin(void)
{
hook_p hookp;
int HOOKSINDEX;
if (!gL || !(hooksAvailable[hook_ServerJoin/8] & (1<<(hook_ServerJoin%8))))
return;
lua_settop(gL, 0);
lua_pushcfunction(gL, LUA_GetErrorMessage);
lua_getfield(gL, LUA_REGISTRYINDEX, "hooks");
HOOKSINDEX = lua_gettop(gL);
I_Assert(lua_istable(L, HOOKSINDEX));
// We can afford not to look for target->type because it will always be MT_PLAYER.
for (hookp = roothook; hookp; hookp = hookp->next)
if (hookp->type == hook_ServerJoin)
{
lua_rawgeti(gL, HOOKSINDEX, hookp->id);
if (lua_pcall(gL, 0, 0, 1)) {
if (!hookp->error || cv_debug & DBG_LUA)
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
lua_pop(gL, 1);
hookp->error = true;
continue;
}
}
lua_settop(gL, 0);
}