Black Knight's Small Cron System for AdminMod (plugin_bk_cron)



 

CONTENTS

  1. Introduction: What is a cron system?
  2. Features: What is the BK Cron System able to do?
  3. Limitations: What is the BK Cron System NOT able to do?
  4. Purposes: What can I do with it?
  5. Installation
  6. Configuration
  7. Commands
  8. Beispiele
  9. Known Bugs
  10. FAQ
  11. Support
  12. ToDo
  13. Thx an
  14. Changelog

Introduction: What is a cron system?

For the linux os there was a need for a system to issue commands at a certain point of time. That is, why the cron system was developed. The main aim was to execute recurring tasks without the need of a user sitting the computer at a certain point of time. The developed concept was highly flexible and easy. Of course, to understand it one has to deal with the syntax first. That may not be that easy in the beginning, but the possibility to generate a complex data flows and tasks with only a few lines makes it very powerful. Any scheduler has to match with this system.
So, a cron system is able to issue preprogammed taskes at different times. It is easy to understand that it would make sense to port it to AdminMod. Of course it can be only a "light" version.

Features: What is the BK Cron System able to do?

  • Able to execute recurring tasks over one year
  • Point of time can be set up by minute, hour, day, month and weekday
  • CVars and commands can be kept over a mapchanges and server crahes or restarts
  • Various points of time for one task by using commata und slashes
  • Interface for editing the schedule.ini (file does not need to be edited by ftp, but can be).
  • log compensation (max. 5 minutes), e.g. in case that the mapchange lasts very long again ;-)
  • A lot of check routines and log messages, which can help in case of mistakes
  • Optional setting of the cvar mp_timeleft every minute, to show the remaining time to the outside

Limitations: What is the BK Cron System NOT able to do?

  • Commata and slashes are not allowed in one time column, in different columns NP!
  • Limited to 50 commands due to less file works.
  • Only 10 commands allowed per column
  • "-" is not implemented.
  • The system brings only few checks for the plausibility of the input
  • It was not designed to show a message every 2 minutes, but you can do so

Purposes: What can I do with it?

  • Changing mapcycles on the base of days, weeks or months
  • Setting up CWs and announce these (recommendation: Englisch v1.2 | short English manual | CW Creator v1.3 German)
  • Changing reserved slots by day time
  • Setting password by day time
  • Advertisements, Information, etc.
  • to be continued...

Installation:

  1. Check if you are running AdminMod 2.50.52 or higher.
  2. Install the plugin in the directory "addons/adminmod/scripts".
  3. Create a schedule.ini in the directory "addons/adminmod/config".
  4. Put "exec addons/adminmod/config/tasks.cfg" at the very end of your server.cfg (This is, where the cvars are kept over the mapchange). If you use the CW Creator be sure to put it BEFORE the entry to the war.cfg. All admin_command line have to be BEHIND these entries.
  5. It is highly recommended to put a "admin_command" command behind the last line. Otherwise the plugin does not start, if nobody is online. You could write: admin_command admin_say Mapstart.
  6. Change the schedule.ini to your needs. This can be done directly or via console. Your choice.
  7. You can aktivate the optional setting of mp_timeleft by issuing the command admin_cron_timeleft 1

Configuration:

The separator is the SPACE (double spaces, tabulators, etc. in the time area will lead to errors, but are allowed in the command area of course)

Example:

* * * * * 1 mp_timelimit 20 delete

  1. Column: Minutes (0-59,*)
  2. Column: Hours (0-23,*)
  3. Column: Days (1-31,*)
  4. Column: Months (1-12,*)
  5. Column: Weekdays (1-7,*) 1=Montag

  6. Column: Cvar (no/yes) (0,1)

  7. Column: The to be executed command
A special feature is column 6. One has to indicate wether it is a cvar or not. If yes (1), this command is going to be written to the tasks.cfg and is going to persist over the mapchange.
In case you want to delete it, you have to write the same task again but appending a "delete".

Example:
0 12 * * * 1 mp_timelimit 20
0 0 * * * 1 mp_timelimit 30 delete

