bzfscron 0.1

Questions, comments, and news on the server side plug-ins and it's API
User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

bzfscron 0.1

Post by DTRemenak » Mon Aug 22, 2005 12:35 pm

Alright, here's one that's been requested a number of times, not least by admins of the various servers which run on dtremenak.bakadigital.com.

bzfscron allows you to run arbitrary / commands on a schedule. It supports a very complete crontab parser that closely approximates those found on most modern *nix systems. See the ReadMe for more details.

This can let you change your server configuration (see /set), reset flags (/flag reset), and so on. Note that it really does mean arbitrary / commands, so you can run commands that other plugins register. This means you could couple it with (for instance) racetoseven and do a scheduled /match start and /match stop. You can also set it up to do /say on a schedule other than 15 minutes, removing the limitation on -admsg.

bzfscron *requires* BZAPI 11 or later. Yes, that means it won't run with b15, so I'll probably need to release a b16 soon.

I haven't tried building it on *nix yet. It should work but the Makefile might require some tweaking. It depends rather heavily on other components of bzflag.

Use -loadplugin /path/to/bzfscron.[so|dll],/path/to/bzfscrontab , where bzfscrontab complies with the specifications as per the Readme, in order to load this plugin.

You will see an "observer" called "bzfscron" on your server when this plugin is running (it takes about 35 seconds to start, so be patient). This "observer" is the chunk of the plugin that actually runs the / commands. Although it seems to be just an ordinary observer, it has antiban and antikick. To remove it, unload the plugin. Sometimes it will deadlock while loading (if you have -dddd you'll notice that it's just tried "connect stage 3"), just kill the server and try again. I need to fix that.

If your server is using -i, make sure it allows connections from 127.0.0.1. This is a very rare case, and you know if it applies to you.

Note to developers: this is a good example of a bad way to write a plugin. Since bzfs does not support "fake players" (e.g. every player must have a socket connection), and cannot run commands without a player to dereference, it uses some miscellaneous connection code mostly snarfed from bzflag and bzadmin to actually connect back to the server and issue a command that way. It (the plugin) promotes itself (the pseudo-player) to administrator automatically, so you don't need to worry about auth. Establishing a TCP connection to one's own thread is very weird and very ugly. However, for the limited purposes of this plugin, it works.

And into the realm of absurdity: if you couple this plugin with janitor, you could hypothetically replace your system cron altogether with...bzfs. Yeah...pretty soon we'll have a whole OS running in bzfs. BZFS - the next emacs.
Attachments
bzfscron-w32-0.1.zip
Win32 binary plugin. Requires 2.0.3b16 or newer.
(113.37 KiB) Downloaded 444 times
bzfscron-src-0.1.zip
bzfscron source. requires bzapi 11 or newer.
(19.02 KiB) Downloaded 476 times
ReadMe.txt
bzfscron readme
(3.8 KiB) Downloaded 601 times

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Mon Aug 22, 2005 1:51 pm

Code: Select all

linux:/home/death/bzflag/plugins/bzfscron # make
g++ -fPIC -frtti -I../../include -O   -c -o bzfscron.o bzfscron.cpp
In file included from bzfscron.cpp:23:
CronJob.h:46:30: warning: no newline at end of file
bzfscron.cpp:365:30: warning: no newline at end of file
g++ -fPIC -frtti -I../../include -O -shared -rdynamic  bzfscron.o -o bzfscron.so
linux:/home/death/bzflag/plugins/bzfscron #    
It made the .so

But without a sample bzfscron file, and the readme reads liek stereo instructions... I'm a bit lost.

If anyone is using this, post your config file.

Code: Select all

lugin:/home/death/bzflag/plugins/racetoseven/racetoseven.so found but expects an older API version (10), upgrade it
WARNING: unable to load the plugin; /home/death/bzflag/plugins/racetoseven/racetoseven.so
Plugin:/home/death/bzflag/plugins/airspawn/airspawn.so loaded
bzfscron: crontab nonexistant or invalid
Plugin:/home/death/bzflag/plugins/bzfscron/bzfscron.so loaded

...This has been a recording.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Mon Aug 22, 2005 3:28 pm

What you put in the crontab depends on what you want it to do, and when. If you can write out what you want to do in english it's pretty easy to translate.

E.g. "I want to reset all unused flags every 10 minutes" turns into

Code: Select all

*/10 * * * * /flag reset unused
While "I want to change the sky color based on the day of the week" might turn into something like

Code: Select all

