aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Core/Core.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MasterServer/Core/Core.pm')
-rwxr-xr-xlib/MasterServer/Core/Core.pm99
1 files changed, 57 insertions, 42 deletions
diff --git a/lib/MasterServer/Core/Core.pm b/lib/MasterServer/Core/Core.pm
index a20172c..3f99a3a 100755
--- a/lib/MasterServer/Core/Core.pm
+++ b/lib/MasterServer/Core/Core.pm
@@ -7,7 +7,7 @@ use AnyEvent;
use Exporter 'import';
use DBI;
-our @EXPORT = qw | halt main |;
+our @EXPORT = qw | halt select_database_type main |;
################################################################################
## Handle shutting down the program in case a fatal error occurs.
@@ -34,6 +34,19 @@ sub halt {
}
################################################################################
+## Set up the database connection
+################################################################################
+sub select_database_type {
+ my $self = shift;
+
+ # Connect to database
+ $self->{dbh} = $self->database_login();
+
+ # and test whether we succeeded.
+ $self->halt() unless (defined $self->{dbh});
+}
+
+################################################################################
## Initialize all processes and start various functions
################################################################################
sub main {
@@ -42,67 +55,69 @@ sub main {
# condition var prevents or allows the program from ending
$self->{must_halt} = AnyEvent->condvar;
- # determine version info
+ # force version info
$self->version();
+ # print startup
+ print "Running...\n";
+
# keep several objects alive outside their original scope
$self->{scope} = ();
# startup procedure information
+ $self->log("info", "");
+ $self->log("info", "");
$self->log("info", "333networks Master Server Application.");
- $self->log("info", "Build: $self->{build_type}");
- $self->log("info", "Version: $self->{build_version}");
- $self->log("info", "Written by $self->{build_author}");
- $self->log("info", "Logs are written to $self->{log_dir}");
+ $self->log("info", "Hostname: $self->{masterserver_hostname}");
+ $self->log("info", "Build: $self->{build_type}");
+ $self->log("info", "Version: $self->{build_version}");
+ $self->log("info", "Author: $self->{build_author}");
+ $self->log("info", "Logs: $self->{log_dir}");
# determine the type of database and load the appropriate module
- {
- # read from login
- my @db_type = split(':', $self->{dblogin}->[0]);
-
- # format supported?
- if ( "Pg SQLite mysql" =~ m/$db_type[1]/i) {
-
- # inform us what DB we try to load
- $self->log("load","Loading $db_type[1] database module.");
-
- # load dbd and tables/queries for this db type
- MasterServer::load_recursive("MasterServer::Database::$db_type[1]");
-
- # Connect to database
- $self->{dbh} = $self->database_login();
-
- # and test whether we succeeded.
- $self->halt() unless (defined $self->{dbh});
- }
- else {
- # raise error and halt
- $self->log("fatal", "The masterserver could not determine the chosen database type.");
- $self->halt();
- }
- }
+ $self->select_database_type();
+
+ #
+ # Prepare necessary tasks for running the masterserver
+ #
# (re)load the list with ciphers from the config file, into the database
$self->load_ciphers();
+ # set first run flag to avoid ignoring servers after downtime
+ $self->{firstrun} = undef;
+ $self->{firstruntime} = time;
+
+ ###
+ #
+ # activate all schedulers and functions
+ #
+ ###
+
+ #
+ # Timers
+ #
+ # tasks that are executed once or twice per hour
+ $self->{scope}->{long_periodic_tasks} = $self->long_periodic_tasks();
+ #
+ # tasks that are executed every few minutes
+ $self->{scope}->{short_periodic_tasks} = $self->short_periodic_tasks();
+ #
+ # tasks that are executed every few milliseconds
+ $self->{scope}->{udp_ticker} = $self->udp_ticker();
+
+ #
+ # Network listeners
+ #
# start the listening service (listen for UDP beacons)
$self->{scope}->{beacon_catcher} = $self->beacon_catcher();
-
- # start the beacon checker service (query entries from the pending list)
- $self->{scope}->{beacon_checker} = $self->beacon_checker() if ($self->{beacon_checker_enabled});
-
+ #
# provide server lists to clients with the browser host server
$self->{scope}->{browser_host} = $self->browser_host();
- # query other masterserver applets to get more server addresses
- $self->{scope}->{ucc_applet_query} = $self->ucc_applet_query_scheduler() if ($self->{master_applet_enabled});
-
- # synchronize with 333networks-based masterservers
- $self->{scope}->{syncer_scheduler} = $self->syncer_scheduler() if ($self->{sync_enabled});
-
# all modules loaded. Running...
$self->log("info", "All modules loaded. Masterserver is now running.");
-
+
# prevent main program from ending prematurely
$self->{must_halt}->recv;
}