2 #########################################################################
4 # Copyright (c) 2003 Aymargeddon Development Team
7 # "FROGS" = Framework for Realtime Online Games of Strategy
9 # FROGS is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by the Free
11 # Software Foundation; either version 2 of the License, or (at your option)
14 # FROGS is distributed in the hope that it will be useful, but WITHOUT
15 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc., 675
20 # Mass Ave, Cambridge, MA 02139, USA.
22 ###########################################################################
27 # ./scheduler.pl [conf-parameter]=[value] ...
29 # ./scheduler.pl -DURATION-PRAY=1000 -DURATION-PRODUCE=1000
35 use FROGS::Config qw ($conf);
43 Util::overwrite_config(@ARGV);
49 require $::conf->{-COMMANDS};
51 Util::log("\n$now Scheduler started...",0);
56 # read next using our db connection (complicated due to poor SQL
57 # implemention of MYSQL :-/
58 my $nulldate = $db->quote('0000-00-00 00:00:00'); # TODO: ugly and unportable :-(
59 my $nullcond = "(DONE IS NULL OR DONE=$nulldate)";
63 $db->commit(); # ??? WHY IS THIS NECESSARY TO SEE COMMANDS FROM CLIENTS ???
64 my ($minexec) = $db ->single_select("SELECT min( exec ) FROM COMMAND ".
65 "WHERE $nullcond and EXEC <= NOW()");
66 $minexec = $db ->quote($minexec);
67 my ($id) = $db ->single_select("SELECT min(id) FROM COMMAND ".
68 "WHERE $nullcond and EXEC = $minexec");
69 $id= $db ->quote($id);
70 my $command_entry = $db ->single_hash_select("COMMAND",
71 "EXEC = $minexec and ID = $id ");
73 # delete outdated events
74 $db->delete_from('EVENT','TIME < NOW()') if $::conf->{-DELETE_OLD_EVENTS};
76 if (! defined $command_entry ) {
77 # sleep if no command in db
78 sleep ($::conf->{-SCHEDULER_SLEEP});
81 if($count % $::conf->{-LOG_TIME_IN_LOOP} == 0){
83 Util::log("\n###\n### $now: counted $count loops\n###\n",1);
88 # create command object
89 my $command = $command_entry->{"COMMAND"}->new($command_entry,$db);