0 0 * * 0 /set _skyColor red
0 0 * * 1 /set _skyColor orange
0 0 * * 2 /set _skyColor yellow
0 0 * * 3 /set _skyColor green
0 0 * * 4 /set _skyColor blue
0 0 * * 5 /set _skyColor indigo
0 0 * * 6 /set _skyColor violet
A crontab is just a list of commands and optionally comments. So if we wanted to combine the above into a sample file we could get something like

Code: Select all

# minute hour day month weekday command
# reset flags every 10 minutes
*/10 * * * * /flag reset unused
# change the sky color based on the day of the week
# and reset it to the right color every hour so no dufuses change it
0 * * * 0 /set _skyColor red
0 * * * 1 /set _skyColor orange
0 * * * 2 /set _skyColor yellow
0 * * * 3 /set _skyColor green
0 * * * 4 /set _skyColor blue
0 * * * 5 /set _skyColor indigo
0 * * * 6 /set _skyColor violet
I haven't tested that but it ought to work.
Note that blank lines are not thrown out in this version but they ought to work.

The file I used for testing was

Code: Select all

*	*	*	*	*	/say "testing"
10-20/2	*/2	*	*	*	/say "hello"
1,5,6,8	1-4,8-12	*	*	*	/say "hello2"
0-10,20-30/2	*	*	*	*	/say "hello3"
Which says "testing" every minute, "hello" every other minute between minutes 10 and 20 of every other hour (e.g. x:10, x:12, x:14, x:16, x:18 and x:20 where x is any even number from 0 to 22), "hello2" at 1:01, 1:05, 1:06, 1:08, 2:01, 2:05, 2:06, 2:08, 3:01, 3:05, 3:06, 3:08, 4:01, 4:05, 4:06, 4:08, 8:01, 8:05, 8:06, 8:08, 9:01, 9:05, 9:06, 9:08, 10:01, 10:05, 10:06, 10:08, 11:01, 11:05, 11:06, 11:08, 12:01, 12:05, 12:06, and 12:08 of every day, and "hello3" every other minute between minutes 0 and 10 and 20 and 30 of every hour (e.g. x:00, x:02, x:04...x:10, x:20, x:22, x:24...x:30 where x is any even number from 0 to 22). That's not really very practical but it does work.

BTW, it's good to know that the makefile worked (although I must admit to being somewhat surprised :) ).

And what's wrong with stereo manuals?

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Fri Aug 26, 2005 4:05 pm

OK, stupid question...

when writing the config file, I see the five arbitors

* * * * * /say woot

and on some of the examples its

*. *. *. *. *. /say woot

Is that...

A - each value separated by a space and a space only?

B - each value separated by a period then a space?

C (i'm going out on a limb here) each valule separated by the pressing of the TAB key?

D. none, its: ____________________

I know this is retarded, but I keep getting errors on this plugin
...This has been a recording.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Fri Aug 26, 2005 8:58 pm

The . is probably your editor's way of saying "there's a tab here". bzfscron splits them based on spaces or tabs.

If you could paste the errors you are getting that could be helpful. I still need to build and test it on linux myself also, so it may just Not Work Yet (tm).

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Fri Aug 26, 2005 9:25 pm

ok DT - If I can't get this working, I am going to have to ask ya to post any working config file - like, post it as an attatchment, so I can take it from there
...This has been a recording.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Fri Aug 26, 2005 9:43 pm

Better yet, here's a copy of the source that actually works on linux. The old Makefile did not compile the whole thing, just one peice of it.

bzfscron 0.2

Changes:
* If connection fails reconnection has a chance of succeeding
* Works on servers which do not have the port specified in -publicaddr (including private servers, but only on 5154)
* Builds correctly on linux
* Include sample (albiet a rather silly one) crontab
Attachments
bzfscron.tar.gz
bzfscron 0.2 source
(16.56 KiB) Downloaded 428 times

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Sat Aug 27, 2005 2:59 am

My archive handling software wanted to act the fool, sorry I ended up downloading that so many times...
...This has been a recording.

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Sat Aug 27, 2005 3:05 am

OK - here are some thoughts...

Since it takes a spot in observer mode, there need to be a little more configuration.

For starters, no one but those I chose should be able to do a /set or a /command - this thing was just resetting my flags every minute. How does it derive its authority? I say give us the ability to give it an actual name & use a password for global auth instead of having bzfscron in observer

The ability to save output to a text file, such as only chat... or the ability to save text like "sky color was set to black by Darth Vader" would be nice, as well as other various informations...

"stepping" as it was put in the readme... /2 in the minutes field makes it go off every two minutes? No, I dont think this works...

Lovely plugin. I'd love to see this come a long way
...This has been a recording.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Sat Aug 27, 2005 3:52 am

bzfscron will only run commands that you add to the crontab, and only on the schedule that you specify. It runs them with the full authority of the server. So no, your admins can't run anything they want, they'd need to have shell access to your computer, modify the file, and restart the server :). If they can do that, they can also modify your userdb file and just make themselves admin anyway, or change your server password in the config file, or any number of other things. There is no way to add a job while bzfs is running, you have to do it with a text editor...bzfscron is totally non-interactive. After a job is added, it will be run on schedule. I'd rather not have it take the observer spot at all but there are technical reasons I can't avoid easily.

