1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-19 04:53:12 +01:00

refactor NetworkAction

This commit is contained in:
Ted John
2016-05-28 18:29:56 +01:00
parent 31ac6e7fdf
commit 3591026078
8 changed files with 457 additions and 241 deletions

View File

@@ -83,8 +83,10 @@
<ClCompile Include="src\management\research.c" />
<ClCompile Include="src\network\http.cpp" />
<ClCompile Include="src\network\network.cpp" />
<ClCompile Include="src\network\NetworkAction.cpp" />
<ClCompile Include="src\network\NetworkAddress.cpp" />
<ClCompile Include="src\network\NetworkConnection.cpp" />
<ClCompile Include="src\network\NetworkGroup.cpp" />
<ClCompile Include="src\network\NetworkKey.cpp" />
<ClCompile Include="src\network\NetworkPacket.cpp" />
<ClCompile Include="src\network\NetworkUser.cpp" />
@@ -361,8 +363,10 @@
<ClInclude Include="src\management\news_item.h" />
<ClInclude Include="src\management\research.h" />
<ClInclude Include="src\network\http.h" />
<ClInclude Include="src\network\NetworkAction.h" />
<ClInclude Include="src\network\NetworkAddress.h" />
<ClInclude Include="src\network\NetworkConnection.h" />
<ClInclude Include="src\network\NetworkGroup.h" />
<ClInclude Include="src\network\NetworkPacket.h" />
<ClInclude Include="src\network\NetworkTypes.h" />
<ClInclude Include="src\network\NetworkUser.h" />

View File

