mirror of
https://github.com/maierfelix/POGOserver.git
synced 2026-04-20 16:37:22 -05:00
Update
- Retry database connection init - Outsourced help cmds - Added node >= 6.x and npm >= 3.x requirement
This commit is contained in:
parent
9736183ddd
commit
0d8c39d37f
6
.help
Normal file
6
.help
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
clients : how many players are connected
|
||||
exit : exit the server
|
||||
kick [PlayerUsername] : kick player by username
|
||||
kickall : kick all players
|
||||
clear : clear the server console
|
||||
save : save all palyers into database
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "POGOServer",
|
||||
"version": "0.2.4",
|
||||
"version": "0.2.5",
|
||||
"description": "",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
@ -11,6 +11,10 @@
|
|||
"babel-node": "babel-node --presets=es2015",
|
||||
"start": "nodemon --exec npm run babel-node -- ./src/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6.x",
|
||||
"npm": ">= 3.x"
|
||||
},
|
||||
"author": "Felix Maier",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export function setupConnection() {
|
|||
mongodb.MongoClient.connect(url, (error, db) => {
|
||||
if (error) {
|
||||
this.print(error, 31);
|
||||
this.retry("Retrying again in ", () => this.setupConnection().then(resolve), 5);
|
||||
} else {
|
||||
this.db.instance = db;
|
||||
this.loadCollection(CFG.SERVER_MONGO_COLLECTION_USERS).then(() => {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,15 @@ export function setupConnection() {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} resolve
|
||||
*/
|
||||
export function closeConnection(resolve) {
|
||||
this.db.instance.end(() => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
export function createTableIfNoExists() {
|
||||
return new Promise((resolve) => {
|
||||
this.db.instance.query(`SHOW TABLES LIKE '${CFG.SERVER_MYSQL_TABLE}';`, (e, rows, fields) => {
|
||||
|
|
@ -79,15 +88,6 @@ export function createTable(name) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} resolve
|
||||
*/
|
||||
export function closeConnection(resolve) {
|
||||
this.db.instance.end(() => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} email
|
||||
*/
|
||||
|
|
|
|||
21
src/index.js
21
src/index.js
|
|
@ -175,10 +175,27 @@ class GameServer {
|
|||
/**
|
||||
* @param {String} msg
|
||||
* @param {Number} color
|
||||
* @param {Boolean} nl
|
||||
*/
|
||||
print(msg, color) {
|
||||
print(msg, color, nl) {
|
||||
color = Number.isInteger(color) ? color : CFG.SERVER_DEFAULT_CONSOLE_COLOR;
|
||||
console.log(`[Console] \x1b[${color};1m${msg}\x1b[0m`);
|
||||
process.stdout.write(`[Console] \x1b[${color};1m${msg}\x1b[0m${nl === void 0 ? "\n" : ""}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} msg
|
||||
* @param {Function} func
|
||||
* @param {Number} timer
|
||||
*/
|
||||
retry(msg, func, timer) {
|
||||
process.stdout.clearLine();
|
||||
process.stdout.cursorTo(0);
|
||||
this.print(`${msg}${timer}s`, 33, true);
|
||||
if (timer >= 1) setTimeout(() => this.retry(msg, func, --timer), 1e3);
|
||||
else {
|
||||
process.stdout.write("\n");
|
||||
func();
|
||||
}
|
||||
}
|
||||
|
||||
greet() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
import fs from "fs";
|
||||
|
||||
import * as CFG from "../cfg";
|
||||
|
||||
const helpMessage = fs.readFileSync(".help", "utf8");
|
||||
|
||||
export function processCommand(cmd, data) {
|
||||
switch (cmd) {
|
||||
// How many active connections there are
|
||||
|
|
@ -25,7 +29,9 @@ export function processCommand(cmd, data) {
|
|||
this.greet();
|
||||
break;
|
||||
case "/help":
|
||||
this.printHelp();
|
||||
console.log("\x1b[36;1m==================================== HELP =====================================\x1b[0m");
|
||||
console.log(`\x1b[${CFG.SERVER_DEFAULT_CONSOLE_COLOR};1m${helpMessage}\x1b[0m`);
|
||||
console.log("\x1b[36;1m===============================================================================\x1b[0m");
|
||||
break;
|
||||
case "/save":
|
||||
this.saveAllPlayers();
|
||||
|
|
@ -38,19 +44,6 @@ export function processCommand(cmd, data) {
|
|||
};
|
||||
};
|
||||
|
||||
export function printHelp() {
|
||||
|
||||
console.log("\x1b[36;1m===================================== HELP =====================================\x1b[0m");
|
||||
this.print("clients : how many players are connected");
|
||||
this.print("exit : exit the server");
|
||||
this.print("kick [PlayerUsername] : kick player by username");
|
||||
this.print("kickall : kick all players");
|
||||
this.print("clear : clear the server console");
|
||||
this.print("save : save all palyers into database");
|
||||
console.log("\n\x1b[36;1m================================================================================\x1b[0m");
|
||||
|
||||
};
|
||||
|
||||
export function stdinInput(data) {
|
||||
data = data.toString().substring(0, data.length - 2);
|
||||
if (data.length < 1) return void 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user