-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_mod_g.php
308 lines (261 loc) · 12.5 KB
/
install_mod_g.php
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
<?php
/***********************************************************************/
// Some info about your mod.
$mod_title = 'FluxBB Arcade Mod';
$mod_version = '1.2.0';
$release_date = '2014-01-09';
$author = 'Koos (original PunBB 1.2 version by ANGO, Dharmil and Pandark)';
$author_email = '[email protected]';
// Versions of FluxBB this mod was created for. A warning will be displayed, if versions do not match
$fluxbb_versions= array('1.4.8', '1.4.9', '1.4.10', '1.4.11', '1.5.0', '1.5.1', '1.5.2', '1.5.3', '1.5.4', '1.5.5', '1.5.6');
// Set this to false if you haven't implemented the restore function (see below)
$mod_restore = true;
// This following function will be called when the user presses the "Install" button
function install()
{
global $db, $db_type, $pun_config;
//New Install
if (!$db->table_exists('arcade_ranking'))
{
$schema = array(
'FIELDS' => array(
'rank_id' => array(
'datatype' => 'SERIAL',
'allow_null' => false
),
'rank_game' => array(
'datatype' => 'VARCHAR(50)',
'allow_null' => false,
'default' => '\'0\''
),
'rank_player' => array(
'datatype' => 'SMALLINT(5)',
'allow_null' => false,
'default' => '0'
),
'rank_score' => array(
'datatype' => 'DOUBLE',
'allow_null' => false,
'default' => '0'
),
'rank_topscore' => array(
'datatype' => 'TINYINT(1)',
'allow_null' => false,
'default' => '0'
),
'rank_date' => array(
'datatype' => 'INT(10) UNSIGNED',
'allow_null' => true,
)
),
'PRIMARY KEY' => array('rank_id'),
);
$db->create_table('arcade_ranking', $schema) or error('Unable to create table '.$db->prefix.'arcade_ranking.', __FILE__, __LINE__, $db->error());
}
if (!$db->table_exists('arcade_games'))
{
$schema = array(
'FIELDS' => array(
'game_id' => array(
'datatype' => 'SERIAL',
'allow_null' => false
),
'game_name' => array(
'datatype' => 'VARCHAR(50)',
'allow_null' => false,
'default' => '\'\''
),
'game_filename' => array(
'datatype' => 'VARCHAR(30)',
'allow_null' => false,
'default' => '\'\''
),
'game_desc' => array(
'datatype' => 'TEXT',
'allow_null' => false,
'default' => '\'\''
),
'game_image' => array(
'datatype' => 'VARCHAR(200)',
'allow_null' => false,
'default' => '\'\''
),
'game_width' => array(
'datatype' => 'SMALLINT(5)',
'allow_null' => false,
'default' => '550'
),
'game_height' => array(
'datatype' => 'SMALLINT(5)',
'allow_null' => false,
'default' => '400'
),
'game_cat' => array(
'datatype' => 'SMALLINT(5)',
'allow_null' => false,
'default' => '0'
),
'game_played' => array(
'datatype' => 'SMALLINT(5)',
'allow_null' => false,
'default' => '0'
)
),
'PRIMARY KEY' => array('game_id'),
);
$db->create_table('arcade_games', $schema) or error('Unable to create table '.$db->prefix.'arcade_games.', __FILE__, __LINE__, $db->error());
}
// Add config options
$config = array(
'arcade_showtop' => "'1'",
'arcade_numchamps' => "'5'",
'arcade_live' => "'1'",
'arcade_numnew' => "'10'",
'arcade_mostplayed' => "'6'",
'arcade_allow_guests' => "'1'"
);
foreach ($config as $conf_name => $conf_value)
{
// Insert new config option if it doesn't exist
$result = $db->query('SELECT 1 FROM '.$db->prefix.'config WHERE conf_name = \''.$conf_name.'\'');
if (!$db->num_rows($result))
$db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES(\''.$conf_name.'\', '.$conf_value.')') or error('Unable to insert config value \''.$conf_name.'\'', __FILE__, __LINE__, $db->error());
}
// Add games
// German game descriptions
$games = array(
//game_name, game_filename, game_desc, game_image, game_width, game_height, game_cat
array("Balloon Hunter", "balloonhunter", "Du musst versuchen mit Pfeil und Bogen Luftballons vom Himmel schiessen.<br />Keine leichte Aufgabe, denn die Windstärke ändert sich von Zeit zu Zeit.", "balloonhunter.jpg", 550, 400, 9),
array("Breakit", "breakit", "Der Spieler muss mit einem Paddel den Ball im Spiel halten und die Steine aus dem Spielfeld entfernen.<br />Breakit ist sehr gute Breakout Umsetzung und bietet sehr gute Grafik und viel Abwechslung.", "breakit.jpg", 640, 480, 4),
array("Diamond Mines", "diamondmine", "Diamond Mine ist ein klassisches Spiel, in dem Sie Reihen aus drei oder vier identischen Steinen aufbauen müssen.", "diamondmine.jpg", 550, 400, 3),
array("Tetrollapse", "tetrollapse", "Bei dieser Tetris Variante muss man die vorhandenen Figuren beseitigen um ins nächste Level zu gelangen.<br />Ansonsten bleiben die Regeln wie gewohnt. Es gibt 33 verschiedene Level.", "tetrollapse.jpg", 640, 480, 3),
array("Frogger", "frogger", "Bringe den Frosch sicher über die stark befahrene Straße und über den Fluss.<br />Der Frosch muss dabei auf der Straße Autos ausweichen und zur Überquerung eines Flusses treibende Äste als Plattformen nutzen.", "frogger.jpg", 400, 450, 1),
array("Space Invaders", "invaders", "Dies ist das originalgetreue Abbild des 1978 erschienen Kult- spiels Space Invaders!<br /> Eine Horde von Aliens wandert den Bildschirm herunter. Je mehr Aliens abgeschossen werden, desto schneller bewegen sie sich.", "invaders.jpg", 520, 440, 1),
array("Reel Gold", "reelgold", "Ziel des Spiel Reel Gold ist es in jedem Level soviele Goldstücke wie möglich mit deiner Seilwinde ans Tageslicht zu befördern.<br />Es können nur glänzende Klumpen geborgen werden. Habt ihr beim Einholen Kontakt mit einem Stein verliert ihr den Goldklumpen.", "reelgold.jpg", 550, 450, 4),
array("Spank The Monkey", "spankmonkey", "Der Spieler muss per Maus mit der virtuelle Hand so schnell und hart wie möglich auf den Affen einschlagen.", "spankmonkey.jpg", 850, 400, 4),
array("Speartoss Wheelchair", "speartoss", "Wie weit kannst Du den Speer werfen?", "speartoss.jpg", 625, 360, 9),
array("Speartoss 5 Shots", "speartoss5shots", "Du hast 5 Versuche um den Speer soweit wie möglich zu werfen. Alle Versuche werden dann am Ende addiert.", "speartoss5shots.jpg", 625, 360, 9),
);
foreach ($games as $value)
{
// Insert new game if it doesn't exist
$result = $db->query('SELECT 1 FROM '.$db->prefix.'arcade_games WHERE game_name = \''.$value[0].'\'');
if (!$db->num_rows($result))
$db->query('INSERT INTO '.$db->prefix.'arcade_games (game_name, game_filename, game_desc, game_image, game_width, game_height, game_cat) VALUES (\''.$value[0].'\', \''.$value[1].'\', \''.$value[2].'\', \''.$value[3].'\', \''.$value[4].'\', \''.$value[5].'\', \''.$value[6].'\')') or error('Unable to add game '.$value[0], __FILE__, __LINE__, $db->error());
}
// Regenerate the config cache
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
generate_config_cache();
}
// This following function will be called when the user presses the "Restore" button (only if $mod_restore is true (see above))
function restore()
{
global $db, $db_type, $pun_config;
$db->drop_table('arcade_ranking') or error('Unable to remove table '.$db->prefix.'arcade_ranking.', __FILE__, __LINE__, $db->error());
$db->drop_table('arcade_games') or error('Unable to remove table '.$db->prefix.'arcade_games.', __FILE__, __LINE__, $db->error());
// Delete arcade config options
$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name="arcade_showtop"') or error('Unable to delete "arcade_showtop" from config table', __FILE__, __LINE__, $db->error());
$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name="arcade_numchamps"') or error('Unable to delete "arcade_numchamps" from config table', __FILE__, __LINE__, $db->error());
$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name="arcade_live"') or error('Unable to delete "arcade_live" from config table', __FILE__, __LINE__, $db->error());
$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name="arcade_numnew"') or error('Unable to delete "arcade_numnew" from config table', __FILE__, __LINE__, $db->error());
$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name="arcade_mostplayed"') or error('Unable to delete "arcade_mostplayed" from config table', __FILE__, __LINE__, $db->error());
$db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name="arcade_allow_guests"') or error('Unable to delete "arcade_allow_guests" from config table', __FILE__, __LINE__, $db->error());
// Regenerate the config cache
if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
require PUN_ROOT.'include/cache.php';
generate_config_cache();
}
/***********************************************************************/
// DO NOT EDIT ANYTHING BELOW THIS LINE!
// Circumvent maintenance mode
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
// We want the complete error message if the script fails
if (!defined('PUN_DEBUG'))
define('PUN_DEBUG', 1);
// Make sure we are running a FluxBB version that this mod works with
$version_warning = !in_array($pun_config['o_cur_version'], $fluxbb_versions);
$style = (isset($pun_user)) ? $pun_user['style'] : $pun_config['o_default_style'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo pun_htmlspecialchars($mod_title) ?> installation</title>
<link rel="stylesheet" type="text/css" href="style/<?php echo $style.'.css' ?>" />
</head>
<body>
<div id="punwrap">
<div id="puninstall" class="pun" style="margin: 10% 20% auto 20%">
<?php
if (isset($_POST['form_sent']))
{
if (isset($_POST['install']))
{
// Run the install function (defined above)
install();
?>
<div class="block">
<h2><span>Installation successful</span></h2>
<div class="box">
<div class="inbox">
<p>Your database has been successfully prepared for <?php echo pun_htmlspecialchars($mod_title) ?>. See readme.txt for further instructions.</p>
</div>
</div>
</div>
<?php
}
else
{
// Run the restore function (defined above)
restore();
?>
<div class="block">
<h2><span>Restore successful</span></h2>
<div class="box">
<div class="inbox">
<p>Your database has been successfully restored.</p>
</div>
</div>
</div>
<?php
}
}
else
{
?>
<div class="blockform">
<h2><span>Mod installation</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?foo=bar">
<div><input type="hidden" name="form_sent" value="1" /></div>
<div class="inform">
<p>This script will update your database to work with the following modification:</p>
<p><strong>Mod title:</strong> <?php echo pun_htmlspecialchars($mod_title.' '.$mod_version) ?></p>
<p><strong>Author:</strong> <?php echo pun_htmlspecialchars($author) ?> (<a href="mailto:<?php echo pun_htmlspecialchars($author_email) ?>"><?php echo pun_htmlspecialchars($author_email) ?></a>)</p>
<p><strong>Disclaimer:</strong> Mods are not officially supported by FluxBB. Mods generally can't be uninstalled without running SQL queries manually against the database. Make backups of all data you deem necessary before installing.</p>
<?php if ($mod_restore): ?>
<p>If you've previously installed this mod and would like to uninstall it, you can click the Restore button below to restore the database.</p>
<?php endif; ?>
<?php if ($version_warning): ?>
<p style="color: #a00"><strong>Warning:</strong> The mod you are about to install was not made specifically to support your current version of FluxBB (<?php echo $pun_config['o_cur_version']; ?>). This mod supports FluxBB versions: <?php echo pun_htmlspecialchars(implode(', ', $fluxbb_versions)); ?>. If you are uncertain about installing the mod due to this potential version conflict, contact the mod author.</p>
<?php endif; ?>
</div>
<p class="buttons"><input type="submit" name="install" value="Install" /><?php if ($mod_restore): ?><input type="submit" name="restore" value="Restore" /><?php endif; ?></p>
</form>
</div>
</div>
<?php
}
?>
</div>
</div>
</body>
</html>
<?php
// End the transaction
$db->end_transaction();
// Close the db connection (and free up any result data)
$db->close();