@@ -0,0 +1,220 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include <algorithm>
#include "NetworkAction.h"
extern "C"
{
#include "../game.h"
#include "../localisation/string_ids.h"
}
int NetworkActions::FindCommand(int command)
{
auto it = std::find_if(Actions.begin(), Actions.end(), [&command](NetworkAction const &action)
{
for (auto it = action.commands.begin(); it != action.commands.end(); it++)
{
if ((*it) == command)
{
return true;
}
}
return false;
});
if (it != Actions.end())
{
return it - Actions.begin();
}
return -1;
}
int NetworkActions::FindCommandByPermissionName(const std::string &permission_name)
{
auto it = std::find_if(Actions.begin(), Actions.end(), [&permission_name](NetworkAction const &action)
{
if (action.permission_name == permission_name)
{
return true;
}
return false;
});
if (it != Actions.end())
{
return it - Actions.begin();
}
return -1;
}
const std::vector<NetworkAction> NetworkActions::Actions =
{
{
STR_ACTION_CHAT, "PERMISSION_CHAT",
{
-1
}
}, {
STR_ACTION_TERRAFORM, "PERMISSION_TERRAFORM",
{
GAME_COMMAND_SET_LAND_HEIGHT,
GAME_COMMAND_RAISE_LAND,
GAME_COMMAND_LOWER_LAND,
GAME_COMMAND_EDIT_LAND_SMOOTH,
GAME_COMMAND_CHANGE_SURFACE_STYLE
}
}, {
STR_ACTION_SET_WATER_LEVEL, "PERMISSION_SET_WATER_LEVEL",
{
GAME_COMMAND_SET_WATER_HEIGHT,
GAME_COMMAND_RAISE_WATER,
GAME_COMMAND_LOWER_WATER
}
}, {
STR_ACTION_TOGGLE_PAUSE, "PERMISSION_TOGGLE_PAUSE",
{
GAME_COMMAND_TOGGLE_PAUSE
}
}, {
STR_ACTION_CREATE_RIDE, "PERMISSION_CREATE_RIDE",
{
GAME_COMMAND_CREATE_RIDE
}
}, {
STR_ACTION_REMOVE_RIDE, "PERMISSION_REMOVE_RIDE",
{
GAME_COMMAND_DEMOLISH_RIDE
}
}, {
STR_ACTION_BUILD_RIDE, "PERMISSION_BUILD_RIDE",
{
GAME_COMMAND_PLACE_TRACK,
GAME_COMMAND_REMOVE_TRACK,
GAME_COMMAND_SET_MAZE_TRACK,
GAME_COMMAND_PLACE_TRACK_DESIGN,
GAME_COMMAND_PLACE_MAZE_DESIGN,
GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT,
GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT
}
}, {
STR_ACTION_RIDE_PROPERTIES, "PERMISSION_RIDE_PROPERTIES",
{
GAME_COMMAND_SET_RIDE_NAME,
GAME_COMMAND_SET_RIDE_APPEARANCE,
GAME_COMMAND_SET_RIDE_STATUS,
GAME_COMMAND_SET_RIDE_VEHICLES,
GAME_COMMAND_SET_RIDE_SETTING,
GAME_COMMAND_SET_RIDE_PRICE,
GAME_COMMAND_SET_BRAKES_SPEED
}
}, {
STR_ACTION_SCENERY, "PERMISSION_SCENERY",
{
GAME_COMMAND_REMOVE_SCENERY,
GAME_COMMAND_PLACE_SCENERY,
GAME_COMMAND_SET_BRAKES_SPEED,
GAME_COMMAND_REMOVE_FENCE,
GAME_COMMAND_PLACE_FENCE,
GAME_COMMAND_REMOVE_LARGE_SCENERY,
GAME_COMMAND_PLACE_LARGE_SCENERY,
GAME_COMMAND_PLACE_BANNER,
GAME_COMMAND_REMOVE_BANNER,
GAME_COMMAND_SET_SCENERY_COLOUR,
GAME_COMMAND_SET_FENCE_COLOUR,
GAME_COMMAND_SET_LARGE_SCENERY_COLOUR,
GAME_COMMAND_SET_BANNER_COLOUR,
GAME_COMMAND_SET_BANNER_NAME,
GAME_COMMAND_SET_SIGN_NAME,
GAME_COMMAND_SET_BANNER_STYLE,
GAME_COMMAND_SET_SIGN_STYLE
}
}, {
STR_ACTION_PATH, "PERMISSION_PATH",
{
GAME_COMMAND_PLACE_PATH,
GAME_COMMAND_PLACE_PATH_FROM_TRACK,
GAME_COMMAND_REMOVE_PATH
}
}, {
STR_ACTION_CLEAR_LANDSCAPE, "PERMISSION_CLEAR_LANDSCAPE",
{
GAME_COMMAND_CLEAR_SCENERY
}
}, {
STR_ACTION_GUEST, "PERMISSION_GUEST",
{
GAME_COMMAND_SET_GUEST_NAME
}
}, {
STR_ACTION_STAFF, "PERMISSION_STAFF",
{
GAME_COMMAND_HIRE_NEW_STAFF_MEMBER,
GAME_COMMAND_SET_STAFF_PATROL,
GAME_COMMAND_FIRE_STAFF_MEMBER,
GAME_COMMAND_SET_STAFF_ORDER,
GAME_COMMAND_SET_STAFF_COLOUR,
GAME_COMMAND_SET_STAFF_NAME
}
}, {
STR_ACTION_PARK_PROPERTIES, "PERMISSION_PARK_PROPERTIES",
{
GAME_COMMAND_SET_PARK_NAME,
GAME_COMMAND_SET_PARK_OPEN,
GAME_COMMAND_SET_PARK_ENTRANCE_FEE,
GAME_COMMAND_SET_LAND_OWNERSHIP,
GAME_COMMAND_BUY_LAND_RIGHTS,
GAME_COMMAND_PLACE_PARK_ENTRANCE,
GAME_COMMAND_REMOVE_PARK_ENTRANCE
}
}, {
STR_ACTION_PARK_FUNDING, "PERMISSION_PARK_FUNDING",
{
GAME_COMMAND_SET_CURRENT_LOAN,
GAME_COMMAND_SET_RESEARCH_FUNDING,
GAME_COMMAND_START_MARKETING_CAMPAIGN
}
}, {
STR_ACTION_KICK_PLAYER, "PERMISSION_KICK_PLAYER",
{
GAME_COMMAND_KICK_PLAYER
}
}, {
STR_ACTION_MODIFY_GROUPS, "PERMISSION_MODIFY_GROUPS",
{
GAME_COMMAND_MODIFY_GROUPS
}
}, {
STR_ACTION_SET_PLAYER_GROUP, "PERMISSION_SET_PLAYER_GROUP",
{
GAME_COMMAND_SET_PLAYER_GROUP
}
}, {
STR_ACTION_CHEAT, "PERMISSION_CHEAT",
{
GAME_COMMAND_CHEAT
}
}, {
STR_ACTION_TOGGLE_SCENERY_CLUSTER, "PERMISSION_TOGGLE_SCENERY_CLUSTER",
{
-2
}
}, {
STR_ACTION_PASSWORDLESS_LOGIN, "PERMISSION_PASSWORDLESS_LOGIN",
{
-3
}
},
};

