forked from witeman/openpoker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.erl
196 lines (177 loc) · 7.03 KB
/
schema.erl
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
%%%% Copyright (C) 2005-2008 Wager Labs, SA
%%%%
%%%% THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS
%%%% CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS
%%%% PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF
%%%% THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT
%%%% LAW IS PROHIBITED.
%%%%
%%%% BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT
%%%% AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT
%%%% THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS
%%%% YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE
%%%% OF SUCH TERMS AND CONDITIONS.
%%%%
%%%% Please see LICENSE for full legal details and the following URL
%%%% for a human-readable explanation:
%%%%
%%%% http://creativecommons.org/licenses/by-nc-sa/3.0/us/
%%%%
-module(schema).
%%%
%%% Database schema
%%%
-export([install/1, install/0, populate/0]).
-include("schema.hrl").
-include("common.hrl").
-include("pp.hrl").
install() ->
install([node()]).
install(Nodes) when is_list(Nodes) ->
mnesia:stop(),
mnesia:delete_schema(Nodes),
catch(mnesia:create_schema(Nodes)),
db:start(), %% 为什么这样命名?上面是mnesia:stop()!
%% 这个结构不如我的_mnesia.erl里面创建表的方法好
install_counter(Nodes),
install_player_info(Nodes),
install_player(Nodes),
install_balance(Nodes),
install_inplay(Nodes),
install_game_xref(Nodes),
install_cluster_config(Nodes),
install_game_config(Nodes),
install_tourney_config(Nodes),
%% 创建些房间的信息
populate(),
%% 重置Counter的信息
reset_counters(),
ok.
install_player_info(Nodes) ->
%% static player info
{atomic, ok} =
mnesia:create_table(tab_player_info,
[
{disc_copies, Nodes},
{index, [nick]},
{type, set},
{attributes, record_info(fields, tab_player_info)}
]).
install_player(Nodes) ->
%% player
{atomic, ok} =
mnesia:create_table(tab_player,
[
{ram_copies, Nodes},
{type, set},
{attributes, record_info(fields, tab_player)}
]).
install_balance(Nodes) ->
{atomic, ok} =
mnesia:create_table(tab_balance,
[
{disc_copies, Nodes},
{type, set},
{attributes, record_info(fields, tab_balance)}
]).
install_inplay(Nodes) ->
{atomic, ok} =
mnesia:create_table(tab_inplay,
[
{disc_copies, Nodes},
{type, set},
{attributes, record_info(fields, tab_inplay)}
]).
install_game_xref(Nodes) ->
%% online game
{atomic, ok} =
mnesia:create_table(tab_game_xref,
[
{ram_copies, Nodes},
{type, set},
{attributes, record_info(fields, tab_game_xref)}
]).
install_cluster_config(Nodes) ->
%% cluster configuration
{atomic, ok} =
mnesia:create_table(tab_cluster_config,
[
{disc_copies, Nodes},
{type, set},
{attributes, record_info(fields, tab_cluster_config)}
]),
Conf = #tab_cluster_config {
id = 0,
mnesia_masters = Nodes,
test_game_pass = <<"@!%#%2E35D$%#$^">>
},
F = fun() -> mnesia:write(Conf) end,
{atomic, ok} = mnesia:transaction(F).
install_game_config(Nodes) ->
{atomic, ok} =
mnesia:create_table(tab_game_config,
[
{disc_copies, Nodes},
{type, set},
{attributes, record_info(fields, tab_game_config)}
]).
install_tourney_config(Nodes) ->
{atomic, ok} =
mnesia:create_table(tab_tourney_config,
[
{disc_copies, Nodes},
{type, set},
{attributes, record_info(fields, tab_tourney_config)}
]).
install_counter(Nodes) ->
%% counter
{atomic, ok} =
mnesia:create_table(tab_counter,
[
{disc_copies, Nodes},
{type, set},
{attributes, record_info(fields, tab_counter)}
]).
populate() ->
%% 创建tab_game_config table 的一条记录
g:setup(?GT_TEXAS_HOLDEM, 9,
#limit{ type = ?LT_FIXED_LIMIT, low = 1, high = 2, min = 20, max = 200},
?START_DELAY, ?SLOW_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 9,
#limit{ type = ?LT_FIXED_LIMIT, low = 1, high = 2, min = 20, max = 200},
?START_DELAY, ?FAST_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 5,
#limit{ type = ?LT_FIXED_LIMIT, low = 1, high = 2, min = 20, max = 200},
?START_DELAY, ?SLOW_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 5,
#limit{ type = ?LT_FIXED_LIMIT, low = 1, high = 2, min = 20, max = 200},
?START_DELAY, ?FAST_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 9,
#limit{ type = ?LT_FIXED_LIMIT, low = 2, high = 4, min = 40, max = 400},
?START_DELAY, ?SLOW_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 9,
#limit{ type = ?LT_FIXED_LIMIT, low = 2, high = 4, min = 40, max = 400},
?START_DELAY, ?FAST_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 5,
#limit{ type = ?LT_FIXED_LIMIT, low = 2, high = 4, min = 40, max = 400},
?START_DELAY, ?SLOW_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 5,
#limit{ type = ?LT_FIXED_LIMIT, low = 2, high = 4, min = 40, max = 400},
?START_DELAY, ?FAST_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 9,
#limit{ type = ?LT_FIXED_LIMIT, low = 5, high = 10, min = 50, max = 1000},
?START_DELAY, ?SLOW_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 9,
#limit{ type = ?LT_FIXED_LIMIT, low = 5, high = 10, min = 50, max = 1000},
?START_DELAY, ?FAST_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 5,
#limit{ type = ?LT_FIXED_LIMIT, low = 5, high = 10, min = 50, max = 1000},
?START_DELAY, ?SLOW_PLAYER_TIMEOUT, 50),
g:setup(?GT_TEXAS_HOLDEM, 5,
#limit{ type = ?LT_FIXED_LIMIT, low = 5, high = 10, min = 50, max = 1000},
?START_DELAY, ?FAST_PLAYER_TIMEOUT, 50).
reset_counters()->
counter:reset(game),
counter:reset(player),
counter:reset(inplay_xref),
ok.