mirror of
https://github.com/maierfelix/POGOserver.git
synced 2026-04-24 23:07:41 -05:00
Update
- Added add pokestop api call - Fixed candies table bug - Added FortSearch, FortDetails - Unique fort ids gets properly generated - Cell id based map objects
This commit is contained in:
parent
aa3743b4bd
commit
1a3a6fd181
95
src/api.js
95
src/api.js
|
|
@ -1,10 +1,13 @@
|
|||
import fs from "fs";
|
||||
import url from "url";
|
||||
import prompt from "prompt";
|
||||
import s2 from "s2-geometry";
|
||||
|
||||
import print from "./print";
|
||||
import CFG from "../cfg";
|
||||
|
||||
const S2Geo = s2.S2;
|
||||
|
||||
prompt.start({
|
||||
message: " ",
|
||||
delimiter: " "
|
||||
|
|
@ -36,13 +39,15 @@ export function processApiCall(req, res, route) {
|
|||
if (this.isApiCall(json)) {
|
||||
json.host = hoster;
|
||||
if (json.action === "login") {
|
||||
let result = this["api_login"](json);
|
||||
this.answerApiCall(res, JSON.stringify(result));
|
||||
this["api_login"](json).then((result) => {
|
||||
this.answerApiCall(res, JSON.stringify(result));
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (this.apiClients[hoster]) {
|
||||
let result = this["api_" + json.action](json);
|
||||
this.answerApiCall(res, JSON.stringify(result));
|
||||
this["api_" + json.action](json).then((result) => {
|
||||
this.answerApiCall(res, JSON.stringify(result));
|
||||
});
|
||||
}
|
||||
else {
|
||||
print(`${hoster} isnt logged in! Kicking..`, 31);
|
||||
|
|
@ -112,26 +117,36 @@ export function api_login(data) {
|
|||
timestamp: +new Date()
|
||||
};
|
||||
}
|
||||
return ({
|
||||
success: success
|
||||
|
||||
return new Promise((resolve) => {
|
||||
resolve({
|
||||
success: success
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export function api_heartBeat() {
|
||||
return ({
|
||||
timestamp: +new Date()
|
||||
return new Promise((resolve) => {
|
||||
resolve({
|
||||
timestamp: +new Date()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function api_getConnectedPlayers() {
|
||||
return ({
|
||||
connected_players: this.world.connectedPlayers
|
||||
return new Promise((resolve) => {
|
||||
resolve({
|
||||
connected_players: this.world.connectedPlayers
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function api_getServerVersion() {
|
||||
return ({
|
||||
version: CFG.VERSION
|
||||
return new Promise((resolve) => {
|
||||
resolve({
|
||||
version: CFG.VERSION
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +154,59 @@ export function api_spawnPkmnToPlayer(data) {
|
|||
let name = String(data.player);
|
||||
let pkmn = String(data.pkmn).toUpperCase();
|
||||
print(`Spawned 1x ${pkmn}'s to ${name}!`);
|
||||
return ({
|
||||
success: true
|
||||
return new Promise((resolve) => {
|
||||
resolve({
|
||||
success: true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function api_addFortToPosition(data) {
|
||||
|
||||
let latitude = data.lat;
|
||||
let longitude = data.lng;
|
||||
|
||||
let name = data.name;
|
||||
let description = data.desc;
|
||||
|
||||
let cellId = S2Geo.keyToId(S2Geo.latLngToKey(latitude, longitude, data.zoom));
|
||||
|
||||
let query = `
|
||||
INSERT INTO forts
|
||||
SET
|
||||
cell_id=?,
|
||||
latitude=?,
|
||||
longitude=?,
|
||||
enabled=?,
|
||||
name=?,
|
||||
description=?,
|
||||
image_url=?,
|
||||
rewards=?
|
||||
`;
|
||||
|
||||
let queryData = [
|
||||
cellId,
|
||||
latitude,
|
||||
longitude,
|
||||
true,
|
||||
name,
|
||||
description,
|
||||
"http://thecatapi.com/api/images/get?format=src&type=png",
|
||||
""
|
||||
];
|
||||
|
||||
return new Promise((resolve) => {
|
||||
this.db.query(query, queryData, (res) => {
|
||||
resolve({
|
||||
result: res,
|
||||
cellId: cellId,
|
||||
success: true
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export function api_getFortsByCellIds(data) {
|
||||
console.log(data);
|
||||
}
|
||||
|
|
@ -50,5 +50,5 @@ tutorial_avatar_selection tinyint(1) NOT NULL,
|
|||
tutorial_pokemon_capture tinyint(1) NOT NULL,
|
||||
tutorial_name_selection tinyint(1) NOT NULL,
|
||||
tutorial_first_time_exp tinyint(1) NOT NULL,
|
||||
candies text(11) NOT NULL,
|
||||
candies text NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
|
|
@ -142,8 +142,20 @@ export default class World {
|
|||
getPacket(type, msg) {
|
||||
return new Promise((resolve) => {
|
||||
switch (type) {
|
||||
case "FORT_SEARCH":
|
||||
this.FortSearch(msg).then((result) => {
|
||||
resolve(result);
|
||||
});
|
||||
break;
|
||||
case "FORT_DETAILS":
|
||||
this.FortDetails(msg).then((result) => {
|
||||
resolve(result);
|
||||
});
|
||||
break;
|
||||
case "GET_MAP_OBJECTS":
|
||||
resolve(this.GetMapObjects(msg));
|
||||
this.GetMapObjects(msg).then((result) => {
|
||||
resolve(result);
|
||||
});
|
||||
break;
|
||||
case "CHECK_CHALLENGE":
|
||||
resolve(this.CheckChallenge(msg));
|
||||
|
|
|
|||
35
src/models/World/packets/FortDetails.js
Normal file
35
src/models/World/packets/FortDetails.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import POGOProtos from "pokemongo-protobuf";
|
||||
|
||||
import print from "../../../print";
|
||||
|
||||
/**
|
||||
* @param {Object} msg
|
||||
* @return {Buffer}
|
||||
*/
|
||||
export default function FortDetails(msg) {
|
||||
|
||||
let id = String(msg.fort_id);
|
||||
let number = id.substring(id.lastIndexOf(".") + 1);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
this.instance.getQueryByColumnFromTable("id", number, "forts").then((forts) => {
|
||||
let fort = forts[0];
|
||||
let buffer = {
|
||||
fort_id: id,
|
||||
name: fort.name,
|
||||
description: fort.description,
|
||||
image_urls: [
|
||||
fort.image_url
|
||||
],
|
||||
type: "CHECKPOINT",
|
||||
latitude: fort.latitude,
|
||||
longitude: fort.longitude,
|
||||
modifiers: []
|
||||
};
|
||||
resolve(
|
||||
POGOProtos.serialize(buffer, "POGOProtos.Networking.Responses.FortDetailsResponse")
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
32
src/models/World/packets/FortSearch.js
Normal file
32
src/models/World/packets/FortSearch.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import POGOProtos from "pokemongo-protobuf";
|
||||
|
||||
import print from "../../../print";
|
||||
|
||||
/**
|
||||
* @param {Object} msg
|
||||
* @return {Buffer}
|
||||
*/
|
||||
export default function FortSearch(msg) {
|
||||
|
||||
let id = String(msg.fort_id);
|
||||
let number = id.substring(id.lastIndexOf(".") + 1);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
this.instance.getQueryByColumnFromTable("id", number, "forts").then((forts) => {
|
||||
let buffer = ({
|
||||
result: "SUCCESS",
|
||||
items_awarded: [{
|
||||
"item_id": 3,
|
||||
"item_count": 1
|
||||
}],
|
||||
experience_awarded: 1337,
|
||||
cooldown_complete_timestamp_ms: +new Date() + 5e3,
|
||||
chain_hack_sequence_number: 2
|
||||
});
|
||||
resolve(
|
||||
POGOProtos.serialize(buffer, "POGOProtos.Networking.Responses.FortSearchResponse")
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
import POGOProtos from "pokemongo-protobuf";
|
||||
|
||||
import s2 from "s2-geometry";
|
||||
|
||||
import print from "../../../print";
|
||||
|
||||
const S2Geo = s2.S2;
|
||||
|
||||
/**
|
||||
* @param {Object} msg
|
||||
* @return {Buffer}
|
||||
|
|
@ -16,23 +22,48 @@ export default function GetMapObjects(msg) {
|
|||
map_cells: cells
|
||||
};
|
||||
|
||||
for (let cell in msg.cell_id) {
|
||||
cells.push({
|
||||
s2_cell_id: cell,
|
||||
current_timestamp_ms: +new Date(),
|
||||
forts: [],
|
||||
spawn_points: [],
|
||||
deleted_objects: [],
|
||||
fort_summaries: [],
|
||||
decimated_spawn_points: [],
|
||||
wild_pokemons: [],
|
||||
catchable_pokemons: [],
|
||||
nearby_pokemons: []
|
||||
});
|
||||
};
|
||||
let limit = msg.cell_id.length;
|
||||
|
||||
return (
|
||||
POGOProtos.serialize(buffer, "POGOProtos.Networking.Responses.GetMapObjectsResponse")
|
||||
);
|
||||
// TODO: oop, forts are world objects!
|
||||
|
||||
return new Promise((resolve) => {
|
||||
var self = this;
|
||||
function getForts(index) {
|
||||
self.instance.getQueryByColumnFromTable("cell_id", msg.cell_id[index], "forts").then((items) => {
|
||||
items = items || [];
|
||||
let forts = [];
|
||||
items.map((fort) => {
|
||||
forts.push({
|
||||
id: fort.cell_id + "." + fort.id,
|
||||
last_modified_timestamp_ms: "1471621873766",
|
||||
latitude: fort.latitude,
|
||||
longitude: fort.longitude,
|
||||
enabled: true,
|
||||
type: "CHECKPOINT"
|
||||
});
|
||||
});
|
||||
cells.push({
|
||||
s2_cell_id: msg.cell_id[index],
|
||||
current_timestamp_ms: +new Date(),
|
||||
forts: forts,
|
||||
spawn_points: [],
|
||||
deleted_objects: [],
|
||||
fort_summaries: [],
|
||||
decimated_spawn_points: [],
|
||||
wild_pokemons: [],
|
||||
catchable_pokemons: [],
|
||||
nearby_pokemons: []
|
||||
});
|
||||
if (index >= limit) {
|
||||
resolve(
|
||||
POGOProtos.serialize(buffer, "POGOProtos.Networking.Responses.GetMapObjectsResponse")
|
||||
);
|
||||
return void 0;
|
||||
}
|
||||
getForts(++index);
|
||||
});
|
||||
};
|
||||
getForts(0);
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
export FortSearch from "./FortSearch";
|
||||
export FortDetails from "./FortDetails";
|
||||
export GetMapObjects from "./GetMapObjects";
|
||||
export CheckChallenge from "./CheckChallenge";
|
||||
export DownloadSettings from "./DownloadSettings";
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ export function processResponse(player, req) {
|
|||
return void 0;
|
||||
break;
|
||||
// Global
|
||||
case "FORT_SEARCH":
|
||||
case "FORT_DETAILS":
|
||||
case "GET_MAP_OBJECTS":
|
||||
case "CHECK_CHALLENGE":
|
||||
case "DOWNLOAD_SETTINGS":
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user