View File

@@ -0,0 +1,37 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#include <vector>
#include "../common.h"
class NetworkAction
{
public:
rct_string_id name;
std::string permission_name;
std::vector<int> commands;
};
class NetworkActions
{
public:
static const std::vector<NetworkAction> Actions;
static int FindCommand(int command);
static int FindCommandByPermissionName(const std::string &permission_name);
};

View File

@@ -0,0 +1,138 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include "NetworkTypes.h"
#include "NetworkAction.h"
#include "NetworkGroup.h"
#include "../core/Exception.hpp"
NetworkGroup::NetworkGroup()
{
actions_allowed = { 0 };
}
NetworkGroup::~NetworkGroup()
{
}
NetworkGroup NetworkGroup::FromJson(const json_t * json)
{
NetworkGroup group;
json_t * jsonId = json_object_get(json, "id");
json_t * jsonName = json_object_get(json, "name");
json_t * jsonPermissions = json_object_get(json, "permissions");
if (jsonId == nullptr || jsonName == nullptr || jsonPermissions == nullptr)
{
throw Exception("Missing group data");
}
group.id = (uint8)json_integer_value(jsonId);
group.name = std::string(json_string_value(jsonName));
for (size_t i = 0; i < group.actions_allowed.size(); i++) {
group.actions_allowed[i] = 0;
}
for (size_t i = 0; i < json_array_size(jsonPermissions); i++) {
json_t * jsonPermissionValue = json_array_get(jsonPermissions, i);
const char * perm_name = json_string_value(jsonPermissionValue);
if (perm_name == nullptr) {
continue;
}
int action_id = NetworkActions::FindCommandByPermissionName(perm_name);
if (action_id != -1) {
group.ToggleActionPermission(action_id);
}
}
return group;
}
json_t * NetworkGroup::ToJson() const
{
json_t * jsonGroup = json_object();
json_object_set_new(jsonGroup, "id", json_integer(id));
json_object_set_new(jsonGroup, "name", json_string(GetName().c_str()));
json_t * actionsArray = json_array();
for (size_t i = 0; i < NetworkActions::Actions.size(); i++)
{
if (CanPerformAction(i))
{
const char * perm_name = NetworkActions::Actions[i].permission_name.c_str();
json_array_append_new(actionsArray, json_string(perm_name));
}
}
json_object_set_new(jsonGroup, "permissions", actionsArray);
return jsonGroup;
}
const std::string & NetworkGroup::GetName() const
{
return name;
}
void NetworkGroup::SetName(std::string name)
{
NetworkGroup::name = name;
}
void NetworkGroup::Read(NetworkPacket &packet)
{
packet >> id;
SetName(packet.ReadString());
for (size_t i = 0; i < actions_allowed.size(); i++)
{
packet >> actions_allowed[i];
}
}
void NetworkGroup::Write(NetworkPacket &packet)
{
packet << id;
packet.WriteString(GetName().c_str());
for (size_t i = 0; i < actions_allowed.size(); i++)
{
packet << actions_allowed[i];
}
}
void NetworkGroup::ToggleActionPermission(size_t index)
{
size_t byte = index / 8;
size_t bit = index % 8;
if (byte >= actions_allowed.size())
{
return;
}
actions_allowed[byte] ^= (1 << bit);
}
bool NetworkGroup::CanPerformAction(size_t index) const
{
size_t byte = index / 8;
size_t bit = index % 8;
if (byte >= actions_allowed.size())
{
return false;
}
return (actions_allowed[byte] & (1 << bit)) ? true : false;
}
bool NetworkGroup::CanPerformCommand(int command) const
{
int action = NetworkActions::FindCommand(command);
if (action != -1)
{
return CanPerformAction(action);
}
return false;
}

