screepsmod-exec-cli-in-console 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # screepsmod-exec-cli-in-console
2
2
 
3
- [English](README.md) | [中文](README.zh.md)
3
+ [English](./README.md) | [中文](./README.zh.md)
4
4
 
5
5
  Allow players to execute **(some)** Screeps server **CLI-only** commands from the **in-game console**.
6
6
 
@@ -93,6 +93,14 @@ Sets `progress = progressTotal - 1` for construction sites in the given rooms.
93
93
  Game.cli.finishConstructionSites(['W1N9'])
94
94
  ```
95
95
 
96
+ ### Common commands
97
+
98
+ #### Modify all ramparts HP
99
+
100
+ ```js
101
+ Game.cli.exec("(function(){var hp=300000000;return storage.db.rooms.find({}).then(function(rs){var rooms=(rs||[]).map(function(r){return r._id});return storage.db['rooms.objects'].find({type:'rampart',room:{$in:rooms}}).then(function(ws){var p=storage.db['rooms.objects'].count({_id:{$in:[]}});(ws||[]).forEach(function(w){p=p.then(function(){return storage.db['rooms.objects'].update({_id:w._id},{$set:{hits:hp,hitsMax:hp}});});});return p.then(function(){return 'OK ramparts='+(ws?ws.length:0);});});});})()")
102
+ ```
103
+
96
104
  ## Security notes
97
105
 
98
106
  Executing arbitrary server CLI JS is powerful:
package/README.zh.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # screepsmod-exec-cli-in-console
2
2
 
3
- [English](README.md) | [中文](README.zh.md)
3
+ [English](./README.md) | [中文](./README.zh.md)
4
4
 
5
5
  让玩家可以在**游戏内控制台**执行(部分)Screeps 私服的**仅 CLI 可用**命令。
6
6
 
@@ -93,6 +93,14 @@ Game.cli.setControllerLevel('67c8...df8', 8)
93
93
  Game.cli.finishConstructionSites(['W1N9'])
94
94
  ```
95
95
 
96
+ ### 常用命令
97
+
98
+ #### 修改所有墙的血量
99
+
100
+ ```js
101
+ Game.cli.exec("(function(){var hp=300000000;return storage.db.rooms.find({}).then(function(rs){var rooms=(rs||[]).map(function(r){return r._id});return storage.db['rooms.objects'].find({type:'rampart',room:{$in:rooms}}).then(function(ws){var p=storage.db['rooms.objects'].count({_id:{$in:[]}});(ws||[]).forEach(function(w){p=p.then(function(){return storage.db['rooms.objects'].update({_id:w._id},{$set:{hits:hp,hitsMax:hp}});});});return p.then(function(){return 'OK ramparts='+(ws?ws.length:0);});});});})()")
102
+ ```
103
+
96
104
  ## 安全说明
97
105
 
98
106
  执行服务端 CLI JS 权限很大:
package/index.js CHANGED
@@ -455,19 +455,19 @@ async function resolveRole(userId) {
455
455
  userId = String(userId);
456
456
  const superSets = getEffectiveSuperAdminSets();
457
457
  const normalSets = getEffectiveNormalSets();
458
+ const defaultRole = SETTINGS.allowAllUsers ? 'normal': null
458
459
 
459
460
  if (superSets.ids.has(userId)) return 'super';
460
- if (SETTINGS.allowAllUsers) return 'normal';
461
461
  if (normalSets.ids.has(userId)) return 'normal';
462
462
 
463
463
  const needNameLookup = superSets.names.size > 0 || normalSets.names.size > 0;
464
- if (!needNameLookup) return null;
464
+ if (!needNameLookup) return defaultRole;
465
465
 
466
466
  const user = await common.storage.db.users.findOne({_id: userId});
467
467
  const usernameLower = user && user.username ? String(user.username).toLowerCase() : '';
468
468
  if (usernameLower && superSets.names.has(usernameLower)) return 'super';
469
469
  if (usernameLower && normalSets.names.has(usernameLower)) return 'normal';
470
- return null;
470
+ return defaultRole;
471
471
  }
472
472
 
473
473
  function withTimeout(promise, ms, label) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screepsmod-exec-cli-in-console",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Allow players to execute (some) server CLI-only commands from the in-game console.",
5
5
  "main": "index.js",
6
6
  "scripts": {},