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

Method JoinGame

src/lua/LuaCallOuts.cpp:449–517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

447//
448
449int LuaCallOuts::JoinGame(lua_State* L) {
450 const int table = 1;
451 luaL_checktype(L, table, LUA_TTABLE);
452
453 std::string address;
454 std::string callsign;
455 std::string password;
456 std::string motto;
457 int port = ServerPort;
458 int team = AutomaticTeam;
459
460 for (lua_pushnil(L); lua_next(L, table); lua_pop(L, 1)) {
461 if (!lua_israwstring(L, -2)) {
462 luaL_error(L, "invalid key");
463 }
464 const std::string key = lua_tostring(L, -2);
465 if (key == "address") {
466 address = luaL_checkstring(L, -1);
467 }
468 else if (key == "callsign") {
469 callsign = luaL_checkstring(L, -1);
470 }
471 else if (key == "password") {
472 password = luaL_checkstring(L, -1);
473 }
474 else if (key == "motto") {
475 motto = luaL_checkstring(L, -1);
476 }
477 else if (key == "port") {
478 port = luaL_checkint(L, -1);
479 }
480 else if (key == "team") {
481 team = luaL_checkint(L, -1);
482 }
483 }
484
485 const TeamColor teamColor = (TeamColor) team;
486
487 if (address.empty()) {
488 lua_pushnil(L); lua_pushliteral(L, "empty address"); return 2;
489 }
490 if (callsign.empty()) {
491 lua_pushnil(L); lua_pushliteral(L, "empty callsign"); return 2;
492 }
493 if ((teamColor != AutomaticTeam) &&
494 ((teamColor < RogueTeam) || (teamColor > ObserverTeam))) {
495 lua_pushnil(L); lua_pushliteral(L, "invalid team"); return 2;
496 }
497
498 if (LuaHandle::GetDevMode()) {
499 address = "127.0.0.1";
500 callsign = "devmode";
501 }
502
503 StartupInfo* info = getStartupInfo();
504
505 strncpy(info->serverName, address.c_str(), ServerNameLen - 1);
506 strncpy(info->callsign, callsign.c_str(), CallSignLen - 1);

Callers

nothing calls this directly

Calls 10

lua_israwstringFunction · 0.85
getStartupInfoFunction · 0.85
c_strMethod · 0.80
luaL_checktypeFunction · 0.50
lua_pushnilFunction · 0.50
lua_nextFunction · 0.50
luaL_errorFunction · 0.50
joinGameFunction · 0.50
lua_pushbooleanFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected