void SendWhoResponse(ChatRoom room, RudpSession session) { Debug.Assert(!IsCommandRoom(room.Kind)); List <ChatWho> whoPackets = new List <ChatWho>(); ChatWho who = new ChatWho(); who.RoomID = room.RoomID; whoPackets.Add(who); room.Members.LockReading(delegate() { foreach (ulong id in room.Members) { if (Network.RudpControl.GetActiveSessions(id).Count > 0) // only send members who are connected { who.Members.Add(id); if (who.Members.Count > 40) // 40 * 8 = 320 bytes { who = new ChatWho(); who.RoomID = room.RoomID; whoPackets.Add(who); } } } }); // send who to already connected locations foreach (ChatWho packet in whoPackets) { session.SendData(ServiceID, 0, packet); } }
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); }
void SendInviteProof(ChatRoom room, RudpSession session) { if (!room.Invites.ContainsKey(Core.UserID)) { return; } // if already sent proof to client, return Tuple <ChatInvite, List <ushort> > tried; if (!room.Invites.TryGetValue(session.UserID, out tried)) { tried = new Tuple <ChatInvite, List <ushort> >(null, new List <ushort>()); room.Invites[session.UserID] = tried; } if (tried.Param2.Contains(session.ClientID)) { return; } tried.Param2.Add(session.ClientID); ChatInvite invite = new ChatInvite(); invite.RoomID = room.RoomID; invite.Title = room.Title; invite.SignedInvite = room.Invites[Core.UserID].Param1.SignedInvite; session.SendData(ServiceID, 0, invite); }
void SendWhoRequest(ChatRoom room, RudpSession session) { ChatWho whoReq = new ChatWho(); whoReq.Request = true; whoReq.RoomID = room.RoomID; session.SendData(ServiceID, 0, whoReq); }
public void Session_Update(RudpSession session) { // send node rooms that we have in common if (session.Status == SessionStatus.Active) { // send invites RoomMap.LockReading(delegate() { // if we are host of room and connect hasn't been sent invite foreach (ChatRoom room in RoomMap.Values) { if (room.NeedSendInvite(session.UserID, session.ClientID)) { // invite not sent if (room.Kind == RoomKind.Private || room.Host == Core.UserID) { session.SendData(ServiceID, 0, room.Invites[session.UserID].Param1); room.Invites[session.UserID].Param2.Add(session.ClientID); ProcessMessage(room, "Invite sent to " + GetNameAndLocation(session)); SendWhoResponse(room, session); } // else private room and we are not the host, send proof we belong here else { SendInviteProof(room, session); } } // ask member who else is in room if (!IsCommandRoom(room.Kind) && room.Members.SafeContains(session.UserID)) { SendWhoRequest(room, session); } } }); SendStatus(session); } // if disconnected if (session.Status == SessionStatus.Closed) { foreach (ChatRoom room in FindRoom(session.UserID)) { if (room.Active) { // don't remove from members unless explicitly told in status Core.RunInGuiThread(room.MembersUpdate); } } } }
void Core_SecondTimer() { // need keep alives because someone else might have IM window open while we have it closed // send keep alives every x secs if (Core.TimeNow.Second % SessionTimeout == 0) { foreach (var userID in ActiveUsers) { IMStatus status = null; if (IMMap.SafeTryGetValue(userID, out status)) { foreach (ushort client in status.TTL.Keys) { if (status.TTL[client].Value > 0) { RudpSession session = Network.RudpControl.GetActiveSession(userID, client); if (session != null) { status.TTL[client].Value = SessionTimeout * 2; session.SendData(ServiceID, 0, new IMKeepAlive()); } } } } } } // timeout sessions IMMap.LockReading(delegate() { foreach (IMStatus status in IMMap.Values) { foreach (BoxInt ttl in status.TTL.Values) { if (ttl.Value > 0) { ttl.Value--; } } } }); }
private void ReceivePublicRequest(RudpSession session) { // if in global im, only allow if on buddies list if (Core.User.Settings.GlobalIM) { if (!Core.Buddies.BuddyList.SafeContainsKey(session.UserID)) { return; } } if (Core.Buddies.IgnoreList.SafeContainsKey(session.UserID)) { return; } if (Local.Hash != null) { session.SendData(ServiceID, DataTypeSession, Local); } }
private void SendStatus(RudpSession session) { // send even if empty so they know to remove us ChatStatus status = new ChatStatus(); RoomMap.LockReading(delegate() { foreach (ChatRoom room in RoomMap.Values) { if (room.Active && !IsCommandRoom(room.Kind)) { if (room.Kind == RoomKind.Secret && !room.Verified.ContainsKey(session.UserID)) { continue; } status.ActiveRooms.Add(room.RoomID); } } }); session.SendData(ServiceID, 0, status); }
private void SendPublicRequest(RudpSession session, ShareCollection collection) { collection.Status = "Requesting List"; session.SendData(ServiceID, DataTypeSession, new PublicShareRequest()); }
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); }
private void SendPublicRequest(RudpSession session, ShareCollection collection) { collection.Status = "Requesting List"; session.SendData(ServiceID, DataTypeSession, new PublicShareRequest(), true); }
private void SendFileRequest(RudpSession session, SharedFile file) { foreach (DhtClient taraget in file.ToRequest.Where(c => c.UserID == session.UserID && c.ClientID == session.ClientID).ToArray()) file.ToRequest.Remove(taraget); file.SaveLocal = false; session.SendData(ServiceID, DataTypeSession, file, true); file.TransferStatus = "Request sent to " + Core.GetName(session.UserID); }
private void ReceivePublicRequest(RudpSession session) { if(Local.Hash != null) session.SendData(ServiceID, DataTypeSession, Local, true); }
private void ReceivePublicRequest(RudpSession session) { // if in global im, only allow if on buddies list if (Core.User.Settings.GlobalIM) if (!Core.Buddies.BuddyList.SafeContainsKey(session.UserID)) return; if (Core.Buddies.IgnoreList.SafeContainsKey(session.UserID)) return; if(Local.Hash != null) session.SendData(ServiceID, DataTypeSession, Local); }