View File

@@ -0,0 +1,48 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#include <array>
#include <jansson.h>
#include "NetworkPacket.h"
#include "../common.h"
class NetworkGroup
{
public:
std::array<uint8, 8> actions_allowed;
uint8 id = 0;
static NetworkGroup FromJson(const json_t * json);
NetworkGroup();
~NetworkGroup();
const std::string & GetName() const;
void SetName(std::string name);
void Read(NetworkPacket &packet);
void Write(NetworkPacket &packet);
void ToggleActionPermission(size_t index);
bool CanPerformAction(size_t index) const;
bool CanPerformCommand(int command) const;
json_t * ToJson() const;
private:
std::string name;
};

View File

@@ -18,6 +18,7 @@
#include <memory>
#include <vector>
#include "NetworkTypes.h"
#include "../common.h"
class NetworkPacket

View File

@@ -54,13 +54,14 @@ extern "C" {
#include "../util/util.h"
#include "../cheats.h"
#include "NetworkAction.h"
#include <openssl/evp.h> // just for OpenSSL_add_all_algorithms()
}
#pragma comment(lib, "Ws2_32.lib")
Network gNetwork;
NetworkActions gNetworkActions;
enum {
ADVERTISE_STATUS_DISABLED,
@@ -116,147 +117,6 @@ void NetworkPlayer::AddMoneySpent(money32 cost)
window_invalidate_by_number(WC_PLAYER, id);
}
int NetworkActions::FindCommand(int command)
{
auto it = std::find_if(actions.begin(), actions.end(), [&command](NetworkAction const& action) {
for (auto it = action.commands.begin(); it != action.commands.end(); it++) {
if ((*it) == command) {
return true;
}
}
return false;
});
if (it != actions.end()) {
return it - actions.begin();
}
return -1;
}
int NetworkActions::FindCommandByPermissionName(const std::string &permission_name)
{
auto it = std::find_if(actions.begin(), actions.end(), [&permission_name](NetworkAction const& action) {
if (action.permission_name == permission_name) {
return true;
}
return false;
});
if (it != actions.end()) {
return it - actions.begin();
}
return -1;
}
NetworkGroup::NetworkGroup()
{
actions_allowed = {0};
}
NetworkGroup::~NetworkGroup()
{
}
void NetworkGroup::Read(NetworkPacket& packet)
{
packet >> id;
SetName(packet.ReadString());
for (size_t i = 0; i < actions_allowed.size(); i++) {
packet >> actions_allowed[i];
}
}
void NetworkGroup::Write(NetworkPacket& packet)
{
packet << id;
packet.WriteString(GetName().c_str());
for (size_t i = 0; i < actions_allowed.size(); i++) {
packet << actions_allowed[i];
}
}
json_t * NetworkGroup::ToJson() const
{
json_t * jsonGroup = json_object();
json_object_set_new(jsonGroup, "id", json_integer(id));
json_object_set_new(jsonGroup, "name", json_string(GetName().c_str()));
json_t * actionsArray = json_array();
for (size_t i = 0; i < gNetworkActions.actions.size(); i++) {
if (CanPerformAction(i)) {
const char * perm_name = gNetworkActions.actions[i].permission_name.c_str();
json_array_append_new(actionsArray, json_string(perm_name));
}
}
json_object_set_new(jsonGroup, "permissions", actionsArray);
return jsonGroup;
}
NetworkGroup NetworkGroup::FromJson(const json_t * json)
{
NetworkGroup group;
json_t * jsonId = json_object_get(json, "id");
json_t * jsonName = json_object_get(json, "name");
json_t * jsonPermissions = json_object_get(json, "permissions");
if (jsonId == nullptr || jsonName == nullptr || jsonPermissions == nullptr) {
throw Exception("Missing group data");
}
group.id = (uint8)json_integer_value(jsonId);
group.name = std::string(json_string_value(jsonName));
for (size_t i = 0; i < group.actions_allowed.size(); i++) {
group.actions_allowed[i] = 0;
}
for (size_t i = 0; i < json_array_size(jsonPermissions); i++) {
json_t * jsonPermissionValue = json_array_get(jsonPermissions, i);
const char * perm_name = json_string_value(jsonPermissionValue);
if (perm_name == nullptr) {
continue;
}
int action_id = gNetworkActions.FindCommandByPermissionName(perm_name);
if (action_id != -1) {
group.ToggleActionPermission(action_id);
}
}
return group;
}
void NetworkGroup::ToggleActionPermission(size_t index)
{
size_t byte = index / 8;
size_t bit = index % 8;
if (byte >= actions_allowed.size()) {
return;
}
actions_allowed[byte] ^= (1 << bit);
}
bool NetworkGroup::CanPerformAction(size_t index) const
{
size_t byte = index / 8;
size_t bit = index % 8;
if (byte >= actions_allowed.size()) {
return false;
}
return (actions_allowed[byte] & (1 << bit)) ? true : false;
}
bool NetworkGroup::CanPerformCommand(int command) const
{
int action = gNetworkActions.FindCommand(command);
if (action != -1) {
return CanPerformAction(action);
}
return false;
}
const std::string& NetworkGroup::GetName() const
{
return name;
}
void NetworkGroup::SetName(std::string name)
{
NetworkGroup::name = name;
}
Network::Network()
{
wsa_initialized = false;
@@ -1413,7 +1273,7 @@ void Network::ProcessGameCommandQueue()
if (cost != MONEY32_UNDEFINED) {
NetworkPlayer* player = GetPlayerByID(gc.playerid);
if (player) {
player->last_action = gNetworkActions.FindCommand(command);
player->last_action = NetworkActions::FindCommand(command);
player->last_action_time = SDL_GetTicks();
player->AddMoneySpent(cost);
}
@@ -1695,7 +1555,7 @@ void Network::Server_Handle_AUTH(NetworkConnection& connection, NetworkPacket& p
bool passwordless = false;
if (connection.authstatus == NETWORK_AUTH_VERIFIED) {
const NetworkGroup * group = GetGroupByID(GetGroupIDByHash(connection.key.PublicKeyHash()));
size_t actionIndex = gNetworkActions.FindCommandByPermissionName("PERMISSION_PASSWORDLESS_LOGIN");
size_t actionIndex = NetworkActions::FindCommandByPermissionName("PERMISSION_PASSWORDLESS_LOGIN");
passwordless = group->CanPerformAction(actionIndex);
}
if (!gameversion || strcmp(gameversion, NETWORK_STREAM_ID) != 0) {
@@ -1878,7 +1738,7 @@ void Network::Server_Handle_GAMECMD(NetworkConnection& connection, NetworkPacket
return;
}
connection.player->last_action = gNetworkActions.FindCommand(commandCommand);
connection.player->last_action = NetworkActions::FindCommand(commandCommand);
connection.player->last_action_time = SDL_GetTicks();
connection.player->AddMoneySpent(cost);
Server_Send_GAMECMD(args[0], args[1], args[2], args[3], args[4], args[5], args[6], playerid, callback);
@@ -2122,7 +1982,7 @@ int network_get_player_last_action(unsigned int index, int time)
void network_set_player_last_action(unsigned int index, int command)
{
gNetwork.player_list[index]->last_action = gNetworkActions.FindCommand(command);
gNetwork.player_list[index]->last_action = NetworkActions::FindCommand(command);
gNetwork.player_list[index]->last_action_time = SDL_GetTicks();
}
@@ -2392,12 +2252,12 @@ uint8 network_get_default_group()
int network_get_num_actions()
{
return gNetworkActions.actions.size();
return NetworkActions::Actions.size();
}
rct_string_id network_get_action_name_string_id(unsigned int index)
{
return gNetworkActions.actions[index].name;
return NetworkActions::Actions[index].name;
}
int network_can_perform_action(unsigned int groupindex, unsigned int index)

View File

@@ -78,6 +78,7 @@ extern "C" {
#include "../core/Nullable.hpp"
#include "NetworkAddress.h"
#include "NetworkConnection.h"
#include "NetworkGroup.h"
#include "NetworkKey.h"
#include "NetworkPacket.h"
#include "NetworkUser.h"
@@ -103,99 +104,6 @@ public:
std::string keyhash;
};
class NetworkAction
{
public:
rct_string_id name;
std::string permission_name;
std::vector<int> commands;
};
class NetworkActions
{
public:
int FindCommand(int command);
int FindCommandByPermissionName(const std::string &permission_name);
const std::vector<NetworkAction> actions = {
{STR_ACTION_CHAT, "PERMISSION_CHAT",
{-1}},
{STR_ACTION_TERRAFORM, "PERMISSION_TERRAFORM",
{GAME_COMMAND_SET_LAND_HEIGHT, GAME_COMMAND_RAISE_LAND, GAME_COMMAND_LOWER_LAND,
GAME_COMMAND_EDIT_LAND_SMOOTH, GAME_COMMAND_CHANGE_SURFACE_STYLE}},
{STR_ACTION_SET_WATER_LEVEL, "PERMISSION_SET_WATER_LEVEL",
{GAME_COMMAND_SET_WATER_HEIGHT, GAME_COMMAND_RAISE_WATER, GAME_COMMAND_LOWER_WATER}},
{STR_ACTION_TOGGLE_PAUSE, "PERMISSION_TOGGLE_PAUSE",
{GAME_COMMAND_TOGGLE_PAUSE}},
{STR_ACTION_CREATE_RIDE, "PERMISSION_CREATE_RIDE",
{GAME_COMMAND_CREATE_RIDE}},
{STR_ACTION_REMOVE_RIDE, "PERMISSION_REMOVE_RIDE",
{GAME_COMMAND_DEMOLISH_RIDE}},
{STR_ACTION_BUILD_RIDE, "PERMISSION_BUILD_RIDE",
{GAME_COMMAND_PLACE_TRACK, GAME_COMMAND_REMOVE_TRACK, GAME_COMMAND_SET_MAZE_TRACK,
GAME_COMMAND_PLACE_TRACK_DESIGN, GAME_COMMAND_PLACE_MAZE_DESIGN, GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT,
GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT}},
{STR_ACTION_RIDE_PROPERTIES, "PERMISSION_RIDE_PROPERTIES",
{GAME_COMMAND_SET_RIDE_NAME, GAME_COMMAND_SET_RIDE_APPEARANCE, GAME_COMMAND_SET_RIDE_STATUS,
GAME_COMMAND_SET_RIDE_VEHICLES, GAME_COMMAND_SET_RIDE_SETTING, GAME_COMMAND_SET_RIDE_PRICE,
GAME_COMMAND_SET_BRAKES_SPEED}},
{STR_ACTION_SCENERY, "PERMISSION_SCENERY",
{GAME_COMMAND_REMOVE_SCENERY, GAME_COMMAND_PLACE_SCENERY, GAME_COMMAND_SET_BRAKES_SPEED,
GAME_COMMAND_REMOVE_FENCE, GAME_COMMAND_PLACE_FENCE, GAME_COMMAND_REMOVE_LARGE_SCENERY,
GAME_COMMAND_PLACE_LARGE_SCENERY, GAME_COMMAND_PLACE_BANNER, GAME_COMMAND_REMOVE_BANNER,
GAME_COMMAND_SET_SCENERY_COLOUR, GAME_COMMAND_SET_FENCE_COLOUR, GAME_COMMAND_SET_LARGE_SCENERY_COLOUR,
GAME_COMMAND_SET_BANNER_COLOUR, GAME_COMMAND_SET_BANNER_NAME, GAME_COMMAND_SET_SIGN_NAME,
GAME_COMMAND_SET_BANNER_STYLE, GAME_COMMAND_SET_SIGN_STYLE}},
{STR_ACTION_PATH, "PERMISSION_PATH",
{GAME_COMMAND_PLACE_PATH, GAME_COMMAND_PLACE_PATH_FROM_TRACK, GAME_COMMAND_REMOVE_PATH}},
{STR_ACTION_CLEAR_LANDSCAPE, "PERMISSION_CLEAR_LANDSCAPE",
{GAME_COMMAND_CLEAR_SCENERY}},
{STR_ACTION_GUEST, "PERMISSION_GUEST",
{GAME_COMMAND_SET_GUEST_NAME}},
{STR_ACTION_STAFF, "PERMISSION_STAFF",
{GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, GAME_COMMAND_SET_STAFF_PATROL, GAME_COMMAND_FIRE_STAFF_MEMBER,
GAME_COMMAND_SET_STAFF_ORDER, GAME_COMMAND_SET_STAFF_COLOUR, GAME_COMMAND_SET_STAFF_NAME}},
{STR_ACTION_PARK_PROPERTIES, "PERMISSION_PARK_PROPERTIES",
{GAME_COMMAND_SET_PARK_NAME, GAME_COMMAND_SET_PARK_OPEN, GAME_COMMAND_SET_PARK_ENTRANCE_FEE,
GAME_COMMAND_SET_LAND_OWNERSHIP, GAME_COMMAND_BUY_LAND_RIGHTS, GAME_COMMAND_PLACE_PARK_ENTRANCE,
GAME_COMMAND_REMOVE_PARK_ENTRANCE}},
{STR_ACTION_PARK_FUNDING, "PERMISSION_PARK_FUNDING",
{GAME_COMMAND_SET_CURRENT_LOAN, GAME_COMMAND_SET_RESEARCH_FUNDING, GAME_COMMAND_START_MARKETING_CAMPAIGN}},
{STR_ACTION_KICK_PLAYER, "PERMISSION_KICK_PLAYER",
{GAME_COMMAND_KICK_PLAYER}},
{STR_ACTION_MODIFY_GROUPS, "PERMISSION_MODIFY_GROUPS",
{GAME_COMMAND_MODIFY_GROUPS}},
{STR_ACTION_SET_PLAYER_GROUP, "PERMISSION_SET_PLAYER_GROUP",
{GAME_COMMAND_SET_PLAYER_GROUP}},
{STR_ACTION_CHEAT, "PERMISSION_CHEAT",
{GAME_COMMAND_CHEAT}},
{STR_ACTION_TOGGLE_SCENERY_CLUSTER, "PERMISSION_TOGGLE_SCENERY_CLUSTER",
{-2}},
{STR_ACTION_PASSWORDLESS_LOGIN, "PERMISSION_PASSWORDLESS_LOGIN",
{-3}},
};
};
class NetworkGroup
{
public:
NetworkGroup();
~NetworkGroup();
void Read(NetworkPacket& packet);
void Write(NetworkPacket& packet);
json_t * ToJson() const;
static NetworkGroup FromJson(const json_t * json);
void ToggleActionPermission(size_t index);
bool CanPerformAction(size_t index) const;
bool CanPerformCommand(int command) const;
const std::string& GetName() const;
void SetName(std::string name);
std::array<uint8, 8> actions_allowed;
uint8 id = 0;
private:
std::string name;
};
class Network
{
public: