Skip to content

Commit

Permalink
添加游戏数据库
Browse files Browse the repository at this point in the history
  • Loading branch information
shihuaping committed Aug 15, 2017
1 parent 80a1835 commit e1bc5b0
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 5 deletions.
52 changes: 52 additions & 0 deletions hall_svr/db-oper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const mysql = require('mysql');
const sysConfig = require('./config/sys-config.json');
const logger = require('./logger');


var pool = null;

function getPool() {
pool = mysql.createPool(
{
connectionLimit: 50,
host: sysConfig.mysqlHost,
port: sysConfig.mysqlPort,
user: sysConfig.mysqlUsername,
password: sysConfig.mysqlPassword,
database: 'gamedb'
}
);
}

getPool();

function getGameList(userInfo) {
return new Promise(function (resolve, reject) {
try {
//avoid sql injection
let sql = 'select * from user_base where account=' + mysql.escape(userInfo.account) +
' and password=' + mysql.escape(userInfo.password);
console.log(sql);

pool.getConnection(function (err, conn) {
conn.query(sql, function (err, results, fields) {

conn.release();
if (err) {
throw err;
}

resolve(results);
});
});

} catch (ex) {
logger.error(ex);
reject(ex);
}
});

}

exports.login = login;

2 changes: 1 addition & 1 deletion login_svr/db-oper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getPool() {
port: sysConfig.mysqlPort,
user: sysConfig.mysqlUsername,
password: sysConfig.mysqlPassword,
database: 'gamedb'
database: 'userdb'
}
);
}
Expand Down
8 changes: 6 additions & 2 deletions protocol/cmd-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
1001-1200 // login server
1201-1300 // center server
1301-1400 // hall server
3000-10000 // game server
Expand All @@ -32,5 +32,9 @@ module.exports = {

CENTER:1201,
SUB_CENTER_UPDATE:1,
SUB_CENTER_GET:2
SUB_CENTER_GET:2,

HALL:1301,
SUB_HALL_GAME_LIST:1,

};
41 changes: 41 additions & 0 deletions sql/gamedb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

create database if not exists gamedb default charset utf8;

use gamedb;

create table if not exists game_list (

gid int not null default '0' comment '游戏ID',
name varchar(32) not null default '' comment '游戏名称',
iconURL varchar(255) not null default '' comment '游戏图标',
index(gid)
) engine=innodb default charset 'utf8';

create table if not exists game_server_list (

gid int not null default '0' comment '游戏ID',
name varchar(64) not null default '' comment '游戏服名称',
ip char(16) not null default '' comment '游戏服ip',
port int not null default '0' comment '游戏服端口',
lowScore bigint not null default '0' comment '允许最低分,为0表示不限制',
upScore bigint not null default '0' comment '允许最高分,为0表示不限制',
status int not null default '0' comment '1为正常,2为维护中,3为停服',
createTime timestamp not null default 0 comment '创建时间',
modifyTime timestamp not null default 0 comment '修改时间',
index(gid,status)
) engine=innodb default charset 'utf8';

create table if not exists user_game_info (

uid int not null default '0' comment '用户id',
uname varchar(64) not null default '' comment '用户昵称',
gid int not null default '0' comment '游戏ID',
score bigint not null default '0' comment '用户得分',
coins bigint not null default '0' comment '用户金币数',
gems int not null default '0' comment '用户钻石数',
loginTime timestamp not null default 0 comment '登录时间',
logoutTime timestamp not null default 0 comment '退出时间',
index(uid,gid)
) engine = innodb default charset 'utf8';


4 changes: 2 additions & 2 deletions login_svr/sql/login.sql → sql/userdb.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

create database if not exists gamedb default charset utf8;
create database if not exists userdb default charset utf8;

use gamedb;
use userdb;

create table if not exists user_base (
uid int not null default 0 comment '用户ID',
Expand Down

0 comments on commit e1bc5b0

Please sign in to comment.