-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.lua
59 lines (45 loc) · 1.11 KB
/
kernel.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package.path = package.path .. ""
require('players/player')
require('players/player_table')
require('events/event_queue')
require('util/debug')
require('items')
require('zone')
function boot_signal()
db_begin("data/world.db")
autoload_zones()
end
function connect_signal(fd, addr)
local player = mk_player(fd, addr)
register_player(player)
player:boot()
end
function control_signal(fd, text)
local player = lookup_player(fd)
assert(player, "control_signal: unable to find player fd="..fd)
player:take_input(text)
end
function disconnect_signal(fd)
local player = lookup_player(fd)
assert(player, "control_signal: unable to find player fd="..fd)
clear_player(fd)
if player.creature then
tell_room_except(
player:location(),
player.creature,
mk_msg(player.creature:name().." disconnected")
)
end
end
function wake_signal(now)
the_event_queue.each_ready_event(now, function(e)
local f = e.data
f(e.time)
end)
local next_time = the_event_queue.next_time()
if next_time then
return math.ceil((next_time - now)*1000000);
else
return nil
end
end