根据在线人数路由
This commit is contained in:
@@ -10,7 +10,7 @@ import { dispatch } from 'app/pubUtils/dispatcher';
|
||||
import { RedisClient } from 'redis';
|
||||
import { REDIS_KEY } from '@consts';
|
||||
import { RegionModel } from '@db/Region';
|
||||
import { resResult } from 'app/pubUtils/util';
|
||||
import { getRandEelmWithWeight, resResult } from 'app/pubUtils/util';
|
||||
|
||||
export default class GameController extends Controller {
|
||||
|
||||
@@ -158,7 +158,18 @@ export default class GameController extends Controller {
|
||||
return
|
||||
}
|
||||
// select connector
|
||||
let res = dispatch(userCode, connectors, 'connector');
|
||||
let sum = connectors.reduce((pre, cur) => pre + (cur['num']||0), 0);
|
||||
let res;
|
||||
if(sum == 0) {
|
||||
res = dispatch(userCode, connectors, 'connector');
|
||||
} else {
|
||||
let serversWithWeight = connectors.map(cur => ({...cur, weight: sum - (cur['num']||0)}));
|
||||
let randResult = getRandEelmWithWeight(serversWithWeight);
|
||||
res = randResult.dic;
|
||||
}
|
||||
let { id, serverType, clientHost, clientPort, num = 0 } = res;
|
||||
|
||||
await redisClient.hsetAsync(REDIS_KEY.SYS_SERVER, id, JSON.stringify({ serverType, clientHost, clientPort, id, num: num + 1 }));
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { host: res.clientHost, port: res.clientPort });
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user