@@ -45,9 +45,11 @@ public function serverCreationPage()
4545 $ auth = config ('shdactyl.pterodactyl.api_key ' );
4646 $ nodes = config ('shdactyl.nodes ' );
4747 $ eggs = Config::get ('shdactyl.eggs ' );
48+ $ fee = Config::get ('shdactyl.fee ' );
4849 return Inertia::render ('Server/Create ' , [
4950 'nodes ' => $ nodes ,
50- 'eggs ' => $ eggs
51+ 'eggs ' => $ eggs ,
52+ 'fee ' => $ fee ,
5153 ]);
5254 }
5355 public function resourceStorePage ()
@@ -352,6 +354,11 @@ public function serverCreation(Request $request)
352354 if ($ total ['servers ' ] + 1 > $ user ->servers ) {
353355 return redirect ('/dashboard/server/create ' )->with ('error ' , '你沒有那麼多 Servers 資源來創建這個伺服器 ' );
354356 }
357+ $ price = config ('shdactyl.fee.create ' ) * config ('shdactyl.fee.node. ' . $ data ['node ' ]) * ((config ('shdactyl.fee.resource.cpu ' ) * $ data ['cpu ' ]) + (config ('shdactyl.fee.resource.ram ' ) * $ data ['ram ' ]) + (config ('shdactyl.fee.resource.disk ' ) * $ data ['disk ' ]) + (config ('shdactyl.fee.resource.databases ' ) * $ data ['databases ' ]) + (config ('shdactyl.fee.resource.backups ' ) * $ data ['backups ' ]) + (config ('shdactyl.fee.resource.ports ' ) * $ data ['ports ' ]));
358+ if ($ user ->coins < $ price ) {
359+ return redirect ('/dashboard/server/create ' )->with ('error ' , '你沒有足夠的代幣來創建伺服器 ' );
360+ }
361+ $ user ->decrement ('coins ' , $ price );
355362 $ category = $ this ->getCategoryById ($ data ['egg ' ]);
356363 $ url = config ('shdactyl.pterodactyl.url ' );
357364 $ auth = config ('shdactyl.pterodactyl.api_key ' );
@@ -387,7 +394,26 @@ public function serverCreation(Request $request)
387394 ],
388395 ]);
389396 if ($ res ->created () === true ) {
390- return redirect ('/dashboard/server/create ' )->with ('success ' , '成功創建伺服器! ' );
397+
398+ $ serverData = json_decode ($ res , true );
399+ DiscordAlert::to ('server ' )->message ("" , [
400+ [
401+ 'title ' => '[創建伺服器] ' ,
402+ 'description ' => '帳號:<@ ' . $ user ->discord_id . '> ( ' . $ user ->discord_id . ')\n ' .
403+ '伺服器識別碼: ' . $ serverData ['attributes ' ]['identifier ' ] . '\n伺服器名稱: ' . $ serverData ['attributes ' ]['name ' ] . '\n節點識別碼: ' . $ serverData ['attributes ' ]['node ' ] . '\n處理器: ' . $ serverData ['attributes ' ]['limits ' ]['cpu ' ] . '%\n記憶體: ' . $ serverData ['attributes ' ]['limits ' ]['memory ' ] . ' MiB\n儲存空間: ' . $ serverData ['attributes ' ]['limits ' ]['disk ' ] . ' MiB\n資料庫: ' . $ serverData ['attributes ' ]['feature_limits ' ]['databases ' ] . ' 個\n額外端口: ' . $ serverData ['attributes ' ]['feature_limits ' ]['allocations ' ] . ' 個\n備份欄位: ' . $ serverData ['attributes ' ]['feature_limits ' ]['backups ' ] . ' 個 ' ,
404+ 'color ' => '#03cafc ' ,
405+ 'footer ' => [
406+ 'icon_url ' => config ('shdactyl.webhook.icon_url ' ),
407+ 'text ' => 'SHDactyl ' ,
408+ ],
409+ 'timestamp ' => Carbon::now (),
410+ 'author ' => [
411+ 'name ' => $ user ->name ,
412+ 'icon_url ' => $ user ->avatar ,
413+ ],
414+ ]
415+ ]);
416+ return redirect ('/dashboard/server/create ' )->with ('success ' , '成功花費 $ ' . number_format ($ price , 2 ) . ' SDC 創建伺服器! ' );
391417 } else {
392418 return redirect ('/dashboard/server/create ' )->with ('error ' , '創建伺服器時發生錯誤 ' . $ res );
393419 }
@@ -421,15 +447,40 @@ public function unsuspendServer(Request $request)
421447 'Authorization ' => $ auth ,
422448 ])->get ($ url . '/api/application/servers/ ' . $ data ['id ' ]);
423449 $ resData = json_decode ($ res , true );
450+ if ($ resData ['attributes ' ]['suspended ' ] === false ) {
451+ return redirect ('/dashboard/server/manage ' )->with ('error ' , '該伺服器不需要續約 ' );
452+ }
424453 if ($ resData ['attributes ' ]['user ' ] === $ user ->panel_id ) {
425454 $ price = config ('shdactyl.fee.unsuspend ' ) * config ('shdactyl.fee.node. ' . $ resData ['attributes ' ]['node ' ]);
455+ if ($ user ->coins < $ price ) {
456+ return redirect ('/dashboard/server/manage ' )->with ('error ' , '你沒有足夠的代幣來續約伺服器 ' );
457+ }
426458 $ user ->decrement ('coins ' , $ price );
427459 $ user ->save ();
428460 $ res = Http::withHeaders ([
429461 'Accept ' => 'application/json ' ,
430462 'Authorization ' => $ auth ,
431463 ])->post ($ url . '/api/application/servers/ ' . $ data ['id ' ] . '/unsuspend ' );
432464 if ($ res ->successful () === true ) {
465+
466+ $ serverData = $ resData ;
467+ DiscordAlert::to ('server ' )->message ("" , [
468+ [
469+ 'title ' => '[續約伺服器] ' ,
470+ 'description ' => '帳號:<@ ' . $ user ->discord_id . '> ( ' . $ user ->discord_id . ')\n ' .
471+ '伺服器識別碼: ' . $ serverData ['attributes ' ]['identifier ' ] . '\n伺服器名稱: ' . $ serverData ['attributes ' ]['name ' ] . '\n節點識別碼: ' . $ serverData ['attributes ' ]['node ' ],
472+ 'color ' => '#03cafc ' ,
473+ 'footer ' => [
474+ 'icon_url ' => config ('shdactyl.webhook.icon_url ' ),
475+ 'text ' => 'SHDactyl ' ,
476+ ],
477+ 'timestamp ' => Carbon::now (),
478+ 'author ' => [
479+ 'name ' => $ user ->name ,
480+ 'icon_url ' => $ user ->avatar ,
481+ ],
482+ ]
483+ ]);
433484 return redirect ('/dashboard/server/manage ' )->with ('success ' , '成功花費 $ ' . number_format ($ price , 2 ) . ' SDC 續約伺服器 ' );
434485 } else {
435486 return redirect ('/dashboard/server/manage ' )->with ('error ' , '續約伺服器時發生錯誤 ' . $ res );
@@ -457,6 +508,24 @@ public function deleteServer(Request $request)
457508 'Authorization ' => $ auth ,
458509 ])->delete ($ url . '/api/application/servers/ ' . $ data ['id ' ]);
459510 if ($ res ->successful () === true ) {
511+ $ serverData = $ resData ;
512+ DiscordAlert::to ('server ' )->message ("" , [
513+ [
514+ 'title ' => '[刪除伺服器] ' ,
515+ 'description ' => '帳號:<@ ' . $ user ->discord_id . '> ( ' . $ user ->discord_id . ')\n ' .
516+ '伺服器識別碼: ' . $ serverData ['attributes ' ]['identifier ' ] . '\n伺服器名稱: ' . $ serverData ['attributes ' ]['name ' ] . '\n節點識別碼: ' . $ serverData ['attributes ' ]['node ' ],
517+ 'color ' => '#03cafc ' ,
518+ 'footer ' => [
519+ 'icon_url ' => config ('shdactyl.webhook.icon_url ' ),
520+ 'text ' => 'SHDactyl ' ,
521+ ],
522+ 'timestamp ' => Carbon::now (),
523+ 'author ' => [
524+ 'name ' => $ user ->name ,
525+ 'icon_url ' => $ user ->avatar ,
526+ ],
527+ ]
528+ ]);
460529 return redirect ('/dashboard/server/manage ' )->with ('success ' , '成功刪除伺服器 ' );
461530 } else {
462531 return redirect ('/dashboard/server/manage ' )->with ('error ' , '刪除伺服器時發生錯誤 ' . $ res );
@@ -527,6 +596,24 @@ public function modifyServer(Request $request)
527596 ],
528597 ]);
529598 if ($ response ->successful () === true ) {
599+ $ serverData = $ responseData ;
600+ DiscordAlert::to ('server ' )->message ("" , [
601+ [
602+ 'title ' => '[編輯伺服器] ' ,
603+ 'description ' => '帳號:<@ ' . $ user ->discord_id . '> ( ' . $ user ->discord_id . ')\n ' .
604+ '伺服器識別碼: ' . $ serverData ['attributes ' ]['identifier ' ] . '\n伺服器名稱: ' . $ serverData ['attributes ' ]['name ' ] . '\n節點識別碼: ' . $ serverData ['attributes ' ]['node ' ] . '\n處理器: ' . $ serverData ['attributes ' ]['limits ' ]['cpu ' ] . '%\n記憶體: ' . $ serverData ['attributes ' ]['limits ' ]['memory ' ] . ' MiB\n儲存空間: ' . $ serverData ['attributes ' ]['limits ' ]['disk ' ] . ' MiB\n資料庫: ' . $ serverData ['attributes ' ]['feature_limits ' ]['databases ' ] . ' 個\n額外端口: ' . $ serverData ['attributes ' ]['feature_limits ' ]['allocations ' ] . ' 個\n備份欄位: ' . $ serverData ['attributes ' ]['feature_limits ' ]['backups ' ] . ' 個 ' ,
605+ 'color ' => '#03cafc ' ,
606+ 'footer ' => [
607+ 'icon_url ' => config ('shdactyl.webhook.icon_url ' ),
608+ 'text ' => 'SHDactyl ' ,
609+ ],
610+ 'timestamp ' => Carbon::now (),
611+ 'author ' => [
612+ 'name ' => $ user ->name ,
613+ 'icon_url ' => $ user ->avatar ,
614+ ],
615+ ]
616+ ]);
530617 return redirect ('/dashboard/server/manage ' )->with ('success ' , '成功編輯伺服器 ' );
531618 } else {
532619 return redirect ('/dashboard/server/manage ' )->with ('error ' , '編輯伺服器時發生錯誤 ' . $ response );
0 commit comments