- Added basic updater
- Handle asset download error
This commit is contained in:
Felix 2016-08-17 15:56:16 +02:00
parent eba199a240
commit 88d4b85860
11 changed files with 161 additions and 18 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
.idea
node_modules/
scripts/

13
.help
View File

@ -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
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

View File

@ -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:

2
cfg.js
View File

@ -1,5 +1,3 @@
export const ASSET_DIGEST_PATH = "asset_digest";
export const MINIMUM_CLIENT_VERSION = "0.33.0";
export const SERVER_PORT = 3000;

View File

@ -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": {}
}
}

1
run-linux.sh vendored
View File

@ -6,4 +6,5 @@ pause() {
cd $(dirname $0)
npm install
npm run start

1
run-windows.bat vendored
View File

@ -1,2 +1,3 @@
npm install
npm run start
pause

View File

@ -203,4 +203,4 @@ export function getUserQueryData(obj) {
obj.email
]);
}
}

View File

@ -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;
}
});
});

View File

@ -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;

93
updater.js Normal file
View File

@ -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);
});
}