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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
--
-- table: `tmw_accounts`
--
CREATE TABLE IF NOT EXISTS `tmw_accounts` (
`id` int(10) unsigned NOT NULL auto_increment,
`username` varchar(64) NOT NULL,
`password` varchar(64) NOT NULL,
`email` varchar(32) NOT NULL,
`level` tinyint(3) unsigned NOT NULL,
`banned` int(10) unsigned NOT NULL,
`registration` int(10) unsigned NOT NULL,
`lastlogin` int(10) unsigned NOT NULL,
--
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_characters`
--
CREATE TABLE IF NOT EXISTS `tmw_characters` (
`id` int(10) unsigned NOT NULL auto_increment,
`user_id` int(10) unsigned NOT NULL,
`name` varchar(32) NOT NULL,
--
`gender` tinyint(3) unsigned NOT NULL,
`hair_style` tinyint(3) unsigned NOT NULL,
`hair_color` tinyint(3) unsigned NOT NULL,
`level` tinyint(3) unsigned NOT NULL,
`char_pts` smallint(5) unsigned NOT NULL,
`correct_pts` smallint(5) unsigned NOT NULL,
`money` int(10) unsigned NOT NULL,
-- location on the map
`x` smallint(5) unsigned NOT NULL,
`y` smallint(5) unsigned NOT NULL,
`map_id` tinyint(3) unsigned NOT NULL,
-- attributes
`str` smallint(5) unsigned NOT NULL,
`agi` smallint(5) unsigned NOT NULL,
`dex` smallint(5) unsigned NOT NULL,
`vit` smallint(5) unsigned NOT NULL,
`int` smallint(5) unsigned NOT NULL,
`will` smallint(5) unsigned NOT NULL,
--
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`)
REFERENCES `tmw_accounts` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_char_skills`
--
CREATE TABLE IF NOT EXISTS `tmw_char_skills` (
`char_id` int(10) unsigned NOT NULL,
`skill_id` smallint(5) unsigned NOT NULL,
`skill_exp` smallint(5) unsigned NOT NULL,
--
PRIMARY KEY (`char_id`, `skill_id`),
FOREIGN KEY (`char_id`)
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8;
--
-- table: `tmw_char_status_effects`
--
CREATE TABLE IF NOT EXISTS `tmw_char_status_effects` (
`char_id` int(10) unsigned NOT NULL,
`status_id` smallint(5) unsigned NOT NULL,
`status_time` int(10) signed NOT NULL,
--
PRIMARY KEY (`char_id`, `status_id`),
FOREIGN KEY (`char_id`)
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGING=InnoDB
DEFAULT CHARSET=utf8;
--
-- table: `tmw_items`
--
CREATE TABLE IF NOT EXISTS `tmw_items` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`description` varchar(255) NOT NULL,
`image` varchar(50) NOT NULL,
`weight` smallint(5) unsigned NOT NULL,
`itemtype` varchar(50) NOT NULL,
`effect` varchar(100) NULL,
`dyestring` varchar(50) NULL,
--
PRIMARY KEY (`id`),
KEY `itemtype` (`itemtype`)
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_item_instances`
--
CREATE TABLE IF NOT EXISTS `tmw_item_instances` (
`item_id` int(10) unsigned NOT NULL auto_increment,
`itemclass_id` int(10) unsigned NOT NULL,
`amount` tinyint(3) unsigned NOT NULL,
--
PRIMARY KEY (`item_id`),
FOREIGN KEY (`itemclass_id`)
REFERENCES `tmw_items` (`id`)
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_item_attributes`
--
CREATE TABLE IF NOT EXISTS `tmw_item_attributes` (
`attribute_id` int(10) unsigned NOT NULL auto_increment,
`item_id` int(10) unsigned NOT NULL,
`attribute_class` tinyint(3) unsigned NOT NULL,
`attribute_value` varchar(500) NULL,
--
PRIMARY KEY (`attribute_id`),
FOREIGN KEY (`item_id`)
REFERENCES `tmw_item_instances` (`item_id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_inventories`
-- todo: remove class_id and amount and reference on tmw_item_instances
--
CREATE TABLE IF NOT EXISTS `tmw_inventories` (
`id` int(10) unsigned NOT NULL auto_increment,
`owner_id` int(10) unsigned NOT NULL,
`slot` tinyint(3) unsigned NOT NULL,
`class_id` int(10) unsigned NOT NULL,
`amount` tinyint(3) unsigned NOT NULL,
--
PRIMARY KEY (`id`),
UNIQUE KEY `owner_id` (`owner_id`, `slot`),
FOREIGN KEY (`owner_id`)
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_world_states`
--
CREATE TABLE IF NOT EXISTS `tmw_world_states` (
`state_name` varchar(100) NOT NULL,
`map_id` int(10) unsigned default NULL,
`value` varchar(255) default NULL,
`moddate` int(10) unsigned NOT NULL,
--
KEY `state_name` (`state_name`)
) ENGINE=InnoDB
DEFAULT CHARSET=utf8;
INSERT INTO tmw_world_states VALUES('accountserver_startup',NULL,NULL,UNIX_TIMESTAMP());
INSERT INTO tmw_world_states VALUES('accountserver_version',NULL,NULL,UNIX_TIMESTAMP());
INSERT INTO tmw_world_states VALUES('database_version', NULL,'3', UNIX_TIMESTAMP());
--
-- table: `tmw_guilds`
--
CREATE TABLE IF NOT EXISTS `tmw_guilds` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(35) NOT NULL,
--
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_guild_members`
--
CREATE TABLE IF NOT EXISTS `tmw_guild_members` (
`guild_id` int(10) unsigned NOT NULL,
`member_id` int(10) unsigned NOT NULL,
`rights` int(10) unsigned NOT NULL,
--
PRIMARY KEY (`guild_id`, `member_id`),
FOREIGN KEY (`guild_id`)
REFERENCES `tmw_guilds` (`id`)
ON DELETE CASCADE,
FOREIGN KEY (`member_id`)
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8;
--
-- table: `tmw_quests`
--
CREATE TABLE IF NOT EXISTS `tmw_quests` (
`owner_id` int(10) unsigned NOT NULL,
`name` varchar(100) NOT NULL,
`value` varchar(200) NOT NULL,
--
PRIMARY KEY (`owner_id`, `name`),
FOREIGN KEY (`owner_id`)
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8;
--
-- table: `tmw_auctions`
--
CREATE TABLE IF NOT EXISTS `tmw_auctions` (
`auction_id` int(10) unsigned NOT NULL auto_increment,
`auction_state` tinyint(3) unsigned NOT NULL,
`char_id` int(10) unsigned NOT NULL,
`itemclass_id` int(10) unsigned NOT NULL,
`amount` int(10) unsigned NOT NULL,
`start_time` int(10) unsigned NOT NULL,
`end_time` int(10) unsigned NOT NULL,
`start_price` int(10) unsigned NOT NULL,
`min_price` int(10) unsigned NULL,
`buyout_price` int(10) unsigned NULL,
`description` varchar(255) NULL,
--
PRIMARY KEY (`auction_id`),
KEY (`auction_state`),
KEY (`itemclass_id`),
KEY (`char_id`),
FOREIGN KEY (`char_id`)
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_auction_bids`
--
CREATE TABLE IF NOT EXISTS `tmw_auction_bids` (
`bid_id` int(10) unsigned NOT NULL auto_increment,
`auction_id` int(10) unsigned NOT NULL,
`char_id` int(10) unsigned NOT NULL,
`bid_time` int(10) unsigned NOT NULL,
`bid_price` int(10) unsigned NOT NULL,
--
PRIMARY KEY (`bid_id`),
KEY (`auction_id`),
KEY (`char_id`),
FOREIGN KEY (`char_id`)
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_post`
--
CREATE TABLE IF NOT EXISTS `tmw_post` (
`letter_id` int(10) unsigned NOT NULL auto_increment,
`sender_id` int(10) unsigned NOT NULL,
`receiver_id` int(10) unsigned NOT NULL,
`letter_type` int(5) unsigned NOT NULL,
`expiration_date` int(10) unsigned NOT NULL,
`sending_date` int(10) unsigned NOT NULL,
`letter_text` TEXT NULL,
--
PRIMARY KEY (`letter_id`),
INDEX `fk_letter_sender` (`sender_id` ASC) ,
INDEX `fk_letter_receiver` (`receiver_id` ASC) ,
--
FOREIGN KEY (`sender_id` )
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE,
FOREIGN KEY (`receiver_id` )
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGINE = InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_post_attachements`
--
CREATE TABLE IF NOT EXISTS `tmw_post_attachments` (
`attachment_id` int(10) unsigned NOT NULL auto_increment,
`letter_id` int(10) unsigned NOT NULL,
`item_id` int(10) unsigned NOT NULL,
--
PRIMARY KEY (`attachment_id`) ,
INDEX `fk_attachment_letter` (`letter_id` ASC) ,
INDEX `fk_attachment_item` (`item_id` ASC),
--
FOREIGN KEY (`letter_id` )
REFERENCES `tmw_post` (`letter_id`)
ON DELETE CASCADE,
FOREIGN KEY (`item_id` )
REFERENCES `tmw_item_instances` (`item_id`)
ON DELETE RESTRICT
) ENGINE = InnoDB
DEFAULT CHARSET=utf8
AUTO_INCREMENT=1 ;
--
-- table: `tmw_online_list`
--
CREATE TABLE IF NOT EXISTS `tmw_online_list` (
`char_id` int(10) unsigned NOT NULL,
`login_date` int(10) NOT NULL,
--
PRIMARY KEY (`char_id`),
FOREIGN KEY (`char_id`)
REFERENCES `tmw_characters` (`id`)
ON DELETE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=utf8 ;
-- create a view to show more details about online users
CREATE VIEW tmw_v_online_chars
AS
SELECT l.char_id as char_id,
l.login_date as login_date,
c.user_id as user_id,
c.name as name,
c.gender as gender,
c.level as level,
c.map_id as map_id
FROM tmw_online_list l
JOIN tmw_characters c
ON l.char_id = c.id;
CREATE TABLE IF NOT EXISTS `tmw_transactions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`char_id` int(11) NOT NULL,
`action` int(11) NOT NULL,
`message` text,
`time` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
AUTO_INCREMENT=0 ;
|