| 251 | } |
| 252 | |
| 253 | String CommandProcessor::setTileProtection(ConnectionId connectionId, String const& argumentString) { |
| 254 | if (auto errorMsg = adminCheck(connectionId, "modify world properties")) { |
| 255 | return *errorMsg; |
| 256 | } |
| 257 | |
| 258 | auto arguments = m_parser.tokenizeToStringList(argumentString); |
| 259 | |
| 260 | if (arguments.size() < 2) |
| 261 | return "Not enough arguments to /settileprotection. Use /settileprotection <dungeonId> <protected>"; |
| 262 | |
| 263 | try { |
| 264 | bool isProtected = Json::parse(arguments.takeLast()).toBool(); |
| 265 | List<DungeonId> dungeonIds; |
| 266 | for (auto& banana : arguments) { |
| 267 | auto slices = banana.split(".."); |
| 268 | auto it = slices.begin(); |
| 269 | DungeonId previous = 0; |
| 270 | while (it != slices.end()) { |
| 271 | DungeonId current = lexicalCast<DungeonId>(*it); |
| 272 | dungeonIds.append(current); |
| 273 | if (it++ != slices.begin() && previous != current) { |
| 274 | if (current < previous) swap(previous, current); |
| 275 | for (DungeonId id = previous + 1; id != current; ++id) |
| 276 | dungeonIds.append(id); |
| 277 | } |
| 278 | previous = current; |
| 279 | } |
| 280 | } |
| 281 | size_t changed = 0; |
| 282 | if (!m_universe->executeForClient(connectionId, [&](WorldServer* world, PlayerPtr const&) { |
| 283 | changed = world->setTileProtection(dungeonIds, isProtected); |
| 284 | })) { |
| 285 | return "Invalid client state"; |
| 286 | } |
| 287 | String output = strf("{} {} dungeon IDs", isProtected ? "Protected" : "Unprotected", changed); |
| 288 | return changed < dungeonIds.size() ? strf("{} ({} unchanged)", output, dungeonIds.size() - changed) : output; |
| 289 | } catch (BadLexicalCast const&) { |
| 290 | return strf("Could not parse /settileprotection parameters. Use /settileprotection <dungeonId...> <protected>", argumentString); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | String CommandProcessor::setDungeonId(ConnectionId connectionId, String const& argumentString) { |
| 295 | if (auto errorMsg = adminCheck(connectionId, "set dungeon id")) { |
nothing calls this directly
no test coverage detected