Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

상점 DB를 수정하거나 /language/flush에 GET 요청을 하면 상점을 정상적으로 로드할 수 없는 현상 해결 #925

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Server/lib/Web/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ Pub.ready = function(isPub){
DB.kkutu_injeong = new mainAgent.Table("kkutu_injeong");
DB.kkutu_shop = new mainAgent.Table("kkutu_shop");
DB.kkutu_shop_desc = new mainAgent.Table("kkutu_shop_desc");
DB.kkutu_shop_desc.refreshLanguage = function(Language){
this.find().on(function($docs){
var lang, i;

for(lang in Language){
var db;

Language[lang].SHOP = db = {};
for(i in $docs)
db[$docs[i]._id] = [ $docs[i][`name_${lang}`], $docs[i][`desc_${lang}`] ];
}
});
};

DB.session = new mainAgent.Table("session");
DB.users = new mainAgent.Table("users");
Expand Down
29 changes: 10 additions & 19 deletions Server/lib/Web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ var Language = {
'en_US': require("./lang/en_US.json")
};
//볕뉘 수정
var ROUTES = [
"major", "consume", "admin", "login"
];
var ROUTES = { major: {}, consume: {}, admin: {}, login: {} };
//볕뉘 수정 끝
var page = WebInit.page;
var gameServers = [];
Expand Down Expand Up @@ -118,6 +116,10 @@ DDDoS.rules[0].logFunction = DDDoS.rules[1].logFunction = function(ip, path){
Server.use(DDDoS.express());*/

WebInit.init(Server, true);
Object.keys(ROUTES).forEach((v) => {
ROUTES[v] = require(`./routes/${v}`);
});

DB.ready = function(){
setInterval(function(){
var q = [ 'createdAt', { $lte: Date.now() - 3600000 * 12 } ];
Expand All @@ -132,19 +134,8 @@ DB.ready = function(){
}, 4000);
JLog.success("DB is ready.");

DB.kkutu_shop_desc.find().on(function($docs){
var i, j;

for(i in Language) flush(i);
function flush(lang){
var db;

Language[lang].SHOP = db = {};
for(j in $docs){
db[$docs[j]._id] = [ $docs[j][`name_${lang}`], $docs[j][`desc_${lang}`] ];
}
}
});
DB.kkutu_shop_desc.refreshLanguage(Language);

Server.listen(80);
if(Const.IS_SECURED) {
const options = Secure();
Expand Down Expand Up @@ -203,9 +194,9 @@ function GameClient(id, url){
}
});
}
ROUTES.forEach(function(v){
require(`./routes/${v}`).run(Server, WebInit.page);
});

for(var i of Object.values(ROUTES)) i.run(Server, WebInit.page);

Server.get("/", function(req, res){
var server = req.query.server;

Expand Down
6 changes: 6 additions & 0 deletions Server/lib/Web/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ var MainDB = require("../db");
var GLOBAL = require("../../sub/global.json");
var JLog = require("../../sub/jjlog");
var Lizard = require("../../sub/lizard.js");
var Language = {
'ko_KR': require("../lang/ko_KR.json"),
'en_US': require("../lang/en_US.json")
};

exports.run = function(Server, page){

Expand Down Expand Up @@ -254,10 +258,12 @@ Server.post("/gwalli/shop", function(req, res){
MainDB.kkutu_shop.upsert([ '_id', item._id ]).set(item.core).on();
MainDB.kkutu_shop_desc.upsert([ '_id', item._id ]).set(item.text).on();
});
MainDB.kkutu_shop_desc.refreshLanguage(Language);
res.sendStatus(200);
});

};

function noticeAdmin(req, ...args){
JLog.info(`[ADMIN] ${req.originalUrl} ${req.ip} | ${args.join(' | ')}`);
}
Expand Down
2 changes: 2 additions & 0 deletions Server/lib/sub/webinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

var GLOBAL = require("./global.json");
var MainDB = require("../Web/db");
var JLog = require("./jjlog");
var Language = {
'ko_KR': require("../Web/lang/ko_KR.json"),
Expand All @@ -32,6 +33,7 @@ function updateLanguage(){
delete require.cache[require.resolve(src)];
Language[i] = require(src);
}
MainDB.kkutu_shop_desc.refreshLanguage(Language);
}
function getLanguage(locale, page, shop){
var i;
Expand Down