Skip to content

Commit

Permalink
Merge pull request #9 from MarcelKaemper/cDevOptimise
Browse files Browse the repository at this point in the history
Merging cDevOptimise with master branch
  • Loading branch information
Exarous authored Dec 2, 2019
2 parents 686291c + f46615c commit 3914b4c
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 98 deletions.
10 changes: 10 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const serverRouter = require('./routes/server');
const stocksRouter = require('./routes/stocks');
const clanRouter = require('./routes/clan');
const mailRouter = require('./routes/mail');
const shopRouter = require('./routes/shop');
const bankRouter = require('./routes/bank');
const consoleRouter = require('./routes/console');
const inventoryRouter = require('./routes/inventory');
const adminRouter = require('./routes/admin');

const app = express();

Expand All @@ -34,6 +39,11 @@ app.use('/server', serverRouter);
app.use('/stocks', stocksRouter);
app.use('/clan', clanRouter);
app.use('/mail', mailRouter);
app.use('/shop', shopRouter);
app.use('/bank', bankRouter);
app.use('/console', consoleRouter);
app.use('/inventory', inventoryRouter);
app.use('/admin', adminRouter);

cronjob();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// >> ######################################## << //
const consoleDefault = require('./console/consoleDefault.js');
const serverDefault = require('./console/serverDefault.js');
const consoleDefault = require('./consoleDefault.js');
const serverDefault = require('./serverDefault.js');
// >> ############ Console Commands ########## << //
const cmdHelp = require('./console/cmdHelp.js');
const cmdClear = require('./console/cmdClear.js');
const cmdCheck = require('./console/cmdCheck.js');
const cmdXp = require('./console/cmdXp.js');
const cmdABank = require('./console/cmdABank.js');
const cmdScan = require('./console/cmdScan.js');
const cmdMoney = require('./console/cmdMoney.js');
const cmdServer = require('./console/cmdServer.js');
const cmdHelp = require('./cmdHelp.js');
const cmdClear = require('./cmdClear.js');
const cmdCheck = require('./cmdCheck.js');
const cmdXp = require('./cmdXp.js');
const cmdABank = require('./cmdABank.js');
const cmdScan = require('./cmdScan.js');
const cmdMoney = require('./cmdMoney.js');
const cmdServer = require('./cmdServer.js');
// >> ######################################## << //
// >> ############ Server Commands ########## << //
const serverCmdExit = require('./console/serverCmdExit.js');
const serverCmdLs = require('./console/serverCmdLs.js');
const serverCmdExecute = require('./console/serverCmdExecute.js');
const serverCmdExit = require('./serverCmdExit.js');
const serverCmdLs = require('./serverCmdLs.js');
const serverCmdExecute = require('./serverCmdExecute.js');
// >> ######################################## << //

