Page 1 of 1

MapChange

Posted: Fri Jan 05, 2007 9:02 pm
by optic delusion
Gnurdux is 100 percent responsible for the creation of this plugin, and since six months have passed and he still doesnt want to release it, I convinced him that I should release it for him.
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
Create a new file "mapchange.sh" that contains the script to run that starts it. You'll have to correct the plugin and bzfs locations.

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
Make that script executable by opening your terminal and cd to the correct directory then...

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
Edit your groups file.
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.
******
Add this line to the conf file for each game

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.

Posted: Sat Jan 06, 2007 9:20 am
by Zelgadis
Yes very nice plugin, i thank to gnurdux that i got it some months ago :)

Very good job :)

Posted: Sat Jan 06, 2007 10:29 am
by Destroyer
yes i agree! Nice Plugin!

Posted: Wed Jan 17, 2007 6:56 pm
by Gnurdux
Sorry about not posting it. I'm just a lazy person. Btw, most plugins of my plugins (probably including ones not yet made at this post) are available at http://gnurdux.homelinux.net/bzplugins -- no warrantee :P

If in doubt, assume they're under the GPL

2-Part conf loading

Posted: Sun Jan 21, 2007 8:29 pm
by optic delusion
Yes, Gnurdux proves that you don't need rank to be king.

Now with the plugin as above, there's one last problem. You have a dozen confs with a dozen maps, and sooner or later you will have to change one setting (maybe your welcome message) in all 12 confs in order to do that. Major pain in the butt.
Here we have modified the mapchange.sh script to load a 2-part conf file. You can have one file that contains all the settings that are the same across all maps, and another much shorter file that contains only the settings that are unique to each individual map. The script combines both files into a new temporary file that is then loaded by bzfs at mapchange.

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
	cat 4040a.conf $(cat $MCOUT) >CONF.tmp
	$BZFS -conf CONF.tmp -loadplugin $PLUGIN,$MCOUT,$MCCFG
	#! Wait some time between restarts
	sleep $SLEEPTIME
done
Just make this new script executable and split your confs into two parts, you now can make changes across all servers by changing only one file, conf-part-A
Every other operation of the plugin remains the same.


note: anybody who saw this on jan20 or 21... I pasted the wrong script... it's fixed now

To whom it may concern.

Posted: Fri Jan 26, 2007 7:17 pm
by optic delusion
The One Thousand Map Library Server!
Read all about it!

http://my.bzflag.org/bb/viewtopic.php?p=100958#100958

Posted: Fri Aug 31, 2007 5:06 am
by Durf
yea im lazy. could someone make something where all someone has to do is put in names and it generates all files ready to use.?

Posted: Fri Aug 31, 2007 9:29 pm
by blast
Durf wrote:yea im lazy. could someone make something where all someone has to do is put in names and it generates all files ready to use.?
Sure, you're more than welcome to create such a tool or script.

Help - Plugin wont load

Posted: Wed Oct 10, 2007 8:20 am
by Grans Remedy
I can't load this plugin - I think I need to compile from source, but when running make over the dir in the supplied zip archive produces an error:
[grans@gransplace mapchange]$ make
make: *** No targets specified and no makefile found. Stop
Can someone give me a clue pse?
This is on Centos 4 - I have the FairCTF plugin working just fine (after compiling from source).

Cheers
Grans.

Re: Help - Plugin wont load

Posted: Wed Oct 10, 2007 8:38 am
by macsforme
Grans Remedy wrote:I can't load this plugin - I think I need to compile from source, but when running make over the dir in the supplied zip archive produces an error:
[grans@gransplace mapchange]$ make
make: *** No targets specified and no makefile found. Stop
Can someone give me a clue pse?
This is on Centos 4 - I have the FairCTF plugin working just fine (after compiling from source).

Cheers
Grans.
You should be able to compile it the same way you compiled FairCTF. Assuming it's just one source code file, you can use newplug.sh to add it to the main source code tree, or use a shell command to compile like:

Code: Select all

g++ -I /path/to/bzflag/include -shared -o mapchange.so mapchange.cpp

Posted: Thu Oct 11, 2007 7:43 am
by Grans Remedy
Thanks Const, I managed to get this to compile, and I can load the plugin. But, server says /maplist is unknown command (even tho the plugin is loadable using /loadplugin /path/to/plugin.so)
Any ideas ?

Cheers
Grans.

Posted: Thu Oct 11, 2007 2:18 pm
by blast
Grans Remedy, run the server with -dddd and check for any plugin loading errors. Of course, you won't want to run that for long, since that will create a huge log file (if you save logs).

edited into the first post

Posted: Fri Oct 26, 2007 8:08 pm
by optic delusion
I have edited the first post in this thread.
I also strongly encourage that you use the SECOND mapchange.sh script that I posted in this thread, and split your confs. It's a bit more work at the start, but will save you a ton of time later.


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.

Re: MapChange

Posted: Fri Mar 29, 2013 11:30 pm
by allejo
I'm sorry, I didn't realize I hadn't posted the updated version for 2.4.x of the plug-in. I haven't tested it so no guarantees that it'll work.

Re: MapChange

Posted: Wed Apr 24, 2013 1:34 am
by Trogdor BurNinat0R
as you probably know, it works.

thanks!

Re: MapChange

Posted: Thu Dec 28, 2017 2:02 am
by allejo
As an update for this plug-in, Constitution's fork of the mapchange plug-in and then my fork of that has moved to github, https://github.com/allejo/mapchange