It will dump more information than you probably want into the log at -dddd levels, including every tick it processes (e.g. every five seconds it will write "tick!"), and every job it matches (e.g. "matched /say "it's midnight!""). It prefaces everything with "bzfscron:" so if you want to do fancy logging you can use tee and grep to split it out from the main server logs. I should probably add timestamping so you can see if it's actually running the jobs at the correct time (afaict it does).

"*/2" in the minutes field should do "every two minutes"
just "/2" is invalid syntax, but since it doesn't do syntax checking it will probably make a bad assumption. I'll call it "undefined behavior".
also "30-59/2" in the minutes field will make it do "every two minutes during the last half hour of every hour" for instance

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Sat Aug 27, 2005 2:15 pm

Is there a way to reload a crontab after the server has been started?

When testing and editing this, I keep restarting the server to do it. Is there a way to try out modified crontabs that has been modified since the server started?
...This has been a recording.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Sat Aug 27, 2005 2:46 pm

No, there's not at this time. I will add that.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Sat Aug 27, 2005 6:05 pm

bzfscron 0.3

Changes:
* Timestamps "matched job" debug messages
* Added "/cron list" command to get a list of jobs
* Added "/cron reload" command to reload the crontab
* Added "BZFSCRON" permission; you will need to add it to a group that you want to have access to the /cron commands.
Attachments
bzfscron.tar.gz
bzfscron 0.3 source
(17.56 KiB) Downloaded 399 times

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Mon Aug 29, 2005 12:11 am

bzfscron 0.3.1

* Correctly handle blank and whitespace-only lines in crontab
* Build with debug information
Attachments
bzfscron.tar.gz
bzfscron 0.3.1
(17.58 KiB) Downloaded 397 times

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Fri Sep 09, 2005 10:41 am

I just got the latest CVS (as of this post) and plugin support is now fixed. Yay. However, I still get one when trying to use bzfscron

Code: Select all

./bzfs: symbol lookup error: /home/death/bzflag/plugins/bzfscron/bzfscron.so: undefined symbol: _ZN9TextUtils13no_whitespaceERKSs
linux:/home/death #  
...This has been a recording.

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Tue Sep 13, 2005 7:29 pm

OK, plugins were broken, fixed, broken again, fixed again...

Now bzfscron does not like my crontab file. Its teh same tried and true crontab I've used in the past... Any chance of an updated version of this (great) plugin?

I've tried my backup of a known working crontab, the sample crontab that comes with the source... and neither work.

In the start up, I get

Code: Select all

bzfscron: crontab nonexistant or invalid
Plugin:/home/death/bzflag/plugins/bzfscron/bzfscron.so loaded
...This has been a recording.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Fri Sep 16, 2005 2:58 am

bzfscron 0.3.2

* Minor bugfixes
* Fixed windows build

If your crontab still will not load, please attach it (or pm or email it to me), and I'll stick it in a debugger and find out what's up.
Attachments
bzfscron-src-0.3.2.zip
bzfscron 0.3.2 source
(21.73 KiB) Downloaded 418 times
bzfscron-w32-0.3.2.zip
bzfscron 0.3.2 windows plugin
(36.37 KiB) Downloaded 412 times

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Sun Sep 18, 2005 4:31 pm

Excellent stuff, DTR.

Check out my new crontab and tell me if I did the holiday's correctly. I would like to add more holiday's, maybe some more birthday's, and I'm not sure what else just yet. When I finish this little project, all anyone will have to do to use it for their own server is replace the string "Planet MoFo" with the name of their server.

But I would like to do alot more with it, I just need ideas as to exactly what to do.
Attachments
crontab.txt
9/18/05 crontab
(2.52 KiB) Downloaded 444 times
...This has been a recording.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Sun Sep 18, 2005 5:01 pm

All those look good. I think you've got the hang of it :)

I assume it's loading correctly for you (e.g. you're not having the problem you were having earlier)?

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Sun Sep 18, 2005 5:04 pm

