-
Notifications
You must be signed in to change notification settings - Fork 1
/
runregion.php
233 lines (201 loc) · 7.47 KB
/
runregion.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
<?php
ob_start();
// ** Find theget next available port on theserver
ini_set("display_errors", 1);
ini_set("log_errors", 1);
error_reporting(E_ALL);
include("config.php");
include("database.php");
#
function dolog($message) {
$message = date("H:i:s") . " - $message" . PHP_EOL;
print($message);
flush();
ob_flush();
}
$arguments = $argv;
function fakeget($param) {
global $arguments;
foreach ($arguments as $arg) {
if (strpos($arg, "=") > -1) {
$arg = str_replace('"', '', $arg);
$key = explode("=", $arg)[0];
$value = explode("=", $arg)[1];
if ($key === $param) {
return $value;
}
}
}
return "";
}
function getUUID() {
$name_space = "5f6384bfec4ca0b2d4114a13aa2a5435";
$string = date("hisa");
$n_hex = str_replace(array('-', '{', '}'), '', $name_space); // Getting hexadecimal components of namespace
$binary_str = ''; // Binary Value
//Namespace UUID to bits conversion
for ($i = 0; $i < strlen($n_hex); $i += 2) {
$binary_str .= chr(hexdec($n_hex[$i] . $n_hex[$i + 1]));
}
//hash value
$hashing = md5($binary_str . $string);
return sprintf('%08s-%04s-%04x-%04x-%12s',
// 32 bits for the time low
substr($hashing, 0, 8),
// 16 bits for the time mid
substr($hashing, 8, 4),
// 16 bits for the time hi,
(hexdec(substr($hashing, 12, 4)) & 0x0fff) | 0x3000,
// 8 bits and 16 bits for the clk_seq_hi_res,
// 8 bits for the clk_seq_low,
(hexdec(substr($hashing, 16, 4)) & 0x3fff) | 0x8000,
// 48 bits for the node
substr($hashing, 20, 12)
);
}
function custom_copy($src, $dst) {
// open the source directory
$dir = opendir($src);
// Make the destination directory if not exist
@mkdir($dst);
// Loop through the files in source directory
foreach (scandir($src) as $file) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($src . '/' . $file)) {
// Recursively calling custom copy function
// for sub directory
custom_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}
function getter($param) {
$test = fakeget($param) . "";
if ($test !== "") {
dolog($param . "=" . $test);
return $test;
}
return readline($param . ":");
// return filter_input(INPUT_POST, $param);
}
$rn = getter("regionname");
dolog("Removing from regions in robust");
dolog("Selecting Region for Region Name or Shortname " . $rn);
$sql = "SELECT * FROM grid.regions where (shortname='" . mysqli_real_escape_string($con, $rn) . "' or regionname='" . mysqli_real_escape_string($con, $rn) . "') and servername='" . $thisservername . "'";
dolog($sql);
$result = $con->query($sql);
$serverport = 10000;
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
// got data lets start a server!
dolog("Starting Region " . $row["regionname"]);
goRegion($row["xpos"], $row["ypos"], $row["regionname"], $row["estatename"], $row["shortname"], $row["owner"], $row["uuid"], $row["port"] . "", $row["databasename"], $row["id"], $row["params"], $row["nocopy"]);
++$serverport;
}
} else {
echo "0 results";
}
$con->close();
/** Create REgion * */
function goRegion($xpos, $ypos, $regionname, $estatename, $shortname, $estateowner, $regionuuid, $serverport, $databasename, $id, $params, $nocopy) {
global $databasehost, $thisservername, $databaseusername, $databasepassword, $regionsfolder, $con, $defaultregionfolder;
if ($databasename === "") {
$databasename = "r-land";
}
if ($serverport === "") {
$serverport = 20000 + $id;
dolog("Setting Port to " . $serverport . " on " . $thisservername);
$con->query("update grid.regions set port='" . $serverport . "' where uuid='" . $regionuuid . "'");
}
$physicsengine = "ubODE";
$mesher = "ubODEMeshmerizer";
/** create folder
*
*/
$shortname = str_replace(" ", "", $shortname);
/*
* Copy Files
* Edit OPENSIM .ini
*/
$regionpath = $regionsfolder . $shortname . "/";
dolog("Create Folders Folder " . $regionpath);
// $todo = "cp -r " . $defaultregionfolder . "bin/ " . $regionpath;
//echo $todo;
if ($nocopy !== "Y") {
shell_exec("rm -r " . $regionpath);
$todo = 'mkdir ' . $regionpath;
shell_exec($todo);
$todo = 'cp -r ' . $defaultregionfolder . '* ' . $regionpath;
shell_exec($todo);
}
dolog("Update OpenSim.ini - Server Port " . $serverport);
$opensim = file_get_contents($regionpath . "/bin/OpenSim.ini"); //< opensim.ini loaded here
$opensim = str_replace("ESTATENAME", $estatename, $opensim);
$opensim = str_replace("ESTATEOWNER", $estateowner, $opensim);
$opensim = str_replace("8888", $serverport, $opensim);
$opensim = str_replace("INSERTMESHERHERE", $mesher, $opensim);
$opensim = str_replace("INSERTPHYSICSHERE", $physicsengine, $opensim);
file_put_contents($regionpath . "bin/OpenSim.ini", $opensim);
dolog("Create Region File");
/*
*
*
* Create REGION INI FILE
*/
$inifile = "[" . $regionname . "]" . PHP_EOL;
$inifile .= "RegionUUID = " . $regionuuid . "" . PHP_EOL;
$inifile .= "Location = " . $xpos . "," . $ypos . "" . PHP_EOL;
$inifile .= "ExternalHostName = " . $thisservername . "" . PHP_EOL;
$inifile .= "InternalAddress = 0.0.0.0" . PHP_EOL;
$inifile .= "InternalPort = " . $serverport . "" . PHP_EOL;
$inifile .= "AllowAlternatePorts = False" . PHP_EOL;
$inifile .= "SizeX = 1024" . PHP_EOL;
$inifile .= "SizeY = 1024" . PHP_EOL;
$inifile .= "MaxPrims = 80000" . PHP_EOL;
$inifile .= "MaxAgents = 60" . PHP_EOL;
$inifile .= "MaxPrimsPerUser = -1" . PHP_EOL;
file_put_contents($regionpath . "bin/Regions/Region.ini", $inifile);
/**
*
*
* Edit Grid Commono.ini
*
*/
dolog("Edit GridCommon.ini");
$gridoptions = file_get_contents($regionpath . "bin/config-include/GridCommon.ini");
$gridoptions = str_replace("DBSCHEMA", $databasename, $gridoptions);
$gridoptions = str_replace("DBUSER", $databaseusername, $gridoptions);
$gridoptions = str_replace("DBPASSWD", $databasepassword, $gridoptions);
$gridoptions = str_replace("localhost", $databasehost, $gridoptions);
file_put_contents($regionpath . "bin/config-include/GridCommon.ini", $gridoptions);
dolog("Create Execution Script");
$execute = '
#!/bin/bash
while true
do
cd ' . $regionpath . 'bin
' . $params . '
rsync -av --exclude=\'*.ini\' ' . $defaultregionfolder . 'bin/ ./
mono --server --optimize=all OpenSim.exe
echo
echo
echo "Restarting 10 seconds. Press [CTRL+C] to stop.."
sleep 10
echo "Restarting Region NOW."
sleep 5
done
';
dolog("Write " . $regionpath . "bin/execute.sh");
file_put_contents($regionpath . "bin/execute.sh", $execute);
dolog("Create Database on main server");
mysqli_query($con, "create database if not exists " . $databasename);
dolog("screen -dmS " . $shortname . " sh " . $regionpath . "bin/execute.sh");
exec("screen -dmS " . $shortname . " sh " . $regionpath . "bin/execute.sh");
// now wait for 10 seconds
sleep(5);
ob_flush();
}