Files
ZYZ/game-server/app/util/routeUtil.ts
2020-11-18 23:58:35 +08:00

55 lines
1.7 KiB
TypeScript

import { dispatch} from './dispatcher';
import { Session, Application } from 'pinus';
export function chat(session: Session, msg: any, app: Application, cb: (err: Error , serverId ?: string) => void) {
let chatServers = app.getServersByType('chat');
if(!chatServers || chatServers.length === 0) {
cb(new Error('can not find chat servers.'));
return;
}
let res = dispatch(session.get('roleId'), chatServers);
cb(null, res.id);
}
export function battle(session: Session, msg: any, app: Application, cb: (err: Error , serverId ?: string) => void) {
let battleServers = app.getServersByType('battle');
if(!battleServers || battleServers.length === 0) {
cb(new Error('can not find battle servers.'));
return;
}
let rid = session.get('roleId');
if (msg.args && msg.args.length > 0) {
for (let arg of msg.args) {
if (!arg.route) continue;
if (arg.route === 'battle.comBattleHandler.createTeam') {
rid = Math.random().toString(36).slice(-8);
session.set('teamCode', rid);
} else if (arg.route.indexOf('battle.comBattleHandler') !== -1) {
if (arg.body.teamCode) {
rid = arg.body.teamCode;
}
}
}
}
let res = dispatch(rid, battleServers);
cb(null, res.id);
}
export function gm(session: Session, msg: any, app: Application, cb: (err: Error , serverId ?: string) => void) {
let gmServers = app.getServersByType('gm');
if(!gmServers || gmServers.length === 0) {
cb(new Error('can not find gm servers.'));
return;
}
let res = dispatch(session.get('roleId'), gmServers);
cb(null, res.id);
}