NPC 생성시 버그 수정

서버 리셋되었을 때 세션 값 안정을 위해 serverID 개념을 추가.
This commit is contained in:
2018-04-01 01:20:35 +09:00
parent 0f97ae8da9
commit 1ddd26c8a1
9 changed files with 64 additions and 34 deletions
+19 -16
View File
@@ -145,7 +145,10 @@ class Session {
if($this->writeClosed){
$this->restart();
}
$this->logoutGame();
if(class_exists('\\sammo\\UniqueConst')){
$this->logoutGame();
}
$this->set('userID', null);
$this->set('userName', null);
$this->set('userGrade', null);
@@ -162,20 +165,20 @@ class Session {
return $this;
}
if(!class_exists('\\sammo\\DB')){
if(!class_exists('\\sammo\\DB') || !class_exists('\\sammo\\UniqueConst')){
if($result !== null){
$result = false;
}
return $this;
}
$prefix = DB::prefix();
$serverID = UniqueConst::$serverID;
$db = DB::db();
$loginDate = $this->get($prefix.static::GAME_KEY_DATE);
$generalID = $this->get($prefix.static::GAME_KEY_GENERAL_ID);
$generalName = $this->get($prefix.static::GAME_KEY_GENERAL_NAME);
$deadTime = $this->get($prefix.static::GAME_KEY_EXPECTED_DEADTIME);
$loginDate = $this->get($serverID.static::GAME_KEY_DATE);
$generalID = $this->get($serverID.static::GAME_KEY_GENERAL_ID);
$generalName = $this->get($serverID.static::GAME_KEY_GENERAL_NAME);
$deadTime = $this->get($serverID.static::GAME_KEY_EXPECTED_DEADTIME);
$now = time();
if(
@@ -220,21 +223,21 @@ class Session {
}
$this->set($prefix.static::GAME_KEY_DATE, $now);
$this->set($prefix.static::GAME_KEY_GENERAL_ID, $generalID);
$this->set($prefix.static::GAME_KEY_GENERAL_NAME, $generalName);
$this->set($prefix.static::GAME_KEY_EXPECTED_DEADTIME, $deadTime);
$this->set($serverID.static::GAME_KEY_DATE, $now);
$this->set($serverID.static::GAME_KEY_GENERAL_ID, $generalID);
$this->set($preserverIDfix.static::GAME_KEY_GENERAL_NAME, $generalName);
$this->set($serverID.static::GAME_KEY_EXPECTED_DEADTIME, $deadTime);
}
public function logoutGame(): Session{
if($this->writeClosed){
$this->restart();
}
$prefix = DB::prefix();
$this->set($prefix.static::GAME_KEY_DATE, null);
$this->set($prefix.static::GAME_KEY_GENERAL_ID, null);
$this->set($prefix.static::GAME_KEY_GENERAL_NAME, null);
$this->set($prefix.static::GAME_KEY_EXPECTED_DEADTIME, null);
$serverID = UniqueConst::$serverID;
$this->set($serverID.static::GAME_KEY_DATE, null);
$this->set($serverID.static::GAME_KEY_GENERAL_ID, null);
$this->set($serverID.static::GAME_KEY_GENERAL_NAME, null);
$this->set($serverID.static::GAME_KEY_EXPECTED_DEADTIME, null);
return $this;
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace sammo;
class UniqueConst{
public static $serverID = '_tK_serverID_';
private function __construct(){}
}
+1
View File
@@ -1567,6 +1567,7 @@ function cutDay($date, int $turnterm) {
}
function increaseRefresh($type="", $cnt=1) {
$generalID = Session::
$date = date('Y-m-d H:i:s');
DB::db()->query('UPDATE game set refresh=refresh+%i where `no`=1', $cnt);
+18 -4
View File
@@ -80,12 +80,19 @@ if(!is_writable(__dir__.'/data')){
]);
}
if(!file_exists(ROOT.'/logs/.htaccess')){
@file_put_contents(ROOT.'/logs/.htaccess', 'Deny from all');
if(!is_writable(__dir__.'/d_setting')){
Json::die([
'result'=>false,
'reason'=>'d_setting 디렉토리의 쓰기 권한이 없습니다'
]);
}
if(!file_exists(ROOT.'/data/.htaccess')){
@file_put_contents(ROOT.'/data/.htaccess', 'Deny from all');
if(!file_exists(__dir__.'/logs/.htaccess')){
@file_put_contents(__dir__.'/logs/.htaccess', 'Deny from all');
}
if(!file_exists(__dir__.'/data/.htaccess')){
@file_put_contents(__dir__.'/data/.htaccess', 'Deny from all');
}
@@ -99,6 +106,13 @@ $startyear = $scenarioObj->getYear();
FileUtil::delInDir("logs");
FileUtil::delInDir("data");
$result = Util::generateFileUsingSimpleTemplate(
__DIR__.'/d_setting/UniqueConst.orig.php',
__DIR__.'/d_setting/UniqueConst.php',[
'serverID'=>DB::prefix().'_'.Util::randomStr(8)
], true
);
if($mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/reset.sql'))){
while(true){
if (!$mysqli_obj->more_results()) {
+6
View File
@@ -43,6 +43,12 @@ if($fullReset && class_exists('\\sammo\\DB')){
if($fullReset){
FileUtil::delInDir(__dir__."/logs");
FileUtil::delInDir(__dir__."/data");
if(file_exists(__dir__.'/d_setting/DB.php')){
@unlink(__dir__.'/d_setting/DB.php');
}
if(file_exists(__dir__.'/d_setting/UniqueConst.php')){
@unlink(__dir__.'/d_setting/UniqueConst.php');
}
}
function dbConnFail($params){
+8 -13
View File
@@ -25,21 +25,16 @@ $game['userCnt'] = $genCnt;
$game['npcCnt'] = $npcCnt;
$game['nationCnt'] = $nationCnt;
$generalID = getGeneralID(false, false);
$userGrade = $session->userGrade;
$me = [
];
$me = [];
if($generalID){
$general = $db->queryFirstRow('SELECT name, picture, imgsvr from general where no=%i', $generalID);
if($general){
$me['name'] = $general['name'];
$general = $db->queryFirstRow('SELECT name, picture, imgsvr from general where owner=%i', $session->userID);
if($general){
$me['name'] = $general['name'];
if($general['imgsvr'] == 0) {
$me['picture'] = '../../image/'.$general['picture'];
} else {
$me['picture'] = '../d_pic/'.$general['picture'];
}
if($general['imgsvr'] == 0) {
$me['picture'] = '../../image/'.$general['picture'];
} else {
$me['picture'] = '../d_pic/'.$general['picture'];
}
}
+1
View File
@@ -0,0 +1 @@
Deny from all
+1
View File
@@ -73,6 +73,7 @@ class NPC{
$year = $env['year'];
$month = $env['month'];
$age = $year - $this->birth;
$name = $this->name;
if($this->death < $year){
return true; //죽었으니 넘어간다.
+1 -1
View File
@@ -4,7 +4,7 @@
CREATE TABLE `general` (
`no` INT(11) NOT NULL AUTO_INCREMENT,
`owner` INT(11) NOT NULL DEFAULT '-1',
`owner` INT(11) NOT NULL DEFAULT '0',
`conmsg` CHAR(255) NOT NULL DEFAULT '',
`npcmsg` CHAR(255) NULL DEFAULT '',
`npcid` INT(5) NULL DEFAULT NULL,