mc-scripts/storage-net/README.md

76 lines
3.0 KiB
Markdown
Raw Normal View History

2024-02-16 23:39:52 -06:00
# Computercraft Storage Network
This is an implementation of a centralized storage network architecture that uses just ComputerCraft and vanilla Minecraft.
## Deployment
2024-02-25 22:14:08 -06:00
The master node must have a modem attached and be within range of all slave nodes.
2024-02-25 23:01:37 -06:00
1. Deploy at least one slave turtle
* The inventory it is to monitor must be above the unit
2024-02-25 22:14:08 -06:00
* The unit should be able to drop below itself to push items to the master node
2024-02-25 23:01:37 -06:00
* Any subsequent slaves should be placed in front of the unit
2. Set up a return system that pushes into the first slave node (can be a hopper or similar)
2024-02-25 22:14:08 -06:00
2024-02-16 23:39:52 -06:00
## Communication Protocol
Messages are sent over rednet with the protocol `ccstoragenet`.
2024-02-16 23:39:52 -06:00
### Packet Format
Packet format is uniform between master <-> slaves and is structured like so:
```
{
// Metadata
networkid: int()
sourceid: int()
sourcetype: str()
2024-02-16 23:39:52 -06:00
destid: int()
// Payload
type: str()
// Optional Arguments
itemname: str()
itemquant: int()
destination: int()
location: [int(),int(),int()]
// Dump for additional body data
body: any
2024-02-16 23:39:52 -06:00
}
```
| Name | Required? | Type | Description
| :-- | :--: | :-- | :--
| `networkid` | true | int | The ID of the network |
| `sourceid` | true | int | The CC ID of the machine sending the packet |
| `sourcetype` | true | string | The mode of the machine sending the packet |
2024-02-16 23:39:52 -06:00
| `destid` | true | int | The CC ID of the intended recipient of the packet |
| `type` | true | string | An arbitrary string literal corresponding to the type of the request. Common examplse include `ping`, `query`, etc. |
| `itemname` | false | string | The unlocalized name of an item. Used for querying, crafting, movement, etc. |
| `itemquant` | false | int | Quantity of the aforementioned item |
| `destination` | false | int | The CC ID of the intended recipient of the item |
| `body` | false | any | Any additional body data per the requirements of a query, such as a detailed list of inventory contents |
2024-02-16 23:39:52 -06:00
### Slave Node Initialization
* The slave starts up and immediately listens for messages
2024-02-16 23:39:52 -06:00
### Master Node Initialization
* The master node starts up
2024-02-25 22:44:46 -06:00
* The master node sends a packet with type `ping`.
* The master node listens for `pong` packets from all slaves.
2024-02-16 23:39:52 -06:00
* The `sourceid` of all `pong` packets is recorded for statistics displays. This cached data is only used for user display. Node availability is evaluated at request time.
### Inventory Search (query)
* The sender node sends a packet with type `query`. Field `itemname` is populated with an item to query for.
* Each available slave responds with type `query`.
2024-02-16 23:41:22 -06:00
* `itemname` is populated with data from the previous packet
* `itemquantity` is populated with the quantity of that item attached to storages the slave has access to.
2024-02-16 23:39:52 -06:00
* The requester waits for a response from each slave that responded to the `ping` or until a configurable timeout is reached.
* Results are consumed