From f0d4c8f7ef1f02e062077d8933b9abdcb40a0eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A0=ED=94=84?= Date: Thu, 22 Jul 2021 21:59:48 +0900 Subject: [PATCH 1/5] =?UTF-8?q?#811=20=EB=93=B1=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/lib/Web/main.js | 21 ++++++++++++--------- Server/lib/sub/webinit.js | 5 +++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Server/lib/Web/main.js b/Server/lib/Web/main.js index 73b099d16..34d7bbff9 100644 --- a/Server/lib/Web/main.js +++ b/Server/lib/Web/main.js @@ -132,19 +132,22 @@ DB.ready = function(){ }, 4000); JLog.success("DB is ready."); - DB.kkutu_shop_desc.find().on(function($docs){ - var i, j; + WebInit.flusherRegister(function(){ + DB.kkutu_shop_desc.find().on(function($docs){ + var i, j; - for(i in Language) flush(i); - function flush(lang){ - var db; + 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}`] ]; + Language[lang].SHOP = db = {}; + for(j in $docs){ + db[$docs[j]._id] = [ $docs[j][`name_${lang}`], $docs[j][`desc_${lang}`] ]; + } } - } + }); }); + Server.listen(80); if(Const.IS_SECURED) { const options = Secure(); diff --git a/Server/lib/sub/webinit.js b/Server/lib/sub/webinit.js index 436ff9c6f..22f596079 100644 --- a/Server/lib/sub/webinit.js +++ b/Server/lib/sub/webinit.js @@ -22,6 +22,7 @@ var Language = { 'ko_KR': require("../Web/lang/ko_KR.json"), 'en_US': require("../Web/lang/en_US.json") }; +var shopFlusher; function updateLanguage(){ var i, src; @@ -42,6 +43,7 @@ function getLanguage(locale, page, shop){ if(shop) for(i in L.SHOP) R[i] = L.SHOP[i]; for(i in L[page]) R[i] = L[page][i]; if(R['title']) R['title'] = `[${process.env['KKT_SV_NAME']}] ${R['title']}`; + shopFlusher(); return R; } @@ -103,4 +105,7 @@ exports.init = function(Server, shop){ res.sendStatus(200); }); }; +exports.flusherRegister = function(flusher){ + shopFlusher = flusher; +}; exports.page = page; \ No newline at end of file From 65d67722feeaaf9767656d4e33c09507b20f1af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A0=ED=94=84?= Date: Fri, 23 Jul 2021 16:53:41 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=ED=94=BC=EB=93=9C=EB=B0=B1=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/lib/Web/main.js | 22 ++++++---------------- Server/lib/Web/routes/admin.js | 24 ++++++++++++++++++++++++ Server/lib/sub/webinit.js | 5 ----- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Server/lib/Web/main.js b/Server/lib/Web/main.js index 34d7bbff9..12114f24a 100644 --- a/Server/lib/Web/main.js +++ b/Server/lib/Web/main.js @@ -118,6 +118,10 @@ DDDoS.rules[0].logFunction = DDDoS.rules[1].logFunction = function(ip, path){ Server.use(DDDoS.express());*/ WebInit.init(Server, true); +ROUTES.forEach(function(v){ + ROUTES[ROUTES.indexOf(v)] = require(`./routes/${v}`); +}); + DB.ready = function(){ setInterval(function(){ var q = [ 'createdAt', { $lte: Date.now() - 3600000 * 12 } ]; @@ -132,21 +136,7 @@ DB.ready = function(){ }, 4000); JLog.success("DB is ready."); - WebInit.flusherRegister(function(){ - 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}`] ]; - } - } - }); - }); + ROUTES[2].flushShop(); Server.listen(80); if(Const.IS_SECURED) { @@ -207,7 +197,7 @@ function GameClient(id, url){ }); } ROUTES.forEach(function(v){ - require(`./routes/${v}`).run(Server, WebInit.page); + v.run(Server, WebInit.page); }); Server.get("/", function(req, res){ var server = req.query.server; diff --git a/Server/lib/Web/routes/admin.js b/Server/lib/Web/routes/admin.js index d50f34cff..f16f3db1f 100644 --- a/Server/lib/Web/routes/admin.js +++ b/Server/lib/Web/routes/admin.js @@ -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){ @@ -254,10 +258,14 @@ 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(); }); + flushShop(); res.sendStatus(200); }); }; + +exports.flushShop = flushShop; + function noticeAdmin(req, ...args){ JLog.info(`[ADMIN] ${req.originalUrl} ${req.ip} | ${args.join(' | ')}`); } @@ -296,4 +304,20 @@ function parseKKuTuHot(){ return R; } return R; +} +function flushShop(){ + MainDB.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}`] ]; + } + } + }); + JLog.log("Flushed Shop DB!"); } \ No newline at end of file diff --git a/Server/lib/sub/webinit.js b/Server/lib/sub/webinit.js index 22f596079..436ff9c6f 100644 --- a/Server/lib/sub/webinit.js +++ b/Server/lib/sub/webinit.js @@ -22,7 +22,6 @@ var Language = { 'ko_KR': require("../Web/lang/ko_KR.json"), 'en_US': require("../Web/lang/en_US.json") }; -var shopFlusher; function updateLanguage(){ var i, src; @@ -43,7 +42,6 @@ function getLanguage(locale, page, shop){ if(shop) for(i in L.SHOP) R[i] = L.SHOP[i]; for(i in L[page]) R[i] = L[page][i]; if(R['title']) R['title'] = `[${process.env['KKT_SV_NAME']}] ${R['title']}`; - shopFlusher(); return R; } @@ -105,7 +103,4 @@ exports.init = function(Server, shop){ res.sendStatus(200); }); }; -exports.flusherRegister = function(flusher){ - shopFlusher = flusher; -}; exports.page = page; \ No newline at end of file From ddd4626a25569050fe2439610c673f1f4e5c3533 Mon Sep 17 00:00:00 2001 From: Seunghoon Lee Date: Sat, 9 Apr 2022 17:36:01 +0900 Subject: [PATCH 3/5] --- Server/lib/Web/main.js | 16 +++++++--------- Server/lib/Web/routes/admin.js | 17 +++++++---------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Server/lib/Web/main.js b/Server/lib/Web/main.js index 12114f24a..b274bba13 100644 --- a/Server/lib/Web/main.js +++ b/Server/lib/Web/main.js @@ -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 = []; @@ -118,8 +116,8 @@ DDDoS.rules[0].logFunction = DDDoS.rules[1].logFunction = function(ip, path){ Server.use(DDDoS.express());*/ WebInit.init(Server, true); -ROUTES.forEach(function(v){ - ROUTES[ROUTES.indexOf(v)] = require(`./routes/${v}`); +Object.keys(ROUTES).forEach((v) => { + ROUTES[v] = require(`./routes/${v}`); }); DB.ready = function(){ @@ -136,7 +134,7 @@ DB.ready = function(){ }, 4000); JLog.success("DB is ready."); - ROUTES[2].flushShop(); + ROUTES.admin.updateShop(); Server.listen(80); if(Const.IS_SECURED) { @@ -196,9 +194,9 @@ function GameClient(id, url){ } }); } -ROUTES.forEach(function(v){ - 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; diff --git a/Server/lib/Web/routes/admin.js b/Server/lib/Web/routes/admin.js index f16f3db1f..2bd2057fa 100644 --- a/Server/lib/Web/routes/admin.js +++ b/Server/lib/Web/routes/admin.js @@ -258,13 +258,13 @@ 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(); }); - flushShop(); + updateShop(); res.sendStatus(200); }); }; -exports.flushShop = flushShop; +exports.updateShop = updateShop; function noticeAdmin(req, ...args){ JLog.info(`[ADMIN] ${req.originalUrl} ${req.ip} | ${args.join(' | ')}`); @@ -305,19 +305,16 @@ function parseKKuTuHot(){ } return R; } -function flushShop(){ +function updateShop(){ MainDB.kkutu_shop_desc.find().on(function($docs){ - var i, j; + var lang, i; - for(i in Language) flush(i); - function flush(lang){ + for(lang in Language){ var db; Language[lang].SHOP = db = {}; - for(j in $docs){ - db[$docs[j]._id] = [ $docs[j][`name_${lang}`], $docs[j][`desc_${lang}`] ]; - } + for(i in $docs) + db[$docs[i]._id] = [ $docs[i][`name_${lang}`], $docs[i][`desc_${lang}`] ]; } }); - JLog.log("Flushed Shop DB!"); } \ No newline at end of file From 21e46e5bcdc7f07f88cc95802d20c4d0103b0783 Mon Sep 17 00:00:00 2001 From: Seunghoon Lee Date: Sat, 3 Sep 2022 01:26:54 +0900 Subject: [PATCH 4/5] Fixed shop issue when GET /language/flush --- Server/lib/Web/db.js | 13 +++++++++++++ Server/lib/Web/main.js | 2 +- Server/lib/Web/routes/admin.js | 17 +---------------- Server/lib/sub/webinit.js | 2 ++ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Server/lib/Web/db.js b/Server/lib/Web/db.js index de07a5d70..6785f746c 100644 --- a/Server/lib/Web/db.js +++ b/Server/lib/Web/db.js @@ -86,6 +86,19 @@ Pub.ready = function(isPub){ /* Enhanced User Block System [S] */ DB.ip_block = new mainAgent.Table("ip_block"); /* Enhanced User Block System [E] */ + DB.updateShop = function(Language){ + this.kkutu_shop_desc.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}`] ]; + } + }); + }; if(exports.ready) exports.ready(Redis, Pg); else JLog.warn("DB.onReady was not defined yet."); diff --git a/Server/lib/Web/main.js b/Server/lib/Web/main.js index b274bba13..240592818 100644 --- a/Server/lib/Web/main.js +++ b/Server/lib/Web/main.js @@ -134,7 +134,7 @@ DB.ready = function(){ }, 4000); JLog.success("DB is ready."); - ROUTES.admin.updateShop(); + DB.updateShop(Language); Server.listen(80); if(Const.IS_SECURED) { diff --git a/Server/lib/Web/routes/admin.js b/Server/lib/Web/routes/admin.js index 2bd2057fa..602f09197 100644 --- a/Server/lib/Web/routes/admin.js +++ b/Server/lib/Web/routes/admin.js @@ -258,14 +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(); }); - updateShop(); + MainDB.updateShop(Language); res.sendStatus(200); }); }; -exports.updateShop = updateShop; - function noticeAdmin(req, ...args){ JLog.info(`[ADMIN] ${req.originalUrl} ${req.ip} | ${args.join(' | ')}`); } @@ -304,17 +302,4 @@ function parseKKuTuHot(){ return R; } return R; -} -function updateShop(){ - MainDB.kkutu_shop_desc.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}`] ]; - } - }); } \ No newline at end of file diff --git a/Server/lib/sub/webinit.js b/Server/lib/sub/webinit.js index 436ff9c6f..0802d983e 100644 --- a/Server/lib/sub/webinit.js +++ b/Server/lib/sub/webinit.js @@ -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"), @@ -32,6 +33,7 @@ function updateLanguage(){ delete require.cache[require.resolve(src)]; Language[i] = require(src); } + MainDB.updateShop(Language); } function getLanguage(locale, page, shop){ var i; From 99b734023ab762fab349299b55e505d1f55c28ba Mon Sep 17 00:00:00 2001 From: Seunghoon Lee Date: Sat, 3 Sep 2022 01:43:56 +0900 Subject: [PATCH 5/5] Change expression more obviously --- Server/lib/Web/db.js | 16 ++++++++-------- Server/lib/Web/main.js | 2 +- Server/lib/Web/routes/admin.js | 2 +- Server/lib/sub/webinit.js | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Server/lib/Web/db.js b/Server/lib/Web/db.js index 6785f746c..8a19cf290 100644 --- a/Server/lib/Web/db.js +++ b/Server/lib/Web/db.js @@ -80,14 +80,8 @@ 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.session = new mainAgent.Table("session"); - DB.users = new mainAgent.Table("users"); - /* Enhanced User Block System [S] */ - DB.ip_block = new mainAgent.Table("ip_block"); - /* Enhanced User Block System [E] */ - DB.updateShop = function(Language){ - this.kkutu_shop_desc.find().on(function($docs){ + DB.kkutu_shop_desc.refreshLanguage = function(Language){ + this.find().on(function($docs){ var lang, i; for(lang in Language){ @@ -100,6 +94,12 @@ Pub.ready = function(isPub){ }); }; + DB.session = new mainAgent.Table("session"); + DB.users = new mainAgent.Table("users"); + /* Enhanced User Block System [S] */ + DB.ip_block = new mainAgent.Table("ip_block"); + /* Enhanced User Block System [E] */ + if(exports.ready) exports.ready(Redis, Pg); else JLog.warn("DB.onReady was not defined yet."); }); diff --git a/Server/lib/Web/main.js b/Server/lib/Web/main.js index 240592818..fa312e1de 100644 --- a/Server/lib/Web/main.js +++ b/Server/lib/Web/main.js @@ -134,7 +134,7 @@ DB.ready = function(){ }, 4000); JLog.success("DB is ready."); - DB.updateShop(Language); + DB.kkutu_shop_desc.refreshLanguage(Language); Server.listen(80); if(Const.IS_SECURED) { diff --git a/Server/lib/Web/routes/admin.js b/Server/lib/Web/routes/admin.js index 602f09197..9af663b63 100644 --- a/Server/lib/Web/routes/admin.js +++ b/Server/lib/Web/routes/admin.js @@ -258,7 +258,7 @@ 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.updateShop(Language); + MainDB.kkutu_shop_desc.refreshLanguage(Language); res.sendStatus(200); }); diff --git a/Server/lib/sub/webinit.js b/Server/lib/sub/webinit.js index 0802d983e..475e10a2e 100644 --- a/Server/lib/sub/webinit.js +++ b/Server/lib/sub/webinit.js @@ -33,7 +33,7 @@ function updateLanguage(){ delete require.cache[require.resolve(src)]; Language[i] = require(src); } - MainDB.updateShop(Language); + MainDB.kkutu_shop_desc.refreshLanguage(Language); } function getLanguage(locale, page, shop){ var i;