It loaded fine early this morning... Check out my "HAPPY NEW YEAR" entry... It goal is to have it say HAPPY NEW YEAR at exactly midnight... you, know moment its a new year... did I do it right? Double check the "examples"

...and tell me your birthday!
...This has been a recording.

User avatar
DTRemenak
General
General
Posts: 625
Joined: Thu Jan 16, 2003 4:54 am
Location: U.S.
Contact:

Post by DTRemenak » Sun Sep 18, 2005 5:10 pm

Yes, the new year entry is correct, as are the examples.

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Sun Sep 18, 2005 6:32 pm

ok, I know you are probably getting tired of dealing with this plugin and me in general...

I'm thinking this error is an API one. I *just* compiled CVS, and loaded the plugin with the EXACT crontab posted above... which was working fine yesterday...

It does the first line of the crontab correctly... but it wants to /say the whole file as per the first line...

I cant explain it right... check my screenshot & see what I mean


Image
...This has been a recording.

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

UPDATE

Post by I_Died_Once » Fri Oct 21, 2005 7:15 pm

OK - Update...

I have managed to fix this plugin. Woot. Now, the guys in IRC all think I am out of my damn mind - thats ok, its not a first. WHat kills me the most is I have been asking, begging, pleading - trying like hell to get an updated version of this plugin to current API... I come up with my fix, say something in IRC, and the quick responce "oh, you could have done THIS the whole time" - thanks alot, guys. Wait 'til I hack a quick custom fix for myself to tell how it should have been fixed in the first place...

OK, in the source - there is a file - bzfscron.cpp

Open it with your favorite text editor, and on the line at the top where it has

Code: Select all

# include "bzfsAPI.h"
I edited it to reflect where the bzfsAPI.h currently is, as in the whole path. For me, it came out to

Code: Select all

# include </home/death/bzflag/include/bzfsAPI.h>
I also copied the bzfsAPI.h to the bzfscron source directory.

I'm not sure which, if either, did the trick - but the trick is done.

I then manually deleted the .o and .so files and ran "make clean" then "make"

The plugin compiled successfully, and carries out a full crontab with no issue.

Now, I know someone is gonna say that if that is all I did, then it wasnt broken to begin with. Well, I cant answer to that. I do know that several, several times, I have ran "make clean" and "make" several times over on the srouce. I've re-downloaded the source several times over, extracted to different directories and went about this from several different directions. I know one might think I was working with an old file and just didnt know it - but if a plugin is already created, and I run "make" it tells you "nothing to do for make"

So, supposedly, all I did was update header informating unique to my system. So, I dunno. But what I did worked, there is no disputing that... I tried tried and tried to great lengths to get this to work in the past, moving the directory, deleting, and recompiling - relinking the .conf file and still nothing. Yet, I update the header, make, and voila. It works.
...This has been a recording.

User avatar
I_Died_Once
Special Forces
Special Forces
Posts: 635
Joined: Sun Nov 28, 2004 5:27 pm
Location: The Dark Side
Contact:

Post by I_Died_Once » Fri Oct 28, 2005 2:54 pm

When making with current CVS, I get this:

Code: Select all

inux:/home/death/bzflag/plugins/bzfscron # make
g++ -g -fPIC -frtti -I../../include -O   -c -o bzfscron.o bzfscron.cpp
bzfscron.cpp: In member function `bool CronManager::connect3()':
bzfscron.cpp:310: error: `bz_setPlayerAdmin' undeclared (first use this
   function)
bzfscron.cpp:310: error: (Each undeclared identifier is reported only once for
   each function it appears in.)
make: *** [bzfscron.o] Error 1
linux:/home/death/bzflag/plugins/bzfscron # 
...This has been a recording.

User avatar
optic delusion
Special Forces
Special Forces
Posts: 998
Joined: Sat Sep 25, 2004 2:29 pm
Location: Planet MoFo
Contact:

Warning

Post by optic delusion » Fri Oct 28, 2005 5:11 pm

Look Out! I am going to jump into this with may Mac 10.3. I'm staying with API 12 for now. I just might be able to mod the makefile correctly, myself. Anybody got any hints.
I already have alot of info, and sample files from Vader. If I can build it, I should be OK.
Take a look at my Defender game mode concept.

Thinking is not an automatic process. A man can choose to think or to let his mind stagnate, or he can choose actively to turn against his intelligence, to evade his knowledge, to subvert his reason. If he refuses to think, he courts disaster: he cannot with impunity reject his means of perceiving reality.

Post Reply