refac: 장수 삭제를 api로 이동
This commit is contained in:
@@ -83,7 +83,6 @@ return [
|
|||||||
'hwe/j_board_article_add.php',
|
'hwe/j_board_article_add.php',
|
||||||
'hwe/j_board_comment_add.php',
|
'hwe/j_board_comment_add.php',
|
||||||
'hwe/j_board_get_articles.php',
|
'hwe/j_board_get_articles.php',
|
||||||
'hwe/j_die_immediately.php',
|
|
||||||
'hwe/j_diplomacy_destroy_letter.php',
|
'hwe/j_diplomacy_destroy_letter.php',
|
||||||
'hwe/j_diplomacy_get_letter.php',
|
'hwe/j_diplomacy_get_letter.php',
|
||||||
'hwe/j_diplomacy_respond_letter.php',
|
'hwe/j_diplomacy_respond_letter.php',
|
||||||
|
|||||||
+7
-7
@@ -5,8 +5,8 @@ namespace sammo;
|
|||||||
include "lib.php";
|
include "lib.php";
|
||||||
include "func.php";
|
include "func.php";
|
||||||
|
|
||||||
$showDieImmediatelyBtn = false;
|
$showDieOnPrestart = false;
|
||||||
$availableDieImmediately = false;
|
$availableDieOnPrestart = false;
|
||||||
|
|
||||||
//로그인 검사
|
//로그인 검사
|
||||||
$session = Session::requireGameLogin()->setReadOnly();
|
$session = Session::requireGameLogin()->setReadOnly();
|
||||||
@@ -32,9 +32,9 @@ $targetTime = addTurn($me->getVar('lastrefresh'), $gameStor->turnterm, 2);
|
|||||||
if ($gameStor->turntime <= $gameStor->opentime) {
|
if ($gameStor->turntime <= $gameStor->opentime) {
|
||||||
//서버 가오픈시 할 수 있는 행동
|
//서버 가오픈시 할 수 있는 행동
|
||||||
if ($me->getNPCType() == 0) {
|
if ($me->getNPCType() == 0) {
|
||||||
$showDieImmediatelyBtn = true;
|
$showDieOnPrestartBtn = true;
|
||||||
if ($targetTime <= TimeUtil::now()) {
|
if ($targetTime <= TimeUtil::now()) {
|
||||||
$availableDieImmediately = true;
|
$availableDieOnPrestart = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ $use_auto_nation_turn = $me->getAuxVar('use_auto_nation_turn') ?? 1;
|
|||||||
<meta name="viewport" content="width=500" />
|
<meta name="viewport" content="width=500" />
|
||||||
<title><?= UniqueConst::$serverName ?>: 내정보</title>
|
<title><?= UniqueConst::$serverName ?>: 내정보</title>
|
||||||
<?= WebUtil::printStaticValues([
|
<?= WebUtil::printStaticValues([
|
||||||
'availableDieImmediately' => $availableDieImmediately,
|
'availableDieOnPrestart' => $availableDieOnPrestart,
|
||||||
'staticValues' => [
|
'staticValues' => [
|
||||||
'items' => Util::mapWithKey(fn (string $key, BaseItem $item) => [
|
'items' => Util::mapWithKey(fn (string $key, BaseItem $item) => [
|
||||||
'name' => $item->getName(),
|
'name' => $item->getName(),
|
||||||
@@ -122,9 +122,9 @@ $use_auto_nation_turn = $me->getAuxVar('use_auto_nation_turn') ?? 1;
|
|||||||
<!--빙의 해제용 삭턴 조절<br>
|
<!--빙의 해제용 삭턴 조절<br>
|
||||||
<a href="b_myPage.php?detachNPC=1"><button type="button" style=background-color:<?= GameConst::$basecolor2 ?>;color:white;width:160px;height:30px;font-size:14px;>빙의 해체 요청</button></a>-->
|
<a href="b_myPage.php?detachNPC=1"><button type="button" style=background-color:<?= GameConst::$basecolor2 ?>;color:white;width:160px;height:30px;font-size:14px;>빙의 해체 요청</button></a>-->
|
||||||
|
|
||||||
<?php if ($showDieImmediatelyBtn) : ?>
|
<?php if ($showDieOnPrestartBtn) : ?>
|
||||||
가오픈 기간 내 장수 삭제 (<?= substr($targetTime, 0, 19) ?> 부터)<br>
|
가오픈 기간 내 장수 삭제 (<?= substr($targetTime, 0, 19) ?> 부터)<br>
|
||||||
<a href="c_die_immediately.php" id='die_immediately'><button type="button" style=background-color:<?= GameConst::$basecolor2 ?>;color:white;width:160px;height:30px;font-size:14px;>장수 삭제</button></a><br><br>
|
<button type="button" id='dieOnPrestart' style=background-color:<?= GameConst::$basecolor2 ?>;color:white;width:160px;height:30px;font-size:14px;>장수 삭제</button><br><br>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($gameStor->npcmode == 2 && $me->getNPCType() == 0) : ?>
|
<?php if ($gameStor->npcmode == 2 && $me->getNPCType() == 0) : ?>
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace sammo;
|
|
||||||
|
|
||||||
include "lib.php";
|
|
||||||
include "func.php";
|
|
||||||
|
|
||||||
|
|
||||||
WebUtil::requireAJAX();
|
|
||||||
|
|
||||||
$availableDieImmediately = false;
|
|
||||||
|
|
||||||
//로그인 검사
|
|
||||||
$session = Session::requireGameLogin();
|
|
||||||
$userID = Session::getUserID();
|
|
||||||
|
|
||||||
$db = DB::db();
|
|
||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
|
||||||
|
|
||||||
$general = $db->queryFirstRow('SELECT no,name,owner_name,npc,lastrefresh FROM general WHERE owner=%i AND npc = 0', $userID);
|
|
||||||
|
|
||||||
if(!$general){
|
|
||||||
Json::die([
|
|
||||||
'result'=>false,
|
|
||||||
'reason'=>'장수가 없습니다.'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
increaseRefresh("장수 삭제", 1);
|
|
||||||
$gameStor->cacheValues(['turnterm', 'opentime', 'turntime', 'year', 'month']);
|
|
||||||
|
|
||||||
if($gameStor->turntime > $gameStor->opentime){
|
|
||||||
Json::die([
|
|
||||||
'result'=>false,
|
|
||||||
'reason'=>'이미 서버가 시작되었습니다.'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$targetTime = addTurn($general['lastrefresh'], $gameStor->turnterm, 2);
|
|
||||||
if($targetTime > TimeUtil::now()){
|
|
||||||
$targetTimeShort = substr($targetTime, 0, 19);
|
|
||||||
Json::die([
|
|
||||||
'result'=>false,
|
|
||||||
'reason'=>"아직 삭제할 수 없습니다. {$targetTimeShort} 부터 가능합니다."
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$generalObj = General::createGeneralObjFromDB($general['no']);
|
|
||||||
if($generalObj instanceof DummyGeneral){
|
|
||||||
trigger_error("올바르지 않은 삭제 프로세스 $userID", E_USER_WARNING);
|
|
||||||
}
|
|
||||||
$generalName = $generalObj->getName();
|
|
||||||
$josaYi = JosaUtil::pick($generalName, '이');
|
|
||||||
$generalObj->kill($db, true, "<Y>{$generalName}</>{$josaYi} 이 홀연히 모습을 <R>감추었습니다</>");
|
|
||||||
|
|
||||||
$session->logoutGame();
|
|
||||||
Json::die([
|
|
||||||
'result'=>true,
|
|
||||||
'reason'=>'success'
|
|
||||||
]);
|
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\API\General;
|
||||||
|
|
||||||
|
use sammo\DB;
|
||||||
|
use sammo\DummyGeneral;
|
||||||
|
|
||||||
|
use sammo\Session;
|
||||||
|
use sammo\General;
|
||||||
|
use sammo\JosaUtil;
|
||||||
|
use sammo\KVStorage;
|
||||||
|
use sammo\TimeUtil;
|
||||||
|
|
||||||
|
use function sammo\addTurn;
|
||||||
|
use function sammo\increaseRefresh;
|
||||||
|
|
||||||
|
class DieOnPrestart extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequiredSessionMode(): int
|
||||||
|
{
|
||||||
|
return static::REQ_GAME_LOGIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||||
|
{
|
||||||
|
//로그인 검사
|
||||||
|
$userID = $session->userID;
|
||||||
|
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
|
$gameStor->cacheValues(['turnterm', 'opentime', 'turntime', 'year', 'month']);
|
||||||
|
|
||||||
|
$general = $db->queryFirstRow('SELECT no,name,owner_name,npc,lastrefresh FROM general WHERE owner=%i AND npc = 0', $userID);
|
||||||
|
|
||||||
|
if (!$general) {
|
||||||
|
return '장수가 없습니다';
|
||||||
|
}
|
||||||
|
|
||||||
|
increaseRefresh("장수 삭제", 1);
|
||||||
|
|
||||||
|
|
||||||
|
if ($gameStor->turntime > $gameStor->opentime) {
|
||||||
|
return '게임이 시작되었습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
//서버 가오픈시 할 수 있는 행동
|
||||||
|
$targetTime = addTurn($general['lastrefresh'], $gameStor->turnterm, 2);
|
||||||
|
if ($targetTime > TimeUtil::now()) {
|
||||||
|
$targetTimeShort = substr($targetTime, 0, 19);
|
||||||
|
return "아직 삭제할 수 없습니다. {$targetTimeShort} 부터 가능합니다.";
|
||||||
|
}
|
||||||
|
|
||||||
|
$generalObj = General::createGeneralObjFromDB($general['no']);
|
||||||
|
if ($generalObj instanceof DummyGeneral) {
|
||||||
|
trigger_error("올바르지 않은 삭제 프로세스 $userID", E_USER_WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
$generalName = $generalObj->getName();
|
||||||
|
$josaYi = JosaUtil::pick($generalName, '이');
|
||||||
|
$generalObj->kill($db, true, "<Y>{$generalName}</>{$josaYi} 이 홀연히 모습을 <R>감추었습니다</>");
|
||||||
|
|
||||||
|
$session->logoutGame();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -125,6 +125,7 @@ const apiRealPath = {
|
|||||||
DropItem: PUT as APICallT<{
|
DropItem: PUT as APICallT<{
|
||||||
itemType: ItemTypeKey;
|
itemType: ItemTypeKey;
|
||||||
}>,
|
}>,
|
||||||
|
DieOnPrestart: POST as APICallT<undefined>,
|
||||||
},
|
},
|
||||||
Global: {
|
Global: {
|
||||||
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
|
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
|
||||||
|
|||||||
+2
-15
@@ -130,22 +130,15 @@ $(function ($) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#die_immediately').on('click', async function (e) {
|
$('#dieOnPrestart').on('click', async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!confirm('정말로 삭제하시겠습니까?')) {
|
if (!confirm('정말로 삭제하시겠습니까?')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result: InvalidResponse;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
await SammoAPI.General.DieOnPrestart();
|
||||||
url: 'j_die_immediately.php',
|
|
||||||
method: 'post',
|
|
||||||
responseType: 'json',
|
|
||||||
});
|
|
||||||
result = response.data;
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
@@ -154,12 +147,6 @@ $(function ($) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.result) {
|
|
||||||
alert(`실패했습니다: ${result.reason}`);
|
|
||||||
location.reload();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
location.replace('..');
|
location.replace('..');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user