forked from shihuaping/gamex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80a1835
commit e1bc5b0
Showing
5 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters