* "Send" a particular CommandQueue to all clients. * @param queue The queue of commands that has to be distributed. * @param owner The client that owns the commands, */
| 324 | * @param owner The client that owns the commands, |
| 325 | */ |
| 326 | static void DistributeQueue(CommandQueue &queue, const NetworkClientSocket *owner) |
| 327 | { |
| 328 | #ifdef DEBUG_DUMP_COMMANDS |
| 329 | /* When replaying we do not want this limitation. */ |
| 330 | int to_go = UINT16_MAX; |
| 331 | #else |
| 332 | int to_go = _settings_client.network.commands_per_frame; |
| 333 | if (owner == nullptr) { |
| 334 | /* This is the server, use the commands_per_frame_server setting if higher */ |
| 335 | to_go = std::max<int>(to_go, _settings_client.network.commands_per_frame_server); |
| 336 | } |
| 337 | #endif |
| 338 | |
| 339 | /* Not technically the most performant way, but consider clients rarely click more than once per tick. */ |
| 340 | for (auto cp = queue.begin(); cp != queue.end(); /* removing some items */) { |
| 341 | /* Do not distribute commands when paused and the command is not allowed while paused. */ |
| 342 | if (_pause_mode.Any() && !IsCommandAllowedWhilePaused(cp->cmd)) { |
| 343 | ++cp; |
| 344 | continue; |
| 345 | } |
| 346 | |
| 347 | /* Limit the number of commands per client per tick. */ |
| 348 | if (--to_go < 0) break; |
| 349 | |
| 350 | DistributeCommandPacket(*cp, owner); |
| 351 | NetworkAdminCmdLogging(owner, *cp); |
| 352 | cp = queue.erase(cp); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | /** Distribute the commands of ourself and the clients. */ |
| 357 | void NetworkDistributeCommands() |
no test coverage detected