コード例 #1
0
        public string Serialize()
        {
            PacketContainer cont = new PacketContainer()
            {
                type    = (int)type,
                data    = data,
                created = ServerTime.GetCurrentUnixTimestampMillis()
            };

            return(JsonConvert.SerializeObject(cont));
        }
コード例 #2
0
        public bool IsAlive()
        {
            if (!tcpclient.Connected)
            {
                return(false);
            }
            if (!stillOk)
            {
                return(false);
            }
            long currentTime = ServerTime.GetCurrentUnixTimestampMillis();

            return((currentTime - lastHeartBeat) < PurgeTimout);
        }
コード例 #3
0
        private static string GenerateSessionId()
        {
            const int    length = 32;
            const string chars  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            Random       random = new Random();

            string session;

            do
            {
                string rand     = (new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()));
                byte[] rawbites = Encoding.UTF8.GetBytes(ServerTime.GetCurrentUnixTimestampMillis() + "." + rand);
                byte[] hash     = SHA1.Create().ComputeHash(rawbites);
                session = Convert.ToBase64String(hash);
            } while (UsedSessions.Contains(session));

            UsedSessions.Add(session);

            return(session);
        }
コード例 #4
0
        public bool IsReliable()
        {
            long currentTime = ServerTime.GetCurrentUnixTimestampMillis();

            return((currentTime - lastHeartBeat) < HeartBeatInterval);
        }
コード例 #5
0
 public void HeartBeatNow()
 {
     lastHeartBeat = ServerTime.GetCurrentUnixTimestampMillis();
 }