MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / SendPlayerVariables

Function SendPlayerVariables

src/bzfs/lua/CallOuts.cpp:838–875  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

836
837
838static int SendPlayerVariables(lua_State* L) {
839 const int playerID = luaL_checkint(L, 1);
840 GameKeeper::Player* gkPlayer = GameKeeper::Player::getPlayerByIndex(playerID);
841 if ((gkPlayer == NULL) || (gkPlayer->netHandler == NULL)) {
842 lua_pushboolean(L, false);
843 return 1;
844 }
845
846 const int tableIndex = 2;
847 luaL_checktype(L, tableIndex, LUA_TTABLE);
848
849 std::map<std::string, std::string> varMap;
850 for (lua_pushnil(L); lua_next(L, tableIndex) != 0; lua_pop(L, 1)) {
851 if (lua_israwstring(L, -2) && lua_isstring(L, -1)) {
852 const std::string key = lua_tostring(L, -2);
853 if (!key.empty()) {
854 varMap[key] = lua_tostring(L, -1);
855 }
856 }
857 }
858
859 if (varMap.empty()) {
860 lua_pushboolean(L, false);
861 return 1;
862 }
863
864 NetMessage netMsg;
865 netMsg.packUInt16(varMap.size());
866 std::map<std::string, std::string>::const_iterator it;
867 for (it = varMap.begin(); it != varMap.end(); ++it) {
868 netMsg.packStdString(it->first);
869 netMsg.packStdString(it->second);
870 }
871 netMsg.send(gkPlayer->netHandler, MsgSetVar);
872
873 lua_pushinteger(L, (int)varMap.size());
874 return 1;
875}
876
877
878//============================================================================//

Callers

nothing calls this directly

Calls 15

lua_israwstringFunction · 0.85
packUInt16Method · 0.80
packStdStringMethod · 0.80
getPlayerByIndexFunction · 0.70
lua_pushbooleanFunction · 0.50
luaL_checktypeFunction · 0.50
lua_pushnilFunction · 0.50
lua_nextFunction · 0.50
lua_isstringFunction · 0.50
lua_pushintegerFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected