22
33namespace Nitrapi \Services \Gameservers ;
44
5+ use Nitrapi \Common \Exceptions \NitrapiErrorException ;
56use Nitrapi \Common \Exceptions \NitrapiHttpErrorException ;
67use Nitrapi \Common \Exceptions \NitrapiServiceNotActiveException ;
78use Nitrapi \Nitrapi ;
@@ -123,7 +124,7 @@ public function getCustomerSettings() {
123124 * @return bool
124125 */
125126 public function doRestart ($ message = null , $ restartMessage = null ) {
126- $ url = " services/ " . $ this ->getId () . " /gameservers/restart " ;
127+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/restart ' ;
127128 $ this ->getApi ()->dataPost ($ url , array (
128129 'message ' => $ message ,
129130 'restart_message ' => $ restartMessage ,
@@ -139,7 +140,7 @@ public function doRestart($message = null, $restartMessage = null) {
139140 * @return bool
140141 */
141142 public function doStop ($ message = null , $ stopMessage = null ) {
142- $ url = " services/ " . $ this ->getId () . " /gameservers/stop " ;
143+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/stop ' ;
143144 $ this ->getApi ()->dataPost ($ url , array (
144145 'message ' => $ message ,
145146 'stop_message ' => $ stopMessage ,
@@ -153,7 +154,7 @@ public function doStop($message = null, $stopMessage = null) {
153154 * @return MariaDB
154155 */
155156 public function createDatabase ($ credentials = array (), $ options = array ()) {
156- $ url = " services/ " . $ this ->getId () . " /gameservers/mariadbs " ;
157+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/mariadbs ' ;
157158
158159 $ result = $ this ->getApi ()->dataPost ($ url , $ credentials , null , $ options );
159160 return MariaDBFactory::factory ($ this , $ result ['database ' ]['id ' ]);
@@ -165,7 +166,7 @@ public function createDatabase($credentials = array(), $options = array()) {
165166 * @return array
166167 */
167168 public function getDatabases () {
168- $ url = " services/ " . $ this ->getId () . " /gameservers/mariadbs " ;
169+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/mariadbs ' ;
169170 $ result = $ this ->getApi ()->dataGet ($ url );
170171 return $ result ['databases ' ];
171172 }
@@ -187,7 +188,7 @@ public function getDatabase($id) {
187188 * @return bool
188189 */
189190 public function deleteDatabase (MariaDB $ database ) {
190- $ url = " services/ " . $ this ->getId () . " /gameservers/mariadbs/ " . $ database ->getId ();
191+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/mariadbs/ ' . $ database ->getId ();
191192 return $ this ->getApi ()->dataDelete ($ url );
192193 }
193194
@@ -197,7 +198,7 @@ public function deleteDatabase(MariaDB $database) {
197198 * @return array
198199 */
199200 public function getLicenseKeys () {
200- $ url = " services/ " . $ this ->getId () . " /gameservers/license_keys " ;
201+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/license_keys ' ;
201202 $ result = $ this ->getApi ()->dataGet ($ url );
202203 $ return = array ();
203204 if (count ($ result ['keys ' ]) > 0 ) {
@@ -216,7 +217,7 @@ public function getLicenseKeys() {
216217 * @return array
217218 */
218219 public function claimLicenseKeys () {
219- $ url = " services/ " . $ this ->getId () . " /gameservers/license_keys/claim_all " ;
220+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/license_keys/claim_all ' ;
220221 $ result = $ this ->getApi ()->dataPost ($ url );
221222 $ return = array ();
222223 if (count ($ result ['keys ' ]) > 0 ) {
@@ -235,7 +236,7 @@ public function claimLicenseKeys() {
235236 * @return bool
236237 */
237238 public function releaseLicenseKeys () {
238- $ url = " services/ " . $ this ->getId () . " /gameservers/license_keys/release_all " ;
239+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/license_keys/release_all ' ;
239240 $ this ->getApi ()->dataPost ($ url );
240241 return true ;
241242 }
@@ -246,7 +247,7 @@ public function releaseLicenseKeys() {
246247 * @return array
247248 */
248249 public function getGames () {
249- $ url = " services/ " . $ this ->getId () . " /gameservers/games " ;
250+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/games ' ;
250251 return $ this ->getApi ()->dataGet ($ url );
251252 }
252253
@@ -258,7 +259,7 @@ public function getGames() {
258259 * @return bool
259260 */
260261 public function installGame ($ game , $ modpack = null ) {
261- $ url = " services/ " . $ this ->getId () . " /gameservers/games/install " ;
262+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/games/install ' ;
262263 $ data = array (
263264 'game ' => $ game ,
264265 );
@@ -274,7 +275,7 @@ public function installGame($game, $modpack = null) {
274275 * @return bool
275276 */
276277 public function uninstallGame ($ game ) {
277- $ url = " services/ " . $ this ->getId () . " /gameservers/games/uninstall " ;
278+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/games/uninstall ' ;
278279 $ this ->getApi ()->dataDelete ($ url , array (
279280 'game ' => $ game ,
280281 ));
@@ -288,7 +289,7 @@ public function uninstallGame($game) {
288289 * @return bool
289290 */
290291 public function startGame ($ game ) {
291- $ url = " services/ " . $ this ->getId () . " /gameservers/games/start " ;
292+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/games/start ' ;
292293 $ this ->getApi ()->dataPost ($ url , array (
293294 'game ' => $ game ,
294295 ));
@@ -302,7 +303,7 @@ public function startGame($game) {
302303 * @return bool
303304 */
304305 public function changeFTPPassword ($ password ) {
305- $ url = " services/ " . $ this ->getId () . " /gameservers/ftp/password " ;
306+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/ftp/password ' ;
306307 $ this ->getApi ()->dataPost ($ url , array (
307308 'password ' => $ password ,
308309 ));
@@ -316,7 +317,7 @@ public function changeFTPPassword($password) {
316317 * @return bool
317318 */
318319 public function changeMySQLPassword ($ password ) {
319- $ url = " services/ " . $ this ->getId () . " /gameservers/mysql/password " ;
320+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/mysql/password ' ;
320321 $ this ->getApi ()->dataPost ($ url , array (
321322 'password ' => $ password ,
322323 ));
@@ -330,7 +331,7 @@ public function changeMySQLPassword($password) {
330331 * @return bool
331332 */
332333 public function resetMySQLDatabase () {
333- $ url = " services/ " . $ this ->getId () . " /gameservers/mysql/reset " ;
334+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/mysql/reset ' ;
334335 $ this ->getApi ()->dataPost ($ url );
335336 return true ;
336337 }
@@ -377,7 +378,7 @@ public function getCallbackHandler() {
377378 * @return array
378379 */
379380 public function getAdminLogs () {
380- $ url = " services/ " . $ this ->getId () . " /gameservers/admin_logs " ;
381+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/admin_logs ' ;
381382 return $ this ->getApi ()->dataGet ($ url );
382383 }
383384
@@ -389,7 +390,7 @@ public function getAdminLogs() {
389390 * @return array
390391 */
391392 public function getStats ($ hours = 24 ) {
392- $ url = " services/ " . $ this ->getId () . " /gameservers/stats " ;
393+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/stats ' ;
393394 return $ this ->getApi ()->dataGet ($ url , null , [
394395 'query ' => [
395396 'hours ' => $ hours
@@ -404,7 +405,7 @@ public function getStats($hours = 24) {
404405 * @return bool
405406 */
406407 public function sendCommand ($ command ) {
407- $ url = " services/ " . $ this ->getId () . " /gameservers/command " ;
408+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/command ' ;
408409 $ this ->getApi ()->dataPost ($ url , [
409410 'command ' => $ command
410411 ]);
@@ -420,10 +421,10 @@ public function sendCommand($command) {
420421 * @throws NitrapiServiceTypeNotFoundException
421422 */
422423 public function getGame ($ game ) {
423- $ class = " Nitrapi \\Services \\Gameservers \\Games \\" . ucfirst ($ game );
424+ $ class = ' Nitrapi \\Services \\Gameservers \\Games \\' . ucfirst ($ game );
424425
425426 if (!class_exists ($ class )) {
426- throw new NitrapiServiceTypeNotFoundException (" Game class " . $ game . " not found " );
427+ throw new NitrapiServiceTypeNotFoundException (' Game class ' . $ game . ' not found ' );
427428 }
428429
429430 return new $ class ($ this );
@@ -437,11 +438,55 @@ public function getGame($game) {
437438 * @return bool
438439 */
439440 public function changeManagedRootSetting ($ key , $ value ) {
440- $ url = " services/ " . $ this ->getId () . " /gameservers/managed_root/ " . $ key ;
441+ $ url = ' services/ ' . $ this ->getId () . ' /gameservers/managed_root/ ' . $ key ;
441442 $ this ->getApi ()->dataPost ($ url , [
442443 $ key => $ value
443444 ]);
444445
445446 return true ;
446447 }
448+
449+ /**
450+ * Returns the created backups of the game server.
451+ *
452+ * @return array
453+ * @throws NitrapiErrorException
454+ */
455+ public function getBackups () {
456+ $ url = 'services/ ' . $ this ->getId () . '/gameservers/backups ' ;
457+ $ response = $ this ->getApi ()->dataGet ($ url );
458+
459+ if (!isset ($ response ['backups ' ])) {
460+ throw new NitrapiErrorException ('No backup have been returned from API. ' );
461+ }
462+
463+ return $ response ['backups ' ];
464+ }
465+
466+ /**
467+ * Restores a backup of a gameserver image.
468+ *
469+ * @return array
470+ */
471+ public function restoreGameserverBackup ($ game , $ number ) {
472+ $ url = 'services/ ' . $ this ->getId () . '/gameservers/backups/gameserver ' ;
473+ return $ this ->getApi ()->dataPost ($ url , [
474+ 'game ' => $ game ,
475+ 'backup ' => $ number
476+ ]);
477+ }
478+
479+ /**
480+ * Restores a backup of a MySQL database.
481+ *
482+ * @return string
483+ */
484+ public function restoreDatabaseBackup ($ database , $ timestamp ) {
485+ $ url = 'services/ ' . $ this ->getId () . '/gameservers/backups/database ' ;
486+ return $ this ->getApi ()->dataPost ($ url , [
487+ 'database ' => $ database ,
488+ 'timestamp ' => $ timestamp
489+ ]);
490+ }
491+
447492}
0 commit comments