66#include < regex>
77#include < sstream>
88
9- #include " INIReader.h"
109#include " ../common/any_type.h"
11- #include " game_thread_messages.h"
12- #include " ../lua/script_lua.h"
1310#include " ../common/base_path.h"
11+ #include " ../lua/script_lua.h"
12+ #include " INIReader.h"
13+ #include " game_thread_messages.h"
1414
1515GameThread::GameThread (
1616 bool db_enabled, bool verbose, std::string log_folder, std::string scripts_folder,
@@ -86,8 +86,7 @@ void GameThread::load_games() {
8686 .script_entrypoint = " main.lua" ,
8787 .logs_folder = logs_folder,
8888 .game_thread = this ,
89- .enabled = lobby_control == " lua" }
90- });
89+ .enabled = lobby_control == " lua" }});
9190 }
9291 for (auto &game : games) {
9392 if (!games_to_open.contains (game.first )) {
@@ -372,16 +371,14 @@ bool GameThread::handle_events() {
372371 // decode message
373372 yyjson_doc *doc = yyjson_read (message.message .c_str (), message.message .size (), 0 );
374373 if (!doc) {
375- on_error (game, EMPTY_STRING , message.id ,
376- ERROR_CANNOT_PARSE_JSON , true );
374+ on_error (game, EMPTY_STRING , message.id , ERROR_CANNOT_PARSE_JSON , true );
377375 break ;
378376 }
379377
380378 yyjson_val *root = yyjson_doc_get_root (doc);
381379 if (!root || !yyjson_is_obj (root)) {
382380 yyjson_doc_free (doc);
383- on_error (game, EMPTY_STRING , message.id ,
384- ERROR_CANNOT_PARSE_JSON , true );
381+ on_error (game, EMPTY_STRING , message.id , ERROR_CANNOT_PARSE_JSON , true );
385382 break ;
386383 }
387384 // get command
@@ -390,8 +387,7 @@ bool GameThread::handle_events() {
390387 std::string command_id = decode_string_or_default (root, " id" , EMPTY_STRING );
391388 if (game.peers .find (message.id ) == game.peers .end ()) {
392389 yyjson_doc_free (doc);
393- on_error (game, command_id, message.id , ERROR_PEER_NOT_FOUND ,
394- true );
390+ on_error (game, command_id, message.id , ERROR_PEER_NOT_FOUND , true );
395391 break ;
396392 }
397393 auto &peer = game.peers [message.id ];
@@ -469,8 +465,7 @@ bool GameThread::handle_events() {
469465 } break ;
470466
471467 default : {
472- on_error (game, std::string (command_id), message.id ,
473- ERROR_UNKOWN_COMMAND , true );
468+ on_error (game, std::string (command_id), message.id , ERROR_UNKOWN_COMMAND , true );
474469 } break ;
475470 }
476471 yyjson_doc_free (doc);
@@ -918,26 +913,23 @@ void GameThread::on_create_lobby(
918913 }
919914 peer.lobby_id = small_uuid;
920915 game.lobbies .emplace (small_uuid,
921- LobbyData{
922- .id = small_uuid,
923- .name = decode_string_or_default (data_val, " n" , " " ),
924- .host = peer.id ,
925- .password = decode_string_or_default (data_val, " _p" , " " ),
926- .max_players = decode_int_or_default (data_val, " m" , 0 ),
927- .peer_ids = {peer.id },
928- .peer_ordered_ids = {peer.id },
929- .create_time = now,
930- .game_id = peer.game_id ,
931- .sealed = decode_bool_or_default (data_val, " s" , game.seal ),
932- .tags = lobby_tags,
933- .lua = ScriptLua{.scripts_folder = game.lua .scripts_folder ,
934- .folder_name = game.lua .folder_name ,
935- .script_entrypoint = " main.lua" ,
936- .logs_folder = game.lua .logs_folder ,
937- .game_thread = this ,
938- .enabled = game.lua .enabled
939- }
940- });
916+ LobbyData{.id = small_uuid,
917+ .name = decode_string_or_default (data_val, " n" , " " ),
918+ .host = peer.id ,
919+ .password = decode_string_or_default (data_val, " _p" , " " ),
920+ .max_players = decode_int_or_default (data_val, " m" , 0 ),
921+ .peer_ids = {peer.id },
922+ .peer_ordered_ids = {peer.id },
923+ .create_time = now,
924+ .game_id = peer.game_id ,
925+ .sealed = decode_bool_or_default (data_val, " s" , game.seal ),
926+ .tags = lobby_tags,
927+ .lua = ScriptLua{.scripts_folder = game.lua .scripts_folder ,
928+ .folder_name = game.lua .folder_name ,
929+ .script_entrypoint = " main.lua" ,
930+ .logs_folder = game.lua .logs_folder ,
931+ .game_thread = this ,
932+ .enabled = game.lua .enabled }});
941933 auto &lobby = game.lobbies [small_uuid];
942934 lobby.open ();
943935 game.lobby_listing_peers .erase (peer.id );
@@ -1056,10 +1048,9 @@ bool GameThread::on_join_lobby(GameData &game, std::string command_id, PeerData
10561048 }
10571049 }
10581050 // if it's relay, send private lobby data too at connection if host
1059- std::string notification_self =
1060- notification_lobby_joined (AnyElement{lobby.to_dict (game.lobby_control == " relay" &&
1061- lobby.host == peer.id )},
1062- AnyElement{game.peers_to_array (lobby.id )}, command_id);
1051+ std::string notification_self = notification_lobby_joined (
1052+ AnyElement{lobby.to_dict (game.lobby_control == " relay" && lobby.host == peer.id )},
1053+ AnyElement{game.peers_to_array (lobby.id )}, command_id);
10631054 send (game, peer.id , notification_self, uWS::OpCode::TEXT );
10641055 // SCRIPTED CALL
10651056 if (!reconnecting) {
@@ -1194,13 +1185,11 @@ void GameThread::on_lobby_tags(GameData &game, std::string command_id, PeerData
11941185 }
11951186 boost::container::flat_map<std::string, AnyElement> new_tags;
11961187 if (!data_val || !yyjson_is_obj (data_val)) {
1197- return on_error (game, command_id, peer.id ,
1198- ERROR_CANNOT_PARSE_JSON );
1188+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
11991189 }
12001190 yyjson_val *tags_val = yyjson_obj_get (data_val, " t" );
12011191 if (!tags_val || !yyjson_is_obj (tags_val)) {
1202- return on_error (game, command_id, peer.id ,
1203- ERROR_CANNOT_PARSE_JSON );
1192+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
12041193 }
12051194 std::string error = decode_object (tags_val, new_tags);
12061195 if (!error.empty ()) {
@@ -1279,13 +1268,11 @@ void GameThread::on_user_data(GameData &game, std::string command_id, PeerData &
12791268 // CHANGES
12801269 boost::container::flat_map<std::string, AnyElement> new_userdata;
12811270 if (!data_val || !yyjson_is_obj (data_val)) {
1282- return on_error (game, command_id, peer.id ,
1283- ERROR_CANNOT_PARSE_JSON );
1271+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
12841272 }
12851273 yyjson_val *userdata_val = yyjson_obj_get (data_val, " ud" );
12861274 if (!userdata_val || !yyjson_is_obj (userdata_val)) {
1287- return on_error (game, command_id, peer.id ,
1288- ERROR_CANNOT_PARSE_JSON );
1275+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
12891276 }
12901277 std::string error = decode_object (userdata_val, new_userdata);
12911278 if (!error.empty ()) {
@@ -1569,8 +1556,7 @@ void GameThread::on_lobby_data(GameData &game, std::string command_id, PeerData
15691556 // CHANGES
15701557 yyjson_val *lobbydata_val = yyjson_obj_get (data_val, " d" );
15711558 if (!lobbydata_val || !yyjson_is_obj (lobbydata_val)) {
1572- return on_error (game, command_id, peer.id ,
1573- ERROR_CANNOT_PARSE_JSON );
1559+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
15741560 }
15751561 boost::container::flat_map<std::string, AnyElement> new_lobbydata;
15761562 std::string error = decode_object (lobbydata_val, new_lobbydata);
@@ -1651,8 +1637,7 @@ void GameThread::on_data_to(GameData &game, std::string command_id, PeerData &pe
16511637 // CHANGES
16521638 yyjson_val *peerdata_val = yyjson_obj_get (data_val, " d" );
16531639 if (!peerdata_val || !yyjson_is_obj (peerdata_val)) {
1654- return on_error (game, command_id, peer.id ,
1655- ERROR_CANNOT_PARSE_JSON );
1640+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
16561641 }
16571642 boost::container::flat_map<std::string, AnyElement> new_data;
16581643 std::string error = decode_object (peerdata_val, new_data);
@@ -1724,8 +1709,7 @@ void GameThread::on_data_to_all(GameData &game, std::string command_id, PeerData
17241709 // CHANGES
17251710 yyjson_val *peerdata_val = yyjson_obj_get (data_val, " d" );
17261711 if (!peerdata_val || !yyjson_is_obj (peerdata_val)) {
1727- return on_error (game, command_id, peer.id ,
1728- ERROR_CANNOT_PARSE_JSON );
1712+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
17291713 }
17301714 boost::container::flat_map<std::string, AnyElement> new_data;
17311715 std::string error = decode_object (peerdata_val, new_data);
@@ -1806,8 +1790,7 @@ void GameThread::on_notify_to(GameData &game, std::string command_id, PeerData &
18061790 // CHANGES
18071791 yyjson_val *peerdata_val = yyjson_obj_get (data_val, " d" );
18081792 if (!peerdata_val || !yyjson_is_obj (peerdata_val)) {
1809- return on_error (game, command_id, peer.id ,
1810- ERROR_CANNOT_PARSE_JSON );
1793+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
18111794 }
18121795 boost::container::flat_map<std::string, AnyElement> new_data;
18131796 std::string error = decode_object (peerdata_val, new_data);
@@ -1836,8 +1819,7 @@ void GameThread::on_lobby_notify(GameData &game, std::string command_id, PeerDat
18361819 // CHANGES
18371820 yyjson_val *peerdata_val = yyjson_obj_get (data_val, " d" );
18381821 if (!peerdata_val || !yyjson_is_obj (peerdata_val)) {
1839- return on_error (game, command_id, peer.id ,
1840- ERROR_CANNOT_PARSE_JSON );
1822+ return on_error (game, command_id, peer.id , ERROR_CANNOT_PARSE_JSON );
18411823 }
18421824 boost::container::flat_map<std::string, AnyElement> new_data;
18431825 std::string error = decode_object (peerdata_val, new_data);
0 commit comments