Skip to content

Commit ddde7b2

Browse files
committed
fixes
1 parent cb02a5b commit ddde7b2

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

src/game/game_thread.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

18671871
void 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

18901897
void GameThread::reload_game(std::string folder_name) {

src/game/game_thread_messages.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#define ERROR_CANNOT_KICK_SELF "ERROR_CANNOT_KICK_SELF"
1616
#define ERROR_INVALID_FUNCTION_MSG "ERROR_INVALID_FUNCTION_MSG"
1717
#define ERROR_INVALID_ARGUMENTS "ERROR_INVALID_ARGUMENTS"
18-
#define ERROR_LOBBY_NOT_SEALED "ERROR_LOBBY_NOT_SEALED"
19-
#define ERROR_LOBBY_SEALED "ERROR_LOBBY_SEALED"
2018
#define ERROR_LOBBY_NOT_FOUND "ERROR_LOBBY_NOT_FOUND"
2119
#define ERROR_LOBBY_WRONG_PASSWORD "ERROR_LOBBY_WRONG_PASSWORD"
2220
#define ERROR_LOBBY_FULL "ERROR_LOBBY_FULL"

src/game/lobby_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct LobbyData {
4545
lobby_dict["c"] = AnyElement{create_time};
4646
lobby_dict["_p"] = AnyElement{bool(password != "")};
4747
lobby_dict["t"] = AnyElement{tags};
48-
lobby_dict["p"] = AnyElement{public_data};
48+
lobby_dict["d"] = AnyElement{public_data};
4949
if (include_private) {
5050
lobby_dict["_p"] = AnyElement{private_data};
5151
}

0 commit comments

Comments
 (0)