Lua Bugfix: send tables inside of sync tables on join

This commit is contained in:
MysterD 2022-03-21 00:15:19 -07:00
parent 0b4dd4cfbc
commit 9538c551e4
2 changed files with 13 additions and 9 deletions

View file

@ -261,7 +261,7 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al
lua_pop(L, 1); // pop seq value
// set seq number
if (!gLuaInitializingScript && alterSeq) {
if (alterSeq) {
seq += MAX_PLAYERS + (MAX_PLAYERS - gNetworkPlayers[0].globalIndex);
lua_pushvalue(L, keyIndex);
lua_pushinteger(L, seq);
@ -282,7 +282,7 @@ static bool smlua_sync_table_send_field(u8 toLocalIndex, int stackIndex, bool al
}
// send over the network
if (!gLuaInitializingScript && seq > 0) {
if (!gLuaInitializingScript) {
network_send_lua_sync_table(toLocalIndex, seq, modRemoteIndex, sUnwoundLntsCount, sUnwoundLnts, &lntValue);
}
@ -513,14 +513,17 @@ static void smlua_sync_table_send_table(u8 toLocalIndex) {
lua_pushnil(L); // first key
while (lua_next(L, internalIndex) != 0) {
// uses 'key' (at index -2) and 'value' (at index -1)
//LOG_INFO(" sending sync table field: %s", lua_tostring(L, -2));
lua_pushvalue(L, tableIndex); // insert sync table
lua_insert(L, -3); // re-order sync table
smlua_sync_table_send_field(toLocalIndex, internalIndex, false);
lua_remove(L, -3); // remove sync table
if (lua_type(L, -1) == LUA_TTABLE) {
LOG_INFO(" sending sync table field (table): %s", lua_tostring(L, -2));
smlua_sync_table_send_table(toLocalIndex);
} else {
LOG_INFO(" sending sync table field: %s", lua_tostring(L, -2));
lua_pushvalue(L, tableIndex); // insert sync table
lua_insert(L, -3); // re-order sync table
smlua_sync_table_send_field(toLocalIndex, internalIndex, false);
lua_remove(L, -3); // remove sync table
}
lua_pop(L, 1); // removed value ; keeps 'key' for next iteration
}

View file

@ -119,6 +119,7 @@ void network_send_lua_sync_table(u8 toLocalIndex, u64 seq, u16 modRemoteIndex, u
packet_write(&p, &modRemoteIndex, sizeof(u16));
packet_write(&p, &lntKeyCount, sizeof(u16));
for (int i = 0; i < lntKeyCount; i++) {
if (!packet_write_lnt(&p, &lntKeys[i])) { return; }
}