change shard code method
This commit is contained in:
parent
2d444146f9
commit
fc47f766bd
@ -1,28 +1,32 @@
|
||||
const Code = require("../lib/code");
|
||||
const Code = require("../../../shared/code");
|
||||
const { query_guild } = require("../lib/db");
|
||||
const userDao = require("./userDao");
|
||||
|
||||
class GuildDao {
|
||||
async listGuild() {
|
||||
const ql = "SELECT idx, gname, logo, gowner, gownername, gmaxmember FROM t_guilds LIMIT 10";
|
||||
const rl = await query_guild(ql);
|
||||
if (rl) {
|
||||
for (let i = 0; i < rl.length; i++) {
|
||||
const guild = rl[i];
|
||||
const q = "SELECT idx, gname, logo, gowner, gownername, gmaxmember FROM t_guilds LIMIT 10";
|
||||
const r = await query_guild(q);
|
||||
if (r) {
|
||||
for (let i = 0; i < r.length; i++) {
|
||||
const guild = r[i];
|
||||
const countmember = await this.countGuildMembers(guild.idx);
|
||||
guild.countmember = countmember;
|
||||
}
|
||||
}
|
||||
return rl;
|
||||
return r;
|
||||
}
|
||||
|
||||
async searchGuild(gName) {
|
||||
const q = `SELECT idx, gname, logo, gowner, gownername, gmaxmember FROM t_guilds WHERE gname LIKE ? LIMIT 10`;
|
||||
const r = await query_guild(q, ["%"+gName+"%"]);
|
||||
if (r) {
|
||||
return r;
|
||||
for (let i = 0; i < r.length; i++) {
|
||||
const guild = r[i];
|
||||
const countmember = await this.countGuildMembers(guild.idx);
|
||||
guild.countmember = countmember;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return r;
|
||||
}
|
||||
|
||||
async createGuild(gName, logo, uId) {
|
||||
@ -92,20 +96,45 @@ class GuildDao {
|
||||
return false;
|
||||
}
|
||||
|
||||
async getGuildInfoByUID(uid) {
|
||||
const gid = await this.getGuildIdByUID(uid);
|
||||
if (gid) {
|
||||
return await this.getGuildInfo(gid);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async getGuildInfo(gId) {
|
||||
const guild = await this.getGuild(gId);
|
||||
if (guild) {
|
||||
const countmember = await this.countGuildMembers(gId);
|
||||
guild.countmember = countmember;
|
||||
return guild;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定公会成员列表
|
||||
*
|
||||
* @param {int} guildId
|
||||
* @param {int} apply 0-正在申请加入 2-已经通过申请成为正式成员
|
||||
* @param {int} apply 0-正在申请加入 1-正在被邀请状态 2-已经通过申请成为正式成员
|
||||
* @returns 工会成员列表或申请列表
|
||||
*/
|
||||
async getGuildMembers(guildId, apply) {
|
||||
const query = "SELECT * FROM t_guild_members WHERE guild_idx=? AND apply=?";
|
||||
const query = "SELECT uid, name, g_rank FROM t_guild_members WHERE guild_idx=? AND apply=?";
|
||||
const r = await query_guild(query, [guildId, apply]);
|
||||
if (r && r.length > 0) {
|
||||
for (let i=0; i<r.length; i++) {
|
||||
const member = r[i];
|
||||
const userInfo = await userDao.getUserInfo(member.uid);
|
||||
if (userInfo) {
|
||||
member.online = 0;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
|
||||
async getInviteList(uId) {
|
||||
@ -225,16 +254,21 @@ class GuildDao {
|
||||
if (rfm) {
|
||||
if (rfm.length > 0) {
|
||||
if (rfm.some((item) => item.apply === 2)) {
|
||||
return false;
|
||||
throw new Error("already in guild");
|
||||
}
|
||||
if (rfm.some((item) => item.guild_idx === gId)) {
|
||||
return false;
|
||||
if (rfm.some((item) => item.guild_idx === gId && item.apply === 0)) {
|
||||
throw new Error("already requested");
|
||||
}
|
||||
if (rfm.some((item) => item.guild_idx === gId && item.apply === 1)) {
|
||||
throw new Error("already invited");
|
||||
}
|
||||
}
|
||||
}
|
||||
const userInfo = await userDao.getUserInfo(uId);
|
||||
const name = userInfo.name;
|
||||
const qim =
|
||||
"INSERT INTO t_guild_members (guild_idx, uid, g_rank, apply) VALUES (?, ?, ?, ?)";
|
||||
const rim = await query_guild(qim, [gId, uId, rank, state]);
|
||||
"INSERT INTO t_guild_members (guild_idx, uid, name, g_rank, apply) VALUES (?, ?, ?, ?, ?)";
|
||||
const rim = await query_guild(qim, [gId, uId, name, rank, state]);
|
||||
return rim != null;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
const redis = require('redis');
|
||||
const pomelo = require('pomelo');
|
||||
const redis = require("redis");
|
||||
const pomelo = require("pomelo");
|
||||
|
||||
const { query_game, query_guild } = require('../lib/db');
|
||||
const { query_game, query_guild } = require("../lib/db");
|
||||
|
||||
const config = pomelo.app.get('redis');
|
||||
const config = pomelo.app.get("redis");
|
||||
|
||||
const client = redis.createClient({ url: `redis://${config.host}:${config.port}` });
|
||||
const client = redis.createClient({
|
||||
url: `redis://${config.host}:${config.port}`,
|
||||
});
|
||||
|
||||
client.on('error', (err) => {
|
||||
client.on("error", (err) => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
@ -17,9 +19,8 @@ async function init() {
|
||||
init();
|
||||
|
||||
class UserDao {
|
||||
|
||||
async getUserInfo(userid) {
|
||||
const cacheResult = await client.hGet(`t_user:${userid}`, 'value');
|
||||
const cacheResult = await client.hGet(`t_user:${userid}`, "value");
|
||||
if (cacheResult != null) {
|
||||
const userInfo = JSON.parse(cacheResult);
|
||||
return userInfo;
|
||||
@ -38,8 +39,8 @@ class UserDao {
|
||||
userInfo.name = userInfo.name.toString();
|
||||
const query_insert = `INSERT INTO t_users (account, username, password) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE account=VALUES(account), username=VALUES(username), password=VALUES(password)`;
|
||||
const r = await query_guild(query_insert, [uid, userInfo.name, ""]);
|
||||
|
||||
await client.hSet(`t_user:${uid}`, 'value', JSON.stringify(userInfo));
|
||||
|
||||
await client.hSet(`t_user:${uid}`, "value", JSON.stringify(userInfo));
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
@ -47,7 +48,7 @@ class UserDao {
|
||||
|
||||
async findUser(name, uid) {
|
||||
const query = `SELECT account_id, name FROM t_user WHERE CAST(name as CHAR) LIKE ?`;
|
||||
const results = await query_game(query, ["%"+name+"%"]);
|
||||
const results = await query_game(query, ["%" + name + "%"]);
|
||||
|
||||
if (results.length === 0) {
|
||||
throw new Error(`User not found: ${name}`);
|
||||
@ -63,7 +64,6 @@ class UserDao {
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new UserDao();
|
||||
|
@ -25,5 +25,6 @@ module.exports = {
|
||||
FA_GUILD_CREATE_FAILED: 4001, // 创建工会失败
|
||||
FA_GUILD_JOIN_FAILED: 4002, // 加入工会失败
|
||||
FA_GUILD_APPROVE_FAILED: 4003, // 审批工会失败
|
||||
FA_GUILD_HAVE_NOT_JOIN: 4004, // 未加入工会
|
||||
},
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
const Code = require("../../../lib/code");
|
||||
const Code = require("../../../../../shared/code");
|
||||
|
||||
module.exports = function (app) {
|
||||
return new ChatHandler(app);
|
||||
@ -65,7 +65,8 @@ class ChatHandler {
|
||||
*
|
||||
*/
|
||||
async leaveWorldChannel(msg, session, next) {
|
||||
const username = session.get("username");
|
||||
const userInfo = session.get("userInfo");
|
||||
const username = userInfo.name;
|
||||
const channelId = "worldChannel";
|
||||
|
||||
const channel = this.channelService.getChannel(channelId, false);
|
||||
@ -153,7 +154,6 @@ class ChatHandler {
|
||||
*/
|
||||
async leaveTeamChannel(msg, session, next) {
|
||||
const uid = session.uid;
|
||||
const username = session.get("username");
|
||||
const teamId = msg.teamId;
|
||||
|
||||
const channelId = `teamChannel_${teamId}`;
|
||||
@ -189,7 +189,7 @@ class ChatHandler {
|
||||
* @apiGroup Chat
|
||||
*
|
||||
* @apiParam {String} content 聊天内容
|
||||
*
|
||||
* @apiParam {String} contentType 内容类型
|
||||
* @apiSuccess {Number} code 状态码
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
@ -204,8 +204,15 @@ class ChatHandler {
|
||||
* }
|
||||
*/
|
||||
async worldChat(msg, session, next) {
|
||||
const username = session.get("username");
|
||||
const userInfo = session.get("userInfo");
|
||||
const senderInfo = {
|
||||
username: userInfo.name,
|
||||
account_id: userInfo.account_id,
|
||||
head_frame: userInfo.head_frame,
|
||||
head_id: userInfo.head_id,
|
||||
};
|
||||
const content = msg.content;
|
||||
const contentType = msg.contentType;
|
||||
const channelId = "worldChannel";
|
||||
|
||||
const channel = this.app.get("channelService").getChannel(channelId, true);
|
||||
@ -213,16 +220,23 @@ class ChatHandler {
|
||||
/**
|
||||
* @api {push} onChat onChat 推送聊天消息
|
||||
* @apiGroup Chat
|
||||
* @apiParam {String} from 发送者
|
||||
* @apiParam {String} from 发送者信息
|
||||
* @apiParam {String} content 聊天内容
|
||||
* @apiParam {String} contentType 内容类型
|
||||
* @apiParam {String} type 聊天类型 [ world | team ]
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "route": "onChat",
|
||||
* "from": "username",
|
||||
* "from": {
|
||||
* "username": "username",
|
||||
* "account_id": "account_id",
|
||||
* "head_frame": "head_frame",
|
||||
* "head_id": "head_id"
|
||||
* },
|
||||
* "content": "content",
|
||||
* "contentType": "contentType",
|
||||
* "type": "world"
|
||||
* }
|
||||
*
|
||||
@ -230,8 +244,9 @@ class ChatHandler {
|
||||
channel.pushMessage({
|
||||
code: Code.OK,
|
||||
route: "onChat",
|
||||
from: username,
|
||||
from: senderInfo,
|
||||
content: content,
|
||||
contentType: contentType,
|
||||
type: "world",
|
||||
});
|
||||
|
||||
@ -243,6 +258,7 @@ class ChatHandler {
|
||||
* @apiGroup Chat
|
||||
*
|
||||
* @apiParam {String} content 聊天内容
|
||||
* @apiParam {String} contentType 内容类型
|
||||
* @apiParam {String} teamId 队伍ID
|
||||
*
|
||||
* @apiSuccess {Number} code 状态码
|
||||
@ -260,9 +276,17 @@ class ChatHandler {
|
||||
*/
|
||||
async teamChat(msg, session, next) {
|
||||
const uid = session.uid;
|
||||
const username = session.get("username");
|
||||
const userInfo = session.get("userInfo");
|
||||
const senderInfo = {
|
||||
username: userInfo.name,
|
||||
account_id: userInfo.account_id,
|
||||
head_frame: userInfo.head_frame,
|
||||
head_id: userInfo.head_id,
|
||||
};
|
||||
const content = msg.content;
|
||||
const contentType = msg.contentType;
|
||||
const teamId = msg.teamId;
|
||||
|
||||
|
||||
const channelId = `teamChannel_${teamId}`;
|
||||
|
||||
@ -271,8 +295,9 @@ class ChatHandler {
|
||||
channel.pushMessage({
|
||||
code: Code.OK,
|
||||
route: "onChat",
|
||||
from: username,
|
||||
from: senderInfo,
|
||||
content: content,
|
||||
contentType: contentType,
|
||||
type: "team",
|
||||
teamId: teamId,
|
||||
});
|
||||
|
@ -1,5 +1,6 @@
|
||||
var logger = require("pomelo-logger").getLogger(__filename);
|
||||
const userDao = require("../../../dao/userDao");
|
||||
const Code = require("../../../lib/code");
|
||||
|
||||
module.exports = function (app) {
|
||||
return new Handler(app);
|
||||
@ -72,6 +73,18 @@ Handler.prototype.entry = function (msg, session, next) {
|
||||
}
|
||||
};
|
||||
|
||||
/** @api {post} connector.entryHandler.heartbeat heartbeat 心跳
|
||||
* @apiGroup connector
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* }
|
||||
*
|
||||
*/
|
||||
Handler.prototype.heartbeat = function (msg, session, next) {
|
||||
next(null, {});
|
||||
}
|
||||
|
||||
var onUserLeave = function (app, session, reason) {
|
||||
if (!session || !session.uid) {
|
||||
return;
|
||||
|
@ -30,6 +30,15 @@ class GuildService {
|
||||
return result;
|
||||
}
|
||||
|
||||
async getGuildInfoByUID(uid) {
|
||||
const result = await guildDao.getGuildInfoByUID(uid);
|
||||
return result;
|
||||
}
|
||||
|
||||
async getGuildInfo(guildId) {
|
||||
const result = await guildDao.getGuildInfo(guildId);
|
||||
}
|
||||
|
||||
async getMembers(guildId, apply) {
|
||||
const result = await guildDao.getGuildMembers(guildId, apply);
|
||||
return result;
|
||||
|
@ -80,6 +80,113 @@ class Handler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} guild.guildHandler.getGuildInfoByUID getGuildInfoByUID 获取工会信息
|
||||
* @apiGroup Guild
|
||||
*
|
||||
* @apiParam {String} uid 用户ID
|
||||
*
|
||||
* @apiSuccess {Number} code 状态码
|
||||
* @apiSuccess {Object} guildInfo 工会信息
|
||||
*
|
||||
* @apiSuccessExample {json} 200:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "guildInfo": {
|
||||
* "idx": 1,
|
||||
* "gname": "guild_1", // 工会名称 (String(48))
|
||||
* "logo": "logo_1", // 工会logo (String(32))
|
||||
* "gowner": "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340", // 工会创建者ID (String(64))
|
||||
* "gownername": "owner_1", // 工会创建者名称 (String(32))
|
||||
* "gmaxmember": 100, // 工会最大成员数 (Number)
|
||||
* "countmember": 1 // 工会成员数 (Number)
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample {json} 200: no guild.
|
||||
* {
|
||||
* "code": 200,
|
||||
* "guildInfo": null,
|
||||
* "msg": "You haven't joined any guild yet."
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample {json} 500:
|
||||
* {
|
||||
* "code": 500,
|
||||
* "msg": "Failed to get guild info."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async getGuildInfoByUID({ uid }, session, next) {
|
||||
try {
|
||||
const guildInfo = await this.guildService.getGuildInfoByUID(uid);
|
||||
if (guildInfo) {
|
||||
next(null, { code: Code.OK, guildInfo });
|
||||
} else {
|
||||
next(null, {
|
||||
code: Code.OK,
|
||||
guildInfo: null,
|
||||
msg: "You haven't joined any guild yet.",
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(null, { code: Code.FAIL, msg: "Failed to get guild info." });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} guild.guildHandler.getGuildInfo getGuildInfo 获取工会信息
|
||||
* @apiGroup Guild
|
||||
*
|
||||
* @apiParam {String} guildId 工会ID
|
||||
*
|
||||
* @apiSuccess {Number} code 状态码
|
||||
* @apiSuccess {Object} guildInfo 工会信息
|
||||
*
|
||||
* @apiSuccessExample {json} 200:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "guildInfo": {
|
||||
* "idx": 1,
|
||||
* "gname": "guild_1", // 工会名称 (String(48))
|
||||
* "logo": "logo_1", // 工会logo (String(32))
|
||||
* "gowner": "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340", // 工会创建者ID (String(64))
|
||||
* "gownername": "owner_1", // 工会创建者名称 (String(32))
|
||||
* "gmaxmember": 100, // 工会最大成员数 (Number)
|
||||
* "countmember": 1 // 工会成员数 (Number)
|
||||
* }
|
||||
*
|
||||
* @apiSuccessExample {json} 200: no guild.
|
||||
* {
|
||||
* "code": 200,
|
||||
* "guildInfo": null,
|
||||
* "msg": "You haven't joined any guild yet."
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample {json} 500:
|
||||
* {
|
||||
* "code": 500,
|
||||
* "msg": "Failed to get guild info."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async getGuildInfo({ guildId }, session, next) {
|
||||
try {
|
||||
const guildInfo = await this.guildService.getGuildInfo(guildId);
|
||||
if (guildInfo) {
|
||||
next(null, { code: Code.OK, guildInfo });
|
||||
} else {
|
||||
next(null, {
|
||||
code: Code.OK,
|
||||
guildInfo: null,
|
||||
msg: "You haven't joined any guild yet.",
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(null, { code: Code.FAIL, msg: "Failed to get guild info." });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} guild.guildHandler.createGuild createGuild 创建工会
|
||||
* @apiGroup Guild
|
||||
@ -165,7 +272,7 @@ class Handler {
|
||||
: { code: Code.GUILD.FA_GUILD_JOIN_FAILED, msg: "Join guild failed" };
|
||||
next(null, response);
|
||||
} catch (error) {
|
||||
next(null, error);
|
||||
next(null, { code: Code.GUILD.FA_GUILD_JOIN_FAILED, msg: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,6 +402,88 @@ class Handler {
|
||||
}
|
||||
}
|
||||
|
||||
/** @api {post} guild.guildHandler.getGuildRequestList getGuildRequestList 获取工会申请列表
|
||||
* @apiGroup Guild
|
||||
*
|
||||
* @apiParam {String} guildId 工会ID
|
||||
*
|
||||
* @apiSuccess {Number} code 状态码
|
||||
* @apiSuccess {String} msg 消息
|
||||
* @apiSuccess {Object[]} members 成员列表
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "Get guild request list done",
|
||||
* "members": [
|
||||
* {
|
||||
* "uid": "6513",
|
||||
* "name": ""
|
||||
* "g_rank": 0,
|
||||
* "online": 0,
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample {json} Error-Response:
|
||||
* {
|
||||
* "code": 500,
|
||||
* "msg": "Get guild request list failed"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async getGuildRequestList({ guildId }, session, next) {
|
||||
try {
|
||||
const result = await this.guildService.getMembers(guildId, 0);
|
||||
if (result) {
|
||||
next(null, { code: Code.OK, members: result });
|
||||
} else {
|
||||
next(null, { code: Code.FAIL, msg: "Get guild request list failed" });
|
||||
}
|
||||
} catch (err) {
|
||||
next(null, err);
|
||||
}
|
||||
}
|
||||
|
||||
/** @api {post} guild.guildHandler.getGuildInviteList getGuildInviteList 获取工会邀请列表
|
||||
* @apiGroup Guild
|
||||
* @apiParam {String} guildId 工会ID
|
||||
* @apiSuccess {Number} code 状态码
|
||||
* @apiSuccess {String} msg 消息
|
||||
* @apiSuccess {Object[]} members 成员列表
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "Get guild invite list done",
|
||||
* "members": [
|
||||
* {
|
||||
* "uid": "6513",
|
||||
* "name": ""
|
||||
* "g_rank": 0,
|
||||
* "online": 1,
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* @apiErrorExample {json} Error-Response:
|
||||
* {
|
||||
* "code": 500,
|
||||
* "msg": "Get guild invite list failed"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
async getGuildInviteList({ guildId }, session, next) {
|
||||
try {
|
||||
const result = await this.guildService.getMembers(guildId, 1);
|
||||
if (result) {
|
||||
next(null, { code: Code.OK, members: result });
|
||||
} else {
|
||||
next(null, { code: Code.FAIL, msg: "Get guild invite list failed" });
|
||||
}
|
||||
} catch (err) {
|
||||
next(null, err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} guild.guildHandler.confirmInvite confirmInvite 确认邀请
|
||||
* @apiGroup Guild
|
||||
@ -402,7 +591,6 @@ class Handler {
|
||||
* @api {post} guild.guildHandler.getGuildMembers getGuildMembers 获取工会成员列表
|
||||
* @apiGroup Guild
|
||||
* @apiParam {String} guildId 工会ID
|
||||
* @apiParam {Boolean} apply 是否是申请列表
|
||||
*
|
||||
* @apiSuccess {Number} code 状态码
|
||||
* @apiSuccess {String} msg 消息
|
||||
@ -413,8 +601,9 @@ class Handler {
|
||||
* "msg": "Get guild members done",
|
||||
* "members": [
|
||||
* {
|
||||
* "idx": 1,
|
||||
* "uid": 1,
|
||||
* "uid": "1",
|
||||
* "name": "test",
|
||||
* "g_rank": 1,
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
@ -427,10 +616,10 @@ class Handler {
|
||||
*
|
||||
*/
|
||||
async getGuildMembers(msg, session, next) {
|
||||
const { guildId, apply } = msg;
|
||||
const { guildId } = msg;
|
||||
try {
|
||||
const result = await this.guildService.getMembers(guildId, apply);
|
||||
next(null, { code: Code.OK, members: result, apply: apply });
|
||||
const result = await this.guildService.getMembers(guildId, 2);
|
||||
next(null, {code: Code.OK, members: result, msg: "Get guild members done" });
|
||||
} catch (err) {
|
||||
next(null, err);
|
||||
}
|
||||
|
27
old-server/app.js
Normal file
27
old-server/app.js
Normal file
@ -0,0 +1,27 @@
|
||||
var express = require('express');
|
||||
var app = express.createServer();
|
||||
|
||||
app.configure(function(){
|
||||
app.use(express.methodOverride());
|
||||
app.use(express.bodyParser());
|
||||
app.use(app.router);
|
||||
app.set('view engine', 'jade');
|
||||
app.set('views', __dirname + '/public');
|
||||
app.set('view options', {layout: false});
|
||||
app.set('basepath',__dirname + '/public');
|
||||
});
|
||||
|
||||
app.configure('development', function(){
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
|
||||
});
|
||||
|
||||
app.configure('production', function(){
|
||||
var oneYear = 31557600000;
|
||||
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
|
||||
app.use(express.errorHandler());
|
||||
});
|
||||
|
||||
console.log("Web server has started.\nPlease log on http://127.0.0.1:3001/index.html");
|
||||
|
||||
app.listen(3001);
|
257
old-server/package-lock.json
generated
Normal file
257
old-server/package-lock.json
generated
Normal file
@ -0,0 +1,257 @@
|
||||
{
|
||||
"name": "r2",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "r2",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"express": "3.4.8"
|
||||
}
|
||||
},
|
||||
"node_modules/batch": {
|
||||
"version": "0.5.0",
|
||||
"resolved": "https://registry.npmjs.org/batch/-/batch-0.5.0.tgz",
|
||||
"integrity": "sha512-avtDJBSxllB5QGphW1OXYF+ujhy/yIGgeFsvK6UiZLU86nWlqsNcZotUKd001wrl9MmZ9QIyVy8WFVEEpRIc5A=="
|
||||
},
|
||||
"node_modules/buffer-crc32": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.1.tgz",
|
||||
"integrity": "sha512-vMfBIRp/wjlpueSz7Sb0OmO7C5SH58SSmbsT8G4D48YfO/Zgbr29xNXMpZVSC14ujVJfrZZH1Bl+kXYRQPuvfQ==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-0.2.1.tgz",
|
||||
"integrity": "sha512-odbk8/wGazOuC1v8v4phoV285/yx8UN5kfQhhuxaVcceig4OUiCZQBtaEtmA1Q78QSTN9iXOQ7X2EViybrEvtQ=="
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-1.3.2.tgz",
|
||||
"integrity": "sha512-uoVVA5dchmxZeTMv2Qsd0vhn/RebJYsWo4all1qtrUL3BBhQFn4AQDF4PL+ZvOeK7gczXKEZaSCyMDMwFBlpBg==",
|
||||
"dependencies": {
|
||||
"keypress": "0.1.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6.x"
|
||||
}
|
||||
},
|
||||
"node_modules/connect": {
|
||||
"version": "2.12.0",
|
||||
"resolved": "https://registry.npmjs.org/connect/-/connect-2.12.0.tgz",
|
||||
"integrity": "sha512-i3poGdQamCEvDhvaFuG99KUDCU1Cvv7S2T6YfpY4X2+a0+uDrUcpRk08AQEge3NhtidVKfODQfpoMW4xlbQ0LQ==",
|
||||
"deprecated": "connect 2.x series is deprecated",
|
||||
"dependencies": {
|
||||
"batch": "0.5.0",
|
||||
"buffer-crc32": "0.2.1",
|
||||
"bytes": "0.2.1",
|
||||
"cookie": "0.1.0",
|
||||
"cookie-signature": "1.0.1",
|
||||
"debug": ">= 0.7.3 < 1",
|
||||
"fresh": "0.2.0",
|
||||
"methods": "0.1.0",
|
||||
"multiparty": "2.2.0",
|
||||
"negotiator": "0.3.0",
|
||||
"pause": "0.0.1",
|
||||
"qs": "0.6.6",
|
||||
"raw-body": "1.1.2",
|
||||
"send": "0.1.4",
|
||||
"uid2": "0.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.1.0.tgz",
|
||||
"integrity": "sha512-YSNOBX085/nzHvrTLEHYHoNdkvpLU1MPjU3r1IGawudZJjfuqnRNIFrcOJJ7bfwC+HWbHL1Y4yMkC0O+HWjV7w==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/cookie-signature": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.1.tgz",
|
||||
"integrity": "sha512-FMG5ziBzXZ5d4j5obbWOH1X7AtIpsU9ce9mQ+lHo/I1++kzz/isNarOj6T1lBPRspP3mZpuIutc7OVDVcaN1Kg=="
|
||||
},
|
||||
"node_modules/core-util-is": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "0.8.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-0.8.1.tgz",
|
||||
"integrity": "sha512-HlXEJm99YsRjLJ8xmuz0Lq8YUwrv7hAJkTEr6/Em3sUlSUNl0UdFA+1SrY4fnykeq1FVkUEUtwRGHs9VvlYbGA==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/express": {
|
||||
"version": "3.4.8",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-3.4.8.tgz",
|
||||
"integrity": "sha512-NC6Ff/tlg4JNjGTrw0is0aOe9k7iAnb3Ra6mF3Be15UscxZKpbP7XCMmXx9EiNpHe9IClbHo6EDslH9eJNo1HQ==",
|
||||
"dependencies": {
|
||||
"buffer-crc32": "0.2.1",
|
||||
"commander": "1.3.2",
|
||||
"connect": "2.12.0",
|
||||
"cookie": "0.1.0",
|
||||
"cookie-signature": "1.0.1",
|
||||
"debug": ">= 0.7.3 < 1",
|
||||
"fresh": "0.2.0",
|
||||
"merge-descriptors": "0.0.1",
|
||||
"methods": "0.1.0",
|
||||
"mkdirp": "0.3.5",
|
||||
"range-parser": "0.0.4",
|
||||
"send": "0.1.4"
|
||||
},
|
||||
"bin": {
|
||||
"express": "bin/express"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fresh": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.2.0.tgz",
|
||||
"integrity": "sha512-ckGdAuSRr1wBmnq7CsW7eU37DBwQxHx3vW8foJUIrF56rkOy8Osm6Fe8KSwemwyKejivKki7jVBgpBpBJexmrw=="
|
||||
},
|
||||
"node_modules/inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"node_modules/isarray": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||
"integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ=="
|
||||
},
|
||||
"node_modules/keypress": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz",
|
||||
"integrity": "sha512-x0yf9PL/nx9Nw9oLL8ZVErFAk85/lslwEP7Vz7s5SI1ODXZIgit3C5qyWjw4DxOuO/3Hb4866SQh28a1V1d+WA=="
|
||||
},
|
||||
"node_modules/merge-descriptors": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-0.0.1.tgz",
|
||||
"integrity": "sha512-1VjrOxz6kouIMS/jZ+oQTAUsXufrF8hVzkfzSxqBh0Wy/KzEqZSvy3OZe/Ntrd5QeHtNCUF1bE0bIRLslzHCcw=="
|
||||
},
|
||||
"node_modules/methods": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/methods/-/methods-0.1.0.tgz",
|
||||
"integrity": "sha512-N4cn4CbDqu7Fp3AT4z3AsO19calgczhsmCGzXLCiUOrWg9sjb1B+yKFKOrnnPGKKvjyJBmw+k6b3adFN2LbuBw=="
|
||||
},
|
||||
"node_modules/mime": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz",
|
||||
"integrity": "sha512-Ysa2F/nqTNGHhhm9MV8ure4+Hc+Y8AWiqUdHxsO7xu8zc92ND9f3kpALHjaP026Ft17UfxrMt95c50PLUeynBw=="
|
||||
},
|
||||
"node_modules/mkdirp": {
|
||||
"version": "0.3.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz",
|
||||
"integrity": "sha512-8OCq0De/h9ZxseqzCH8Kw/Filf5pF/vMI6+BH7Lu0jXz2pqYCjTAQRolSxRIi+Ax+oCCjlxoJMP0YQ4XlrQNHg==",
|
||||
"deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)"
|
||||
},
|
||||
"node_modules/multiparty": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/multiparty/-/multiparty-2.2.0.tgz",
|
||||
"integrity": "sha512-fiFMI4tSze1TsrWFZNABRwy7kF/VycEWz4t0UFESOoP5IdJh29AUFmbirWXv/Ih/rNw62OO2YaQpQEiw1BFQpQ==",
|
||||
"dependencies": {
|
||||
"readable-stream": "~1.1.9",
|
||||
"stream-counter": "~0.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.3.0.tgz",
|
||||
"integrity": "sha512-q9wF64uB31BDZQ44DWf+8gE7y8xSpBdREAsJfnBO2WX9ecsutfUO6S9uWEdixlDLOlWaqnlnFXXwZxUUmyLfgg==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/pause": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz",
|
||||
"integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg=="
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "0.6.6",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-0.6.6.tgz",
|
||||
"integrity": "sha512-kN+yNdAf29Jgp+AYHUmC7X4QdJPR8czuMWLNLc0aRxkQ7tB3vJQEONKKT9ou/rW7EbqVec11srC9q9BiVbcnHA==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/range-parser": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-0.0.4.tgz",
|
||||
"integrity": "sha512-okJVEq9DbZyg+5lD8pr6ooQmeA0uu8DYIyAU7VK1WUUK7hctI1yw2ZHhKiKjB6RXaDrYRmTR4SsIHkyiQpaLMA==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-body": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-1.1.2.tgz",
|
||||
"integrity": "sha512-9Vyxam2+QrtmNIc3mFrwazAXOeQdxgFvS3vvkvH02R5YbdsaSqL4N9M93s0znkh0q4cGBk8CbrqOSGkz3BUeDg==",
|
||||
"dependencies": {
|
||||
"bytes": "~0.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/readable-stream": {
|
||||
"version": "1.1.14",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
|
||||
"integrity": "sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==",
|
||||
"dependencies": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.1",
|
||||
"isarray": "0.0.1",
|
||||
"string_decoder": "~0.10.x"
|
||||
}
|
||||
},
|
||||
"node_modules/send": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/send/-/send-0.1.4.tgz",
|
||||
"integrity": "sha512-NJnIaB29/EcNqkNneUAm16oEVnzM2LeNBc/hmgKuExv2k9pCZQEw8SHJeCdjqesHJTyWAr7x5HjeOmRFS4BoFw==",
|
||||
"dependencies": {
|
||||
"debug": "*",
|
||||
"fresh": "0.2.0",
|
||||
"mime": "~1.2.9",
|
||||
"range-parser": "0.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/stream-counter": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/stream-counter/-/stream-counter-0.2.0.tgz",
|
||||
"integrity": "sha512-GjA2zKc2iXUUKRcOxXQmhEx0Ev3XHJ6c8yWGqhQjWwhGrqNwSsvq9YlRLgoGtZ5Kx2Ln94IedaqJ5GUG6aBbxA==",
|
||||
"dependencies": {
|
||||
"readable-stream": "~1.1.8"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
|
||||
"integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ=="
|
||||
},
|
||||
"node_modules/uid2": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.3.tgz",
|
||||
"integrity": "sha512-5gSP1liv10Gjp8cMEnFd6shzkL/D6W1uhXSFNCxDC+YI8+L8wkCYCbJ7n77Ezb4wE/xzMogecE+DtamEe9PZjg=="
|
||||
}
|
||||
}
|
||||
}
|
8
old-server/package.json
Normal file
8
old-server/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "r2",
|
||||
"version": "0.0.1",
|
||||
"private": false,
|
||||
"dependencies": {
|
||||
"express": "3.4.8"
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
3
package.json
Normal file
3
package.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "r2"
|
||||
}
|
@ -41,6 +41,14 @@ function proxy(config) {
|
||||
repPush(route, body);
|
||||
}
|
||||
);
|
||||
|
||||
pomelo.on("close", ()=> {
|
||||
try {
|
||||
socket.destroy();
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("connect", () => {
|
||||
console.log("connect");
|
||||
@ -73,6 +81,7 @@ function proxy(config) {
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
socket.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -5,9 +5,9 @@ describe("guild", () => {
|
||||
const tbc = new TestBaseClient();
|
||||
|
||||
test("entry", async () => {
|
||||
await tbc.init("6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340");
|
||||
await tbc.init("6513_2006_0OJ853n4WbMT4pF0tIUdVSZvFlYZCpUH");
|
||||
msg = await tbc.rpc("connector.entryHandler.entry", {
|
||||
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
|
||||
uid: "6513_2006_0OJ853n4WbMT4pF0tIUdVSZvFlYZCpUH",
|
||||
});
|
||||
console.log(msg);
|
||||
expect(msg.code).toBe(200);
|
||||
@ -19,6 +19,12 @@ describe("guild", () => {
|
||||
expect(msg.code).toBe(200);
|
||||
});
|
||||
|
||||
// test("join", async () => {
|
||||
// msg = await tbc.rpc("guild.guildHandler.joinGuild", { guildId: 64 });
|
||||
// console.log(msg);
|
||||
// expect(msg.code).toBe(200);
|
||||
// })
|
||||
|
||||
test("end", async () => {
|
||||
tbc.destroy();
|
||||
});
|
||||
|
@ -243,12 +243,11 @@ const StackBuffer = function (bufferSize) {
|
||||
let unReadHeadLen = (_dataHeadLen+2) - buffLastCanReadLen;
|
||||
_buffer.copy(headBuffer, buffLastCanReadLen, 0, unReadHeadLen);
|
||||
// 默认大端接收数据
|
||||
dataLen = headBuffer[_readIntMethod]() + _dataHeadLen+2;
|
||||
dataLen = headBuffer[_readIntMethod]();// + _dataHeadLen+2;
|
||||
}
|
||||
else {
|
||||
_buffer.copy(headBuffer, 0, _dataReadPosition, _dataReadPosition + _dataHeadLen+2);
|
||||
dataLen = headBuffer[_readIntMethod]();
|
||||
// dataLen += _dataHeadLen+2;
|
||||
dataLen = headBuffer[_readIntMethod]();// + _dataHeadLen+2;
|
||||
}
|
||||
// 数据长度不够读取,直接返回
|
||||
if (getDataLen() < dataLen) {
|
||||
@ -304,7 +303,8 @@ const StackBuffer = function (bufferSize) {
|
||||
}
|
||||
|
||||
if (dataLen !== _dataLen) {
|
||||
console.log('程序有漏洞,dataLen长度不合法');
|
||||
console.log(`程序有漏洞,dataLen长度不合法 ${dataLen} - ${_dataLen}`);
|
||||
throw new Error('程序有漏洞,dataLen长度不合法');
|
||||
}
|
||||
return dataLen;
|
||||
}
|
||||
|
@ -25,5 +25,6 @@ module.exports = {
|
||||
FA_GUILD_CREATE_FAILED: 4001, // 创建工会失败
|
||||
FA_GUILD_JOIN_FAILED: 4002, // 加入工会失败
|
||||
FA_GUILD_APPROVE_FAILED: 4003, // 审批工会失败
|
||||
FA_GUILD_HAVE_NOT_JOIN: 4004, // 未加入工会
|
||||
},
|
||||
};
|
||||
|
0
shared/dao/kkkj.js
Normal file
0
shared/dao/kkkj.js
Normal file
0
shared/index.js
Normal file
0
shared/index.js
Normal file
1
shared/lib/bbc.js
Normal file
1
shared/lib/bbc.js
Normal file
@ -0,0 +1 @@
|
||||
npmfasdfasdfasffffffffffffss
|
14
shared/package.json
Normal file
14
shared/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "shared",
|
||||
"version": "1.0.5",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"lib": "lib"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
3
web-server/.gitignore
vendored
Normal file
3
web-server/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.DS_Store
|
||||
/.vscode
|
||||
/node_modules
|
8
web-server/apidoc.json
Normal file
8
web-server/apidoc.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "r2 web-server api",
|
||||
"version": "0.1.1",
|
||||
"description": "r2 web-server",
|
||||
"title": "r2 web-server",
|
||||
"url": "https://api.cebggame.com",
|
||||
"sampleUrl": "http://192.168.100.83:3000"
|
||||
}
|
@ -1,27 +1,53 @@
|
||||
var express = require('express');
|
||||
var app = express.createServer();
|
||||
const Koa = require('koa')
|
||||
const app = new Koa()
|
||||
const views = require('koa-views')
|
||||
const json = require('koa-json')
|
||||
const onerror = require('koa-onerror')
|
||||
const bodyparser = require('koa-bodyparser')
|
||||
const cors = require('koa2-cors')
|
||||
const logger = require('koa-logger')
|
||||
|
||||
app.configure(function(){
|
||||
app.use(express.methodOverride());
|
||||
app.use(express.bodyParser());
|
||||
app.use(app.router);
|
||||
app.set('view engine', 'jade');
|
||||
app.set('views', __dirname + '/public');
|
||||
app.set('view options', {layout: false});
|
||||
app.set('basepath',__dirname + '/public');
|
||||
const config = require("./config")
|
||||
|
||||
const game = require('./routes/game/game');
|
||||
|
||||
const Code = require("shared/code");
|
||||
|
||||
// error handler
|
||||
onerror(app)
|
||||
|
||||
if (!!config.debug) {
|
||||
app.use(cors({
|
||||
origin: function (ctx) {
|
||||
return config.cors.default;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// app.use(koabody({multipart:true}));
|
||||
// middlewares
|
||||
app.use(bodyparser({
|
||||
enableTypes:['json', 'form', 'text'],
|
||||
multipart: true
|
||||
}))
|
||||
app.use(json())
|
||||
app.use(logger())
|
||||
app.use(require('koa-static')(__dirname + '/static'))
|
||||
|
||||
// logger
|
||||
app.use(async (ctx, next) => {
|
||||
const start = new Date()
|
||||
await next()
|
||||
const ms = new Date() - start
|
||||
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`)
|
||||
})
|
||||
|
||||
// routes
|
||||
app.use(game.routes(), game.allowedMethods());
|
||||
|
||||
// error-handling
|
||||
app.on('error', (err, ctx) => {
|
||||
console.error('server error', err, ctx)
|
||||
});
|
||||
|
||||
app.configure('development', function(){
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
|
||||
});
|
||||
|
||||
app.configure('production', function(){
|
||||
var oneYear = 31557600000;
|
||||
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
|
||||
app.use(express.errorHandler());
|
||||
});
|
||||
|
||||
console.log("Web server has started.\nPlease log on http://127.0.0.1:3001/index.html");
|
||||
|
||||
app.listen(3001);
|
||||
module.exports = app
|
||||
|
19
web-server/config.js
Normal file
19
web-server/config.js
Normal file
@ -0,0 +1,19 @@
|
||||
const config = {
|
||||
db: {
|
||||
host: "mysql.lo",
|
||||
port: 3307,
|
||||
user: "root",
|
||||
password: "123456",
|
||||
database: "invitation"
|
||||
},
|
||||
redis: {
|
||||
url: "redis://192.168.100.83:6379",
|
||||
},
|
||||
cors: {
|
||||
default: "*"
|
||||
},
|
||||
debug: true,
|
||||
campaign_api: "https://shop-api-test.lifo.ai/api/v1"
|
||||
}
|
||||
|
||||
module.exports = config;
|
35
web-server/lib/db.js
Normal file
35
web-server/lib/db.js
Normal file
@ -0,0 +1,35 @@
|
||||
const mysql = require("mysql2");
|
||||
const config = require("../config")
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: config.db.host,
|
||||
port: config.db.port,
|
||||
user: config.db.user,
|
||||
password: config.db.password,
|
||||
database: config.db.database
|
||||
});
|
||||
|
||||
function query(sql, values) {
|
||||
return new Promise((resolve, reject) => {
|
||||
pool.getConnection(function (err, connection) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
connection.query(sql, values, (err, rows) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
resolve(rows);
|
||||
}
|
||||
connection.release();
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
query
|
||||
};
|
21
web-server/lib/redis.js
Normal file
21
web-server/lib/redis.js
Normal file
@ -0,0 +1,21 @@
|
||||
const redis = require('redis');
|
||||
const config = require("../config");
|
||||
const Code = require("shared").code;
|
||||
const client = redis.createClient(config.redis);
|
||||
client.on("error", function (err) {
|
||||
console.log("Error " + err);
|
||||
});
|
||||
client.connect();
|
||||
|
||||
async function hGet(key, field) {
|
||||
return await client.HGET(key, field);
|
||||
}
|
||||
|
||||
async function hSet(key, field, value) {
|
||||
return await client.HSET(key, field, value);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hGet,
|
||||
hSet,
|
||||
}
|
7
web-server/lib/utils.js
Normal file
7
web-server/lib/utils.js
Normal file
@ -0,0 +1,7 @@
|
||||
function verify_wallet_address(address) {
|
||||
return (/^0x[0123456789abcdefgABCDEFG]{40}$/).test(address);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
verify_wallet_address
|
||||
};
|
4279
web-server/package-lock.json
generated
4279
web-server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,42 @@
|
||||
{
|
||||
"name": "r2",
|
||||
"version": "0.0.1",
|
||||
"private": false,
|
||||
"name": "invitationServer",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "hello invitation server",
|
||||
"apidoc": {
|
||||
"title": "docs",
|
||||
"url": "http://localhost:3000"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node www",
|
||||
"dev": "./node_modules/.bin/nodemon www",
|
||||
"prd": "pm2 start www",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"doc": "apidoc -i . -o /var/www/api -f routes"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "3.4.8"
|
||||
"@breejs/later": "^4.1.0",
|
||||
"axios": "^1.1.3",
|
||||
"debug": "^4.1.1",
|
||||
"ejs": "~2.3.3",
|
||||
"joi": "^17.7.0",
|
||||
"koa": "^2.7.0",
|
||||
"koa-body": "^5.0.0",
|
||||
"koa-bodyparser": "^4.2.1",
|
||||
"koa-convert": "^1.2.0",
|
||||
"koa-json": "^2.0.2",
|
||||
"koa-logger": "^3.2.0",
|
||||
"koa-onerror": "^4.1.0",
|
||||
"koa-redis": "^4.0.1",
|
||||
"koa-router": "^7.4.0",
|
||||
"koa-static": "^5.0.0",
|
||||
"koa-views": "^6.2.0",
|
||||
"koa2-cors": "^2.0.6",
|
||||
"mysql2": "^2.3.3",
|
||||
"redis": "^4.6.6",
|
||||
"shared": "file:../shared"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^1.19.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
web-server/routes/game/game.js
Normal file
38
web-server/routes/game/game.js
Normal file
@ -0,0 +1,38 @@
|
||||
const router = require('koa-router')();
|
||||
router.prefix('/api/game');
|
||||
const { hGet, hSet } = require("../../lib/redis");
|
||||
const Code = require("shared").code;
|
||||
|
||||
/** @api {post} /api/game/userinfo userinfo 获取用户信息
|
||||
* @apiGroup game
|
||||
*
|
||||
* @apiBody {String} token='6516_2006_0x44b9bd78ed5e9d00bd83f270b3d97909e8c904dc' 用户token
|
||||
*
|
||||
* @apiSuccess {Number} code 错误码
|
||||
* @apiSuccess {String} msg 错误信息
|
||||
* @apiSuccess {Object} data 用户信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {
|
||||
* "code": 0,
|
||||
* "msg": "ok",
|
||||
* "data": {
|
||||
* "id": 1,
|
||||
* "username": "admin",
|
||||
* "nickname": "管理员",
|
||||
* "avatar": "http://localhost:3000/static/images/avatar.png",
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
router.post('/userinfo', async function(ctx, next) {
|
||||
const { token } = ctx.request.body;
|
||||
const userInfo = await hGet(`t_user:${token}`, "value");
|
||||
ctx.body = {
|
||||
errcode: 0,
|
||||
errmsg: "/api/game/userinfo ok",
|
||||
data: JSON.parse(userInfo)
|
||||
};
|
||||
});
|
||||
|
||||
module.exports = router;
|
130
web-server/sql/invitation.sql
Normal file
130
web-server/sql/invitation.sql
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 80030
|
||||
Source Host : localhost:3306
|
||||
Source Schema : invitation
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 80030
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 22/11/2022 18:57:34
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for aa1_eventlog
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `aa1_eventlog`;
|
||||
CREATE TABLE `aa1_eventlog` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`create_time` datetime NOT NULL,
|
||||
`account` varchar(64) NOT NULL,
|
||||
`operator` varchar(64) CHARACTER SET utf8mb4 NOT NULL COMMENT 'twitter_id',
|
||||
`event` varchar(32) NOT NULL COMMENT '1:注册 2:lv1关联推荐 3:lv2关联人推荐',
|
||||
`point` int NOT NULL COMMENT '奖励积分',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `user_index` (`create_time`,`account`,`operator`),
|
||||
KEY `account` (`account`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8mb4 ;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for aa1_leadboard
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `aa1_leadboard`;
|
||||
CREATE TABLE `aa1_leadboard` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`rank` int NOT NULL,
|
||||
`account` varchar(64) NOT NULL,
|
||||
`twitter` varchar(64) CHARACTER SET utf8mb4 NOT NULL,
|
||||
`clan` int NOT NULL,
|
||||
`point` varchar(64) NOT NULL,
|
||||
PRIMARY KEY (`id`,`account`),
|
||||
UNIQUE KEY `account` (`account`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4 ;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for aa1_user
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `aa1_user`;
|
||||
CREATE TABLE `aa1_user` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`point` int NOT NULL DEFAULT '0' COMMENT '积分',
|
||||
`create_time` datetime DEFAULT NULL,
|
||||
`success_time` datetime DEFAULT NULL,
|
||||
`account` varchar(64) CHARACTER SET utf8mb4 NOT NULL COMMENT '钱包地址',
|
||||
`quest_status` int DEFAULT NULL COMMENT '??',
|
||||
`invite_account` varchar(64) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '推荐人钱包地址',
|
||||
`invite_code` varchar(64) DEFAULT NULL,
|
||||
`my_invite_code` varchar(64) CHARACTER SET utf8mb4 NOT NULL COMMENT '6-8位推荐码',
|
||||
`comefrom` varchar(64) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '用户所在国家',
|
||||
`email` varchar(64) DEFAULT NULL,
|
||||
`twitter_account` varchar(64) DEFAULT NULL,
|
||||
`discord_account` varchar(64) DEFAULT NULL,
|
||||
`clan_member` int NOT NULL DEFAULT '0' COMMENT '关联推荐人数',
|
||||
`rank` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`,`account`),
|
||||
UNIQUE KEY `account` (`account`),
|
||||
KEY `point` (`point` DESC) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=150 DEFAULT CHARSET=utf8mb4 ;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for user
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `user`;
|
||||
CREATE TABLE `user` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
|
||||
`create_time` datetime DEFAULT NULL COMMENT 'Create Time',
|
||||
`name` varchar(255) DEFAULT NULL,
|
||||
`headpic` varchar(255) DEFAULT NULL,
|
||||
`account` varchar(255) CHARACTER SET utf8mb4 NOT NULL COMMENT 'btc account id, wallet address',
|
||||
`commander` varchar(255) DEFAULT NULL COMMENT 'Uplink commander',
|
||||
`cache_c_num` int DEFAULT '0' COMMENT '司令下线数量',
|
||||
`ambassador` varchar(255) DEFAULT NULL COMMENT 'Uplink ambassador',
|
||||
`cache_a_num` int DEFAULT '0' COMMENT '大使下线数量',
|
||||
`rank_level` int NOT NULL DEFAULT '0' COMMENT '0-user / 1-commander / 2-ambassador',
|
||||
`email` varchar(255) DEFAULT NULL,
|
||||
`comefrom` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL,
|
||||
`bcexp` int DEFAULT '0' COMMENT 'Blockchain experience',
|
||||
`followcebg` int DEFAULT '0' COMMENT 'Follow CEBG’s Twitter',
|
||||
`joinedcebg` int DEFAULT '0' COMMENT 'Joined CEBG Discord',
|
||||
`aboutme` varchar(512) CHARACTER SET utf8mb4 DEFAULT NULL,
|
||||
PRIMARY KEY (`id`,`account`) USING BTREE,
|
||||
UNIQUE KEY `account` (`account`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1995 DEFAULT CHARSET=utf8mb4 ;
|
||||
|
||||
-- ----------------------------
|
||||
-- View structure for aa1_rank
|
||||
-- ----------------------------
|
||||
DROP VIEW IF EXISTS `aa1_rank`;
|
||||
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `aa1_rank` AS
|
||||
select @rank:=@rank + 1 AS rank,a.* from
|
||||
(select account, `aa1_user`.`twitter_account` AS `twitter_account`,`aa1_user`.`clan_member` AS `clan_member`,`aa1_user`.`point` AS `point` from `aa1_user` WHERE `aa1_user`.`success_time` IS NOT NULL ORDER BY `aa1_user`.`point` desc) a,
|
||||
(SELECT @rank:= 0) b;
|
||||
|
||||
select row_number() OVER (ORDER BY `aa1_user`.`point` desc ) AS `rank`,`aa1_user`.`id` AS `id`,`aa1_user`.`twitter_account` AS `twitter_account`,`aa1_user`.`clan_member` AS `clan_member`,`aa1_user`.`point` AS `point` from `aa1_user`;
|
||||
|
||||
-- ----------------------------
|
||||
-- View structure for tttt
|
||||
-- ----------------------------
|
||||
DROP VIEW IF EXISTS `tttt`;
|
||||
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tttt` AS select `user`.`account` AS `account` from `user` where (`user`.`rank_level` = 2);
|
||||
|
||||
-- ----------------------------
|
||||
-- Procedure structure for NewProc
|
||||
-- ----------------------------
|
||||
DROP PROCEDURE IF EXISTS `NewProc`;
|
||||
delimiter ;;
|
||||
CREATE PROCEDURE `NewProc`(param1 int)
|
||||
BEGIN
|
||||
#Routine body goes here...
|
||||
END
|
||||
;;
|
||||
delimiter ;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
90
web-server/www
Executable file
90
web-server/www
Executable file
@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var app = require('./app');
|
||||
var debug = require('debug')('demo:server');
|
||||
var http = require('http');
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
|
||||
var port = normalizePort(process.env.PORT || '3000');
|
||||
// app.set('port', port);
|
||||
|
||||
/**
|
||||
* Create HTTP server.
|
||||
*/
|
||||
|
||||
var server = http.createServer(app.callback());
|
||||
|
||||
/**
|
||||
* Listen on provided port, on all network interfaces.
|
||||
*/
|
||||
|
||||
server.listen(port);
|
||||
server.on('error', onError);
|
||||
server.on('listening', onListening);
|
||||
|
||||
/**
|
||||
* Normalize a port into a number, string, or false.
|
||||
*/
|
||||
|
||||
function normalizePort(val) {
|
||||
var port = parseInt(val, 10);
|
||||
|
||||
if (isNaN(port)) {
|
||||
// named pipe
|
||||
return val;
|
||||
}
|
||||
|
||||
if (port >= 0) {
|
||||
// port number
|
||||
return port;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "error" event.
|
||||
*/
|
||||
|
||||
function onError(error) {
|
||||
if (error.syscall !== 'listen') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
var bind = typeof port === 'string'
|
||||
? 'Pipe ' + port
|
||||
: 'Port ' + port;
|
||||
|
||||
// handle specific listen errors with friendly messages
|
||||
switch (error.code) {
|
||||
case 'EACCES':
|
||||
console.error(bind + ' requires elevated privileges');
|
||||
process.exit(1);
|
||||
break;
|
||||
case 'EADDRINUSE':
|
||||
console.error(bind + ' is already in use');
|
||||
process.exit(1);
|
||||
break;
|
||||
default:
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "listening" event.
|
||||
*/
|
||||
|
||||
function onListening() {
|
||||
var addr = server.address();
|
||||
var bind = typeof addr === 'string'
|
||||
? 'pipe ' + addr
|
||||
: 'port ' + addr.port;
|
||||
debug('Listening on ' + bind);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user