Thanks also to A_Temporal_Distraction, Thumper, and A_Meteorite for help in making this post.
Map rotation scripts have been around for a few years, the chief benefit of the plugin is you get to choose which map will run after restart.
I put a debian-compiled .so in the zip. Not sure how it will behave on your system.
I provide example code here, but you'll have to use your own paths to /plugins and /bzfs.
Compile or place mapchange.so in your normal plugins directory.
Where you usually keep your .conf's, make a directory named to match the port of your map change server. I used 4242-mapchange
Into that directory put all the desired regular .bzw and .conf files.
Edit all of these conf files to use the same port number chosen. Add helpfiles, srvmsg, etc. if desired.
Create a new text file "mapchange.conf" that contains the names of the server conf files used. The first word is the command that will be entered in-game, the second word is the exact name of the conf that corresponds with the command. Here's a sample from mofo-mapchange:
mapchange.conf
Code: Select all
1v1 1v1.conf
4team 4team.conf
HTF HTF.conf
hunt hunt.conf
pillbox pillbox.conf
redvsblue redvsblue.conf
mapchange.sh
Code: Select all
#!/bin/bash
#!
#! Mapchange script
#!
#! FILE - sets the name of the mapchange configuration file and list of configurations
#! if FILE=mapchange then you get 'mapchange.out' as the output file of the plugin
#! with the selected configuration and 'mapchange.conf' is the list of configurations
#! to choose from.
#! Configuration
#!
FILE=mapchange # base of configuration filename and output file
SLEEPTIME=2.5 # Time in seconds to sleep between restarts
PLUGIN=plugins/mapchange # mapchange plugin
BZFS=./bzfs # bzflag server binary
#! Build the output file and configuration file parameters for the mapchange plugin
MCOUT=$FILE.out
MCCFG=$FILE.conf
#! Loop forever - display name of the selected configuration
while cat $MCOUT; do
#! Run the server
$BZFS -conf $(cat $MCOUT) -loadplugin $PLUGIN,$MCOUT,$MCCFG
#! Wait some time between restarts
sleep $SLEEPTIME
done
Code: Select all
chmod +x mapchange.sh
Create the initial output file "mapchange.out" that is written by the script.
This text file should initially contain the name of the first map to load
#EDIT people are getting tripped up on this step.
The mapchange.out file is needed by the plugin. It contains the name of the NEXT conf that the plugin will load (and nothing else). When you run the command "/mapchange name" (from the client) the plugin will write the name of the next conf to the mapchange.out file.
You need to provide mapchange.out for the plugin the first time you run the mapchange script, so the plugin knows which conf is needed. It does not need to be chmod'd, it is a text file.
After the server is running, and you change a map or conf file (badly) causing the server to hang... the mapchange script keeps running, there is a 5 second delay built into the script to prevent mapchange from consuming 100 percent of CPU while the script loops, but you still need to start the server. There are 2 ways to fix the server.
1. Fix the file you broke while the loop continues, the script will pick up the changes on the next loop.
2. open mapchange.out and edit a known "good" conf into it, the script will pick up the changes on the next loop. Now you can fix the broken bzw or conf while the server is running, and hope no one does /mapchange broken again.
#end EDIT
mapchange.out
Code: Select all
redvsblue.conf
Add CONFCHANGE to which evey groups you want to have the power to run the /mapchange command. (It's CONFchange -- not MAPchange permission... a legacy of early development with this plugin.)
The mapchange server should work now.
Run the script with ./mapchange.sh
I like to add a help file as well.
mapchange-help.txt
Code: Select all
*******
Mapchange commands that an admin can do
/maplist
/mapchange <map>
/maprandom
When you use the '/mapchange <map>' command, the server
will restart immediately, so give some warning before you do it.
******
Code: Select all
-helpmsg ./mapchange-help.txt mapchange
After it's running, you'll want to add new maps:
simply add a conf and map to the directory
edit the conf for correct port, etc.
edit one line into mapchange.conf
restart server using a pre-existing conf
your new map will be available.