-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavegame.php
125 lines (113 loc) · 3.52 KB
/
savegame.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
<?php
@define('NWNADMIN_BASE', dirname(__FILE__));
require_once NWNADMIN_BASE . '/lib/base.php';
/**
* Delete a file, or a folder and its contents
*
* @author Aidan Lister <aidan@php.net>
* @version 1.0.2
* @param string $dirname Directory to delete
* @return bool Returns TRUE on success, FALSE on failure
*/
function rmdirr($dirname)
{
// Sanity check
if (!file_exists($dirname)) {
return false;
}
// Simple delete for a file
if (is_file($dirname)) {
return unlink($dirname);
}
// Loop through the folder
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Recurse
rmdirr("$dirname/$entry");
}
// Clean up
$dir->close();
return rmdir($dirname);
}
// script global variables
global $nwndriver;
$admin = Auth::isAdmin('nwnadmin:admin');
$adminDelete = Auth::isAdmin('nwnadmin:admin', PERMS_DELETE);
$saveDir = NWNAdmin::getSaveGamePath();
$serverUp = $nwndriver->serverRunning();
if ($admin && !$serverUp) {
$notification->push(_("The server is down; save game loading is ".
"unavailable."));
}
// figure out what to do
$actionId = Util::getFormData('actionId');
$saveName = Util::getFormData('saveName');
if (isset($actionId) && !isset($saveName)) {
$notification->push(_("Invalid options! Try again..."), 'horde.warning');
} else {
switch($actionId) {
case 'delete':
$result = false;
$length = strlen($conf['server']['root']);
if ($adminDelete &&
substr($saveName, 0, $length) == $conf['server']['root']) {
$saveName = str_replace('../', '', $saveName);
$result = rmdirr(escapeshellcmd($saveName));
}
if (!$result) {
$notification->push(_("Could not delete the save game."),
'horde.error');
} else {
$notification->push(_("Successfully deleted the saved game."),
'horde.success');
}
break;
case 'load':
$result = false;
if ($admin) {
$result = NWNAdmin::sendCommand('load ' .$saveName);
}
if (is_a($result, 'PEAR_Error')) {
$notification->push(
_("There was a problem loading the game: ") .
$result->getMessage(), 'horde.error');
} else {
$notification->push(_("Save game loaded."),
'horde.sucess');
}
break;
}
}
// get the listing of modules
$saveList = NWNAdmin::getSaveGameList($saveDir);
$saveDone = empty($saveList);
if ($saveDone) {
$notification->push(_("No save games were found"), 'horde.warning');
}
// page setup
$title = _("Saved Games");
require_once NWNADMIN_TEMPLATES . '/common-header.inc';
require_once NWNADMIN_TEMPLATES . '/menu.inc';
// render the available modules
if (!$saveDone) {
require NWNADMIN_TEMPLATES . '/savegame/header.inc';
$style = 'item1';
foreach ($saveList as $savegame) {
$baseSave = basename($savegame);
$args = split("/\s+/", $baseSave);
$saveNumber = sprintf("%d", $args[0]);
if ($style == 'item1') {
$style = 'item0';
} else {
$style = 'item1';
}
include NWNADMIN_TEMPLATES . '/savegame/savegame.inc';
}
require NWNADMIN_TEMPLATES . '/savegame/footer.inc';
}
// finish up the page
require_once $registry->get('templates', 'horde') . '/common-footer.inc';