mirror of
https://github.com/maierfelix/POGOserver.git
synced 2026-04-22 01:17:21 -05:00
Adding files
This commit is contained in:
parent
b5ac5d5ecb
commit
89dd1501b0
7
cfg.js
Normal file
7
cfg.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
export const SERVER_PORT = 3000;
|
||||
export const SERVER_GAME_MODE = 0;
|
||||
export const SERVER_TICK_INTERVAL = 1; // better dont change
|
||||
export const SERVER_SAVE_INTERVAL = 120000; // all 120s
|
||||
export const SERVER_MAX_CONNECTIONS = 64;
|
||||
|
||||
export const SERVER_DEFAULT_CONSOLE_COLOR = 32;
|
||||
27
package.json
Normal file
27
package.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "POGOServer",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/maierfelix/POGOServer.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"babel-node": "babel-node --presets=es2015",
|
||||
"start": "nodemon --exec npm run babel-node -- ./src/index.js"
|
||||
},
|
||||
"author": "Felix Maier",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.11.4",
|
||||
"babel-preset-es2015": "^6.13.1",
|
||||
"babel-preset-stage-0": "^6.5.0",
|
||||
"body-parser": "^1.15.2",
|
||||
"concat-stream": "^1.5.1",
|
||||
"nodemon": "^1.7.1",
|
||||
"protobufjs": "^5.0.1",
|
||||
"pkmngo-proto": "^0.2.3"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
73
requests.js
Normal file
73
requests.js
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
export const REQUEST = {
|
||||
METHOD_UNSET: 0, // No implementation required
|
||||
PLAYER_UPDATE: 1, // Implemented [R & M]
|
||||
GET_PLAYER: 2, // Implemented [R & M]
|
||||
GET_INVENTORY: 4, // Implemented [R & M]
|
||||
DOWNLOAD_SETTINGS: 5, // Implemented [R & M]
|
||||
DOWNLOAD_ITEM_TEMPLATES: 6, // Implemented [R & M]
|
||||
DOWNLOAD_REMOTE_CONFIG_VERSION: 7, // Implemented [R & M]
|
||||
FORT_SEARCH: 101, // Implemented [R & M]
|
||||
ENCOUNTER: 102, // Implemented [R & M]
|
||||
CATCH_POKEMON: 103, // Implemented [R & M]
|
||||
FORT_DETAILS: 104, // Implemented [R & M]
|
||||
ITEM_USE: 105, // Can't find this one
|
||||
GET_MAP_OBJECTS: 106, // Implemented [R & M]
|
||||
FORT_DEPLOY_POKEMON: 110, // Implemented [R & M]
|
||||
FORT_RECALL_POKEMON: 111, // Implemented [R & M]
|
||||
RELEASE_POKEMON: 112, // Implemented [R & M]
|
||||
USE_ITEM_POTION: 113, // Implemented [R & M]
|
||||
USE_ITEM_CAPTURE: 114, // Implemented [R & M]
|
||||
USE_ITEM_FLEE: 115, // Can't find this one
|
||||
USE_ITEM_REVIVE: 116, // Implemented [R & M]
|
||||
TRADE_SEARCH: 117, // Not yet implemented in the game
|
||||
TRADE_OFFER: 118, // Not yet implemented in the game
|
||||
TRADE_RESPONSE: 119, // Not yet implemented in the game
|
||||
TRADE_RESULT: 120, // Not yet implemented in the game
|
||||
GET_PLAYER_PROFILE: 121, // Implemented [R & M]
|
||||
GET_ITEM_PACK: 122, // Can't find this one
|
||||
BUY_ITEM_PACK: 123, // Can't find this one
|
||||
BUY_GEM_PACK: 124, // Can't find this one
|
||||
EVOLVE_POKEMON: 125, // Implemented [R & M]
|
||||
GET_HATCHED_EGGS: 126, // Implemented [R & M]
|
||||
ENCOUNTER_TUTORIAL_COMPLETE: 127, // Implemented [R & M]
|
||||
LEVEL_UP_REWARDS: 128, // Implemented [R & M]
|
||||
CHECK_AWARDED_BADGES: 129, // Implemented [R & M]
|
||||
USE_ITEM_GYM: 133, // Implemented [R & M]
|
||||
GET_GYM_DETAILS: 134, // Implemented [R & M]
|
||||
START_GYM_BATTLE: 135, // Implemented [R & M]
|
||||
ATTACK_GYM: 136, // Implemented [R & M]
|
||||
RECYCLE_INVENTORY_ITEM: 137, // Implemented [R & M]
|
||||
COLLECT_DAILY_BONUS: 138, // Implemented [R & M]
|
||||
USE_ITEM_XP_BOOST: 139, // Implemented [R & M]
|
||||
USE_ITEM_EGG_INCUBATOR: 140, // Implemented [R & M]
|
||||
USE_INCENSE: 141, // Implemented [R & M]
|
||||
GET_INCENSE_POKEMON: 142, // Implemented [R & M]
|
||||
INCENSE_ENCOUNTER: 143, // Implemented [R & M]
|
||||
ADD_FORT_MODIFIER: 144, // Implemented [R & M]
|
||||
DISK_ENCOUNTER: 145, // Implemented [R & M]
|
||||
COLLECT_DAILY_DEFENDER_BONUS: 146, // Implemented [R & M]
|
||||
UPGRADE_POKEMON: 147, // Implemented [R & M]
|
||||
SET_FAVORITE_POKEMON: 148, // Implemented [R & M]
|
||||
NICKNAME_POKEMON: 149, // Implemented [R & M]
|
||||
EQUIP_BADGE: 150, // Implemented [R & M]
|
||||
SET_CONTACT_SETTINGS: 151, // Implemented [R & M]
|
||||
GET_ASSET_DIGEST: 300, // Implemented [R & M]
|
||||
GET_DOWNLOAD_URLS: 301, // Implemented [R & M]
|
||||
GET_SUGGESTED_CODENAMES: 401, // Implemented [R & M]
|
||||
CHECK_CODENAME_AVAILABLE: 402, // Implemented [R & M] TEST RESPONSE
|
||||
CLAIM_CODENAME: 403, // Implemented [R & M] TEST RESPONSE
|
||||
SET_AVATAR: 404, // Implemented [R & M]
|
||||
SET_PLAYER_TEAM: 405, // Implemented [R & M]
|
||||
MARK_TUTORIAL_COMPLETE: 406, // Implemented [R & M]
|
||||
LOAD_SPAWN_POINTS: 500, // Can't find this one
|
||||
ECHO: 666, // Implemented [R & M]
|
||||
DEBUG_UPDATE_INVENTORY: 700,
|
||||
DEBUG_DELETE_PLAYER: 701,
|
||||
SFIDA_REGISTRATION: 800, // Not yet released.
|
||||
SFIDA_ACTION_LOG: 801, // Not yet released.
|
||||
SFIDA_CERTIFICATION: 802, // Not yet released.
|
||||
SFIDA_UPDATE: 803, // Not yet released.
|
||||
SFIDA_ACTION: 804, // Not yet released.
|
||||
SFIDA_DOWSER: 805, // Not yet released.
|
||||
SFIDA_CAPTURE: 806 // Not yet released.
|
||||
};
|
||||
9
run-linux.sh
Normal file
9
run-linux.sh
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
pause() {
|
||||
read -p "Press [Enter] key to exit"
|
||||
}
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
npm run start
|
||||
2
run-windows.bat
Normal file
2
run-windows.bat
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
npm run start
|
||||
pause
|
||||
53
src/cycle.js
Normal file
53
src/cycle.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import * as CFG from "../cfg";
|
||||
|
||||
export function startCycle() {
|
||||
this.cycleInstance = setTimeout(() => this.cycle(), CFG.SERVER_TICK_INTERVAL);
|
||||
}
|
||||
|
||||
export function stopCycle() {
|
||||
clearTimeout(this.cycleInstance);
|
||||
}
|
||||
|
||||
export function cycle() {
|
||||
|
||||
this.stopCycle();
|
||||
this.startCycle();
|
||||
|
||||
if (this.STATES.PAUSE === true) return void 0;
|
||||
if (this.STATES.CRASH === true) return void 0;
|
||||
|
||||
this.updateTimers();
|
||||
|
||||
if (this.passedTicks <= 0) return void 0;
|
||||
|
||||
this.updatePlayers();
|
||||
|
||||
this.resetTimers();
|
||||
|
||||
return void 0;
|
||||
|
||||
}
|
||||
|
||||
export function updateTimers() {
|
||||
let local = new Date();
|
||||
this.passedTicks = local - this.time;
|
||||
this.tick += this.passedTicks;
|
||||
this.time = local;
|
||||
return void 0;
|
||||
}
|
||||
|
||||
export function resetTimers() {
|
||||
if (this.tick >= 25) {
|
||||
this.fullTick++;
|
||||
if (this.fullTick >= 2) {
|
||||
this.fullTick = 0;
|
||||
}
|
||||
this.tick = 0;
|
||||
}
|
||||
this.saveTick++;
|
||||
if (this.saveTick >= CFG.SERVER_SAVE_INTERVAL) {
|
||||
this.savePlayers();
|
||||
this.saveTick = 0;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
0
src/database.js
Normal file
0
src/database.js
Normal file
141
src/index.js
Normal file
141
src/index.js
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
import fs from "fs";
|
||||
import http from "http";
|
||||
|
||||
import { inherit } from "./utils";
|
||||
|
||||
import * as CFG from "../cfg";
|
||||
import { REQUEST } from "../requests";
|
||||
|
||||
import * as _setup from "./setup";
|
||||
import * as _cycle from "./cycle";
|
||||
import * as _process from "./process";
|
||||
import * as _database from "./database";
|
||||
|
||||
/**
|
||||
* @class GameServer
|
||||
*/
|
||||
class GameServer {
|
||||
|
||||
/** @constructor */
|
||||
constructor() {
|
||||
|
||||
this.STATES = {
|
||||
PAUSE: false,
|
||||
DEBUG: false,
|
||||
CRASH: false
|
||||
};
|
||||
|
||||
this.paused = false;
|
||||
|
||||
this.proto = null;
|
||||
this.socket = null;
|
||||
this.cycleInstance = null;
|
||||
|
||||
// Timer things
|
||||
this.tick = 0;
|
||||
this.time = 0;
|
||||
this.fullTick = 0;
|
||||
this.saveTick = 0;
|
||||
this.passedTicks = 0;
|
||||
|
||||
this.setup();
|
||||
|
||||
}
|
||||
|
||||
createHTTPServer() {
|
||||
this.socket = http.createServer(this.onRequest).listen(CFG.SERVER_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Request} req
|
||||
* @param {Response} resp
|
||||
*/
|
||||
onRequest(req, resp) {
|
||||
if (this.validRequest(req)) {
|
||||
this.answer(valid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Request} req
|
||||
* @return {Boolean}
|
||||
*/
|
||||
validRequest(req) {
|
||||
console.log(req);
|
||||
return (true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} msg
|
||||
* @param {Number} color
|
||||
*/
|
||||
print(msg, color) {
|
||||
color = Number.isInteger(color) ? color : CFG.SERVER_DEFAULT_CONSOLE_COLOR;
|
||||
console.log(`\x1b[${color};1m${msg}\x1b[0m`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Request} req
|
||||
*/
|
||||
answer(req) {
|
||||
|
||||
switch (req.request_type) {
|
||||
// #LOGIN START
|
||||
case REQUEST.GET_PLAYER:
|
||||
|
||||
break;
|
||||
case REQUEST.GET_HATCHED_EGGS:
|
||||
|
||||
break;
|
||||
case REQUEST.GET_INVENTORY:
|
||||
|
||||
break;
|
||||
case REQUEST.CHECK_AWARDED_BADGES:
|
||||
|
||||
break;
|
||||
case REQUEST.DOWNLOAD_SETTINGS:
|
||||
|
||||
break;
|
||||
case REQUEST.DOWNLOAD_ITEM_TEMPLATES:
|
||||
|
||||
break;
|
||||
// #LOGIN END
|
||||
case REQUEST.GET_PLAYER_PROFILE:
|
||||
|
||||
break;
|
||||
case REQUEST.GET_MAP_OBJECTS:
|
||||
|
||||
break;
|
||||
case REQUEST.GET_GYM_DETAILS:
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
updatePlayers() {
|
||||
//this.print("Updating players");
|
||||
return void 0;
|
||||
}
|
||||
|
||||
savePlayers() {
|
||||
this.print("Saving players into database");
|
||||
return void 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inherit(GameServer, _setup);
|
||||
inherit(GameServer, _cycle);
|
||||
inherit(GameServer, _process);
|
||||
inherit(GameServer, _database);
|
||||
|
||||
let server = new GameServer();
|
||||
|
||||
process.openStdin().addListener("data", function(data) {
|
||||
server.stdinInput(data);
|
||||
});
|
||||
|
||||
process.on("uncaughtException", function(data) {
|
||||
server.uncaughtException(data);
|
||||
});
|
||||
39
src/process.js
Normal file
39
src/process.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import * as CFG from "../cfg";
|
||||
|
||||
function processCommand(cmd, data) {
|
||||
switch (cmd) {
|
||||
// How many active connections there are
|
||||
case "/clients":
|
||||
this.print("There are many connected players!", 33);
|
||||
break;
|
||||
// Kill the server
|
||||
case "/exit":
|
||||
this.print("Killed the server!", 31);
|
||||
process.exit();
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
export function stdinInput(data) {
|
||||
data = data.toString().substring(0, data.length - 2);
|
||||
if (data.length < 1) return void 0;
|
||||
data = data.split(" ");
|
||||
var cmd = data[0];
|
||||
processCommand();
|
||||
};
|
||||
|
||||
export function uncaughtException(excp) {
|
||||
switch (excp.errno) {
|
||||
case "EADDRINUSE":
|
||||
this.print(`Port ${CFG.SERVER_PORT} is already in use!`, 31);
|
||||
break;
|
||||
case "EACCES":
|
||||
this.print("No root privileges!", 31);
|
||||
break;
|
||||
default:
|
||||
console.log("Unhandled exception occurred: ", code);
|
||||
console.log(excp.stack);
|
||||
break;
|
||||
};
|
||||
this.print("The server has crashed!", 31);
|
||||
};
|
||||
24
src/setup.js
Normal file
24
src/setup.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import path from "path";
|
||||
|
||||
import proto from "pkmngo-proto";
|
||||
|
||||
import * as CFG from "../cfg";
|
||||
|
||||
export function setup() {
|
||||
|
||||
this.print("Booting server...", 33);
|
||||
|
||||
this.proto = proto;
|
||||
|
||||
if (CFG.SERVER_PORT < 1) {
|
||||
this.print("Invalid port!", 31);
|
||||
return void 0;
|
||||
}
|
||||
|
||||
this.socket = this.createHTTPServer();
|
||||
|
||||
setTimeout(this::this.cycle, 1);
|
||||
|
||||
this.print("Server listening on port " + CFG.SERVER_PORT);
|
||||
|
||||
}
|
||||
16
src/utils.js
Normal file
16
src/utils.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* @param {Object} cls
|
||||
* @param {Object} prot
|
||||
* @export
|
||||
*/
|
||||
export function inherit(cls, prot) {
|
||||
|
||||
let key = null;
|
||||
|
||||
for (key in prot) {
|
||||
if (prot[key] instanceof Function) {
|
||||
cls.prototype[key] = prot[key];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user