mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
Merge pull request #9244 from duncanspumpkin/modify_kick_ga
Implement Modify Group and Kick Player Actions.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <openrct2-ui/interface/Widget.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/Game.h>
|
||||
#include <openrct2/actions/NetworkModifyGroupAction.hpp>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/drawing/Drawing.h>
|
||||
#include <openrct2/localisation/Localisation.h>
|
||||
@@ -741,11 +742,17 @@ static void window_multiplayer_groups_mouseup(rct_window* w, rct_widgetindex wid
|
||||
}
|
||||
break;
|
||||
case WIDX_ADD_GROUP:
|
||||
game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, 0, GAME_COMMAND_MODIFY_GROUPS, 0, 0);
|
||||
break;
|
||||
{
|
||||
auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::AddGroup);
|
||||
GameActions::Execute(&networkModifyGroup);
|
||||
}
|
||||
break;
|
||||
case WIDX_REMOVE_GROUP:
|
||||
game_do_command(1 | (_selectedGroup << 8), GAME_COMMAND_FLAG_APPLY, 0, 0, GAME_COMMAND_MODIFY_GROUPS, 0, 0);
|
||||
break;
|
||||
{
|
||||
auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::RemoveGroup, _selectedGroup);
|
||||
GameActions::Execute(&networkModifyGroup);
|
||||
}
|
||||
break;
|
||||
case WIDX_RENAME_GROUP:;
|
||||
int32_t groupIndex = network_get_group_index(_selectedGroup);
|
||||
const utf8* groupName = network_get_group_name(groupIndex);
|
||||
@@ -788,10 +795,12 @@ static void window_multiplayer_groups_dropdown(rct_window* w, rct_widgetindex wi
|
||||
switch (widgetIndex)
|
||||
{
|
||||
case WIDX_DEFAULT_GROUP_DROPDOWN:
|
||||
game_do_command(
|
||||
4 | (network_get_group_id(dropdownIndex) << 8), GAME_COMMAND_FLAG_APPLY, 0, 0, GAME_COMMAND_MODIFY_GROUPS, 0,
|
||||
0);
|
||||
break;
|
||||
{
|
||||
auto networkModifyGroup = NetworkModifyGroupAction(
|
||||
ModifyGroupType::SetDefault, network_get_group_id(dropdownIndex));
|
||||
GameActions::Execute(&networkModifyGroup);
|
||||
}
|
||||
break;
|
||||
case WIDX_SELECTED_GROUP_DROPDOWN:
|
||||
_selectedGroup = network_get_group_id(dropdownIndex);
|
||||
break;
|
||||
@@ -838,7 +847,9 @@ static void window_multiplayer_groups_scrollmousedown(rct_window* w, int32_t scr
|
||||
w->selected_list_item = index;
|
||||
window_invalidate(w);
|
||||
|
||||
game_do_command(2 | (_selectedGroup << 8), GAME_COMMAND_FLAG_APPLY, index, 0, GAME_COMMAND_MODIFY_GROUPS, 0, 0);
|
||||
auto networkModifyGroup = NetworkModifyGroupAction(
|
||||
ModifyGroupType::SetPermissions, _selectedGroup, "", index, PermissionState::Toggle);
|
||||
GameActions::Execute(&networkModifyGroup);
|
||||
}
|
||||
|
||||
static void window_multiplayer_groups_scrollmouseover(rct_window* w, int32_t scrollIndex, int32_t x, int32_t y)
|
||||
@@ -861,15 +872,8 @@ static void window_multiplayer_groups_text_input(rct_window* w, rct_widgetindex
|
||||
if (text == nullptr)
|
||||
return;
|
||||
|
||||
game_do_command(
|
||||
3 | (_selectedGroup << 8) | (1 << 16), GAME_COMMAND_FLAG_APPLY, w->number, *((int32_t*)(text + 0)),
|
||||
GAME_COMMAND_MODIFY_GROUPS, *((int32_t*)(text + 8)), *((int32_t*)(text + 4)));
|
||||
game_do_command(
|
||||
3 | (_selectedGroup << 8) | (2 << 16), GAME_COMMAND_FLAG_APPLY, w->number, *((int32_t*)(text + 12)),
|
||||
GAME_COMMAND_MODIFY_GROUPS, *((int32_t*)(text + 20)), *((int32_t*)(text + 16)));
|
||||
game_do_command(
|
||||
3 | (_selectedGroup << 8) | (0 << 16), GAME_COMMAND_FLAG_APPLY, w->number, *((int32_t*)(text + 24)),
|
||||
GAME_COMMAND_MODIFY_GROUPS, *((int32_t*)(text + 32)), *((int32_t*)(text + 28)));
|
||||
auto networkModifyGroup = NetworkModifyGroupAction(ModifyGroupType::SetName, _selectedGroup, text);
|
||||
GameActions::Execute(&networkModifyGroup);
|
||||
}
|
||||
|
||||
static void window_multiplayer_groups_invalidate(rct_window* w)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/Game.h>
|
||||
#include <openrct2/Input.h>
|
||||
#include <openrct2/actions/PlayerKickAction.hpp>
|
||||
#include <openrct2/actions/PlayerSetGroupAction.hpp>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/drawing/Drawing.h>
|
||||
@@ -284,8 +285,11 @@ void window_player_overview_mouse_up(rct_window* w, rct_widgetindex widgetIndex)
|
||||
}
|
||||
break;
|
||||
case WIDX_KICK:
|
||||
game_do_command(w->number, GAME_COMMAND_FLAG_APPLY, 0, 0, GAME_COMMAND_KICK_PLAYER, 0, 0);
|
||||
break;
|
||||
{
|
||||
auto kickPlayerAction = PlayerKickAction(w->number);
|
||||
GameActions::Execute(&kickPlayerAction);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1219,8 +1219,8 @@ GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = {
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
game_command_modify_groups,
|
||||
game_command_kick_player,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
game_command_pickup_guest,
|
||||
game_command_pickup_staff,
|
||||
|
||||
@@ -82,9 +82,9 @@ enum GAME_COMMAND
|
||||
GAME_COMMAND_SET_BANNER_STYLE, // GA
|
||||
GAME_COMMAND_SET_SIGN_STYLE, // GA
|
||||
GAME_COMMAND_SET_PLAYER_GROUP, // GA
|
||||
GAME_COMMAND_MODIFY_GROUPS,
|
||||
GAME_COMMAND_KICK_PLAYER,
|
||||
GAME_COMMAND_CHEAT,
|
||||
GAME_COMMAND_MODIFY_GROUPS, // GA
|
||||
GAME_COMMAND_KICK_PLAYER, // GA
|
||||
GAME_COMMAND_CHEAT, // GA
|
||||
GAME_COMMAND_PICKUP_GUEST,
|
||||
GAME_COMMAND_PICKUP_STAFF,
|
||||
GAME_COMMAND_BALLOON_PRESS, // GA
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "LargeScenerySetColourAction.hpp"
|
||||
#include "LoadOrQuitAction.hpp"
|
||||
#include "MazeSetTrackAction.hpp"
|
||||
#include "NetworkModifyGroupAction.hpp"
|
||||
#include "ParkEntranceRemoveAction.hpp"
|
||||
#include "ParkMarketingAction.hpp"
|
||||
#include "ParkSetDateAction.hpp"
|
||||
@@ -44,6 +45,7 @@
|
||||
#include "PauseToggleAction.hpp"
|
||||
#include "PlaceParkEntranceAction.hpp"
|
||||
#include "PlacePeepSpawnAction.hpp"
|
||||
#include "PlayerKickAction.hpp"
|
||||
#include "PlayerSetGroupAction.hpp"
|
||||
#include "RideCreateAction.hpp"
|
||||
#include "RideDemolishAction.hpp"
|
||||
@@ -99,6 +101,7 @@ namespace GameActions
|
||||
Register<FootpathSceneryRemoveAction>();
|
||||
Register<GuestSetNameAction>();
|
||||
Register<MazeSetTrackAction>();
|
||||
Register<NetworkModifyGroupAction>();
|
||||
Register<ParkMarketingAction>();
|
||||
Register<ParkEntranceRemoveAction>();
|
||||
Register<ParkSetLoanAction>();
|
||||
@@ -107,6 +110,7 @@ namespace GameActions
|
||||
Register<ParkSetResearchFundingAction>();
|
||||
Register<PlaceParkEntranceAction>();
|
||||
Register<PlacePeepSpawnAction>();
|
||||
Register<PlayerKickAction>();
|
||||
Register<PlayerSetGroupAction>();
|
||||
Register<RideCreateAction>();
|
||||
Register<RideDemolishAction>();
|
||||
|
||||
81
src/openrct2/actions/NetworkModifyGroupAction.hpp
Normal file
81
src/openrct2/actions/NetworkModifyGroupAction.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../network/network.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
enum class ModifyGroupType : uint8_t
|
||||
{
|
||||
AddGroup,
|
||||
RemoveGroup,
|
||||
SetPermissions,
|
||||
SetName,
|
||||
SetDefault,
|
||||
Count
|
||||
};
|
||||
|
||||
enum class PermissionState : uint8_t
|
||||
{
|
||||
Toggle,
|
||||
SetAll,
|
||||
ClearAll,
|
||||
Count
|
||||
};
|
||||
|
||||
DEFINE_GAME_ACTION(NetworkModifyGroupAction, GAME_COMMAND_MODIFY_GROUPS, GameActionResult)
|
||||
{
|
||||
private:
|
||||
uint8_t _type{ static_cast<uint8_t>(ModifyGroupType::Count) };
|
||||
uint8_t _groupId{ std::numeric_limits<uint8_t>::max() };
|
||||
std::string _name;
|
||||
uint32_t _permissionIndex{ std::numeric_limits<uint32_t>::max() };
|
||||
uint8_t _permissionState{ static_cast<uint8_t>(PermissionState::Count) };
|
||||
|
||||
public:
|
||||
NetworkModifyGroupAction() = default;
|
||||
|
||||
NetworkModifyGroupAction(
|
||||
ModifyGroupType type, uint8_t groupId = std::numeric_limits<uint8_t>::max(), const std::string name = "",
|
||||
uint32_t permissionIndex = 0, PermissionState permissionState = PermissionState::Count)
|
||||
: _type(static_cast<uint8_t>(type))
|
||||
, _groupId(groupId)
|
||||
, _name(name)
|
||||
, _permissionIndex(permissionIndex)
|
||||
, _permissionState(static_cast<uint8_t>(permissionState))
|
||||
{
|
||||
}
|
||||
|
||||
uint16_t GetActionFlags() const override
|
||||
{
|
||||
return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED;
|
||||
}
|
||||
|
||||
void Serialise(DataSerialiser & stream) override
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_type) << DS_TAG(_groupId) << DS_TAG(_name) << DS_TAG(_permissionIndex) << DS_TAG(_permissionState);
|
||||
}
|
||||
|
||||
GameActionResult::Ptr Query() const override
|
||||
{
|
||||
return network_modify_groups(
|
||||
GetPlayer(), static_cast<ModifyGroupType>(_type), _groupId, _name, _permissionIndex,
|
||||
static_cast<PermissionState>(_permissionState), false);
|
||||
}
|
||||
|
||||
GameActionResult::Ptr Execute() const override
|
||||
{
|
||||
return network_modify_groups(
|
||||
GetPlayer(), static_cast<ModifyGroupType>(_type), _groupId, _name, _permissionIndex,
|
||||
static_cast<PermissionState>(_permissionState), true);
|
||||
}
|
||||
};
|
||||
48
src/openrct2/actions/PlayerKickAction.hpp
Normal file
48
src/openrct2/actions/PlayerKickAction.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../network/network.h"
|
||||
#include "GameAction.h"
|
||||
|
||||
DEFINE_GAME_ACTION(PlayerKickAction, GAME_COMMAND_KICK_PLAYER, GameActionResult)
|
||||
{
|
||||
private:
|
||||
NetworkPlayerId_t _playerId{ -1 };
|
||||
|
||||
public:
|
||||
PlayerKickAction() = default;
|
||||
|
||||
PlayerKickAction(NetworkPlayerId_t playerId)
|
||||
: _playerId(playerId)
|
||||
{
|
||||
}
|
||||
|
||||
uint16_t GetActionFlags() const override
|
||||
{
|
||||
return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED;
|
||||
}
|
||||
|
||||
void Serialise(DataSerialiser & stream) override
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
|
||||
stream << DS_TAG(_playerId);
|
||||
}
|
||||
GameActionResult::Ptr Query() const override
|
||||
{
|
||||
return network_kick_player(_playerId, false);
|
||||
}
|
||||
|
||||
GameActionResult::Ptr Execute() const override
|
||||
{
|
||||
return network_kick_player(_playerId, true);
|
||||
}
|
||||
};
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "../OpenRCT2.h"
|
||||
#include "../PlatformEnvironment.h"
|
||||
#include "../actions/LoadOrQuitAction.hpp"
|
||||
#include "../actions/NetworkModifyGroupAction.hpp"
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../platform/platform.h"
|
||||
#include "../ui/UiContext.h"
|
||||
@@ -32,7 +33,7 @@
|
||||
// This string specifies which version of network stream current build uses.
|
||||
// It is used for making sure only compatible builds get connected, even within
|
||||
// single OpenRCT2 version.
|
||||
#define NETWORK_STREAM_VERSION "29"
|
||||
#define NETWORK_STREAM_VERSION "30"
|
||||
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
|
||||
|
||||
static Peep* _pickup_peep = nullptr;
|
||||
@@ -3639,117 +3640,71 @@ GameActionResult::Ptr network_set_player_group(
|
||||
return std::make_unique<GameActionResult>();
|
||||
}
|
||||
|
||||
void game_command_modify_groups(
|
||||
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, [[maybe_unused]] int32_t* esi, int32_t* edi, int32_t* ebp)
|
||||
GameActionResult::Ptr network_modify_groups(
|
||||
NetworkPlayerId_t actionPlayerId, ModifyGroupType type, uint8_t groupId, const std::string& name, uint32_t permissionIndex,
|
||||
PermissionState permissionState, bool isExecuting)
|
||||
{
|
||||
uint8_t action = (uint8_t)*eax;
|
||||
uint8_t groupid = (uint8_t)(*eax >> 8);
|
||||
uint8_t nameChunkIndex = (uint8_t)(*eax >> 16);
|
||||
|
||||
switch (action)
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
{ // add group
|
||||
if (*ebx & GAME_COMMAND_FLAG_APPLY)
|
||||
case ModifyGroupType::AddGroup:
|
||||
{
|
||||
if (isExecuting)
|
||||
{
|
||||
NetworkGroup* newgroup = gNetwork.AddGroup();
|
||||
if (!newgroup)
|
||||
if (newgroup == nullptr)
|
||||
{
|
||||
gGameCommandErrorTitle = STR_CANT_DO_THIS;
|
||||
gGameCommandErrorText = STR_NONE;
|
||||
*ebx = MONEY32_UNDEFINED;
|
||||
return;
|
||||
}
|
||||
|
||||
// Log add player group event
|
||||
NetworkPlayer* game_command_player = gNetwork.GetPlayerByID(game_command_playerid);
|
||||
if (game_command_player)
|
||||
{
|
||||
char log_msg[256];
|
||||
const char* args[2] = {
|
||||
game_command_player->Name.c_str(),
|
||||
newgroup->GetName().c_str(),
|
||||
};
|
||||
format_string(log_msg, 256, STR_LOG_ADD_PLAYER_GROUP, args);
|
||||
network_append_server_log(log_msg);
|
||||
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_CANT_DO_THIS);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{ // remove group
|
||||
if (groupid == 0)
|
||||
case ModifyGroupType::RemoveGroup:
|
||||
{
|
||||
if (groupId == 0)
|
||||
{
|
||||
gGameCommandErrorTitle = STR_THIS_GROUP_CANNOT_BE_MODIFIED;
|
||||
gGameCommandErrorText = STR_NONE;
|
||||
*ebx = MONEY32_UNDEFINED;
|
||||
return;
|
||||
return std::make_unique<GameActionResult>(GA_ERROR::DISALLOWED, STR_THIS_GROUP_CANNOT_BE_MODIFIED);
|
||||
}
|
||||
for (auto it = gNetwork.player_list.begin(); it != gNetwork.player_list.end(); it++)
|
||||
for (const auto& it : gNetwork.player_list)
|
||||
{
|
||||
if ((*it)->Group == groupid)
|
||||
if ((it.get())->Group == groupId)
|
||||
{
|
||||
gGameCommandErrorTitle = STR_CANT_REMOVE_GROUP_THAT_PLAYERS_BELONG_TO;
|
||||
gGameCommandErrorText = STR_NONE;
|
||||
*ebx = MONEY32_UNDEFINED;
|
||||
return;
|
||||
return std::make_unique<GameActionResult>(
|
||||
GA_ERROR::DISALLOWED, STR_CANT_REMOVE_GROUP_THAT_PLAYERS_BELONG_TO);
|
||||
}
|
||||
}
|
||||
if (*ebx & GAME_COMMAND_FLAG_APPLY)
|
||||
if (isExecuting)
|
||||
{
|
||||
// Log remove player group event
|
||||
NetworkPlayer* game_command_player = gNetwork.GetPlayerByID(game_command_playerid);
|
||||
NetworkGroup* group = gNetwork.GetGroupByID(groupid);
|
||||
if (game_command_player && group)
|
||||
{
|
||||
char log_msg[256];
|
||||
const char* args[2] = {
|
||||
game_command_player->Name.c_str(),
|
||||
group->GetName().c_str(),
|
||||
};
|
||||
format_string(log_msg, 256, STR_LOG_REMOVE_PLAYER_GROUP, args);
|
||||
network_append_server_log(log_msg);
|
||||
}
|
||||
|
||||
gNetwork.RemoveGroup(groupid);
|
||||
gNetwork.RemoveGroup(groupId);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{ // set permissions
|
||||
int32_t index = *ecx;
|
||||
bool all = *edx & 1;
|
||||
bool allvalue = (*edx >> 1) & 1;
|
||||
if (groupid == 0)
|
||||
case ModifyGroupType::SetPermissions:
|
||||
{
|
||||
if (groupId == 0)
|
||||
{ // cant change admin group permissions
|
||||
gGameCommandErrorTitle = STR_THIS_GROUP_CANNOT_BE_MODIFIED;
|
||||
gGameCommandErrorText = STR_NONE;
|
||||
*ebx = MONEY32_UNDEFINED;
|
||||
return;
|
||||
return std::make_unique<GameActionResult>(GA_ERROR::DISALLOWED, STR_THIS_GROUP_CANNOT_BE_MODIFIED);
|
||||
}
|
||||
NetworkGroup* mygroup = nullptr;
|
||||
NetworkPlayer* player = gNetwork.GetPlayerByID(game_command_playerid);
|
||||
if (player && !all)
|
||||
NetworkPlayer* player = gNetwork.GetPlayerByID(actionPlayerId);
|
||||
if (player != nullptr && permissionState == PermissionState::Toggle)
|
||||
{
|
||||
mygroup = gNetwork.GetGroupByID(player->Group);
|
||||
if (!mygroup || !mygroup->CanPerformAction(index))
|
||||
if (mygroup == nullptr || !mygroup->CanPerformAction(permissionIndex))
|
||||
{
|
||||
gGameCommandErrorTitle = STR_CANT_MODIFY_PERMISSION_THAT_YOU_DO_NOT_HAVE_YOURSELF;
|
||||
gGameCommandErrorText = STR_NONE;
|
||||
*ebx = MONEY32_UNDEFINED;
|
||||
return;
|
||||
return std::make_unique<GameActionResult>(
|
||||
GA_ERROR::DISALLOWED, STR_CANT_MODIFY_PERMISSION_THAT_YOU_DO_NOT_HAVE_YOURSELF);
|
||||
}
|
||||
}
|
||||
if (*ebx & GAME_COMMAND_FLAG_APPLY)
|
||||
if (isExecuting)
|
||||
{
|
||||
NetworkGroup* group = gNetwork.GetGroupByID(groupid);
|
||||
if (group)
|
||||
NetworkGroup* group = gNetwork.GetGroupByID(groupId);
|
||||
if (group != nullptr)
|
||||
{
|
||||
if (all)
|
||||
if (permissionState != PermissionState::Toggle)
|
||||
{
|
||||
if (mygroup)
|
||||
if (mygroup != nullptr)
|
||||
{
|
||||
if (allvalue)
|
||||
if (permissionState == PermissionState::SetAll)
|
||||
{
|
||||
group->ActionsAllowed = mygroup->ActionsAllowed;
|
||||
}
|
||||
@@ -3761,155 +3716,87 @@ void game_command_modify_groups(
|
||||
}
|
||||
else
|
||||
{
|
||||
group->ToggleActionPermission(index);
|
||||
group->ToggleActionPermission(permissionIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Log edit player group permissions event
|
||||
char log_msg[256];
|
||||
const char* args[2] = {
|
||||
player->Name.c_str(),
|
||||
group->GetName().c_str(),
|
||||
};
|
||||
format_string(log_msg, 256, STR_LOG_EDIT_PLAYER_GROUP_PERMISSIONS, args);
|
||||
network_append_server_log(log_msg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{ // set group name
|
||||
NetworkGroup* group = gNetwork.GetGroupByID(groupid);
|
||||
case ModifyGroupType::SetName:
|
||||
{
|
||||
NetworkGroup* group = gNetwork.GetGroupByID(groupId);
|
||||
const char* oldName = group->GetName().c_str();
|
||||
static char newName[128];
|
||||
|
||||
size_t nameChunkOffset = nameChunkIndex - 1;
|
||||
if (nameChunkIndex == 0)
|
||||
nameChunkOffset = 2;
|
||||
nameChunkOffset *= 12;
|
||||
nameChunkOffset = (std::min)(nameChunkOffset, std::size(newName) - 12);
|
||||
std::memcpy((void*)((uintptr_t)newName + (uintptr_t)nameChunkOffset + 0), edx, sizeof(uint32_t));
|
||||
std::memcpy((void*)((uintptr_t)newName + (uintptr_t)nameChunkOffset + 4), ebp, sizeof(uint32_t));
|
||||
std::memcpy((void*)((uintptr_t)newName + (uintptr_t)nameChunkOffset + 8), edi, sizeof(uint32_t));
|
||||
|
||||
if (nameChunkIndex != 0)
|
||||
if (strcmp(oldName, name.c_str()) == 0)
|
||||
{
|
||||
*ebx = 0;
|
||||
return;
|
||||
return std::make_unique<GameActionResult>();
|
||||
}
|
||||
|
||||
if (strcmp(oldName, newName) == 0)
|
||||
if (name.empty())
|
||||
{
|
||||
*ebx = 0;
|
||||
return;
|
||||
return std::make_unique<GameActionResult>(
|
||||
GA_ERROR::INVALID_PARAMETERS, STR_CANT_RENAME_GROUP, STR_INVALID_GROUP_NAME);
|
||||
}
|
||||
|
||||
if (newName[0] == 0)
|
||||
if (isExecuting)
|
||||
{
|
||||
gGameCommandErrorTitle = STR_CANT_RENAME_GROUP;
|
||||
gGameCommandErrorText = STR_INVALID_GROUP_NAME;
|
||||
*ebx = MONEY32_UNDEFINED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (*ebx & GAME_COMMAND_FLAG_APPLY)
|
||||
{
|
||||
if (group)
|
||||
if (group != nullptr)
|
||||
{
|
||||
// Log edit player group name event
|
||||
NetworkPlayer* player = gNetwork.GetPlayerByID(game_command_playerid);
|
||||
char log_msg[256];
|
||||
const char* args[3] = {
|
||||
player->Name.c_str(),
|
||||
oldName,
|
||||
newName,
|
||||
};
|
||||
format_string(log_msg, 256, STR_LOG_EDIT_PLAYER_GROUP_NAME, args);
|
||||
network_append_server_log(log_msg);
|
||||
|
||||
group->SetName(newName);
|
||||
group->SetName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{ // set default group
|
||||
if (groupid == 0)
|
||||
case ModifyGroupType::SetDefault:
|
||||
{
|
||||
if (groupId == 0)
|
||||
{
|
||||
gGameCommandErrorTitle = STR_CANT_SET_TO_THIS_GROUP;
|
||||
gGameCommandErrorText = STR_NONE;
|
||||
*ebx = MONEY32_UNDEFINED;
|
||||
return;
|
||||
return std::make_unique<GameActionResult>(GA_ERROR::DISALLOWED, STR_CANT_SET_TO_THIS_GROUP);
|
||||
}
|
||||
if (*ebx & GAME_COMMAND_FLAG_APPLY)
|
||||
if (isExecuting)
|
||||
{
|
||||
gNetwork.SetDefaultGroup(groupid);
|
||||
|
||||
// Log edit default player group event
|
||||
NetworkPlayer* player = gNetwork.GetPlayerByID(game_command_playerid);
|
||||
NetworkGroup* group = gNetwork.GetGroupByID(groupid);
|
||||
char log_msg[256];
|
||||
const char* args[2] = {
|
||||
player->Name.c_str(),
|
||||
group->GetName().c_str(),
|
||||
};
|
||||
format_string(log_msg, 256, STR_LOG_EDIT_DEFAULT_PLAYER_GROUP, args);
|
||||
network_append_server_log(log_msg);
|
||||
gNetwork.SetDefaultGroup(groupId);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log_error("Invalid Modify Group Type: %u", static_cast<uint8_t>(type));
|
||||
return std::make_unique<GameActionResult>(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
|
||||
break;
|
||||
}
|
||||
|
||||
gNetwork.SaveGroups();
|
||||
|
||||
*ebx = 0;
|
||||
return std::make_unique<GameActionResult>();
|
||||
}
|
||||
|
||||
void game_command_kick_player(
|
||||
int32_t* eax, int32_t* ebx, [[maybe_unused]] int32_t* ecx, [[maybe_unused]] int32_t* edx, [[maybe_unused]] int32_t* esi,
|
||||
[[maybe_unused]] int32_t* edi, [[maybe_unused]] int32_t* ebp)
|
||||
GameActionResult::Ptr network_kick_player(NetworkPlayerId_t playerId, bool isExecuting)
|
||||
{
|
||||
uint8_t playerid = (uint8_t)*eax;
|
||||
NetworkPlayer* player = gNetwork.GetPlayerByID(playerid);
|
||||
NetworkPlayer* kicker = gNetwork.GetPlayerByID(game_command_playerid);
|
||||
NetworkPlayer* player = gNetwork.GetPlayerByID(playerId);
|
||||
if (player == nullptr)
|
||||
{
|
||||
// Player might be already removed by the PLAYERLIST command, need to refactor non-game commands executing too early.
|
||||
return;
|
||||
return std::make_unique<GameActionResult>(GA_ERROR::UNKNOWN, STR_NONE);
|
||||
}
|
||||
|
||||
if (player && player->Flags & NETWORK_PLAYER_FLAG_ISSERVER)
|
||||
{
|
||||
gGameCommandErrorTitle = STR_CANT_KICK_THE_HOST;
|
||||
gGameCommandErrorText = STR_NONE;
|
||||
*ebx = MONEY32_UNDEFINED;
|
||||
return;
|
||||
return std::make_unique<GameActionResult>(GA_ERROR::DISALLOWED, STR_CANT_KICK_THE_HOST);
|
||||
}
|
||||
|
||||
if (*ebx & GAME_COMMAND_FLAG_APPLY)
|
||||
if (isExecuting)
|
||||
{
|
||||
if (gNetwork.GetMode() == NETWORK_MODE_SERVER)
|
||||
{
|
||||
gNetwork.KickPlayer(playerid);
|
||||
gNetwork.KickPlayer(playerId);
|
||||
|
||||
NetworkUserManager* networkUserManager = &gNetwork._userManager;
|
||||
networkUserManager->Load();
|
||||
networkUserManager->RemoveUser(player->KeyHash);
|
||||
networkUserManager->Save();
|
||||
}
|
||||
|
||||
if (kicker != nullptr)
|
||||
{
|
||||
// Log kick player event
|
||||
char log_msg[256];
|
||||
const char* args[2] = {
|
||||
player->Name.c_str(),
|
||||
kicker->Name.c_str(),
|
||||
};
|
||||
format_string(log_msg, 256, STR_LOG_PLAYER_KICKED, args);
|
||||
network_append_server_log(log_msg);
|
||||
}
|
||||
}
|
||||
*ebx = 0;
|
||||
return std::make_unique<GameActionResult>();
|
||||
}
|
||||
|
||||
uint8_t network_get_default_group()
|
||||
@@ -4329,12 +4216,15 @@ GameActionResult::Ptr network_set_player_group(
|
||||
{
|
||||
return std::make_unique<GameActionResult>();
|
||||
}
|
||||
void game_command_modify_groups(
|
||||
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp)
|
||||
GameActionResult::Ptr network_modify_groups(
|
||||
NetworkPlayerId_t actionPlayerId, ModifyGroupType type, uint8_t groupId, const std::string& name, uint32_t permissionIndex,
|
||||
PermissionState permissionState, bool isExecuting)
|
||||
{
|
||||
return std::make_unique<GameActionResult>();
|
||||
}
|
||||
void game_command_kick_player(int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp)
|
||||
GameActionResult::Ptr network_kick_player(NetworkPlayerId_t playerId, bool isExecuting)
|
||||
{
|
||||
return std::make_unique<GameActionResult>();
|
||||
}
|
||||
uint8_t network_get_default_group()
|
||||
{
|
||||
|
||||
@@ -26,6 +26,8 @@ struct GameAction;
|
||||
struct Peep;
|
||||
struct LocationXYZ16;
|
||||
class GameActionResult;
|
||||
enum class ModifyGroupType : uint8_t;
|
||||
enum class PermissionState : uint8_t;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
@@ -75,9 +77,10 @@ int32_t network_get_num_groups();
|
||||
const char* network_get_group_name(uint32_t index);
|
||||
std::unique_ptr<GameActionResult> network_set_player_group(
|
||||
NetworkPlayerId_t actionPlayerId, NetworkPlayerId_t playerId, uint8_t groupId, bool isExecuting);
|
||||
void game_command_modify_groups(
|
||||
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
|
||||
void game_command_kick_player(int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
|
||||
std::unique_ptr<GameActionResult> network_modify_groups(
|
||||
NetworkPlayerId_t actionPlayerId, ModifyGroupType type, uint8_t groupId, const std::string& name, uint32_t permissionIndex,
|
||||
PermissionState permissionState, bool isExecuting);
|
||||
std::unique_ptr<GameActionResult> network_kick_player(NetworkPlayerId_t playerId, bool isExecuting);
|
||||
uint8_t network_get_default_group();
|
||||
int32_t network_get_num_actions();
|
||||
rct_string_id network_get_action_name_string_id(uint32_t index);
|
||||
|
||||
Reference in New Issue
Block a user