· 7 years ago · Sep 10, 2018, 11:49 PM
1<?php
2define('DATABASE_NAME', 'ripple');
3define('DATABASE_USER', 'DB_USR');
4define('DATABASE_PASS', 'DB_PSW');
5define('DATABASE_HOST', 'localhost');
6define('DATABASE_WHAT', 'host');
7
8$db = new DBPDO();
9
10$q = <<<'ENDOFMYSQLQUERY'
11SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
12CREATE DATABASE IF NOT EXISTS `ripple` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
13USE `ripple`;
14
15CREATE TABLE IF NOT EXISTS `2fa` (
16 `userid` int(11) NOT NULL,
17 `ip` int(11) NOT NULL,
18 PRIMARY KEY (`userid`)
19) ENGINE=InnoDB DEFAULT CHARSET=latin1;
20
21CREATE TABLE IF NOT EXISTS `2fa_telegram` (
22 `id` int(11) NOT NULL AUTO_INCREMENT,
23 `userid` int(11) NOT NULL,
24 PRIMARY KEY (`id`)
25) ENGINE=InnoDB DEFAULT CHARSET=latin1;
26
27CREATE TABLE IF NOT EXISTS `2fa_totp` (
28 `enabled` tinyint(1) NOT NULL DEFAULT '0',
29 `userid` int(11) NOT NULL,
30 PRIMARY KEY (`userid`)
31) ENGINE=InnoDB DEFAULT CHARSET=latin1;
32
33CREATE TABLE IF NOT EXISTS `achievements` (
34 `id` int(11) NOT NULL AUTO_INCREMENT,
35 `name` varchar(64) NOT NULL,
36 `description` varchar(128) NOT NULL,
37 `icon` varchar(32) NOT NULL,
38 `version` int(11) NOT NULL DEFAULT '0',
39 PRIMARY KEY (`id`)
40) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
41
42CREATE TABLE IF NOT EXISTS `badges` (
43 `id` int(11) NOT NULL AUTO_INCREMENT,
44 `name` varchar(32) NOT NULL,
45 `icon` varchar(32) NOT NULL,
46 PRIMARY KEY (`id`)
47) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
48
49INSERT INTO `badges` (`id`, `name`, `icon`) VALUES
50(1, 'Beta tester 1.5', 'fa-gift'),
51(2, 'None', '');
52
53CREATE TABLE IF NOT EXISTS `bancho_channels` (
54 `id` int(11) NOT NULL AUTO_INCREMENT,
55 `name` varchar(32) NOT NULL,
56 `description` varchar(127) NOT NULL,
57 `public_read` tinyint(4) NOT NULL,
58 `public_write` tinyint(4) NOT NULL,
59 `status` tinyint(4) NOT NULL,
60 `temp` tinyint(1) NOT NULL DEFAULT '0',
61 `hidden` tinyint(1) NOT NULL DEFAULT '0',
62 PRIMARY KEY (`id`)
63) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
64
65INSERT INTO `bancho_channels` (`id`, `name`, `description`, `public_read`, `public_write`, `status`, `temp`, `hidden`) VALUES
66(1, '#osu', 'Main Ripple channel', 1, 1, 1, 0, 0),
67(2, '#announce', 'Announce channel', 1, 0, 1, 0, 0),
68(3, '#admin', 'Admin only channel', 0, 0, 1, 0, 0),
69(4, '#italian', 'Italian community channel', 1, 1, 1, 0, 0),
70(5, '#english', 'English speaking channel', 1, 1, 1, 0, 0);
71
72CREATE TABLE IF NOT EXISTS `bancho_messages` (
73 `id` int(11) NOT NULL AUTO_INCREMENT,
74 `msg_from_userid` int(11) NOT NULL,
75 `msg_from_username` varchar(30) NOT NULL,
76 `msg_to` varchar(32) NOT NULL,
77 `msg` varchar(127) NOT NULL,
78 `time` int(11) NOT NULL,
79 PRIMARY KEY (`id`)
80) ENGINE=InnoDB DEFAULT CHARSET=latin1;
81
82CREATE TABLE IF NOT EXISTS `bancho_private_messages` (
83 `id` int(11) NOT NULL AUTO_INCREMENT,
84 `msg_from_userid` int(11) NOT NULL,
85 `msg_from_username` varchar(30) NOT NULL,
86 `msg_to` varchar(32) NOT NULL,
87 `msg` varchar(127) NOT NULL,
88 `time` int(11) NOT NULL,
89 PRIMARY KEY (`id`)
90) ENGINE=InnoDB DEFAULT CHARSET=latin1;
91
92CREATE TABLE IF NOT EXISTS `bancho_settings` (
93 `id` int(11) NOT NULL AUTO_INCREMENT,
94 `name` varchar(32) NOT NULL,
95 `value_int` int(11) NOT NULL DEFAULT '0',
96 `value_string` varchar(512) NOT NULL,
97 PRIMARY KEY (`id`)
98) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
99
100INSERT INTO `bancho_settings` (`id`, `name`, `value_int`, `value_string`) VALUES
101(1, 'bancho_maintenance', 0, ''),
102(2, 'free_direct', 1, ''),
103(3, 'menu_icon', 0, 'https://i.imgur.com/L61sxgX.png|http://emily.steffen.sexy'),
104(4, 'login_messages', 0, ''),
105(5, 'restricted_joke', 0, ''),
106(6, 'login_notification', 0, 'Welcome to pep.py'),
107(7, 'osu_versions', 0, ''),
108(8, 'osu_md5s', 0, '');
109
110
111CREATE TABLE IF NOT EXISTS `bancho_tokens` (
112 `id` int(11) NOT NULL AUTO_INCREMENT,
113 `token` varchar(16) NOT NULL,
114 `osu_id` int(11) NOT NULL,
115 `latest_message_id` int(11) NOT NULL,
116 `latest_private_message_id` int(11) NOT NULL,
117 `latest_packet_time` int(11) NOT NULL,
118 `latest_heavy_packet_time` int(11) NOT NULL,
119 `joined_channels` varchar(512) NOT NULL,
120 `game_mode` tinyint(4) NOT NULL,
121 `action` int(11) NOT NULL,
122 `action_text` varchar(128) NOT NULL,
123 `kicked` tinyint(4) NOT NULL,
124 PRIMARY KEY (`id`)
125) ENGINE=InnoDB DEFAULT CHARSET=latin1;
126
127CREATE TABLE IF NOT EXISTS `beatmaps` (
128 `id` int(11) NOT NULL AUTO_INCREMENT,
129 `beatmap_id` int(11) NOT NULL DEFAULT '0',
130 `beatmapset_id` int(11) NOT NULL DEFAULT '0',
131 `beatmap_md5` varchar(32) NOT NULL DEFAULT '',
132 `song_name` varchar(128) NOT NULL DEFAULT '',
133 `ar` float NOT NULL DEFAULT '0',
134 `od` float NOT NULL DEFAULT '0',
135 `difficulty_std` float NOT NULL DEFAULT '0',
136 `difficulty_taiko` float NOT NULL DEFAULT '0',
137 `difficulty_ctb` float NOT NULL DEFAULT '0',
138 `difficulty_mania` float NOT NULL DEFAULT '0',
139 `max_combo` int(11) NOT NULL DEFAULT '0',
140 `hit_length` int(11) NOT NULL DEFAULT '0',
141 `bpm` int(11) NOT NULL DEFAULT '0',
142 `ranked` tinyint(4) NOT NULL DEFAULT '0',
143 `latest_update` int(11) NOT NULL DEFAULT '0',
144 `ranked_status_freezed` tinyint(1) NOT NULL DEFAULT '0',
145 `playcount` int(11) NOT NULL DEFAULT '0',
146 `passcount` int(11) NOT NULL DEFAULT '0',
147 `pp_100` int(11) NOT NULL DEFAULT '0',
148 `pp_99` int(11) NOT NULL DEFAULT '0',
149 `pp_98` int(11) NOT NULL DEFAULT '0',
150 `pp_95` int(11) NOT NULL DEFAULT '0',
151 PRIMARY KEY (`id`)
152) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
153
154CREATE TABLE IF NOT EXISTS `beatmaps_names` (
155 `id` int(11) NOT NULL AUTO_INCREMENT,
156 `beatmap_md5` varchar(32) NOT NULL DEFAULT '',
157 `beatmap_name` varchar(256) NOT NULL DEFAULT '',
158 PRIMARY KEY (`id`)
159) ENGINE=InnoDB DEFAULT CHARSET=latin1;
160
161CREATE TABLE IF NOT EXISTS `beta_keys` (
162 `id` int(11) NOT NULL AUTO_INCREMENT,
163 `key_md5` varchar(32) NOT NULL DEFAULT '',
164 `description` varchar(128) NOT NULL DEFAULT '',
165 `allowed` tinyint(4) NOT NULL DEFAULT '0',
166 `public` tinyint(4) NOT NULL DEFAULT '0',
167 PRIMARY KEY (`id`)
168) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
169
170INSERT INTO `beta_keys` (`id`, `key_md5`, `description`, `allowed`, `public`) VALUES
171(1, '110fe4a3830966be01d0b513fcdb4f66', 'betakey', 1, 1);
172
173CREATE TABLE IF NOT EXISTS `cakes` (
174 `id` int(11) NOT NULL AUTO_INCREMENT,
175 `userid` int(11) NOT NULL,
176 `score_id` int(11) NOT NULL,
177 `processes` blob NOT NULL,
178 `detected` json NOT NULL,
179 `flags` int(11) NOT NULL DEFAULT '0',
180 PRIMARY KEY (`id`)
181) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
182
183CREATE TABLE IF NOT EXISTS `discord_roles` (
184 `id` int(11) NOT NULL AUTO_INCREMENT,
185 `userid` int(11) NOT NULL,
186 `discordid` int(11) NOT NULL,
187 `roleid` int(11) NOT NULL,
188 PRIMARY KEY (`id`)
189) ENGINE=InnoDB DEFAULT CHARSET=latin1;
190
191CREATE TABLE IF NOT EXISTS `docs` (
192 `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
193 `doc_name` varchar(255) NOT NULL DEFAULT 'New Documentation File',
194 `doc_contents` mediumtext NOT NULL,
195 `public` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
196 `old_name` varchar(200) DEFAULT NULL,
197 PRIMARY KEY (`id`)
198) ENGINE=MyISAM DEFAULT CHARSET=latin1;
199
200CREATE TABLE IF NOT EXISTS `eggs` (
201 `id` int(11) NOT NULL AUTO_INCREMENT,
202 `type` enum('hash','path','file','title') NOT NULL DEFAULT 'hash',
203 `value` varchar(128) NOT NULL,
204 `tag` varchar(128) NOT NULL,
205 `ban` tinyint(1) NOT NULL DEFAULT '0',
206 `is_regex` tinyint(1) NOT NULL DEFAULT '0',
207 PRIMARY KEY (`id`)
208) ENGINE=InnoDB DEFAULT CHARSET=latin1;
209
210CREATE TABLE IF NOT EXISTS `hw_user` (
211 `id` int(11) NOT NULL AUTO_INCREMENT,
212 `userid` int(11) NOT NULL,
213 `mac` varchar(32) NOT NULL,
214 `unique_id` varchar(32) NOT NULL,
215 `disk_id` varchar(32) NOT NULL,
216 `occurencies` int(11) NOT NULL DEFAULT '0',
217 `activated` tinyint(1) NOT NULL DEFAULT '0',
218 PRIMARY KEY (`id`),
219 UNIQUE KEY `userid` (`userid`)
220) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
221
222CREATE TABLE IF NOT EXISTS `identity_tokens` (
223 `userid` int(11) NOT NULL,
224 `token` varchar(64) NOT NULL,
225 UNIQUE KEY `userid` (`userid`)
226) ENGINE=InnoDB DEFAULT CHARSET=latin1;
227
228CREATE TABLE IF NOT EXISTS `ip_user` (
229 `userid` int(11) NOT NULL,
230 `ip` text NOT NULL,
231 `occurencies` int(11) NOT NULL,
232 UNIQUE KEY `userid` (`userid`)
233) ENGINE=InnoDB DEFAULT CHARSET=latin1;
234
235CREATE TABLE IF NOT EXISTS `irc_tokens` (
236 `userid` int(11) NOT NULL DEFAULT '0',
237 `token` varchar(32) NOT NULL DEFAULT '',
238 UNIQUE KEY `userid` (`userid`)
239) ENGINE=InnoDB DEFAULT CHARSET=latin1;
240
241CREATE TABLE IF NOT EXISTS `leaderboard_ctb` (
242 `position` int(10) UNSIGNED NOT NULL,
243 `user` int(11) NOT NULL,
244 `v` bigint(20) NOT NULL,
245 PRIMARY KEY (`position`)
246) ENGINE=InnoDB DEFAULT CHARSET=latin1;
247
248CREATE TABLE IF NOT EXISTS `leaderboard_mania` (
249 `position` int(10) UNSIGNED NOT NULL,
250 `user` int(11) NOT NULL,
251 `v` bigint(20) NOT NULL,
252 PRIMARY KEY (`position`)
253) ENGINE=InnoDB DEFAULT CHARSET=latin1;
254
255CREATE TABLE IF NOT EXISTS `leaderboard_std` (
256 `position` int(10) UNSIGNED NOT NULL,
257 `user` int(11) NOT NULL,
258 `v` bigint(20) NOT NULL,
259 PRIMARY KEY (`position`)
260) ENGINE=InnoDB DEFAULT CHARSET=latin1;
261
262CREATE TABLE IF NOT EXISTS `leaderboard_taiko` (
263 `position` int(10) UNSIGNED NOT NULL,
264 `user` int(11) NOT NULL,
265 `v` bigint(20) NOT NULL,
266 PRIMARY KEY (`position`)
267) ENGINE=InnoDB DEFAULT CHARSET=latin1;
268
269CREATE TABLE IF NOT EXISTS `main_menu_icons` (
270 `file_id` int(11) NOT NULL AUTO_INCREMENT,
271 `url` varchar(128) NOT NULL,
272 `is_current` tinyint(1) NOT NULL,
273 PRIMARY KEY (`file_id`)
274) ENGINE=InnoDB DEFAULT CHARSET=latin1;
275
276CREATE TABLE IF NOT EXISTS `osin_access` (
277 `scope` int(11) NOT NULL DEFAULT '0',
278 `created_at` int(11) NOT NULL DEFAULT '0',
279 `client` int(11) NOT NULL DEFAULT '0',
280 `extra` int(11) NOT NULL DEFAULT '0'
281) ENGINE=InnoDB DEFAULT CHARSET=latin1;
282
283CREATE TABLE IF NOT EXISTS `osin_client` (
284 `id` int(11) NOT NULL AUTO_INCREMENT,
285 `secret` varchar(64) NOT NULL DEFAULT '',
286 `extra` varchar(127) NOT NULL DEFAULT '',
287 `redirect_uri` varchar(127) NOT NULL DEFAULT '',
288 PRIMARY KEY (`id`)
289) ENGINE=InnoDB DEFAULT CHARSET=latin1;
290
291CREATE TABLE IF NOT EXISTS `osin_client_user` (
292 `client_id` int(11) NOT NULL DEFAULT '0',
293 `user` int(11) NOT NULL DEFAULT '0'
294) ENGINE=InnoDB DEFAULT CHARSET=latin1;
295
296CREATE TABLE IF NOT EXISTS `password_recovery` (
297 `id` int(11) NOT NULL AUTO_INCREMENT,
298 `k` varchar(80) NOT NULL,
299 `u` varchar(30) NOT NULL,
300 `t` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
301 PRIMARY KEY (`id`)
302) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
303
304CREATE TABLE IF NOT EXISTS `privileges_groups` (
305 `id` int(11) NOT NULL AUTO_INCREMENT,
306 `name` varchar(32) NOT NULL,
307 `privileges` int(11) NOT NULL,
308 `color` varchar(32) NOT NULL,
309 PRIMARY KEY (`id`),
310 UNIQUE KEY `name` (`name`)
311) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
312
313INSERT INTO `privileges_groups` (`id`, `name`, `privileges`, `color`) VALUES
314(1, 'Banned', 0, ''),
315(2, 'BAT', 267, ''),
316(3, 'Chat Moderators', 2883911, ''),
317(4, 'Community Manager ', 978427, ''),
318(5, 'Developer', 1043995, ''),
319(6, 'Donor', 7, ''),
320(7, 'God', 1048575, 'primary'),
321(8, 'Normal User', 3, ''),
322(9, 'Pending', 1048576, ''),
323(10, 'Restricted', 2, '');
324
325CREATE TABLE IF NOT EXISTS `profile_backgrounds` (
326 `uid` int(11) NOT NULL,
327 `time` int(11) NOT NULL,
328 `type` int(11) NOT NULL,
329 `value` text NOT NULL,
330 PRIMARY KEY (`uid`)
331) ENGINE=InnoDB DEFAULT CHARSET=latin1;
332
333CREATE TABLE IF NOT EXISTS `rank_requests` (
334 `id` int(11) NOT NULL AUTO_INCREMENT,
335 `userid` int(11) NOT NULL,
336 `bid` int(11) NOT NULL,
337 `type` varchar(8) NOT NULL,
338 `time` int(11) NOT NULL,
339 `blacklisted` tinyint(1) NOT NULL,
340 PRIMARY KEY (`id`),
341 UNIQUE KEY `bid` (`bid`)
342) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
343
344CREATE TABLE IF NOT EXISTS `rap_logs` (
345 `id` int(11) NOT NULL AUTO_INCREMENT,
346 `userid` int(11) NOT NULL,
347 `text` varchar(512) NOT NULL,
348 `datetime` int(11) NOT NULL,
349 `through` varchar(64) NOT NULL,
350 PRIMARY KEY (`id`)
351) ENGINE=InnoDB DEFAULT CHARSET=latin1;
352
353
354CREATE TABLE IF NOT EXISTS `remember` (
355 `id` int(11) NOT NULL AUTO_INCREMENT,
356 `userid` int(11) NOT NULL,
357 `series_identifier` int(11) DEFAULT NULL,
358 `token_sha` varchar(255) DEFAULT NULL,
359 PRIMARY KEY (`id`)
360) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
361
362CREATE TABLE IF NOT EXISTS `reports` (
363 `id` int(11) NOT NULL AUTO_INCREMENT,
364 `name` varchar(128) NOT NULL,
365 `from_username` varchar(32) NOT NULL,
366 `content` varchar(1024) NOT NULL,
367 `type` tinyint(4) NOT NULL,
368 `open_time` varchar(18) NOT NULL,
369 `update_time` varchar(18) NOT NULL,
370 `status` tinyint(4) NOT NULL,
371 `response` varchar(1024) NOT NULL,
372 PRIMARY KEY (`id`)
373) ENGINE=InnoDB DEFAULT CHARSET=latin1;
374
375CREATE TABLE IF NOT EXISTS `scores` (
376 `id` int(11) NOT NULL AUTO_INCREMENT,
377 `beatmap_md5` varchar(32) NOT NULL DEFAULT '',
378 `userid` int(11) NOT NULL,
379 `score` bigint(20) DEFAULT NULL,
380 `max_combo` int(11) NOT NULL DEFAULT '0',
381 `full_combo` tinyint(1) NOT NULL DEFAULT '0',
382 `mods` int(11) NOT NULL DEFAULT '0',
383 `300_count` int(11) NOT NULL DEFAULT '0',
384 `100_count` int(11) NOT NULL DEFAULT '0',
385 `50_count` int(11) NOT NULL DEFAULT '0',
386 `katus_count` int(11) NOT NULL DEFAULT '0',
387 `gekis_count` int(11) NOT NULL DEFAULT '0',
388 `misses_count` int(11) NOT NULL DEFAULT '0',
389 `time` varchar(18) NOT NULL DEFAULT '',
390 `play_mode` tinyint(4) NOT NULL DEFAULT '0',
391 `completed` tinyint(11) NOT NULL DEFAULT '0',
392 `accuracy` float(15,12) DEFAULT NULL,
393 `pp` float DEFAULT '0',
394 PRIMARY KEY (`id`)
395) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
396
397CREATE TABLE IF NOT EXISTS `system_settings` (
398 `id` int(11) NOT NULL AUTO_INCREMENT,
399 `name` varchar(32) NOT NULL,
400 `value_int` int(11) NOT NULL DEFAULT '0',
401 `value_string` varchar(512) NOT NULL,
402 PRIMARY KEY (`id`)
403) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
404
405INSERT INTO `system_settings` (`id`, `name`, `value_int`, `value_string`) VALUES
406(1, 'website_maintenance', 0, ''),
407(2, 'game_maintenance', 0, ''),
408(3, 'website_global_alert', 0, ''),
409(4, 'website_home_alert', 0, ''),
410(5, 'registrations_enabled', 1, '');
411
412CREATE TABLE IF NOT EXISTS `tokens` (
413 `id` int(11) NOT NULL AUTO_INCREMENT,
414 `user` varchar(31) NOT NULL,
415 `privileges` int(11) NOT NULL,
416 `description` varchar(255) NOT NULL,
417 `token` varchar(127) NOT NULL,
418 `private` tinyint(4) NOT NULL,
419 `last_updated` int(11) NOT NULL DEFAULT '0',
420 PRIMARY KEY (`id`)
421) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
422
423CREATE TABLE IF NOT EXISTS `users` (
424 `id` int(11) NOT NULL AUTO_INCREMENT,
425 `username` varchar(30) NOT NULL,
426 `username_safe` varchar(30) NOT NULL,
427 `password_md5` varchar(127) NOT NULL,
428 `salt` varchar(32) NOT NULL,
429 `email` varchar(254) NOT NULL,
430 `register_datetime` int(10) NOT NULL,
431 `rank` tinyint(1) NOT NULL DEFAULT '1',
432 `achievements_version` int(11) NOT NULL DEFAULT '0',
433 `allowed` tinyint(1) NOT NULL DEFAULT '1',
434 `latest_activity` int(10) NOT NULL DEFAULT '0',
435 `silence_end` int(11) NOT NULL DEFAULT '0',
436 `silence_reason` varchar(127) NOT NULL DEFAULT '',
437 `notes` varchar(127) NOT NULL DEFAULT '',
438 `ban_datetime` int(11) NOT NULL DEFAULT '0',
439 `password_version` tinyint(4) NOT NULL DEFAULT '1',
440 `privileges` int(11) NOT NULL,
441 `donor_expire` int(11) NOT NULL DEFAULT '0',
442 `flags` int(11) NOT NULL DEFAULT '0',
443 PRIMARY KEY (`id`)
444) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
445
446CREATE TABLE IF NOT EXISTS `users_achievements` (
447 `user_id` int(11) NOT NULL,
448 `achievement_id` int(11) NOT NULL,
449 `time` int(11) NOT NULL
450) ENGINE=InnoDB DEFAULT CHARSET=latin1;
451
452CREATE TABLE IF NOT EXISTS `users_relationships` (
453 `id` int(11) NOT NULL AUTO_INCREMENT,
454 `user1` int(11) NOT NULL,
455 `user2` int(11) NOT NULL,
456 PRIMARY KEY (`id`)
457) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
458
459CREATE TABLE IF NOT EXISTS `users_stats` (
460 `id` int(11) NOT NULL AUTO_INCREMENT,
461 `username` varchar(30) NOT NULL,
462 `username_aka` varchar(32) NOT NULL DEFAULT '',
463 `user_color` varchar(16) NOT NULL DEFAULT 'black',
464 `user_style` varchar(128) NOT NULL DEFAULT '',
465 `ranked_score_std` bigint(20) DEFAULT NULL,
466 `playcount_std` int(11) NOT NULL DEFAULT '0',
467 `total_score_std` bigint(20) DEFAULT NULL,
468 `replays_watched_std` int(11) UNSIGNED NOT NULL DEFAULT '0',
469 `ranked_score_taiko` bigint(20) DEFAULT NULL,
470 `playcount_taiko` int(11) NOT NULL DEFAULT '0',
471 `total_score_taiko` bigint(20) DEFAULT NULL,
472 `replays_watched_taiko` int(11) NOT NULL DEFAULT '0',
473 `ranked_score_ctb` bigint(20) DEFAULT NULL,
474 `playcount_ctb` int(11) NOT NULL DEFAULT '0',
475 `total_score_ctb` bigint(20) DEFAULT NULL,
476 `replays_watched_ctb` int(11) NOT NULL DEFAULT '0',
477 `ranked_score_mania` bigint(20) DEFAULT NULL,
478 `playcount_mania` int(11) NOT NULL DEFAULT '0',
479 `total_score_mania` bigint(20) DEFAULT NULL,
480 `replays_watched_mania` int(10) UNSIGNED NOT NULL DEFAULT '0',
481 `total_hits_std` int(11) NOT NULL DEFAULT '0',
482 `total_hits_taiko` int(11) NOT NULL DEFAULT '0',
483 `total_hits_ctb` int(11) NOT NULL DEFAULT '0',
484 `total_hits_mania` int(11) NOT NULL DEFAULT '0',
485 `country` char(2) NOT NULL DEFAULT 'XX',
486 `show_country` tinyint(4) NOT NULL DEFAULT '1',
487 `level_std` int(11) NOT NULL DEFAULT '1',
488 `level_taiko` int(11) NOT NULL DEFAULT '1',
489 `level_ctb` int(11) NOT NULL DEFAULT '1',
490 `level_mania` int(11) NOT NULL DEFAULT '1',
491 `avg_accuracy_std` float(15,12) NOT NULL DEFAULT '0.000000000000',
492 `avg_accuracy_taiko` float(15,12) NOT NULL DEFAULT '0.000000000000',
493 `avg_accuracy_ctb` float(15,12) NOT NULL DEFAULT '0.000000000000',
494 `avg_accuracy_mania` float(15,12) NOT NULL DEFAULT '0.000000000000',
495 `pp_std` int(11) NOT NULL DEFAULT '0',
496 `pp_taiko` int(11) NOT NULL DEFAULT '0',
497 `pp_ctb` int(11) NOT NULL DEFAULT '0',
498 `pp_mania` int(11) NOT NULL DEFAULT '0',
499 `badges_shown` varchar(24) NOT NULL DEFAULT '1,0,0,0,0,0',
500 `safe_title` tinyint(4) NOT NULL DEFAULT '0',
501 `userpage_content` mediumtext,
502 `play_style` smallint(6) NOT NULL DEFAULT '0',
503 `favourite_mode` tinyint(4) NOT NULL DEFAULT '0',
504 `custom_badge_icon` varchar(32) NOT NULL DEFAULT '',
505 `custom_badge_name` varchar(32) NOT NULL DEFAULT '',
506 `can_custom_badge` tinyint(1) NOT NULL DEFAULT '0',
507 `show_custom_badge` tinyint(1) NOT NULL DEFAULT '0',
508 PRIMARY KEY (`id`)
509) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
510
511CREATE TABLE IF NOT EXISTS `user_badges` (
512 `user` int(11) NOT NULL,
513 `badge` int(11) NOT NULL,
514 PRIMARY KEY (`user`)
515) ENGINE=InnoDB DEFAULT CHARSET=latin1;
516ENDOFMYSQLQUERY;
517
518$db->execute($q);
519
520function randomString($l) {
521 $c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
522 $res = '';
523 srand((float) microtime() * 1000000);
524 for ($i = 0; $i < $l; $i++) {
525 $res .= $c[rand() % strlen($c)];
526 }
527
528 return $res;
529}
530
531echo "Fokabot doesn't exist. Creating account...\n";
532$plainPassword = randomString(8);
533$options = ['cost' => 9, 'salt' => base64_decode(base64_encode(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)))];
534$md5Password = crypt(md5($plainPassword), '$2y$'.$options['salt']);
535$db->execute("INSERT INTO `users`(`id`, `username`, `username_safe`, `password_md5`, `salt`, `email`, `register_datetime`, `rank`, `allowed`, `latest_activity`, `silence_end`, `silence_reason`, `password_version`, `privileges`, `flags`) VALUES ('999', 'FokaBot', 'fokabot', ?, ?, 'fo@kab.ot', '1452544880', '4', '1', '0', '0', '', 1, 978427, 0);", [$md5Password, base64_encode($options['salt'])]);
536$db->execute("INSERT INTO `users_stats`(`id`, `username`, `username_aka`, `user_color`, `user_style`, `ranked_score_std`, `playcount_std`, `total_score_std`, `replays_watched_std`, `ranked_score_taiko`, `playcount_taiko`, `total_score_taiko`, `replays_watched_taiko`, `ranked_score_ctb`, `playcount_ctb`, `total_score_ctb`, `replays_watched_ctb`, `ranked_score_mania`, `playcount_mania`, `total_score_mania`, `replays_watched_mania`, `total_hits_std`, `total_hits_taiko`, `total_hits_ctb`, `total_hits_mania`, `country`, `show_country`, `level_std`, `level_taiko`, `level_ctb`, `level_mania`, `avg_accuracy_std`, `avg_accuracy_taiko`, `avg_accuracy_ctb`, `avg_accuracy_mania`, `pp_std`, `pp_taiko`, `pp_ctb`, `pp_mania`, `badges_shown`, `safe_title`, `userpage_content`, `play_style`, `favourite_mode`) VALUES ('999', 'FokaBot', '', 'black', '', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'XX', '1', '0', '0', '0', '0', '0.000000000000', '0.000000000000', '0.000000000000', '0.000000000000', '0', '0', '0', '0', '3,4,11,0,0,0', '0', '', 0, 0);");
537echo 'Fokabot account created! Password is: '.$plainPassword."\n";
538echo 'Yepp... thats all we got for now. Some stuff might be missing as not everything is tested and set up correctly.';
539
540class DBPDO {
541 public $pdo;
542 private $error;
543
544 public function __construct() {
545 $this->connect();
546 }
547
548 public function prep_query($query) {
549 return $this->pdo->prepare($query);
550 }
551
552 public function connect() {
553 if (!$this->pdo) {
554 $dsn = 'mysql:dbname='.DATABASE_NAME.';'.DATABASE_WHAT.'='.DATABASE_HOST;
555 $user = DATABASE_USER;
556 $password = DATABASE_PASS;
557 try {
558 $this->pdo = new PDO($dsn, $user, $password, [PDO::ATTR_PERSISTENT => true]);
559
560 return true;
561 }
562 catch(PDOException $e) {
563 $this->error = $e->getMessage();
564 die($this->error);
565
566 return false;
567 }
568 } else {
569 $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
570
571 return true;
572 }
573 }
574
575 public function table_exists($table_name) {
576 $stmt = $this->prep_query('SHOW TABLES LIKE ?');
577 $stmt->execute([$this->add_table_prefix($table_name)]);
578
579 return $stmt->rowCount() > 0;
580 }
581
582 public function execute($query, $values = null) {
583 if ($values === null) {
584 $values = [];
585 } elseif (!is_array($values)) {
586 $values = [$values];
587 }
588 $stmt = $this->prep_query($query);
589 $stmt->execute($values);
590
591 return $stmt;
592 }
593
594 public function fetch($query, $values = null) {
595 if ($values === null) {
596 $values = [];
597 } elseif (!is_array($values)) {
598 $values = [$values];
599 }
600 $stmt = $this->execute($query, $values);
601
602 return $stmt->fetch(PDO::FETCH_ASSOC);
603 }
604
605 public function fetchAll($query, $values = null, $key = null) {
606 if ($values === null) {
607 $values = [];
608 } elseif (!is_array($values)) {
609 $values = [$values];
610 }
611 $stmt = $this->execute($query, $values);
612 $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
613 // Allows the user to retrieve results using a
614 // column from the results as a key for the array
615 if ($key != null && $results[0][$key]) {
616 $keyed_results = [];
617 foreach ($results as $result) {
618 $keyed_results[$result[$key]] = $result;
619 }
620 $results = $keyed_results;
621 }
622
623 return $results;
624 }
625
626 public function lastInsertId() {
627 return $this->pdo->lastInsertId();
628 }
629}
630?>