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; } } /// /// 简单判断一个id是否是sessionid /// /// /// public static bool IsGateSessionIDOrUserID(long id) { if(id >= (((long)1)<<48)) { return true; } return false; } } }