MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ModifyGroups

Function ModifyGroups

src/openrct2/network/NetworkBase.cpp:3659–3797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3657 }
3658
3659 GameActions::Result ModifyGroups(
3660 PlayerId_t actionPlayerId, GameActions::ModifyGroupType type, uint8_t groupId, const std::string& name,
3661 uint32_t permissionIndex, GameActions::PermissionState permissionState, bool isExecuting)
3662 {
3663 auto& network = GetContext()->GetNetwork();
3664 switch (type)
3665 {
3666 case GameActions::ModifyGroupType::addGroup:
3667 {
3668 if (isExecuting)
3669 {
3670 NetworkGroup* newgroup = network.AddGroup();
3671 if (newgroup == nullptr)
3672 {
3673 return GameActions::Result(GameActions::Status::unknown, STR_CANT_DO_THIS, kStringIdNone);
3674 }
3675 }
3676 }
3677 break;
3678 case GameActions::ModifyGroupType::removeGroup:
3679 {
3680 if (groupId == 0)
3681 {
3682 return GameActions::Result(
3683 GameActions::Status::disallowed, STR_THIS_GROUP_CANNOT_BE_MODIFIED, kStringIdNone);
3684 }
3685 for (const auto& it : network.player_list)
3686 {
3687 if ((it.get())->group == groupId)
3688 {
3689 return GameActions::Result(
3690 GameActions::Status::disallowed, STR_CANT_REMOVE_GROUP_THAT_PLAYERS_BELONG_TO, kStringIdNone);
3691 }
3692 }
3693 if (isExecuting)
3694 {
3695 network.RemoveGroup(groupId);
3696 }
3697 }
3698 break;
3699 case GameActions::ModifyGroupType::setPermissions:
3700 {
3701 if (groupId == 0)
3702 { // can't change admin group permissions
3703 return GameActions::Result(
3704 GameActions::Status::disallowed, STR_THIS_GROUP_CANNOT_BE_MODIFIED, kStringIdNone);
3705 }
3706 NetworkGroup* mygroup = nullptr;
3707 Player* player = network.GetPlayerByID(actionPlayerId);
3708 auto networkPermission = static_cast<Permission>(permissionIndex);
3709 if (player != nullptr && permissionState == GameActions::PermissionState::toggle)
3710 {
3711 mygroup = network.GetGroupByID(player->group);
3712 if (mygroup == nullptr || !mygroup->canPerformAction(networkPermission))
3713 {
3714 return GameActions::Result(
3715 GameActions::Status::disallowed, STR_CANT_MODIFY_PERMISSION_THAT_YOU_DO_NOT_HAVE_YOURSELF,
3716 kStringIdNone);

Callers 2

QueryMethod · 0.85
ExecuteMethod · 0.85

Calls 14

GetContextFunction · 0.85
AddGroupMethod · 0.80
RemoveGroupMethod · 0.80
GetPlayerByIDMethod · 0.80
GetGroupByIDMethod · 0.80
canPerformActionMethod · 0.80
SetDefaultGroupMethod · 0.80
SaveGroupsMethod · 0.80
ResultClass · 0.70
getMethod · 0.65
getNameMethod · 0.45

Tested by

no test coverage detected