diff --git a/.gitignore b/.gitignore index 5b04c74..344f0b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -.idea node_modules/ +scripts/ \ No newline at end of file diff --git a/.help b/.help index 5a6393d..6e62458 100644 --- a/.help +++ b/.help @@ -1,6 +1,7 @@ -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 \ No newline at end of file +clients : How many players are connected +exit : Exit the server +update : Update the server +kick [PlayerUsername] : Kick player by username +kickall : Kick all players +clear : Clear the server console +save : Save all players into database \ No newline at end of file diff --git a/README.md b/README.md index 207a9f2..6f50353 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,44 @@ ______ _____ _____ _____ # Getting started +## Setup + +Open ``cfg.js`` and fill the following fields: + +````js +export const SERVER_POGO_CLIENT_PROVIDER = "GOOGLE"; +export const SERVER_POGO_CLIENT_USERNAME = "USERNAME"; +export const SERVER_POGO_CLIENT_PASSWORD = "PASSWORD"; +```` + ## Tunneling setup -For now, the pokemon go app traffic has to get forwarded manually to this custom server. To do so, download [this](https://github.com/rastapasta/pokemon-go-xposed/releases) app and follow the installation instructions [here](https://github.com/rastapasta/pokemon-go-xposed#how-to-use-it). +For now, the pokemon go app traffic has to get forwarded manually to this custom server. To do so, download [rastapasta](https://github.com/rastapasta)'s [Pokemon Go Xposed](https://github.com/rastapasta/pokemon-go-xposed/releases) app and follow the installation instructions [here](https://github.com/rastapasta/pokemon-go-xposed#how-to-use-it). + +## Database setup + +You can choose between using MySQL or MongoDB. + +To setup a database connection, open ``cfg.js`` and set the database type (MySQL in this case): + +````js +export const SERVER_USE_DATABASE = "MYSQL"; +```` + +Make sure to enter your database login credentials as well. + +````js +export const SERVER_MYSQL_PORT = 3306; +export const SERVER_MYSQL_HOST_IP = "127.0.0.1"; +export const SERVER_MYSQL_DB_NAME = "pogosql"; +export const SERVER_MYSQL_USERNAME = "root"; +export const SERVER_MYSQL_PASSWORD = ""; +export const SERVER_MYSQL_TABLE = "users"; +```` ## Server setup -You need a running mongodb or mysql service, enter your credentials into ``./cfg.js``. +You need at minimum [Node.js](https://nodejs.org/en/) version 6.x and npm version 3.x. +Depending on your OS, you need to run either ``run-linux.sh`` or ``run-windows.bat`` from the root folder. If everything went fine, it should look like: diff --git a/cfg.js b/cfg.js index 073b767..47b7a69 100644 --- a/cfg.js +++ b/cfg.js @@ -1,5 +1,3 @@ -export const ASSET_DIGEST_PATH = "asset_digest"; - export const MINIMUM_CLIENT_VERSION = "0.33.0"; export const SERVER_PORT = 3000; diff --git a/package.json b/package.json index 6fcbf2b..54e2fe1 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "description": "", "repository": { "type": "git", - "url": "git+https://github.com/maierfelix/POGOServer.git" + "url": "git://github.com/maierfelix/POGOServer.git" }, "scripts": { "test": "echo \"Error: no test specified\"", "babel-node": "babel-node --presets=es2015", - "start": "nodemon --exec npm run babel-node -- ./src/index.js" + "start": "nodemon --ignore tmp/ --exec npm run babel-node -- ./src/index.js" }, "engines": { "node": ">= 6.x", @@ -28,7 +28,11 @@ "long": "^3.2.0", "pogo-asset-downloader": "^0.2.1", "node-pogo-protos": "^1.3.0", - "path": "^0.12.7" + "path": "^0.12.7", + "rimraf": "^2.5.4", + "directory-tree": "^1.1.0", + "nodegit": "^0.14.1", + "fs-exists-sync": "^0.1.0" }, "devDependencies": {} -} +} \ No newline at end of file diff --git a/run-linux.sh b/run-linux.sh index 7ca50ae..93cae92 100644 --- a/run-linux.sh +++ b/run-linux.sh @@ -6,4 +6,5 @@ pause() { cd $(dirname $0) +npm install npm run start \ No newline at end of file diff --git a/run-windows.bat b/run-windows.bat index 0c6c316..9fce93f 100644 --- a/run-windows.bat +++ b/run-windows.bat @@ -1,2 +1,3 @@ +npm install npm run start pause \ No newline at end of file diff --git a/src/db/mysql.js b/src/db/mysql.js index cbdc068..1d27f21 100644 --- a/src/db/mysql.js +++ b/src/db/mysql.js @@ -203,4 +203,4 @@ export function getUserQueryData(obj) { obj.email ]); -} +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 15e9944..f5e3976 100644 --- a/src/index.js +++ b/src/index.js @@ -87,8 +87,14 @@ class GameServer { password: CFG.SERVER_POGO_CLIENT_PASSWORD, downloadModels: false }).then((asset) => { - this.print("Created asset download session"); - resolve(asset); + if (asset && asset.digest && asset.digest.length) { + this.print("Created asset download session"); + resolve(asset); + } + else { + this.print("Failed to download asset digest!", 31); + return void 0; + } }); }); diff --git a/src/process.js b/src/process.js index 1154eb0..934fef2 100644 --- a/src/process.js +++ b/src/process.js @@ -2,6 +2,8 @@ import fs from "fs"; import * as CFG from "../cfg"; +import updater from "../updater"; + const helpMessage = fs.readFileSync(".help", "utf8"); export function processCommand(cmd, data) { @@ -38,6 +40,11 @@ export function processCommand(cmd, data) { var length = this.clients.length; this.print(`Saved ${length} player${length === 1 ? "": "s"} into database!`); break; + case "/update": + updater().then(() => { + // bla + }); + break; default: this.print(`${cmd} is not a valid command!`, 31); break; diff --git a/updater.js b/updater.js new file mode 100644 index 0000000..a861d20 --- /dev/null +++ b/updater.js @@ -0,0 +1,93 @@ +import fs from "fs"; +import rimraf from "rimraf"; +import git from "nodegit"; +import dirTree from "directory-tree"; +import exists from "fs-exists-sync"; + +let tmpDir = "./tmp"; +let cloneDir = JSON.parse(fs.readFileSync("./package.json")).repository.url; + +let ignore = [".git", "cfg.js"]; + +function deleteFolder(path) { + return new Promise((resolve) => { + try { + rimraf(path, (error) => { + resolve(); + }); + } catch (e) { console.log(e); } + }); +} + +function deleteFile(path) { + if (exists(path)) { + fs.unlinkSync(path); + } +} + +function skip() { + return new Promise((resolve) => { + deleteFolder(tmpDir).then(() => { + console.log(`Skipped update to version ${newVersion}`); + resolve(); + }); + }); +} + +function updateProject() { + return new Promise((resolve) => { + let newFiles = dirTree("./tmp"); + // only walk root tree + for (let node of newFiles.children) { + let name = node.name; + if (ignore.indexOf(name) > -1) continue; + let isDir = node.hasOwnProperty("children"); + if (isDir) console.log("Path: ", name); + else console.log("File: ", name); + if (isDir) deleteFolder(name); + else deleteFile(name); + }; + resolve(); + }); +} + +export function update() { + return new Promise((resolve) => { + console.log("Preparing to update.."); + setTimeout(() => { + deleteFolder(tmpDir).then(() => { + let currentVersion = JSON.parse(fs.readFileSync("./package.json")).version; + console.log(`Your current version is ${currentVersion}!`); + setTimeout(() => { + console.log("Fetching latest version.."); + git.Clone(cloneDir, tmpDir).then((res, rofl) => { + let newVersion = null; + try { + newVersion = JSON.parse(fs.readFileSync(`${tmpDir}/package.json`)).version; + } catch (e) { + console.log("Version check failed!"); + return resolve(); + } + if (currentVersion === newVersion) { + console.log(`You are already running the latest version ${currentVersion}!`); + skip().then(resolve); + return void 0; + } + else if (currentVersion > newVersion) { + console.log(`Your version ${currentVersion} is newer than ${newVersion}!`); + skip().then(resolve); + return void 0; + } + console.log(`Updating to version ${newVersion}`); + updateProject().then(() => { + deleteFolder(tmpDir).then(() => { + console.log("Update successfully completed, please restart!"); + resolve(); + }); + }); + }); + }, 2e3); + }); + }, 1e3); + }); +} \ No newline at end of file