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.
49 lines
1.1 KiB
49 lines
1.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace Sog.Service
|
|
{
|
|
public class GateSessionID
|
|
{
|
|
private static long SessionIDSeq = 0;
|
|
static long nowStamp = 0;
|
|
|
|
static object locker = new object();
|
|
public static long GenNextID(uint serverID)
|
|
{
|
|
lock (locker)
|
|
{
|
|
long sessionIndex = ++SessionIDSeq;
|
|
|
|
long iInstID = ServerIDUtils.GetInstanceID(serverID);
|
|
if (nowStamp == 0)
|
|
{
|
|
nowStamp = AppTime.GetNowSysSecond();
|
|
}
|
|
long sessionID = (iInstID << 48) + (nowStamp << 16) + sessionIndex;
|
|
|
|
return sessionID;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 简单判断一个id是否是sessionid
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public static bool IsGateSessionIDOrUserID(long id)
|
|
{
|
|
if(id >= (((long)1)<<48))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|