forked from pikdum/thistle_tea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.ex
88 lines (73 loc) · 2.26 KB
/
application.ex
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
defmodule ThistleTea.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
# these are the defaults anyways
@handler_options %{
backlog: 1024,
nodelay: true,
send_timeout: 30_000,
send_timeout_close: true,
reuseaddr: true
}
@auth_port 3724
@game_port 8085
use Application
require Logger
def setup_database do
# in memory for now, so need to re-seed on startup
Memento.Table.create!(ThistleTea.Account)
ThistleTea.Account.register("pikdum", "pikdum")
ThistleTea.Account.register("test", "test")
Enum.each(1..10, fn i ->
ThistleTea.Account.register("test#{i}", "test#{i}")
end)
Memento.Table.create!(ThistleTea.Character)
end
@impl true
def start(_type, _args) do
children =
[
ThistleTea.Telemetry,
{Registry, keys: :duplicate, name: ThistleTea.ChatChannel},
ThistleTea.DBC,
ThistleTea.Mangos,
ThistleTea.MobSupervisor,
ThistleTea.GameObjectSupervisor,
{ThousandIsland,
port: @auth_port, handler_module: ThistleTea.Auth, handler_options: @handler_options},
{ThousandIsland,
port: @game_port, handler_module: ThistleTea.Game, handler_options: @handler_options}
]
:ets.new(:session, [:named_table, :public])
:ets.new(:guid_name, [:named_table, :public])
setup_database()
SpatialHash.setup_tables()
:telemetry.attach(
"handle-packet-handler",
[:thistle_tea, :handle_packet, :stop],
&ThistleTea.Telemetry.handle_event/4,
nil
)
:telemetry.attach(
"mob-wake-up-handler",
[:thistle_tea, :mob, :wake_up],
&ThistleTea.Telemetry.handle_event/4,
nil
)
:telemetry.attach(
"mob-try-sleep-handler",
[:thistle_tea, :mob, :try_sleep],
&ThistleTea.Telemetry.handle_event/4,
nil
)
Logger.info("Loading maps...")
map_dir = Application.fetch_env!(:thistle_tea, :map_dir)
Namigator.load(map_dir)
Logger.info("ThistleTea started.")
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: ThistleTea.Supervisor]
Supervisor.start_link(children, opts)
end
end