Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maierfelix committed Aug 26, 2016
1 parent a500b0c commit 59c2bc0
Show file tree
Hide file tree
Showing 74 changed files with 1,100 additions and 3,390 deletions.
5 changes: 1 addition & 4 deletions .gitignore
@@ -1,6 +1,3 @@
node_modules/
scripts/
logs/
data/
cfg.js
npm-debug.*
data/
16 changes: 8 additions & 8 deletions .help
@@ -1,8 +1,8 @@
clients : How many players are connected
exit : Exit the server
update : Update the server
kick [PlayerName] : Kick player by username
kickall : Kick all players
clear : Clear the server console
save : Save all players into database
spawn [PlayerName] [PokemonName] [Amount] : Spawn pokemons at specific player
clients : How many players are connected
exit : Exit the server
update : Update the server
kick [Username] : Kick player by username
kickall : Kick all players
clear : Clear the server console
save : Save all players into database
spawn [Username] [Pkmn] [Amount] : Spawn pokemons at users position
2 changes: 2 additions & 0 deletions install-windows.bat
@@ -0,0 +1,2 @@
set LIBPROTOBUF=%CD%\protobuf
npm install node-protobuf && npm install
13 changes: 3 additions & 10 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "POGOServer",
"version": "0.4.9",
"version": "0.5.0",
"description": "",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
"scripts": {
"test": "echo \"Error: no test specified\"",
"babel-node": "babel-node --presets=es2015",
"start": "nodemon --ignore tmp/ --ignore data/ --ignore logs/ --exec npm run babel-node -- ./src/index.js"
"start": "npm run babel-node -- ./src/index.js"
},
"engines": {
"node": ">= 6.x",
Expand All @@ -21,17 +21,10 @@
"babel-cli": "^6.11.4",
"babel-preset-es2015": "^6.13.1",
"babel-preset-stage-0": "^6.5.0",
"nodemon": "^1.7.1",
"mongodb": "^2.2.5",
"fs-extra": "^0.30.0",
"mysql": "^2.11.1",
"jwt-decode": "^2.1.0",
"long": "^3.2.0",
"pogo-asset-downloader": "^0.3.1",
"node-pogo-protos": "^1.3.0",
"path": "^0.12.7",
"directory-tree": "^1.1.0",
"nodegit": "^0.14.1",
"fs-extra": "^0.30.0",
"pokemongo-protobuf": "^1.11.0",
"pcrypt": "git+https://github.com/laverdet/pcrypt.git"
},
Expand Down
2 changes: 1 addition & 1 deletion run-windows.bat
@@ -1,2 +1,2 @@
npm install && npm run start
npm run start
pause
21 changes: 11 additions & 10 deletions src/cycle.js
Expand Up @@ -20,8 +20,6 @@ export function cycle() {

if (this.passedTicks <= 0) return void 0;

this.updatePlayers();

this.resetTimers();

return void 0;
Expand Down Expand Up @@ -49,25 +47,28 @@ export function resetTimers() {
this.saveTick++;
// Save interval
if (this.saveTick >= CFG.SAVE_INTERVAL) {
this.saveAllPlayers();
//this.saveAllPlayers();
this.saveTick = 0;
}
return void 0;
}

export function playerTimeoutTick() {

let client = null;
let player = null;
let maxTimeout = CFG.PLAYER_CONNECTION_TIMEOUT;

let ii = 0, length = this.clients.length;
let players = this.world.players;

let ii = 0;
let length = players.length;

for (; ii < length; ++ii) {
client = this.clients[ii];
if (this.time - client.timeout >= maxTimeout) {
this.print(`${client.remoteAddress} timed out`, 34);
this.savePlayer(client);
this.removePlayer(client);
player = players[ii];
if (this.time - player.timeout >= maxTimeout) {
this.print(`${player.remoteAddress} timed out`, 34);
this.savePlayer(player);
this.removePlayer(player);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/db/create.js
@@ -1,7 +1,7 @@
import fs from "fs";
import CFG from "../../cfg";

export function createTableIfNoExists(name) {
export function createTableIfNotExists(name) {
return new Promise((resolve) => {
this.db.instance.query(`SHOW TABLES LIKE '${name}';`, (e, rows, fields) => {
if (e) console.log(e);
Expand Down Expand Up @@ -33,7 +33,7 @@ export function createTable(name) {
this.print(`Creating table ${name}`, 36);

let query = `
CREATE TABLE ${name} (
CREATE TABLE IF NOT EXISTS ${name} (
${fs.readFileSync(__dirname + "/tables/" + name + ".table", "utf8")}
) ENGINE=InnoDB;
`;
Expand Down
37 changes: 1 addition & 36 deletions src/db/get.js
Expand Up @@ -27,39 +27,4 @@ export function deleteQueryByColumnFromTable(column, value, table) {
else resolve(void 0);
});
});
}

/**
* @param {String} column
* @param {String} value
*/
export function getPkmnByColumn(column, value) {
return new Promise((resolve) => {
this.getQueryByColumnFromTable(column, value, CFG.MYSQL_OWNED_PKMN_TABLE).then((query) => {
resolve(query || []);
});
});
}

/**
* @param {String} column
* @param {String} value
*/
export function getUserByColumn(column, value) {
return new Promise((resolve) => {
this.getQueryByColumnFromTable(column, value, CFG.MYSQL_USERS_TABLE).then((query) => {
resolve(query);
});
});
}

/**
* @param {String} email
*/
export function getUserByEmail(email) {
return new Promise((resolve) => {
this.getQueryByColumnFromTable("email", email, CFG.MYSQL_USERS_TABLE).then((query) => {
resolve(query);
});
});
}
}
110 changes: 5 additions & 105 deletions src/db/index.js
@@ -1,9 +1,8 @@
import fs from "fs";
import mysql from "mysql";

import CFG from "../../cfg";

export function setupConnection() {
export function setupDatabaseConnection() {

let connection = mysql.createConnection({
host : CFG.MYSQL_HOST_IP,
Expand All @@ -17,20 +16,20 @@ export function setupConnection() {
connection.connect((error) => {
if (error) {
this.print("MySQL " + error, 31);
this.retry("Retrying again in ", () => this.setupConnection().then(resolve), 5);
this.retry("Retrying again in ", () => this.setupDatabaseConnection().then(resolve), 5);
return void 0;
}
this.db.instance = connection;
this.createTableIfNoExists(CFG.MYSQL_USERS_TABLE).then(() => {
this.createTableIfNoExists(CFG.MYSQL_OWNED_PKMN_TABLE).then(() => {
this.createTableIfNotExists(CFG.MYSQL_USERS_TABLE).then(() => {
this.createTableIfNotExists(CFG.MYSQL_OWNED_PKMN_TABLE).then(() => {
this.print(`\x1b[36;1mMySQL\x1b[0m\x1b[32;1m connection established\x1b[0m`);
resolve();
});
});
});
connection.on("error", (error) => {
this.print("MySQL " + error, 31);
this.retry("Trying to reconnect in ", () => this.setupConnection().then(resolve), 5);
this.retry("Trying to reconnect in ", () => this.setupDatabaseConnection().then(resolve), 5);
});
});

Expand All @@ -43,103 +42,4 @@ export function closeConnection(resolve) {
this.db.instance.end(() => {
resolve();
});
}

/**
* @param {Object} obj
*/
export function createUser(obj) {

let query = this.getUserQuery("INSERT INTO", "");
let data = this.getUserQueryData(obj);

return new Promise((resolve) => {
this.db.instance.query(query, data, (e) => {
if (e) this.print(e, 31);
else resolve();
});
});

}

/**
* @param {Object} obj
*/
export function createOwnedPokemon(obj) {

let query = this.getOwnedPkmnQuery("INSERT INTO", "");
let data = this.getOwnedPkmnQueryData(obj);

return new Promise((resolve) => {
this.db.instance.query(query, data, resolve);
});

}

/**
* @param {Object} obj
*/
export function deleteOwnedPokemon(id) {

return new Promise((resolve) => {
this.deleteQueryByColumnFromTable("id", id, CFG.MYSQL_OWNED_PKMN_TABLE).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.db.instance.query(query, data, resolve);
});

}

/**
* @param {Player} player
*/
export function updateUserItems(player) {

let query = this.getUserItemQuery("UPDATE", "WHERE email=? LIMIT 1");
let data = this.getUserItemQueryData(player);

return new Promise((resolve) => {
this.db.instance.query(query, data, resolve);
});

}

/**
* @param {Player} player
*/
export function updateUserParty(player) {

let pkmn = null;
let data = null;
let query = this.getOwnedPkmnQuery("UPDATE", "WHERE id=? AND owner_id=? LIMIT 1");

return new Promise((resolve) => {
let ii = 0;
let index = 0;
let length = player.party.length;
// dont go on if party empty
if (!length) return resolve();
for (; ii < length; ++ii) {
pkmn = player.party[ii];
data = this.getOwnedPkmnQueryData(pkmn);
data.push(pkmn.id, player.owner_id);
this.db.instance.query(query, data, () => {
if (++index >= length) resolve();
});
};
});

}
8 changes: 0 additions & 8 deletions src/db/tables/candy.table

This file was deleted.

8 changes: 0 additions & 8 deletions src/db/tables/forts.table

This file was deleted.

40 changes: 23 additions & 17 deletions src/db/tables/users.table
@@ -1,25 +1,25 @@
id int(11) NOT NULL AUTO_INCREMENT,
username longtext NOT NULL,
email longtext NOT NULL,
exp int(255) NOT NULL,
level int(11) NOT NULL,
stardust int(255) NOT NULL,
pokecoins int(255) NOT NULL,
team int(11) NOT NULL,
username varchar(16) NOT NULL,
email varchar(32) NOT NULL,
exp int(11) NOT NULL,
level smallint(11) NOT NULL,
stardust int(11) NOT NULL,
pokecoins int(11) NOT NULL,
team tinyint(11) NOT NULL,
latitude double NOT NULL,
longitude double NOT NULL,
altitude int(255) NOT NULL,
altitude double NOT NULL,
send_marketing_emails tinyint(1) NOT NULL,
send_push_notifications tinyint(1) NOT NULL,
skin int(11) NOT NULL,
hair int(11) NOT NULL,
shirt int(11) NOT NULL,
pants int(11) NOT NULL,
hat int(11) NOT NULL,
shoes int(11) NOT NULL,
eyes int(11) NOT NULL,
gender int(11) NOT NULL,
backpack int(11) NOT NULL,
avatar_skin tinyint(1) NOT NULL,
avatar_hair tinyint(1) NOT NULL,
avatar_shirt tinyint(1) NOT NULL,
avatar_pants tinyint(1) NOT NULL,
avatar_hat tinyint(1) NOT NULL,
avatar_shoes tinyint(1) NOT NULL,
avatar_eyes tinyint(1) NOT NULL,
avatar_gender tinyint(1) NOT NULL,
avatar_backpack tinyint(1) NOT NULL,
item_poke_ball int(11) NOT NULL,
item_great_ball int(11) NOT NULL,
item_ultra_ball int(11) NOT NULL,
Expand All @@ -45,4 +45,10 @@ item_incubator_basic int(11) NOT NULL,
item_incubator_basic_unlimited int(11) NOT NULL,
item_pokemon_storage_upgrade int(11) NOT NULL,
item_storage_upgrade int(11) NOT NULL,
tutorial_legal_screen tinyint(1) NOT NULL,
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,

This comment has been minimized.

Copy link
@ruchernchong

ruchernchong Aug 26, 2016

Contributor

I reckon should not be in the users table since candies are tied to each Pokemon evolution chain.

This comment has been minimized.

Copy link
@maierfelix

maierfelix Aug 26, 2016

Author Owner

Using 151 (even more in future) columns affects mysql performance pretty bad. Using a text (up to 65,535 chars) with a syntax like PKMN_ID:CANDY_AMOUNT;PKMN_ID:CANDY_AMOUNT should be a better solution imo - maybe outsource the candy column into a seperate table later. Candy column gets parsed here

This comment has been minimized.

Copy link
@aididhaiqal

aididhaiqal Aug 26, 2016

@maierfelix Any idea why this branch code wont accept connection?

This comment has been minimized.

Copy link
@maierfelix

maierfelix Aug 26, 2016

Author Owner

@aididhaiqal im currently coding free hand without testing - this is a early stage recode, not usable yet

PRIMARY KEY (id)

0 comments on commit 59c2bc0

Please sign in to comment.