MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / setTileProtection

Method setTileProtection

source/game/StarCommandProcessor.cpp:253–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253String 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
294String CommandProcessor::setDungeonId(ConnectionId connectionId, String const& argumentString) {
295 if (auto errorMsg = adminCheck(connectionId, "set dungeon id")) {

Callers

nothing calls this directly

Calls 11

strfFunction · 0.85
tokenizeToStringListMethod · 0.80
toBoolMethod · 0.80
executeForClientMethod · 0.80
parseFunction · 0.50
sizeMethod · 0.45
takeLastMethod · 0.45
splitMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected