mirror of
https://github.com/maierfelix/POGOserver.git
synced 2026-10-26 01:49:46 -05:00
Update
- Splitted database stages - Refactored config - Added mysql config - Correct map object pokemon id - Added updated discord link
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import mongodb from "mongodb";
|
||||
|
||||
import * as CFG from "../cfg";
|
||||
import * as CFG from "../../cfg";
|
||||
|
||||
export function setupMongo() {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
mongodb.MongoClient.connect(CFG.SERVER_MONGO_URL, (error, db) => {
|
||||
if (error) {
|
||||
this.print("Unable to connect to database", 31);
|
||||
this.print(error, 31);
|
||||
} else {
|
||||
this.db.instance = db;
|
||||
this.loadCollection(CFG.SERVER_MONGO_COLLECTION_USERS).then(() => {
|
||||
26
src/db/mysql.js
Normal file
26
src/db/mysql.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import mysql from "mysql";
|
||||
|
||||
import * as CFG from "../../cfg";
|
||||
|
||||
export function setupMySQL() {
|
||||
|
||||
let connection = mysql.createConnection({
|
||||
host : CFG.SERVER_MYSQL_HOST_IP,
|
||||
port : CFG.SERVER_MYSQL_PORT,
|
||||
database : CFG.SERVER_MYSQL_DB_NAME,
|
||||
user : CFG.SERVER_MYSQL_USERNAME,
|
||||
password : CFG.SERVER_MYSQL_PASSWORD
|
||||
});
|
||||
|
||||
return new Promise((resolve) => {
|
||||
connection.connect((error) => {
|
||||
if (error) {
|
||||
this.print(error, 31);
|
||||
return void 0;
|
||||
}
|
||||
this.db.instance = connection;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
@@ -16,7 +16,8 @@ import * as _player from "./player";
|
||||
import * as _request from "./request";
|
||||
import * as _response from "./response";
|
||||
import * as _process from "./process";
|
||||
import * as _database from "./database";
|
||||
import * as _mongo from "./db/mongo";
|
||||
import * as _mysql from "./db/mysql";
|
||||
|
||||
const greetMessage = fs.readFileSync(".greet", "utf8");
|
||||
|
||||
@@ -153,7 +154,8 @@ inherit(GameServer, _player);
|
||||
inherit(GameServer, _request);
|
||||
inherit(GameServer, _response);
|
||||
inherit(GameServer, _process);
|
||||
inherit(GameServer, _database);
|
||||
inherit(GameServer, _mongo);
|
||||
inherit(GameServer, _mysql);
|
||||
|
||||
let server = new GameServer();
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ export default function GetMapObjects(request) {
|
||||
longitude: -96.58502161502839,
|
||||
spawn_point_id: "87bdd289c69",
|
||||
pokemon_data: new proto.Data.PokemonData({
|
||||
pokemon_id: 19,
|
||||
pokemon_id: 16,
|
||||
cp: 277,
|
||||
stamina: 41,
|
||||
stamina_max: 41,
|
||||
|
||||
26
src/setup.js
26
src/setup.js
@@ -8,7 +8,7 @@ export function setup() {
|
||||
|
||||
this.createAssetDownloadSession().then(() => {
|
||||
this.print("Created asset download session");
|
||||
this.setupMongo().then(() => {
|
||||
this.setupDatabaseConnection().then(() => {
|
||||
|
||||
this.print("Database connection established");
|
||||
|
||||
@@ -26,4 +26,28 @@ export function setup() {
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export function setupDatabaseConnection() {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
||||
let name = String(CFG.SERVER_USE_DATABASE).toUpperCase();
|
||||
|
||||
switch (name) {
|
||||
case "MONGO":
|
||||
case "MONGODB":
|
||||
this.setupMongo().then(resolve);
|
||||
break;
|
||||
case "MYSQL":
|
||||
this.setupMySQL().then(resolve);
|
||||
break;
|
||||
default:
|
||||
this.print("Invalid database connection type!", 31);
|
||||
return void 0;
|
||||
break;
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user