| 3018 | } |
| 3019 | |
| 3020 | void NetworkBase::ServerHandleGameAction(Connection& connection, Packet& packet) |
| 3021 | { |
| 3022 | uint32_t tick; |
| 3023 | GameCommand actionType; |
| 3024 | |
| 3025 | Player* player = connection.player; |
| 3026 | if (player == nullptr) |
| 3027 | { |
| 3028 | return; |
| 3029 | } |
| 3030 | |
| 3031 | packet >> tick >> actionType; |
| 3032 | |
| 3033 | // Don't let clients send pause or quit |
| 3034 | if (actionType == GameCommand::TogglePause || actionType == GameCommand::LoadOrQuit) |
| 3035 | { |
| 3036 | return; |
| 3037 | } |
| 3038 | |
| 3039 | if (actionType != GameCommand::Custom) |
| 3040 | { |
| 3041 | // Check if player's group permission allows command to run |
| 3042 | NetworkGroup* group = GetGroupByID(connection.player->group); |
| 3043 | if (group == nullptr || group->canPerformCommand(actionType) == false) |
| 3044 | { |
| 3045 | ServerSendShowError(connection, STR_CANT_DO_THIS, STR_PERMISSION_DENIED); |
| 3046 | return; |
| 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | // Create and enqueue the action. |
| 3051 | GameActions::GameAction::Ptr ga = GameActions::Create(actionType); |
| 3052 | if (ga == nullptr) |
| 3053 | { |
| 3054 | LOG_ERROR( |
| 3055 | "Received unregistered game action type: 0x%08X from player: (%d) %s", actionType, connection.player->id, |
| 3056 | connection.player->name.c_str()); |
| 3057 | return; |
| 3058 | } |
| 3059 | |
| 3060 | // Player who is hosting is not affected by cooldowns. |
| 3061 | if ((player->flags & PlayerFlags::kIsServer) == 0) |
| 3062 | { |
| 3063 | auto cooldownIt = player->cooldownTime.find(actionType); |
| 3064 | if (cooldownIt != std::end(player->cooldownTime)) |
| 3065 | { |
| 3066 | if (cooldownIt->second > 0) |
| 3067 | { |
| 3068 | ServerSendShowError(connection, STR_CANT_DO_THIS, STR_NETWORK_ACTION_RATE_LIMIT_MESSAGE); |
| 3069 | return; |
| 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | uint32_t cooldownTime = ga->GetCooldownTime(); |
| 3074 | if (cooldownTime > 0) |
| 3075 | { |
| 3076 | player->cooldownTime[actionType] = cooldownTime; |
| 3077 | } |
nothing calls this directly
no test coverage detected