The first task sets the time limit to 20 minutes every day at 12 o'clock (independently from month and weekday). This persits over all mapchanges, whatever set in the server.cfg.
The second task deletes the first task from the tasks.cfg and sets the time limit to 30 minutes. This value is valid until the next mapchange. Afterwards the value from the server.cfg will be vaild, as long as it is defined there.

One task at different points of time:
You want to execute the same task at different points of time. There are two possibilities:

Example for a task issued every quarter of an hour:
0,15,30,45 * * * * 0 say quarter of an hour reached!
or
60/4 * * * * 0 say quarter of an hour reached!

Both examples do the same. But the second always starts at zero!

Execute a adminmod command:
This is easy. Just put a admin_command in front of your command. Once again, an example like shown above:

0,15,30,45 * * * * 0 admin_command quarter of an hour reached!

Executing a lot of commands at one point of time:
Just use the "exec" command. Of course you should have the right file on the server. Furthermore, please note that you can use the exec command as a cvar to persist the values included, but is only one exec command allowed in the tasks.cfg.

Limitations:
  1. Commata and slashes are not allowed in one time column, in different columns NP!
  2. Limited to 50 commands due to less file works. Please note that the number of entries in the schedule.ini is not the same as the number of commands. Let us take a look at the quarter-hour example. This entry produces 4 commands. If you want to calculate the number of commands, you have to multiply the entries in the columns. Same example: 4*1*1*1*1=4 (Joker count as 1).
  3. Only 10 commands allowed per column.
  4. Only one exec command allowed in the tasks.cfg.

Commands:

You need to have the right 65536 to execute these!

admin_cron_add <command>
This command writes a new task to the first free place at the schedule.ini. "Command" must follow the structure of the examplar.

admin_cron_del <line>
Admin_cron_del deletes a specific entry in the schedule.ini. A line number is needed, which could be obtained by admin_cron_list.

admin_cron_edit <line> <command>
Changes the entry of a specific entry in the schedule.ini. Be aware that this always overwrites the whole entry.

admin_cron_forcecheck
This command overwrites the timer and checks if something should be executed. I used this for debuging issues. Because it does not take a lot of space, I kept it.

admin_cron_forceexe <line>
The command admin_cron_forceexe executes a command independently from the point of time. You have to provide the line number of course (see admin_cron_list). This command might be useful after long server outtakes, so you can execute every command which was skipped manually.

admin_cron_list <line>
This command shows the contents of the schedule.ini in steps by ten entries. The parameter is optional. In case you provide a 11, it shows the lines 11-20. Furthermore, you get the line number, which is needed for some of the other commands.

admin_cron_refresh
This should be executed, if the schedule.ini was edited manually. The schedule.ini will be reread then. You can achieve the same by doing a mapchange.

admin_cron_timeleft <0/1>
This command deactivates/activates (0/1) the setting of the mp_timeleft cvar. By activating the current timeleft gets written to this cvar every minute. So, the remaining time can be seen from tools like hlsw or hldm


Beispiele:

Sundaymapcycle:
Supposing we want to do a Sunday-Custummap. Of course, it should work automatically. If you set mapcyclefile in your server.cfg, the tasks would be:

0 0 * * 7 1 mapcyclefile sunmapcycle.txt
0 0 * * 1 1 mapcyclefile mapcycle.txt delete

The first task will be executed every sunday (7) at 0:00 setting mapcyclefile to sunmapcycle.txt and writing this to the tasks.cfg. The value of mapcyclefile will therefore remain in case of a mapchange.
The second task will be executed every monday (1) at 0:00 setting mapcyclefile back to mapcycle.txt and deleting it from the tasks.cfg. After the next mapchange, the value in the server.cfg will be set (therefore you already set this value).

If no mapcyclefile is set in the server.cfg, you can handle that a little different, although the first variant will works, too:

0 0 * * 7 0 mapcyclefile sunmapcycle.txt
0 0 * * 1 0 mapcyclefile mapcycle.txt

Because no value is set in the server.cfg, it remains in case of a mapchange. It is valid until the next setting, server crash or restart. If the server crashes during the sunday it would switch back to mapcycle.txt on restart. That is, why I recommend using variant 1.

Daily mapcycle:
It may be that you want to change the mapcycle on a daily basis:

0 0 * * 1 1 mapcyclefile monmapcycle.txt
0 0 * * 2 1 mapcyclefile tuemapcycle.txt
0 0 * * 3 1 mapcyclefile wedmapcycle.txt
0 0 * * 4 1 mapcyclefile thumapcycle.txt
0 0 * * 5 1 mapcyclefile frimapcycle.txt
0 0 * * 6 1 mapcyclefile satmapcycle.txt
0 0 * * 7 1 mapcyclefile sunmapcycle.txt

You can leave out "delete", because only one entry of each cvar can exist in the tasks.cfg and this gets overwritten.

Changing mapcycle 2 times a month:

0 0 1 * * 1 mapcyclefile mapcycle1.txt
0 0 15 * * 1 mapcyclefile mapcycle2.txt

The mapcycle is changed on every first and fifteenth of the month.

Announcing clanwar:
If you have a public server, of course you would dislike to immediately kick everybody without warning. So an announcement would be a nice thing:

40,45,50,55 19 * * * 0 admin_command admin_csay Clanwar at 8 PM!

This task executes a csay every 5 minutes from 19:40 until 19:55. Instead of the asterisk you can use a real date, so in case you forgot to delete this entry, it would not display on the next day:

40,45,50,55 19 4 1 * 0 admin_command admin_csay Clanwar at 8 PM!

This entry is only valid on the 4th of January.

Starting the clanwar:
Of course you can also load the war settings:

0 20 * * * 1 exec cw.cfg
0 23 * * * 1 exec server.cfg delete

The war settings are loaded from 8-11 PM. Unfortunately, the plugin does not know about the end of the war. That is, why I recommend using the CW Creator v1.2:

0 20 * * * 0 admin_command admin_war_set [WING] [-+MfG+-] password de_dust de_dust2 esl.cfg

The war can be ended anytime you use admin_war_end. You just have to delete the set-entry.

Announcement of Friday the 13th:
OK, it is not really a useful example, but it should give an idea, what can be done with this plugin:

0 0 13 * 5 0 admin_command admin_tsay Friday the 13th.^nGood luck!

Every Friday the 13th at 12 PM, this command is issued.


Known Bugs:

  • The lag compensation does not know about the length of each month (it always asumes the 31.). In case of a lag compensation at the first of a month between 0:00 und 0:03, this might cause a small problem. OK, this is a very, very, rare case. The programming expense is too high. It is not worth the work. ;-)
  • At the first start of the plugin, you will see the lag compensation in the logs. Do not worry about it, it is due to the missing vault.ini entry. This should do only few or no problems at all. I mentioned it for the sake of completeness.
  • The display in admin_cron_list is limited to 186 letter per line. Those who need more should rethink, what they are doing. ;-)

FAQ:

  • Where to find the latest version? - Download here
  • How does my example has to look like? - Please, read the examples carefully. Then ask again! ;-)

Support:

ToDo:

  • Nothing now

Thanks to:

  • my clan colleague Sir Drink a lot for his incredible patience, the helpful discussions, his stimulating working assiduity and for my ego, because he did not understand my code. ;-)
  • Rinde for making some remark regarding good programming.
  • my beta testers hal, DarkEyes und Hoon!x.
  • the rest of my clan, although neither they will ever read this nor they are interested (main point: it works).
    Visit: Homepage | WAP | Server-Stats | Gameserver: wing-csserver.skyfall.de:27015
  • the AdminMod beta team, from whom I still learn a lot.
  • daRope because, although he does not play anymore, still works on AdminMod.
  • anybody, who came that far reading my English. I apologize for that. ;-)

Changelog

v1.02
Fix: If a quotation mark is the last character, this character would not be read from the schedule.ini. No real issue, but does not look nice. (Bug found by Aufnahmeleiter)
v1.01 (never published)
Fix: Removing workaround for readfile(), because the bug was removed in the beta versions. Thx to daRope.
v1.0
fix: Too long log messages get truncated
new: Readme includes examples
fix: Some minor code changes
vb1.0 RC2
fix: Workaround for a bug in filesize. To long lines in the schedule.ini caused a wrong filesize.
fix: Problems solved displaying lines by admin_cron_list. Lines are now wrapped.
vb1.0 RC1
new: user interface
new: lag compensation
new: setting timeleft
new: readme files
new: variable-check
vb1.0
First published beta version