const consolecmd = (req, cmd) => {
Expand Down
3 changes: 1 addition & 2 deletions public/javascripts/functions/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const checkAdmin = require('./checkAdmin.js');
const pwh = require('password-hash');
const setLoggedIn = require('./setLoggedIn.js');
const writeRealIP = require('./writeRealIP.js');
const consolecmd = require('./console.js');
const consolecmd = require('./console/consolecmd.js');

const login = (req, arg_login, arg_password) => {
return new Promise(async(resolve, reject) => {
Expand Down Expand Up @@ -43,7 +43,6 @@ const login = (req, arg_login, arg_password) => {
req.session.ip = results2[0].ip_address;
req.session.mail = results2[0].mail_address;


req.session.isAdmin = await checkAdmin(req.session.uuid);
await writeActivity(req.session.uuid);
await setLoggedIn(req.session.loggedIn, req.session.uuid);
Expand Down
21 changes: 21 additions & 0 deletions routes/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const getAllPlayers = require('../public/javascripts/functions/getAllPlayers.js');
const adminAreaHandler = require('../public/javascripts/functions/admin/adminHandler.js');

router.get('/', async(req, res, next) => {
await stdCall(req);
res.render('admin', stdParameter(req, 'Adminarea', { players: await getAllPlayers(req.session.uuid, "everyone"), user: await getUserInfo(req) }));
});

router.post('/', async(req, res, next) => {
if (req.body.confirm) {
await adminAreaHandler(req.body.operation, req.body.user, req.body.additional);
}
res.redirect('/admin');
});

module.exports = router;
21 changes: 21 additions & 0 deletions routes/bank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const transferMoney = require('../public/javascripts/functions/transferMoney.js');
const getAllPlayers = require('../public/javascripts/functions/getAllPlayers.js');

router.get('/', async(req, res, next) => {
await stdCall(req);
let players = await getAllPlayers(req.session.uuid, "everyoneButYou");
res.render('bank', stdParameter(req, 'Bank', { money: req.session.money, players: players, user: await getUserInfo(req) }));
});

router.post('/', async(req, res, next) => {
await stdCall(req);
await transferMoney(req);
res.redirect('/bank');
});

module.exports = router;
2 changes: 1 addition & 1 deletion routes/clan.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const loadClans = require('../public/javascripts/functions/clans/loadClans.js');
const createClan = require('../public/javascripts/functions/clans/createClan.js');
const joinClan = require('../public/javascripts/functions/clans/joinClan');
const clanInfo = require('../public/javascripts/functions/clans/clanInfo');
const leaveClan = require('../public/javascripts/functions/clans/leaveClan.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');

router.get('/', async(req, res, next) => {
await stdCall(req);
Expand Down
18 changes: 18 additions & 0 deletions routes/console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const consolecmd = require('../public/javascripts/functions/console/consolecmd.js');

router.get('/', async(req, res, next) => {
await stdCall(req);
res.render('console', stdParameter(req, 'Console', { message: req.session.command_log, user: await getUserInfo(req) }));
});

router.post('/', async(req, res, next) => {
await consolecmd(req, req.body.command);
res.redirect('/console');
});

module.exports = router;
80 changes: 3 additions & 77 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const setLoggedIn = require('../public/javascripts/functions/setLoggedIn.js');
const getOnlinePlayers = require('../public/javascripts/functions/getOnlinePlayers.js');
const consolecmd = require('../public/javascripts/functions/console.js');
const getAllPlayers = require('../public/javascripts/functions/getAllPlayers.js');
const transferMoney = require('../public/javascripts/functions/transferMoney.js');
const changeMoney = require('../public/javascripts/functions/changeMoney.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const adminAreaHandler = require('../public/javascripts/functions/admin/adminHandler.js');
const signup = require('../public/javascripts/functions/signup.js');
const login = require('../public/javascripts/functions/login.js');
const cashbonus = require('../public/javascripts/functions/cashbonus.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const listShop = require('../public/javascripts/functions/shop/listShop.js');
const loadInventory = require('../public/javascripts/functions/inventory/loadInventroy.js');
const getItemData = require('../public/javascripts/functions/inventory/getItemData.js');
const buyShop = require('../public/javascripts/functions/shop/buyShop.js');
const sellShop = require('../public/javascripts/functions/shop/sellShop.js');
const getTopPlayers = require('../public/javascripts/functions/getTopPlayers.js');

/* GET home page. */
Expand All @@ -36,88 +27,23 @@ router.get('/login', async(req, res, next) => {
res.render('login', stdParameter(req, 'Login', {}));
});

router.get('/bank', async(req, res, next) => {
await stdCall(req);
let players = await getAllPlayers(req.session.uuid, "everyoneButYou");
res.render('bank', stdParameter(req, 'Bank', { money: req.session.money, players: players, user: await getUserInfo(req) }));
});

router.post('/bank', async(req, res, next) => {
await stdCall(req);
await transferMoney(req);
res.redirect('/bank');
});

router.get('/admin', async(req, res, next) => {
await stdCall(req);
res.render('admin', stdParameter(req, 'Adminarea', { players: await getAllPlayers(req.session.uuid, "everyone"), user: await getUserInfo(req) }));
});

router.post('/deposit', async(req, res, next) => {
await stdCall(req);
await changeMoney(req.session.uuid, req.body.amount, "give");
res.redirect('/');
});

router.get('/profile', async(req, res, next) => {
await stdCall(req);
res.render('profile', stdParameter(req, 'Profile', { user: await getUserInfo(req) }));
});

router.get('/logout', async(req, res, next) => {
await setLoggedIn(false, req.session.uuid);
req.session.destroy();
res.redirect('/');
});

router.get('/console', async(req, res, next) => {
await stdCall(req);
res.render('console', stdParameter(req, 'Console', { message: req.session.command_log, user: await getUserInfo(req) }));
});

router.get('/shop', async(req, res, next) => {
await stdCall(req);
res.render('shop', stdParameter(req, 'Shop', { shoplist: await listShop(), message: req.query.error, user: await getUserInfo(req) }));
});

router.post('/buyshop', async(req, res, next) => {
var success = await buyShop(req);
if (success) {
res.redirect('/shop');
} else {
res.redirect('/shop?error=buyFailed');
}
});

router.post('/sellshop', async(req, res, next) => {
await sellShop(req);
res.redirect('/inventory');
});

router.get('/inventory', async(req, res, next) => {
var getinventory = await loadInventory(req.session.uuid);
var inventory = await getItemData(getinventory);
res.render('inventory', stdParameter(req, 'Inventory', { inventory: inventory, user: await getUserInfo(req) }));
});

router.get('/cashbonus', async(req, res, next) => {
await cashbonus(req.session.uuid);
res.redirect('/');
});

router.post('/admin', async(req, res, next) => {
if (req.body.confirm) {
await adminAreaHandler(req.body.operation, req.body.user, req.body.additional);
}
res.redirect('/admin');
});

router.post('/console', async(req, res, next) => {
await consolecmd(req, req.body.command);
//res.render('console', {loggedIn: req.session.loggedIn, message: message});
res.redirect('/console');
});

router.post('/login', async(req, res, next) => {
var success = await login(req, req.body.login, req.body.password);

Expand Down
16 changes: 16 additions & 0 deletions routes/inventory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const loadInventory = require('../public/javascripts/functions/inventory/loadInventroy.js');
const getItemData = require('../public/javascripts/functions/inventory/getItemData.js');

router.get('/', async(req, res, next) => {
await stdCall(req);
var getinventory = await loadInventory(req.session.uuid);
var inventory = await getItemData(getinventory);
res.render('inventory', stdParameter(req, 'Inventory', { inventory: inventory, user: await getUserInfo(req) }));
});

module.exports = router;
2 changes: 1 addition & 1 deletion routes/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const sendMail = require('../public/javascripts/functions/mail/sendMail.js');
const loadInbox = require('../public/javascripts/functions/mail/loadInbox.js');
const deleteMail = require('../public/javascripts/functions/mail/delMail.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');

router.get('/', async(req, res, next) => {
stdCall(req);
Expand Down
4 changes: 2 additions & 2 deletions routes/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const countServer = require('../public/javascripts/functions/server/countServer.js');
const buyServer = require('../public/javascripts/functions/server/buyServer.js');
const listServer = require('../public/javascripts/functions/server/listServer.js');
Expand All @@ -11,8 +12,7 @@ const genNewPassword = require('../public/javascripts/functions/server/genNewPas
const loadInventory = require('../public/javascripts/functions/inventory/loadInventroy.js');
const getItemData = require('../public/javascripts/functions/inventory/getItemData.js');
const installSrvItem = require('../public/javascripts/functions/inventory/installSrvItem.js');
const consolecmd = require('../public/javascripts/functions/console.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const consolecmd = require('../public/javascripts/functions/console/consolecmd.js');

router.get('/', async(req, res, next) => {
await stdCall(req);
Expand Down
29 changes: 29 additions & 0 deletions routes/shop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const express = require('express');
const router = express.Router();
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const listShop = require('../public/javascripts/functions/shop/listShop.js');
const buyShop = require('../public/javascripts/functions/shop/buyShop.js');
const sellShop = require('../public/javascripts/functions/shop/sellShop.js');

router.get('/', async(req, res, next) => {
await stdCall(req);
res.render('shop', stdParameter(req, 'Shop', { shoplist: await listShop(), message: req.query.error, user: await getUserInfo(req) }));
});

router.post('/buyshop', async(req, res, next) => {
var success = await buyShop(req);
if (success) {
res.redirect('/shop');
} else {
res.redirect('/shop?error=buyFailed');
}
});

router.post('/sellshop', async(req, res, next) => {
await sellShop(req);
res.redirect('/inventory');
});

module.exports = router;
4 changes: 2 additions & 2 deletions routes/stocks.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const express = require('express');
const router = express.Router();
const stdCall = require('../public/javascripts/functions/stdCall.js');
const stdParameter = require('../public/javascripts/functions/stdParameter.js');
const stdCall = require('../public/javascripts/functions/stdCall.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');
const stocks = require('../public/javascripts/functions/stocks/getStock.js');
const buyStock = require('../public/javascripts/functions/stocks/buyStock.js');
const loadStocks = require('../public/javascripts/functions/stocks/loadStocks.js');
const sellStock = require('../public/javascripts/functions/stocks/sellStock.js');
const getUserInfo = require('../public/javascripts/functions/getUserInfo.js');

router.get('/', async(req, res, next) => {
await stdCall(req);
Expand Down

0 comments on commit 3914b4c

Please sign in to comment.