You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.7 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
namespace Friend
{
public static class FriendSvrIDUtils
{
public static int DBServerNum { get; private set; }
public static int friendSvrNum { get; private set; }
public static void Init(ServerApp app)
{
DBServerNum = app.GetCluster().GetChannelCount((int)ServerType.GameDb);
TraceLog.Trace("FriendSvrIDUtils.Init DBServer channel count is {0}", DBServerNum);
if (DBServerNum == 0)
{
TraceLog.Error("FriendSvrIDUtils.Init DBServer channel num is 0, use 1 instead");
// 肯定会有1个DB, 默认值1, 信息发送仍然会失败, 但是这样错误日志能多打印些信息
DBServerNum = 1;
}
friendSvrNum = app.GetCluster().GetChannelCount((int) ServerType.Friend) + 1;
TraceLog.Trace("FriendSvrIDUtils.Init FriendSvr num {0}", friendSvrNum);
}
public static uint GetDBServerID( long userId)
{
int dbIndex;
//根据uid
dbIndex = (int)(userId % DBServerNum);
//最后一个,这么些是为了刚好直观匹配,比如10003在第三张表
if (dbIndex == 0)
{
dbIndex = DBServerNum;
}
return ServerIDUtils.GetLevel1ServerIDByType(FriendServerUtils.GetAppID(), (int)ServerType.GameDb, (int)dbIndex);
}
public static uint GetDBServerID(PlayerInfoFriend playerInfo)
{
return GetDBServerID(playerInfo.UserID);
}
}
}