게임 코드에도 Composer의 ClassLoader를 이용하는 코드로 변경

입구 코드에서 WebUtil::setHeaderNoCache(); 수동 지정
에러 페이지 변경
This commit is contained in:
2018-04-04 02:51:14 +09:00
parent e1c97b1ca0
commit fcbd801dc7
11 changed files with 116 additions and 123 deletions
+1 -11
View File
@@ -8,11 +8,6 @@ define('IMAGES', '../../images');
define('ROOT', realpath(__dir__.'/..'));
function CustomHeader() {
//xxx: CustomHeader를 제거하기 전까진 유지
WebUtil::setHeaderNoCache();
}
function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext){
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting, so let it fall
@@ -22,14 +17,9 @@ function logErrorByCustomHandler(int $errno, string $errstr, string $errfile, in
$date = date("Ymd_His");
file_put_contents(__DIR__.'/../d_log/err_log.txt',"$date, $errno, $errstr, $errfile, $errline\n", FILE_APPEND);
file_put_contents(ROOT.'/d_log/err_log.txt',"$date, $errno, $errstr, $errfile, $errline\n", FILE_APPEND);
/* Don't execute PHP internal error handler */
//return true;
}
set_error_handler("\sammo\logErrorByCustomHandler");
function Error($msg) {
file_put_contents(ROOT.'/d_log/err.txt', $msg."\n", FILE_APPEND);
exit(1);
}
+22 -13
View File
@@ -3,8 +3,6 @@ namespace sammo;
require(__dir__.'/../vendor/autoload.php');
?>
<!DOCTYPE html>
<html lang="ko">
@@ -35,14 +33,16 @@ require(__dir__.'/../vendor/autoload.php');
<div class="form-group row">
<label for="db_host" class="col-sm-3 col-form-label">DB호스트</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="db_host" id="db_host" placeholder="호스트" value="localhost" />
<input type="text" class="form-control" name="db_host" id="db_host"
placeholder="호스트" value="localhost" />
</div>
</div>
<div class="form-group row">
<label for="db_port" class="col-sm-3 col-form-label">DB포트</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="db_port" id="db_port" placeholder="접속 포트" value="3306" />
<input type="text" class="form-control" name="db_port" id="db_port"
placeholder="접속 포트" value="3306" />
</div>
</div>
@@ -57,28 +57,32 @@ require(__dir__.'/../vendor/autoload.php');
<div class="form-group row">
<label for="db_pw" class="col-sm-3 col-form-label">DB비밀번호</label>
<div class="col-sm-9">
<input type="password" class="form-control" name="db_pw" id="db_pw" placeholder="DB비밀번호"/>
<input type="password" class="form-control" name="db_pw" id="db_pw"
placeholder="DB비밀번호"/>
</div>
</div>
<div class="form-group row">
<label for="db_name" class="col-sm-3 col-form-label">DB명</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="db_name" id="db_name" placeholder="DB명(예:sammo)"/>
<input type="text" class="form-control" name="db_name" id="db_name"
placeholder="DB명(예:sammo)"/>
</div>
</div>
<div class="form-group row">
<label for="serv_host" class="col-sm-3 col-form-label">접속 경로</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="serv_host" id="serv_host" placeholder="접속경로(예:http://www.example.com)"/>
<input type="text" class="form-control" name="serv_host" id="serv_host"
placeholder="접속경로(예:http://www.example.com)"/>
</div>
</div>
<div class="form-group row">
<div class="col-sm-3"></div>
<div class="col-sm-9">
<button type="submit" class="btn btn-primary btn-lg btn-block login-button">설정 파일 생성</button>
<button type="submit"
class="btn btn-primary btn-lg btn-block login-button">설정 파일 생성</button>
</div>
</div>
</form>
@@ -94,7 +98,8 @@ require(__dir__.'/../vendor/autoload.php');
<div class="form-group row">
<label for="username" class="col-sm-3 col-form-label">계정명</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="username" id="username" placeholder="계정명"/>
<input type="text" class="form-control" name="username" id="username"
placeholder="계정명"/>
</div>
</div>
@@ -102,21 +107,24 @@ require(__dir__.'/../vendor/autoload.php');
<div class="form-group row">
<label for="password" class="col-sm-3 col-form-label">비밀번호</label>
<div class="col-sm-9">
<input type="password" class="form-control" name="password" id="password" placeholder="비밀번호"/>
<input type="password" class="form-control" name="password" id="password"
placeholder="비밀번호"/>
</div>
</div>
<div class="form-group row">
<label for="confirm_password" class="col-sm-3 col-form-label">비밀번호 확인</label>
<div class="col-sm-9">
<input type="password" class="form-control" name="confirm_password" id="confirm_password" placeholder="비밀번호 확인"/>
<input type="password" class="form-control" name="confirm_password" id="confirm_password"
placeholder="비밀번호 확인"/>
</div>
</div>
<div class="form-group row">
<label for="nickname" class="col-sm-3 col-form-label">닉네임</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="nickname" id="nickname" placeholder="닉네임" value="운영자"/>
<input type="text" class="form-control" name="nickname" id="nickname"
placeholder="닉네임" value="운영자"/>
</div>
</div>
@@ -125,7 +133,8 @@ require(__dir__.'/../vendor/autoload.php');
<div class="form-group row">
<div class="col-sm-3"></div>
<div class="col-sm-9">
<button type="submit" class="btn btn-primary btn-lg btn-block login-button">관리자 계정 생성</button>
<button type="submit"
class="btn btn-primary btn-lg btn-block login-button">관리자 계정 생성</button>
</div>
</div>
</form>
-33
View File
@@ -1,33 +0,0 @@
<?php
namespace sammo;
file_put_contents("logs/_db_bug.txt", $message."\n", FILE_APPEND);
?>
<!DOCTYPE html>
<html>
<head>
<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>
<title>에러</title>
<link rel=stylesheet href=css/common.css type=text/css>
</head>
<body>
<br><br><br><br><br>
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13px;word-break:break-all; id=bg0>
<tr><td align=center style=background-color:225500;><font color=orange size=5>서 버 에 러</font></td></tr>
<tr>
<td>
<font color=white size=3>두가지 중 한가지 이유일 수 있습니다.<br><br>
1. 현재 서버가 처리중입니다. 몇초 후 아래 버튼을 눌러주세요.<br><br>
2. 오랫동안 이 메세지가 뜰 경우는 서버에 에러가 발생하여 잠시 중단된 상태입니다.<br>
&nbsp;&nbsp;&nbsp;운영자가 처리할 때까지 기다려주세요.</font>
</td>
</tr>
<tr><td align=center><font color=white size=3>잠시 후 아래의 버튼을 눌러주세요.</font></td></tr>
<tr><td align=center><input type=button value='몇초간 지난 후 눌러주세요' onclick=location.replace('index.php')></td></tr>
<tr><td align=center><?=$message;?></td></tr>
<tr><td><?php debug_print_backtrace(); ?></td></tr>
</table>
</body>
</html>
-1
View File
@@ -1,7 +1,6 @@
<?php
namespace sammo;
require(__dir__.'/../vendor/autoload.php');
require_once 'process_war.php';
require_once 'func_gamerule.php';
require_once 'func_process.php';
+55 -62
View File
@@ -1,46 +1,23 @@
<?php
namespace sammo;
/**
* https://php.net/manual/kr/language.oop5.autoload.php#120258
* 현재 디렉토리 기준으로 php 파일 탐색.
*/
class Autoloader
{
public static function register()
{
static $isRegisterd = false;
if($isRegisterd){
return;
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __dir__.'/../vendor/autoload.php';
$loader->addPsr4('sammo\\', __DIR__.'/sammo', true);
$loader->addClassMap((function(){
$d_settingMap = [];
foreach(glob(__dir__.'/d_setting/*.php') as $filepath){
$filename = basename($filepath);
if(Util::ends_with($filename, '.orig.php')){
continue;
}
$classname = explode('.', $filename)[0];
$d_settingMap['sammo\\'.$classname] = $filepath;
};
return $d_settingMap;
})());
//trick, 개인용 세팅의 경우 d_setting의 값을 우선시하도록 함.
spl_autoload_register(function ($class) {
$class = Util::array_last(explode('\\', $class));
$file = __DIR__."/d_setting/{$class}.php";
if (file_exists($file)) {
require $file;
return true;
}
return false;
});
$isRegisterd = true;
spl_autoload_register(function ($class) {
$file = __DIR__.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
if (file_exists($file)) {
require $file;
return true;
}
return false;
});
}
}
Autoloader::register();
require(__dir__.'/../vendor/autoload.php');
/******************************************************************************
체섭용 인클루드 파일
@@ -50,8 +27,6 @@ require(__dir__.'/../vendor/autoload.php');
// @header ("P3P : CP=\"ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC OTC\"");
//디버그용 매크로
define('__OLINE__',__LINE__);
define('__LINE__',__FILE__." ".__FUNCTION__." ".__LINE__." : ");
ini_set("session.cache_expire", 10080); // minutes
@@ -105,60 +80,78 @@ session_cache_limiter('nocache');//NOTE: 캐시가 가능하도록 설정해야
* Session에 보관된 장수 정보를 제거함.
* _prefix_p_no, _prefix_p_name 두 값임
*/
function resetSessionGeneralValues(){
function resetSessionGeneralValues()
{
Session::Instance()->logoutGame();
}
// MySQL 데이타 베이스에 접근
function dbConn($isRoot=false) {
if($isRoot){
function dbConn($isRoot=false)
{
if ($isRoot) {
return RootDB::db()->get();
}
return DB::db()->get();
}
// 에러 메세지 출력
function Error($message, $url="") {
global $setup, $connect, $dir, $config_dir;
include "error.php";
if($connect) @MYDB_close($connect);
exit;
function Error($message, $url="")
{
if(!$url){
$url = $_SERVER['REQUEST_URI'];
}
WebUtil::setHeaderNoCache();
file_put_contents(__dir__."/logs/_db_bug.txt", "{\"url\":$url,\"msg\":\"$message\"}\n", FILE_APPEND);
$templates = new \League\Plates\Engine('templates');
die($templates->render('error', [
'message' => $msg
]));
}
// 게시판의 생성유무 검사
function isTable($connect, $str, $dbname='') {
if(!$dbname) {
function isTable($connect, $str, $dbname='')
{
if (!$dbname) {
$f=@file("d_setting/DB.php") or Error("DB.php파일이 없습니다. DB설정을 먼저 하십시요");
for($i=1;$i<=4;$i++) $f[$i]=str_replace("\n","",$f[$i]);
for ($i=1;$i<=4;$i++) {
$f[$i]=str_replace("\n", "", $f[$i]);
}
$dbname=$f[4];
}
$result = MYDB_list_tables($dbname, $connect) or Error(__LINE__." : list_table error : ".MYDB_error($connect),"");
$result = MYDB_list_tables($dbname, $connect) or Error(__LINE__." : list_table error : ".MYDB_error($connect), "");
$cnt = MYDB_num_rows($result);
for($i=0; $i < $cnt; $i++) {
for ($i=0; $i < $cnt; $i++) {
$tablename = MYDB_fetch_row($result);
if($str == $tablename[0]) return 1;
if ($str == $tablename[0]) {
return 1;
}
}
return 0;
}
function MessageBox($str) {
function MessageBox($str)
{
echo "<script>alert('$str');</script>";
}
function PrintElapsedTime() {
function PrintElapsedTime()
{
global $_startTime;
$_endTime = round(microtime(true) - $_startTime, 3);
echo "<table width=1000 align=center style=font-size:10;><tr><td align=right>경과시간 : {$_endTime}초</td></tr></table>";
}
function LogText($prefix, $variable){
function LogText($prefix, $variable)
{
$fp = fopen('logs/dbg_logs.txt', 'a+');
if($fp == false){
if ($fp == false) {
$directory_name = dirname('logs/dbg_logs.txt');
if(!is_dir($directory_name)){
if (!is_dir($directory_name)) {
mkdir($directory_name);
$fp = fopen('logs/dbg_logs.txt', 'a+');
}
@@ -168,9 +161,9 @@ function LogText($prefix, $variable){
}
if(isset($_POST) && count($_POST) > 0){
if (isset($_POST) && count($_POST) > 0) {
LogText($_SERVER['REQUEST_URI'], $_POST);
}
extract($_POST, EXTR_SKIP);
extract($_POST, EXTR_SKIP);
//XXX: $_POST를 추출 없이 그냥 쓰는 경우가 많아서 일단 디버깅을 위해 씀!!!! 절대 production 서버에서 사용 금지!
//todo: $_POST로 제공되는 데이터를 각 페이지마다 분석할것.
//todo: $_POST로 제공되는 데이터를 각 페이지마다 분석할것.
+32
View File
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>에러</title>
<link rel='stylesheet' href='../css/config.css' type='text/css'>
</head>
<body>
<div class="bg0 legacy_layout"
style="width:1000px;color:white;position:absolute;left:50%;top:50%;transform:translateX(-50%) translateY(-50%) ;">
<h2 class="with_border bg1" style="color:orange;text-align:center;"> </h2>
<main class="with_border" >
두가지 한가지 이유일 있습니다.<br><br>
1. 현재 서버가 처리중입니다. 몇초 아래 버튼을 눌러주세요.<br><br>
2. 오랫동안 메세지가 경우는 서버에 에러가 발생하여 잠시 중단된 상태입니다.<br>
&nbsp;&nbsp;&nbsp;운영자가 처리할 때까지 기다려주세요
</main>
<div class="with_border">
<button style='width:200px;height:2em;font-size:1.2em;' onclick="location.replace('index.php')"> 눌러주세요</button>
</div>
<div class="with_border">
<?=$message?>
</div>
<div class="with_border">
<?php debug_print_backtrace(); ?>
</div>
</div>
</body>
</html>
+1
View File
@@ -3,6 +3,7 @@ namespace sammo;
require(__dir__.'/../vendor/autoload.php');
WebUtil::setHeaderNoCache();
$session = Session::requireLogin()->setReadOnly();
$templates = new \League\Plates\Engine('templates');
+1 -1
View File
@@ -3,7 +3,7 @@ namespace sammo;
require(__dir__.'/../vendor/autoload.php');
WebUtil::setHeaderNoCache();
$category = Util::array_get($_GET['category'], 0);
//FIXME: 겨우 category 구분을 위해 php를 써야하는가? JavaScript로 바꾸자
$images = IMAGES;
+1 -1
View File
@@ -2,7 +2,7 @@
namespace sammo;
require(__dir__.'/../vendor/autoload.php');
WebUtil::setHeaderNoCache();//FIXME: 이 파일에는 이럴 이유가 없다. javascript 기반으로 바꿔도 충분
$images = IMAGES;
if($sel == 0) $sel = 1;
+1 -1
View File
@@ -4,7 +4,7 @@ namespace sammo;
require(__dir__.'/../vendor/autoload.php');
WebUtil::setHeaderNoCache();
$session = Session::Instance()->setReadOnly();
$access_token = $session->access_token;
+2
View File
@@ -5,6 +5,8 @@ require(__dir__.'/../vendor/autoload.php');
use \kakao\Kakao_REST_API_Helper as Kakao_REST_API_Helper;
WebUtil::setHeaderNoCache();
$auth_code = Util::array_get($_GET['code']);
if(!$auth_code){