public string Serialize() { PacketContainer cont = new PacketContainer() { type = (int)type, data = data, created = ServerTime.GetCurrentUnixTimestampMillis() }; return(JsonConvert.SerializeObject(cont)); }
public bool IsAlive() { if (!tcpclient.Connected) { return(false); } if (!stillOk) { return(false); } long currentTime = ServerTime.GetCurrentUnixTimestampMillis(); return((currentTime - lastHeartBeat) < PurgeTimout); }
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); }
public bool IsReliable() { long currentTime = ServerTime.GetCurrentUnixTimestampMillis(); return((currentTime - lastHeartBeat) < HeartBeatInterval); }
public void HeartBeatNow() { lastHeartBeat = ServerTime.GetCurrentUnixTimestampMillis(); }