@@ -918,6 +918,10 @@ void GameThread::on_create_lobby(
918918 // CHANGES before scripted call, reverted if scripted call fails
919919 auto uuid = to_string (gen ());
920920 auto small_uuid = uuid.substr (0 , 8 );
921+ auto max_players = decode_int_or_default (data_val, " m" , 0 );
922+ if (max_players < 1 ) {
923+ return on_error (game, command_id, peer.id , ERROR_LOBBY_FULL );
924+ }
921925 boost::container::flat_map<std::string, AnyElement> lobby_tags;
922926 if (previous_tags != nullptr ) {
923927 lobby_tags = *previous_tags;
@@ -933,7 +937,7 @@ void GameThread::on_create_lobby(
933937 .name = decode_string_or_default (data_val, " n" , " " ),
934938 .host = peer.id ,
935939 .password = decode_string_or_default (data_val, " _p" , " " ),
936- .max_players = decode_int_or_default (data_val, " m " , 0 ) ,
940+ .max_players = max_players ,
937941 .peer_ids = {peer.id },
938942 .peer_ordered_ids = {peer.id },
939943 .create_time = now,
@@ -1413,7 +1417,7 @@ void GameThread::on_seal_lobby(GameData &game, std::string command_id, PeerData
14131417 return on_error (game, command_id, peer.id , ERROR_PEER_NOT_HOST );
14141418 }
14151419 if (lobby.sealed ) {
1416- return on_error (game, command_id , peer.id , ERROR_LOBBY_SEALED );
1420+ return set_lobby_sealed (game, lobby , peer.id , command_id, true );
14171421 }
14181422 // SCRIPTED CALL
14191423 if (game.enabled_callbacks .find (" _can_host_seal" ) != game.enabled_callbacks .end ()) {
@@ -1442,7 +1446,7 @@ void GameThread::on_unseal_lobby(GameData &game, std::string command_id, PeerDat
14421446 return on_error (game, command_id, peer.id , ERROR_PEER_NOT_HOST );
14431447 }
14441448 if (!lobby.sealed ) {
1445- return on_error (game, command_id , peer.id , ERROR_LOBBY_NOT_SEALED );
1449+ return set_lobby_sealed (game, lobby , peer.id , command_id, false );
14461450 }
14471451 // SCRIPTED CALL
14481452 if (game.enabled_callbacks .find (" _can_host_seal" ) != game.enabled_callbacks .end ()) {
@@ -1467,9 +1471,9 @@ void GameThread::on_lobby_max_players(GameData &game, std::string command_id, Pe
14671471 return on_error (game, command_id, peer.id , ERROR_PEER_NOT_IN_A_LOBBY );
14681472 }
14691473 auto &lobby = game.lobbies [peer.lobby_id ];
1470- auto max_players = decode_int_or_default (data_val, " max_players " , 0 );
1474+ auto max_players = decode_int_or_default (data_val, " m " , 0 );
14711475 if (max_players < lobby.peer_ids .size ()) {
1472- return on_error (game, command_id, peer.id , " Invalid max players " );
1476+ return on_error (game, command_id, peer.id , ERROR_LOBBY_FULL );
14731477 }
14741478 // SCRIPTED CALL
14751479 if (game.enabled_callbacks .find (" _can_host_resize" ) != game.enabled_callbacks .end ()) {
@@ -1866,25 +1870,28 @@ void GameThread::on_lobby_notify(GameData &game, std::string command_id, PeerDat
18661870
18671871void GameThread::set_lobby_sealed (GameData &game, LobbyData &lobby, std::string peer_id,
18681872 std::string command_id, bool sealed) {
1873+ bool updated = lobby.sealed != sealed;
18691874 // CHANGES
18701875 lobby.sealed = sealed;
18711876 // NOTIFICATION
1872- std::string notification_others = notification_lobby_unsealed (EMPTY_STRING );
1873- if (sealed) {
1874- notification_others = notification_lobby_sealed (EMPTY_STRING );
1875- }
1876- for (auto lobby_peer_id : lobby.peer_ids ) {
1877- if (lobby_peer_id == peer_id) {
1878- continue ;
1877+ if (updated) {
1878+ std::string notification_others = notification_lobby_unsealed (EMPTY_STRING );
1879+ if (sealed) {
1880+ notification_others = notification_lobby_sealed (EMPTY_STRING );
18791881 }
1880- send (game, lobby_peer_id, notification_others, uWS::OpCode::TEXT );
1882+ for (auto lobby_peer_id : lobby.peer_ids ) {
1883+ if (lobby_peer_id == peer_id) {
1884+ continue ;
1885+ }
1886+ send (game, lobby_peer_id, notification_others, uWS::OpCode::TEXT );
1887+ }
1888+ game.lobbies_updated .insert (lobby.id );
18811889 }
18821890 std::string notification_self = notification_lobby_unsealed (command_id);
18831891 if (sealed) {
18841892 notification_self = notification_lobby_sealed (command_id);
18851893 }
18861894 send (game, peer_id, notification_self, uWS::OpCode::TEXT );
1887- game.lobbies_updated .insert (lobby.id );
18881895}
18891896
18901897void GameThread::reload_game (std::string folder_name) {
0 commit comments