Annotate

core/hostmanager.lua @ 569:5216efe6088b

Add hostmanager, and eventmanager
author Matthew Wild <mwild1@gmail.com>
date Sat, 06 Dec 2008 03:41:49 +0000
child 575:428c951d0a33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
569
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 hosts = {};
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local hosts = hosts;
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local configmanager = require "core.configmanager";
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local eventmanager = require "core.eventmanager";
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local pairs = pairs;
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 module "hostmanager"
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local function load_enabled_hosts(config)
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local defined_hosts = config or configmanager.getconfig();
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 for host, host_config in pairs(defined_hosts) do
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 activate(host, host_config);
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 eventmanager.add_event_hook("server-starting", load_enabled_hosts);
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 function activate(host, host_config)
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} };
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 eventmanager.fire_event("host-activated", host, host_config);
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 function deactivate(host)
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local host_session = hosts[host];
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 eventmanager.fire_event("host-deactivating", host, host_session);
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 -- Disconnect local users, s2s connections
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 for user, session_list in pairs(host_session.sessions) do
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 for resource, session in pairs(session_list) do
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 session:close("host-gone");
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 -- Components?
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 hosts[host] = nil;
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 eventmanager.fire_event("host-deactivated", host);
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 function getconfig(name)
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49