diff --git a/cfg.js.example b/cfg.js.example index 6e58587..9022b4e 100644 --- a/cfg.js.example +++ b/cfg.js.example @@ -20,7 +20,7 @@ export default { // otherwise leave it blank LOCAL_IP: "", GAME_MODE: 0, - SAVE_INTERVAL: 6e4, + SAVE_INTERVAL: 1e4, // Better dont touch these TICK_INTERVAL: 1, // Timeouts diff --git a/package.json b/package.json index d25ae46..bc47872 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "POGOServer", - "version": "0.5.8", + "version": "0.5.9", "description": "", "repository": { "type": "git", diff --git a/src/commands.js b/src/commands.js new file mode 100644 index 0000000..f9b8cae --- /dev/null +++ b/src/commands.js @@ -0,0 +1,65 @@ +import print from "./print"; +import CFG from "../cfg"; + +export function saveAllPlayers() { + if (this.world.players.length > 0) { + for (let player of this.world.players) { + this.savePlayer(player); + }; + } +} + +/** + * @param {Player} player + */ +export function savePlayer(player) { + return new Promise((resolve) => { + if (player.authenticated) { + this.updateUser(player).then(resolve); + } + }); +} + +/** + * @param {Player} player + */ +export function updateUser(player) { + let query = this.getUserQuery("UPDATE", "WHERE email=? LIMIT 1"); + let data = this.getUserQueryData(player); + + return new Promise((resolve) => { + this.world.instance.db.query(query, data, (e, res) => { + resolve(); + }); + }); +} + +/** + * @param {Object} obj + * @return {Array} + */ +export function getUserQueryData(obj) { + return ([ + obj.username, + obj.email, + obj.info._exp, + obj.info._level, + obj.info.stardust, + obj.info.pokecoins, + obj.info._team, + // position + obj.latitude, + obj.longitude, + obj.altitude, + // contact settings + 0, //obj.contact.sendMarketingEmails, + 0, //obj.contact.sendPushNotifications, + // inventory + '{}', //obj.candyBag, + '{}', //obj.bag, + '{}', //obj.avatar, + '{"0":1,"1":1,"3":1,"4":1,"7":1}', //obj.tutorial, + // WHERE + obj.email + ]); +} \ No newline at end of file diff --git a/src/cycle.js b/src/cycle.js index 1f19ee0..bdda2c8 100644 --- a/src/cycle.js +++ b/src/cycle.js @@ -52,7 +52,7 @@ export function resetTimers() { this.saveTick++; // Save interval if (this.saveTick >= CFG.SAVE_INTERVAL) { - //this.saveAllPlayers(); + this.saveAllPlayers(); this.saveTick = 0; } this.spawnTick++; diff --git a/src/index.js b/src/index.js index 3effc34..dc458ed 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,7 @@ import CFG from "../cfg"; import World from "./models/World"; import * as _api from "./api"; +import * as _commands from "./commands"; import * as _dump from "./dump"; import * as _http from "./http"; import * as _setup from "./setup"; @@ -192,6 +193,7 @@ export default class GameServer { } inherit(GameServer, _api); +inherit(GameServer, _commands); inherit(GameServer, _dump); inherit(GameServer, _http); inherit(GameServer, _setup);