[Script] Blockland Dedicated Server for Linux (Updated 2017/01/09)

Author Topic: [Script] Blockland Dedicated Server for Linux (Updated 2017/01/09)  (Read 3157 times)

I made an easy script to run a Blockland server on Linux. Follow the instructions below.



  • Place all Blockland files in $HOME/blockland-server/. (You can specify a custom path - more on that later)
  • Take this script and place it in a file called blockland-server in your ~/bin directory (create if needed):
Code: [Select]
#!/bin/sh

## Blockland Dedicated Server Launcher
## Written by Greek2me.

# Define defaults.

attach_screen=false
game_mode="Custom"
server_mode="dedicated"
server_number=-1
server_path="$HOME/blockland-server"
server_port=

# Parse arguments.

OPTIND=1
while getopts "ac:d:g:ln:p:" opt; do
case "$opt" in
a) attach_screen=true
;;
c) server_customArgs=$OPTARG
;;
d) server_path=$OPTARG
;;
g) game_mode=$OPTARG
;;
l) server_mode="dedicatedLAN"
;;
n) server_number=$OPTARG
;;
p) server_port=-port $OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift

# Validate the server path.

if [ ! -f "$server_path/Blockland.exe" ]; then
echo "No Blockland server was found at $server_path."
exit 1
fi

# Determine which server number this is.

if [ "$server_number" -lt 0 ]; then
server_number=$(screen -list | grep -c blockland-server)
fi

# Launch the server.

screen -dmS blockland-server$server_number xvfb-run  -a wine wineconsole --backend=curses $server_path/Blockland.exe ptlaaxobimwroe -$server_mode -gamemode $game_mode $server_port $server_customArgs

sleep 1

# Check that the server exists.

if screen -list | grep -q "blockland-server$server_number"; then
echo "Starting server $server_number"
echo " > Running game mode $game_mode"
else
echo "Failed to start server."
exit 1
fi

# Attach to the server.

if [ "$attach_screen" = true ]; then
screen -x blockland-server$server_number
if [ $? -gt 0 ]; then
echo "Failed to attach to server."
fi
fi
    [/li]
  • You can now launch the server by running blockland-server. Arguments:
    • -a Attach to the console automatically. Otherwise, the server will not be displayed in console.
    • -c '-trace -exampleArg' Allows you to pass custom arguments to the server.
    • -g gamemode_name Specify the game mode.
    • -l Starts a LAN server.
    • -n number Specifies a server number. Not needed for most people.
    • -d /path/to/server Specify a custom location for the server.
    • -p 28000 Specify a custom port number for the server.


To attach to a running server's console:
Type this into terminal:
Code: [Select]
screen -x blockland-server0Increment 0 if you have multiple servers.

To detach from a server console:
Press Ctrl+a and then press d.

Required Packages:
  • wine
  • xvfb
  • screen


Changes 2017/01/09:
  • Added shutdown script.
Changes 2016/12/13:
  • Now works on Debian
  • Added -p argument for port.
  • Changing server path now uses -d argument.




NEW - Shutdown Script:
Code: [Select]
#!/bin/bash

SERVER_COUNT=$(screen -list | grep -c blockland-server)
IDX=0
while [[ $IDX -lt $SERVER_COUNT ]]
do
        echo "Shutting down server $IDX"
        screen -S blockland-server$IDX -p 0 -X stuff "$(printf \\r)commandToAll('MessageBoxOK',\"Warning\",\"The server is shutting down in 5 seconds.\");scheduleNoQuota(5000,0,shutdown);scheduleNoQuota(7000,0,quit);$(printf \\r)"
        IDX=$(( $IDX + 1 ))
done
echo "Sent quit command to all servers."
Shuts down all servers.
« Last Edit: January 09, 2017, 09:42:24 PM by Greek2me »

literally all the people will be running servers now :(

literally all the people will be running servers now :(
I fail to see the issue.
Nice work Greek.

Ooo
Too bad I don't really use Linux any more though

Does anybody know how old a topic can be without getting the "topic too old" error?

Does anybody know how old a topic can be without getting the "topic too old" error?
Several months.
Yeah, that wasn't helpful.

EDIT: Okay, I went back through the pages of General Discussion. Feb 20 were not too old, Feb 18 was, and it's April 19. So I think it's 2 months.
« Last Edit: April 19, 2014, 03:50:25 PM by TristanLuigi »

Does anybody know how old a topic can be without getting the "topic too old" error?

Roughly two months. Editing the OP counts as a new post though.

Roughly two months. Editing the OP counts as a new post though.
damnit you posted while I was editing
I hate you