mirror of
https://github.com/maierfelix/POGOserver.git
synced 2026-09-14 21:46:46 -05:00
Update
- Added item enums - Fort live editing seems stable - Better cell neighbor lookup - ForDetails and FortSearch doesnt use db queries anymore - Setup process resolves now after success
This commit is contained in:
2
.save
2
.save
@@ -1 +1 @@
|
||||
{"isFirstRun":false,"allowedApiHosts":["localhost"],"loginDetails":{"username":"root","password":"13377"}}
|
||||
{"isFirstRun":true,"allowedApiHosts":["localhost"],"loginDetails":{"username":"root","password":"1337"}}
|
||||
@@ -23,10 +23,12 @@
|
||||
"babel-preset-stage-0": "^6.5.0",
|
||||
"url": "^0.11.0",
|
||||
"prompt": "^1.0.0",
|
||||
"s2-geometry": "^1.2.9",
|
||||
"fs-extra": "^0.30.0",
|
||||
"mysql": "^2.11.1",
|
||||
"jwt-decode": "^2.1.0",
|
||||
"pogo-asset-downloader": "^0.3.1",
|
||||
"node-pogo-protos": "^1.4.0",
|
||||
"pokemongo-protobuf": "^1.11.0",
|
||||
"pcrypt": "git+https://github.com/laverdet/pcrypt.git"
|
||||
},
|
||||
|
||||
@@ -183,6 +183,7 @@ export function api_deleteFortById(data) {
|
||||
return new Promise((resolve) => {
|
||||
this.world.deleteFort(cellId, uid).then(() => {
|
||||
resolve({
|
||||
id: cellId + "." + uid,
|
||||
success: true
|
||||
});
|
||||
});
|
||||
@@ -216,13 +217,14 @@ export function getNeighbors(lat, lng, lvl) {
|
||||
let next = S2Geo.nextKey(origin);
|
||||
let prev = S2Geo.prevKey(origin);
|
||||
let ii = 0;
|
||||
let length = 30;
|
||||
let length = 10;
|
||||
for (; ii < length; ++ii) {
|
||||
walk.push(S2Geo.toId(prev));
|
||||
walk.push(S2Geo.toId(next));
|
||||
next = S2Geo.nextKey(next);
|
||||
prev = S2Geo.prevKey(prev);
|
||||
};
|
||||
walk.sort((a, b) => a - b);
|
||||
return (walk);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
cell_id varchar(64) NOT NULL,
|
||||
cell_uid int(11) NOT NULL,
|
||||
latitude double NOT NULL,
|
||||
longitude double NOT NULL,
|
||||
name varchar(64) NOT NULL,
|
||||
description varchar(128) NOT NULL,
|
||||
image_url varchar(128) NOT NULL,
|
||||
rewards varchar(64) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
experience int(11) NOT NULL DEFAULT '0',
|
||||
rewards varchar(64) NOT NULL DEFAULT '{}',
|
||||
PRIMARY KEY (id)
|
||||
16
src/dump.js
16
src/dump.js
@@ -60,19 +60,15 @@ export function decode(req, res) {
|
||||
* @param {Response} res
|
||||
*/
|
||||
export function dumpTraffic(req, res) {
|
||||
|
||||
let decoded = this.decode(req, res);
|
||||
|
||||
let out = {
|
||||
Request: decoded.req,
|
||||
Response: decoded.res
|
||||
};
|
||||
|
||||
try {
|
||||
let decoded = JSON.stringify(out, null, 2);
|
||||
let decoded = this.decode(req, res);
|
||||
let out = {
|
||||
Request: decoded.req,
|
||||
Response: decoded.res
|
||||
};
|
||||
decoded = JSON.stringify(out, null, 2);
|
||||
fse.outputFileSync(CFG.DEBUG_DUMP_PATH + Date.now(), decoded);
|
||||
} catch (e) {
|
||||
print("Dump traffic: " + e, 31);
|
||||
}
|
||||
|
||||
}
|
||||
18
src/enum.js
Normal file
18
src/enum.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import proto from "node-pogo-protos";
|
||||
|
||||
export default {
|
||||
ITEMS: proto.Inventory.Item.ItemId,
|
||||
getItemNameById: (emu, id) => {
|
||||
id <<= 0;
|
||||
for (let key in emu) {
|
||||
if (emu[key] === id) return (key);
|
||||
};
|
||||
return (null);
|
||||
},
|
||||
getItemIdByName: (emu, name) => {
|
||||
for (let key in emu) {
|
||||
if (key === name) return (emu[key]);
|
||||
};
|
||||
return (null);
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,9 @@ export default class GameServer {
|
||||
if (current < latest) {
|
||||
print(`WARNING: Please update to the latest build v${latest}!`, 33);
|
||||
}
|
||||
this.world = new World(this);
|
||||
this.setup();
|
||||
this.setup().then(() => {
|
||||
this.world = new World(this);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Pokemon from "index";
|
||||
import CaptureProbability from "CaptureProbability";
|
||||
import Pokemon from "../index";
|
||||
//import CaptureProbability from "CaptureProbability";
|
||||
|
||||
/**
|
||||
* @class WildPokemon
|
||||
@@ -50,10 +50,12 @@ export default class Cell extends MapObject {
|
||||
}
|
||||
else {
|
||||
this.getFortsFromDatabase().then((forts) => {
|
||||
this.forts = [];
|
||||
forts.map((fort) => {
|
||||
this.processDeletedFort(this.addFort(fort));
|
||||
});
|
||||
this.synced = true;
|
||||
print(`Synced ${this.cellId} with database..`, 33);
|
||||
resolve(this.forts);
|
||||
});
|
||||
}
|
||||
@@ -81,10 +83,24 @@ export default class Cell extends MapObject {
|
||||
// wait for the next map refresh
|
||||
setTimeout(() => {
|
||||
this.deleteFortById(fort.uid);
|
||||
this.deleteFortFromDatabase(fort).then(() => {
|
||||
|
||||
});
|
||||
}, (MAP_REFRESH_RATE * 1e3) * 3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Fort} fort
|
||||
*/
|
||||
deleteFortFromDatabase(fort) {
|
||||
return new Promise((resolve) => {
|
||||
this.world.instance.db.query(`DELETE FROM ${CFG.MYSQL_FORT_TABLE} WHERE cell_id=? AND id=? LIMIT 1`, [fort.cellId, fort.uid], (e, res) => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} id
|
||||
* @return {Number}
|
||||
@@ -92,7 +108,7 @@ export default class Cell extends MapObject {
|
||||
getFortIndexById(id) {
|
||||
let index = 0;
|
||||
for (let fort of this.forts) {
|
||||
if (fort.uid === id) return (index);
|
||||
if (fort.uid === id || fort.uid === id << 0) return (index);
|
||||
++index;
|
||||
};
|
||||
return (-1);
|
||||
@@ -125,8 +141,6 @@ export default class Cell extends MapObject {
|
||||
addFort(obj) {
|
||||
obj.world = this.world;
|
||||
let fort = new Fort(obj);
|
||||
fort.parent = this;
|
||||
fort.cellId = fort.parent.cellId;
|
||||
this.forts.push(fort);
|
||||
return (fort);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
validName
|
||||
} from "../../../utils";
|
||||
|
||||
import enum from "../../../enum";
|
||||
|
||||
/**
|
||||
* @class Fort
|
||||
*/
|
||||
@@ -20,8 +22,6 @@ export default class Fort extends MapObject {
|
||||
|
||||
super(obj);
|
||||
|
||||
this.parent = null;
|
||||
|
||||
this.enabled = true;
|
||||
this.deleted = false;
|
||||
|
||||
@@ -46,7 +46,7 @@ export default class Fort extends MapObject {
|
||||
init(obj) {
|
||||
obj = obj || {};
|
||||
for (let key in obj) {
|
||||
if (this.hasOwnProperty(key)) {
|
||||
if (this.hasOwnProperty(key) && key !== "rewards") {
|
||||
this[key] = obj[key];
|
||||
}
|
||||
};
|
||||
@@ -76,7 +76,7 @@ export default class Fort extends MapObject {
|
||||
let amount = this.rewards[key] << 0;
|
||||
for (let ii = 0; ii < amount; ++ii) {
|
||||
out.push({
|
||||
item_id: key
|
||||
item_id: enum.getItemNameById(enum.ITEMS, key << 0)
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -32,12 +32,12 @@ export default class MapObject {
|
||||
if (this.hasOwnProperty(key)) {
|
||||
this[key] = obj[key];
|
||||
}
|
||||
else if (key === "id") {
|
||||
this.uid = obj[key];
|
||||
}
|
||||
else if (key === "cell_id") {
|
||||
this.cellId = obj[key];
|
||||
}
|
||||
else if (key === "cell_uid") {
|
||||
this.uid = obj[key];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,28 @@ import CFG from "../../../cfg";
|
||||
|
||||
import print from "../../print";
|
||||
|
||||
/**
|
||||
* @param {String} id
|
||||
*/
|
||||
export function getFortDataById(id) {
|
||||
|
||||
id = id.split(".") || [];
|
||||
|
||||
let uid = id[1];
|
||||
let cellId = id[0];
|
||||
|
||||
let cell = this.getCellById(cellId);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (!cellId || !uid || !cell) return resolve();
|
||||
cell.loadForts().then(() => {
|
||||
let fort = cell.getFortById(uid);
|
||||
resolve(fort);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array} cells
|
||||
* @param {Array} out
|
||||
@@ -71,44 +93,31 @@ export function deleteFort(cellId, uid) {
|
||||
let cell = this.getCellById(cellId);
|
||||
let fort = cell.getFortById(uid);
|
||||
return new Promise((resolve) => {
|
||||
this.deleteFortFromDatabase(fort).then(() => {
|
||||
fort.delete();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function insertFortIntoDatabase(obj) {
|
||||
return new Promise((resolve) => {
|
||||
this.addFort(obj).then((fort) => {
|
||||
let query = `INSERT INTO ${CFG.MYSQL_FORT_TABLE} SET cell_id=?, cell_uid=?, latitude=?, longitude=?, name=?, description=?, image_url=?, rewards=?`;
|
||||
let id = fort.parent.cellId;
|
||||
let lat = fort.latitude;
|
||||
let lng = fort.longitude;
|
||||
let name = fort.name;
|
||||
let desc = fort.description;
|
||||
let img = "http://thecatapi.com/api/images/get?format=src&type=png&d=" + +new Date();
|
||||
this.instance.db.query(query, [id, 0, lat, lng, name, desc, img, ""], (e, res) => {
|
||||
let insertId = res.insertId;
|
||||
this.instance.db.query(`SELECT * from ${CFG.MYSQL_FORT_TABLE} WHERE cell_id=? ORDER BY cell_uid DESC`, [id], (e, res) => {
|
||||
let index = res instanceof Array ? res[0].cell_uid + 1 : 0;
|
||||
this.instance.db.query(`UPDATE ${CFG.MYSQL_FORT_TABLE} SET cell_uid=? WHERE id=?`, [index, insertId], (e, res) => {
|
||||
fort.uid = index;
|
||||
resolve(fort);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
fort.delete();
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Fort} fort
|
||||
* @param {Object} obj
|
||||
*/
|
||||
export function deleteFortFromDatabase(fort) {
|
||||
export function insertFortIntoDatabase(obj) {
|
||||
return new Promise((resolve) => {
|
||||
this.instance.db.query(`DELETE FROM ${CFG.MYSQL_FORT_TABLE} WHERE cell_id=? AND cell_uid=? LIMIT 1`, [fort.cellId, fort.uid], (e, res) => {
|
||||
resolve();
|
||||
let cellId = Cell.getIdByPosition(obj.latitude, obj.longitude, obj.zoom);
|
||||
let query = `INSERT INTO ${CFG.MYSQL_FORT_TABLE} SET cell_id=?, latitude=?, longitude=?, name=?, description=?, image_url=?, experience=?, rewards=?`;
|
||||
let lat = obj.latitude;
|
||||
let lng = obj.longitude;
|
||||
let name = obj.name;
|
||||
let desc = obj.description;
|
||||
let img = obj.image || "";
|
||||
let exp = obj.experience || 500;
|
||||
this.instance.db.query(query, [cellId, lat, lng, name, desc, img, exp, ""], (e, res) => {
|
||||
let insertId = res.insertId;
|
||||
obj.uid = insertId;
|
||||
obj.cell_id = cellId;
|
||||
this.addFort(obj).then((fort) => {
|
||||
resolve(fort);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import POGOProtos from "pokemongo-protobuf";
|
||||
|
||||
import CFG from "../../../../CFG";
|
||||
import print from "../../../print";
|
||||
|
||||
/**
|
||||
@@ -8,18 +9,17 @@ import print from "../../../print";
|
||||
*/
|
||||
export default function FortDetails(msg) {
|
||||
|
||||
let id = msg.fort_id.split(".");
|
||||
|
||||
return new Promise((resolve) => {
|
||||
this.instance.db.query(`SELECT * from ${CFG.MYSQL_FORT_TABLE} WHERE cell_id=? AND cell_uid=?`, [id[0], id[1]], (e, forts) => {
|
||||
let fort = forts[0];
|
||||
this.getFortDataById(msg.fort_id).then((fort) => {
|
||||
if (!fort) return void 0;
|
||||
let ts = +new Date();
|
||||
let url = fort.image_url;
|
||||
let buffer = {
|
||||
fort_id: msg.fort_id,
|
||||
name: fort.name,
|
||||
description: fort.description,
|
||||
image_urls: [
|
||||
fort.image_url
|
||||
url
|
||||
],
|
||||
type: "CHECKPOINT",
|
||||
latitude: fort.latitude,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import POGOProtos from "pokemongo-protobuf";
|
||||
|
||||
import CFG from "../../../../CFG";
|
||||
import print from "../../../print";
|
||||
|
||||
/**
|
||||
@@ -8,19 +9,13 @@ import print from "../../../print";
|
||||
*/
|
||||
export default function FortSearch(msg) {
|
||||
|
||||
let id = msg.fort_id.split(".");
|
||||
|
||||
return new Promise((resolve) => {
|
||||
this.instance.db.query(`SELECT * from ${CFG.MYSQL_FORT_TABLE} WHERE cell_id=? AND cell_uid=?`, [id[0], id[1]], (e, forts) => {
|
||||
let fort = forts[0];
|
||||
this.getFortDataById(msg.fort_id).then((fort) => {
|
||||
if (!fort) return void 0;
|
||||
let buffer = ({
|
||||
result: "SUCCESS",
|
||||
items_awarded: [
|
||||
{ item_id: 3 },
|
||||
{ item_id: 4 }
|
||||
],
|
||||
experience_awarded: 1337,
|
||||
items_awarded: fort.serializeRewards(),
|
||||
experience_awarded: fort.experience,
|
||||
cooldown_complete_timestamp_ms: +new Date() + fort.cooldown,
|
||||
chain_hack_sequence_number: 2
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import POGOProtos from "pokemongo-protobuf";
|
||||
|
||||
import s2 from "s2-geometry";
|
||||
|
||||
import CFG from "../../../../CFG";
|
||||
import print from "../../../print";
|
||||
|
||||
const S2Geo = s2.S2;
|
||||
@@ -30,9 +31,20 @@ export default function GetMapObjects(msg) {
|
||||
this.getFortsByCells(msg.cell_id, [], 0).then((cells) => {
|
||||
cells.map((cell) => {
|
||||
if (cell.forts.length) {
|
||||
console.log("###" + cell.cellId + "###");
|
||||
let ids = [];
|
||||
/*console.log("###" + cell.cellId + "###");
|
||||
cell.forts.map((fort) => {
|
||||
console.log(fort.uid, fort.latitude, fort.longitude);
|
||||
});*/
|
||||
cell.forts.map((fort) => {
|
||||
let id = fort.cellId + "." + fort.uid;
|
||||
if (ids.indexOf(id) > -1) {
|
||||
print(`Duplicated!!!! => ${id}`, 31);
|
||||
}
|
||||
else {
|
||||
ids.push(id);
|
||||
}
|
||||
print(`Active fort: ${fort.cellId}.${fort.uid}`, 35);
|
||||
});
|
||||
}
|
||||
mapCells.push({
|
||||
|
||||
@@ -14,8 +14,8 @@ export default {
|
||||
pokemon_visible_range: 70.00196078431372,
|
||||
poke_nav_range_meters: 751.0156862745098,
|
||||
encounter_range_meters: 50.25098039215686,
|
||||
get_map_objects_min_refresh_seconds: 8,
|
||||
get_map_objects_max_refresh_seconds: 8,
|
||||
get_map_objects_min_refresh_seconds: 4,
|
||||
get_map_objects_max_refresh_seconds: 4,
|
||||
get_map_objects_min_distance_meters: 10.007843017578125,
|
||||
google_maps_api_key: CFG.GMAPS_KEY
|
||||
},
|
||||
|
||||
67
src/setup.js
67
src/setup.js
@@ -17,42 +17,47 @@ import {
|
||||
|
||||
export function setup() {
|
||||
|
||||
let save = JSON.parse(fs.readFileSync(".save", "utf8"));
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (save.isFirstRun) {
|
||||
print("Required assets are missing! Preparing dump session..", 33);
|
||||
setTimeout(() => {
|
||||
this.onFirstRun(() => {
|
||||
save.isFirstRun = false;
|
||||
fs.writeFileSync(".save", JSON.stringify(save), "utf8");
|
||||
this.setup();
|
||||
let save = JSON.parse(fs.readFileSync(".save", "utf8"));
|
||||
|
||||
if (save.isFirstRun) {
|
||||
print("Required assets are missing! Preparing dump session..", 33);
|
||||
setTimeout(() => {
|
||||
this.onFirstRun(() => {
|
||||
save.isFirstRun = false;
|
||||
fs.writeFileSync(".save", JSON.stringify(save), "utf8");
|
||||
this.setup().then(resolve);
|
||||
});
|
||||
}, 1e3);
|
||||
return void 0;
|
||||
}
|
||||
|
||||
// make sure all assets got loaded properly
|
||||
this.validateAssets().then(() => {
|
||||
|
||||
print(`Downloaded assets are valid! Proceeding..`);
|
||||
|
||||
let parsedMaster = this.parseGameMaster();
|
||||
shared.GAME_MASTER = new GameMaster(parsedMaster);
|
||||
|
||||
this.setupDatabaseConnection().then(() => {
|
||||
if (CFG.PORT < 1) {
|
||||
print("Invalid port!", 31);
|
||||
return void 0;
|
||||
}
|
||||
this.socket = this.createHTTPServer();
|
||||
setTimeout(this::this.cycle, 1);
|
||||
let localIPv4 = this.getLocalIPv4();
|
||||
print(`Server listening at ${localIPv4}:${CFG.PORT}`, 33);
|
||||
resolve();
|
||||
});
|
||||
}, 1e3);
|
||||
return void 0;
|
||||
}
|
||||
|
||||
// make sure all assets got loaded properly
|
||||
this.validateAssets().then(() => {
|
||||
|
||||
print(`Downloaded assets are valid! Proceeding..`);
|
||||
|
||||
let parsedMaster = this.parseGameMaster();
|
||||
shared.GAME_MASTER = new GameMaster(parsedMaster);
|
||||
|
||||
this.setupDatabaseConnection().then(() => {
|
||||
if (CFG.PORT < 1) {
|
||||
print("Invalid port!", 31);
|
||||
return void 0;
|
||||
}
|
||||
this.socket = this.createHTTPServer();
|
||||
setTimeout(this::this.cycle, 1);
|
||||
let localIPv4 = this.getLocalIPv4();
|
||||
print(`Server listening at ${localIPv4}:${CFG.PORT}`, 33);
|
||||
}).catch((e) => {
|
||||
//fse.removeSync(CFG.DUMP_ASSET_PATH);
|
||||
print("Error: " + e + " was not found!", 31);
|
||||
});
|
||||
|
||||
}).catch((e) => {
|
||||
//fse.removeSync(CFG.DUMP_ASSET_PATH);
|
||||
print("Error: " + e + " was not found!", 31);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user