Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mgmerino/restric-mc-access
Bash utility to restrict server access based on time.
https://github.com/mgmerino/restric-mc-access
bash cron minecraft server
Last synced: 7 days ago
JSON representation
Bash utility to restrict server access based on time.
- Host: GitHub
- URL: https://github.com/mgmerino/restric-mc-access
- Owner: mgmerino
- Created: 2024-09-06T21:21:25.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-09T22:19:04.000Z (about 2 months ago)
- Last Synced: 2024-10-10T15:41:47.868Z (28 days ago)
- Topics: bash, cron, minecraft, server
- Language: Shell
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![status-badge](http://pajaro-carpintero.hal9.xyz/api/badges/1/status.svg)](http://pajaro-carpintero.hal9.xyz/repos/1)
# Restrict access to Minecraft Server during certain hours.
This bash script is used to ban ALL users connected to a Minecraft server at a given time. It could be useful for parents who want to restrict their children's access to the server during school hours or at night.
The script assumes a docker based installation, rcon-cli installed and enabled in order to run the ban/unban command. The script is executed by a cron job. Jq is used to parse the json file containing the banned users.
The script will ban ALL connected users starting at certain hour. All banned users listed in allowed-players.txt will be unbanned at a later time. You can configure the script to suit your needs using a crontab entry.
## Wait, what!? A bash script to ban users from a Minecraft server?
Are you serious? Yes, I am. I have a Minecraft server running for my kids and I want to restrict their access to the server during school hours and at night. I could have used a plugin to do that, but I wanted to learn more about the Minecraft server and how to interact with it using bash scripts.
And of course, I learned how to test bash scripts using BATS.
## Requirements
- Minecraft Server (for example https://github.com/itzg/docker-minecraft-server)
- rcon-cli
- bash
- jq### TODO
- [ ] Add more tests
- [ ] Add more documentation
- [x] Add a CI/CD pipeline## Usage
Fill in the allowed-players.txt file with the list of players you want to unban automatically always on the server. One player per line. This will ensure that the script will unban those whitelisted players and not all who were banned (from banned-players.json file).
Create a crontab entry to run the script to suit your needs. In my case, I execute the script at 23:00 to ban the users and at 12:00 to unban the users.
```bash
0 23 * * * /home/mcadmin/mc-config/goto-bed.sh
0 12 * * * /home/mcadmin/mc-config/goto-bed.sh
```### Testing
Tests are written used BATS. To run the tests, install bats and run the following command:
```bash
bats test/goto-bed.bats
```### Contributing
If you have any suggestions or improvements, please open an issue or a pull request.
### License
MIT