diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index a3a9b858b2..62b1152b0d 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -562,13 +562,16 @@ declare global { */ interface Network { readonly mode: NetworkMode; - readonly groups: number; - readonly players: number; + readonly numGroups: number; + readonly numPlayers: number; + readonly groups: PlayerGroup[]; + readonly players: Player[]; defaultGroup: number; getServerInfo(): ServerInfo; + addGroup(): void; getGroup(index: number): PlayerGroup; - setGroups(groups: PlayerGroup[]): void; + removeGroup(index: number): void; getPlayer(index: number): Player; kickPlayer(index: number): void; sendMessage(message: string): void; diff --git a/src/openrct2/scripting/ScNetwork.hpp b/src/openrct2/scripting/ScNetwork.hpp index 94e5ab47a0..af0f6c7b3f 100644 --- a/src/openrct2/scripting/ScNetwork.hpp +++ b/src/openrct2/scripting/ScNetwork.hpp @@ -271,7 +271,7 @@ namespace OpenRCT2::Scripting # endif return "none"; } - int32_t players_get() const + int32_t numPlayers_get() const { # ifndef DISABLE_NETWORK return network_get_num_players(); @@ -279,7 +279,7 @@ namespace OpenRCT2::Scripting return 0; # endif } - int32_t groups_get() const + int32_t numGroups_get() const { # ifndef DISABLE_NETWORK return network_get_num_groups(); @@ -303,6 +303,34 @@ namespace OpenRCT2::Scripting # endif } + std::vector> groups_get() const + { + std::vector> groups; +# ifndef DISABLE_NETWORK + auto numGroups = network_get_num_groups(); + for (int32_t i = 0; i < numGroups; i++) + { + auto groupId = network_get_group_id(i); + groups.push_back(std::make_shared(groupId)); + } +# endif + return groups; + } + + std::vector> players_get() const + { + std::vector> players; +# ifndef DISABLE_NETWORK + auto numPlayers = network_get_num_players(); + for (int32_t i = 0; i < numPlayers; i++) + { + auto playerId = network_get_player_id(i); + players.push_back(std::make_shared(playerId)); + } +# endif + return players; + } + std::shared_ptr getPlayer(int32_t index) const { # ifndef DISABLE_NETWORK @@ -329,6 +357,27 @@ namespace OpenRCT2::Scripting return nullptr; } + void addGroup() + { +# ifndef DISABLE_NETWORK + auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::AddGroup); + GameActions::Execute(&networkModifyGroup); +# endif + } + + void removeGroup(int32_t index) + { +# ifndef DISABLE_NETWORK + auto numGroups = network_get_num_groups(); + if (index < numGroups) + { + auto groupId = network_get_group_id(index); + auto networkAction = NetworkModifyGroupAction(ModifyGroupType::RemoveGroup, groupId); + GameActions::Execute(&networkAction); + } +# endif + } + void kickPlayer(int32_t index) { # ifndef DISABLE_NETWORK @@ -359,10 +408,14 @@ namespace OpenRCT2::Scripting static void Register(duk_context* ctx) { dukglue_register_property(ctx, &ScNetwork::mode_get, nullptr, "mode"); + dukglue_register_property(ctx, &ScNetwork::numGroups_get, nullptr, "numGroups"); + dukglue_register_property(ctx, &ScNetwork::numPlayers_get, nullptr, "numPlayers"); dukglue_register_property(ctx, &ScNetwork::groups_get, nullptr, "groups"); dukglue_register_property(ctx, &ScNetwork::players_get, nullptr, "players"); dukglue_register_property(ctx, &ScNetwork::defaultGroup_get, &ScNetwork::defaultGroup_set, "defaultGroup"); + dukglue_register_method(ctx, &ScNetwork::addGroup, "addGroup"); dukglue_register_method(ctx, &ScNetwork::getGroup, "getGroup"); + dukglue_register_method(ctx, &ScNetwork::removeGroup, "removeGroup"); dukglue_register_method(ctx, &ScNetwork::getPlayer, "getPlayer"); dukglue_register_method(ctx, &ScNetwork::kickPlayer, "kickPlayer"); dukglue_register_method(ctx, &ScNetwork::sendMessage, "sendMessage");