diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 2d470b551..bd7f5f335 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3716,8 +3716,11 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) players[newplayernum].splitscreenindex = splitscreenplayer; players[newplayernum].bot = false; + + // player_t is the only place in the game that a key is null-terminated, for ease of Lua push. + memset(players[newplayernum].public_key, 0, 32 + 1); CONS_Printf("Adding player from node %d with ID %s\n", node, GetPrettyRRID(lastReceivedKey[node][splitscreenplayer], true)); - memcpy(players[newplayernum].public_key, lastReceivedKey[node][splitscreenplayer], sizeof(players[newplayernum].public_key)); + memcpy(players[newplayernum].public_key, lastReceivedKey[node][splitscreenplayer], 32); CONS_Printf("Node %d now has ID %s\n", node, GetPrettyRRID(players[newplayernum].public_key, true)); playerconsole[newplayernum] = console; diff --git a/src/d_player.h b/src/d_player.h index 455db72f3..aedbb06b3 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -713,7 +713,7 @@ struct player_t mobj_t *stumbleIndicator; mobj_t *sliptideZipIndicator; - uint8_t public_key[32]; + uint8_t public_key[32 + 1]; #ifdef HWRENDER fixed_t fovadd; // adjust FOV for hw rendering diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 76325ebc9..62efe43d5 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -507,6 +507,8 @@ static int player_get(lua_State *L) #endif else if (fastcmp(field,"ping")) lua_pushinteger(L, playerpingtable[( plr - players )]); + else if (fastcmp(field, "public_key")) + lua_pushstring(L, plr->public_key); else { lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); I_Assert(lua_istable(L, -1)); diff --git a/src/p_saveg.c b/src/p_saveg.c index 3781925ca..6daf025fc 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -407,7 +407,7 @@ static void P_NetArchivePlayers(savebuffer_t *save) WRITEUINT8(save->p, players[i].sliptideZipDelay); WRITEUINT16(save->p, players[i].sliptideZipBoost); - WRITESTRINGN(save->p, players[i].public_key, 32); + WRITESTRINGN(save->p, players[i].public_key, 32 + 1); // respawnvars_t WRITEUINT8(save->p, players[i].respawn.state); @@ -789,7 +789,7 @@ static void P_NetUnArchivePlayers(savebuffer_t *save) players[i].sliptideZipDelay = READUINT8(save->p); players[i].sliptideZipBoost = READUINT16(save->p); - READSTRINGN(save->p, players[i].public_key, 32); + READSTRINGN(save->p, players[i].public_key, 32 + 1); // respawnvars_t players[i].respawn.state = READUINT8(save->p);