| 836 | |
| 837 | |
| 838 | static 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 | //============================================================================// |
nothing calls this directly
no test coverage detected