Danger mode and masked links

This commit is contained in:
Bigjango13 2024-09-24 22:40:59 -07:00
parent 55304d1c59
commit 7a917a0c7e
4 changed files with 33 additions and 25 deletions

View File

@ -65,11 +65,11 @@ This includes:
- Sets a block of `id:data` at the specified point, if the block is a sign, it will attempt to set lines 1 through 4 of the sign to the given text
- For the API, the lines must be below 100 characters, however when loading signs MCPI will cap it at 16 characters (this can be disabled by patching out the call at `0xd1e2c`).
- The lines are optional
- The wiki has a list of blocks: https://mcpirevival.miraheze.org/wiki/Minecraft:_Pi_Edition_Complete_Block_List, sign is 63 and wall sign is 68
- The wiki has a [list of blocks](https://mcpirevival.miraheze.org/wiki/Minecraft:_Pi_Edition_Complete_Block_List), sign is 63 and wall sign is 68
- [x] `world.spawnEntity(x: int, y: int, z: int, type: int) -> int`
- Spawns an entity of `type` at the given position
- Entities with a type of 0 cannot be spawned
- The list of entity types can be found by running the command below, or on the wiki: https://mcpirevival.miraheze.org/wiki/Minecraft:_Pi_Edition_Complete_Entity_List
- The list of entity types can be found by running the command below, or on the [wiki](https://mcpirevival.miraheze.org/wiki/Minecraft:_Pi_Edition_Complete_Entity_List).
- [x] `world.getEntityTypes() -> {type: int, name: str}`
- Returns a list of known entity types, if there are modded entities this list may be incorrect
- [x] `player.getAbsPos() -> {x: int, y: int, z: int}`
@ -89,8 +89,13 @@ Egdecases:
- `world.removeEntities`/`player.removeEntities`/`entity.removeEntities` will not remove players when given 0 or -1 for type.
- `entity.getName` will not get the name of non-player entities with a type id of 0 due to ambiguity.
- All Raspberry Juice commands/responses involving the player name are designed around the MCJE username restrictions, not the much looser MCPI restrictions. They may cause problems.
- Chat messages will have `|` turned into `\` to prevent bad parsing
Extras:
- [x] `reborn.enableDangerMode` and `reborn.disableDangerMode`
- With "danger mode" enabled, chat messages will have `|` turned into `\`
## How does it work?
![Reborn-API.png](Reborn-API.png)

View File

@ -1,79 +1,79 @@
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" version="24.7.16">
<diagram name="Page-1" id="jwWo0YrG7pLoplSde7jo">
<mxGraphModel dx="1173" dy="609" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" background="#000000" math="0" shadow="0">
<mxGraphModel dx="1114" dy="579" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" background="#000000" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="uj48QsM38hnUiDGvlzeM-1" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#66FF66;strokeColor=#FFFFFF;strokeWidth=2;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-1" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#66FF66;strokeColor=#FFFFFF;strokeWidth=2;" parent="1" vertex="1">
<mxGeometry x="10" y="170" width="470" height="330" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-3" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" edge="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-3" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="410" y="296" as="sourcePoint" />
<mxPoint x="410" y="256" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-6" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#66FF66;strokeColor=#FFFFFF;strokeWidth=2;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-6" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#66FF66;strokeColor=#FFFFFF;strokeWidth=2;" parent="1" vertex="1">
<mxGeometry x="30" y="190" width="430" height="60" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-8" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FF9933;strokeColor=#FFFFFF;strokeWidth=2;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-8" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#FF9933;strokeColor=#FFFFFF;strokeWidth=2;" parent="1" vertex="1">
<mxGeometry x="30" y="302" width="430" height="60" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-12" value="CommandServer_parse_injection" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-12" value="CommandServer_parse_injection" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" parent="1" vertex="1">
<mxGeometry x="190" y="312" width="100" height="40" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-15" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#66FF66;strokeColor=#FFFFFF;strokeWidth=2;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-15" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#66FF66;strokeColor=#FFFFFF;strokeWidth=2;" parent="1" vertex="1">
<mxGeometry x="30" y="414" width="430" height="60" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-16" value="CommandServer::tick" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-16" value="CommandServer::tick" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" parent="1" vertex="1">
<mxGeometry x="190" y="200" width="100" height="40" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-17" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" edge="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-17" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="410" y="407" as="sourcePoint" />
<mxPoint x="410" y="367" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-19" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" edge="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-19" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="85" y="256" as="sourcePoint" />
<mxPoint x="85" y="296" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-20" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" edge="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-20" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="86" y="370" as="sourcePoint" />
<mxPoint x="86" y="410" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-25" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#007FFF;strokeColor=#FFFFFF;strokeWidth=2;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-25" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#007FFF;strokeColor=#FFFFFF;strokeWidth=2;" parent="1" vertex="1">
<mxGeometry x="10" y="10" width="470" height="60" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-26" value="&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;&lt;font style=&quot;font-size: 11px;&quot;&gt;Reborn&#39;s injection hands it off to the&amp;nbsp;original&lt;/font&gt;&lt;/blockquote&gt;&lt;div style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;&lt;font style=&quot;font-size: 11px;&quot;&gt;CommandServer::parse for the normal commands.&lt;/font&gt;&lt;/div&gt;" style="text;strokeColor=none;fillColor=none;html=1;fontSize=11;fontStyle=1;verticalAlign=middle;align=center;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-26" value="&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;&lt;font style=&quot;font-size: 11px;&quot;&gt;Reborn&#39;s injection hands it off to the&amp;nbsp;original&lt;/font&gt;&lt;/blockquote&gt;&lt;div style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;&lt;font style=&quot;font-size: 11px;&quot;&gt;CommandServer::parse for the normal commands.&lt;/font&gt;&lt;/div&gt;" style="text;strokeColor=none;fillColor=none;html=1;fontSize=11;fontStyle=1;verticalAlign=middle;align=center;" parent="1" vertex="1">
<mxGeometry x="220" y="340" width="60" height="90" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-27" value="&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;Reborn inject into CommandServer::parse&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;and checks if the command is non-standard,&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;if it is, Reborn runs it and returns the result.&lt;/blockquote&gt;" style="text;strokeColor=none;fillColor=none;html=1;fontSize=11;fontStyle=1;verticalAlign=middle;align=center;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-27" value="&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;Reborn injects into CommandServer::parse&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;and checks if the command is non-standard,&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;if it is, Reborn runs it and returns the result.&lt;/blockquote&gt;" style="text;strokeColor=none;fillColor=none;html=1;fontSize=11;fontStyle=1;verticalAlign=middle;align=center;" parent="1" vertex="1">
<mxGeometry x="220" y="230" width="60" height="90" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-11" value="CommandServer::parse" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-11" value="CommandServer::parse" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" parent="1" vertex="1">
<mxGeometry x="190" y="420" width="100" height="40" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-31" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" edge="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-31" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="410" y="160" as="sourcePoint" />
<mxPoint x="409" y="80" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-32" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" edge="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-32" value="" style="shape=flexArrow;endArrow=classic;html=1;rounded=0;strokeColor=none;fillColor=#FFFFFF;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="85" y="80" as="sourcePoint" />
<mxPoint x="85" y="160" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-33" value="&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;All commands are sent over a&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;TCP socket from the&amp;nbsp;&lt;span style=&quot;background-color: initial;&quot;&gt;user to&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: initial;&quot;&gt;MCPI&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;This is often on port&amp;nbsp;4711.&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;This means many languages&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;can use the API, not just&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;Python and Java.&lt;/blockquote&gt;" style="text;strokeColor=none;fillColor=none;html=1;fontSize=11;fontStyle=1;verticalAlign=middle;align=center;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-33" value="&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;All commands are sent over a&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;TCP socket from the&amp;nbsp;&lt;span style=&quot;background-color: initial;&quot;&gt;user to&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: initial;&quot;&gt;MCPI&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;This is often on port&amp;nbsp;4711.&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;This means many languages&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;can use the API, not just&lt;/blockquote&gt;&lt;blockquote style=&quot;line-height: 10%; font-size: 11px;&quot;&gt;Python and Java.&lt;/blockquote&gt;" style="text;strokeColor=none;fillColor=none;html=1;fontSize=11;fontStyle=1;verticalAlign=middle;align=center;" parent="1" vertex="1">
<mxGeometry x="210" y="77" width="60" height="90" as="geometry" />
</mxCell>
<mxCell id="uj48QsM38hnUiDGvlzeM-35" value="Whatever MCPI API you want!" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" vertex="1" parent="1">
<mxCell id="uj48QsM38hnUiDGvlzeM-35" value="Whatever MCPI API you want!" style="text;strokeColor=none;fillColor=none;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;" parent="1" vertex="1">
<mxGeometry x="190" y="20" width="100" height="40" as="geometry" />
</mxCell>
</root>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

View File

@ -122,6 +122,7 @@ static ProjectileHitEvent popProjectile() {
}
static const std::string fail = "Fail\n";
bool safe_mode = true;
std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServer *commandserver, ConnectedClient &client, const std::string &command) {
size_t arg_start = command.find("(");
if (arg_start == std::string::npos) return fail;
@ -178,9 +179,7 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
if (ret != 1) return "0\n";
Entity *entity = commandserver->minecraft->level->getEntity(id);
if (entity != NULL) {
// It may be a good idea to check if the entity is a player before removing
// but it doesn't crash, just lock the player in place until you rejoin the world
if (entity != NULL && !entity->isPlayer()) {
entity->remove();
return "1\n";
}
@ -202,7 +201,7 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
std::string ret = "";
for (GuiMessage gm : commandserver->minecraft->gui.messages) {
std::string message = gm.message;
std::replace(message.begin(), message.end(), '|', '\\');
if (safe_mode) std::replace(message.begin(), message.end(), '|', '\\');
ret += "0," + message + "|";
}
if (ret.size() > 1) ret.pop_back();
@ -415,6 +414,10 @@ std::string CommandServer_parse_injection(CommandServer_parse_t old, CommandServ
return std::to_string(commandserver->minecraft->player->x) + ","
+ std::to_string(commandserver->minecraft->player->y) + ","
+ std::to_string(commandserver->minecraft->player->z) + "\n";
} else if (cmd == "reborn.enableDangerMode") {
safe_mode = false;
} else if (cmd == "reborn.disableDangerMode") {
safe_mode = true;
} else {
// Either invalid or a vanilla command, either way hand it off to the orignal handler
return old(commandserver, client, command);