void Session_Data(RudpSession session, byte[] data) { IMStatus status = OpenStatus(session.UserID); G2Header root = new G2Header(data); if (G2Protocol.ReadPacket(root)) { if (root.Name == IMPacket.Message) { MessageData message = MessageData.Decode(root); if (message.TargetID != 0) { Debug.Assert(session.UserID == Core.UserID); if (session.UserID != Core.UserID) { return; } status = OpenStatus(message.TargetID); } ProcessMessage(status, new InstantMessage(Core, session, message)); } if (root.Name == IMPacket.Alive) { status.SetTTL(session.ClientID, SessionTimeout * 2); } } }
public void Session_Update(RudpSession session) { if (!ActiveUsers.Contains(session.UserID)) { return; } IMStatus status = null; if (!IMMap.SafeTryGetValue(session.UserID, out status)) { return; } if (session.Status == SessionStatus.Active) { // needs to be set here as well be cause we don't receive a keep alive from remote host on connect status.SetTTL(session.ClientID, SessionTimeout * 2); session.SendData(ServiceID, 0, new IMKeepAlive()); } Update(status); }