Exemple #1
0
        void Session_Data(RudpSession session, byte[] data)
        {
            G2Header root = new G2Header(data);

            if (G2Protocol.ReadPacket(root))
            {
                switch (root.Name)
                {
                case ChatPacket.Data:
                    ReceiveMessage(ChatText.Decode(root), session);
                    break;

                case ChatPacket.Status:
                    ReceiveStatus(ChatStatus.Decode(root), session);
                    break;

                case ChatPacket.Invite:
                    ReceiveInvite(ChatInvite.Decode(root), session);
                    break;

                case ChatPacket.Who:
                    ReceiveWho(ChatWho.Decode(root), session);
                    break;
                }
            }
        }
Exemple #2
0
        void ReceiveStatus(ChatStatus status, RudpSession session)
        {
            // status is what nodes send to each other to tell what rooms they are active in

            RoomMap.LockReading(delegate()
            {
                foreach (ChatRoom room in RoomMap.Values)
                {
                    bool update = false;

                    // remove from room
                    if (!status.ActiveRooms.Contains(room.RoomID) && room.Members.SafeContains(session.UserID))
                    {
                        if (!IsCommandRoom(room.Kind))
                        {
                            if (room.Members.SafeContains(session.UserID))
                            {
                                ProcessMessage(room, GetNameAndLocation(session) + " left the room");
                            }

                            room.RemoveMember(session.UserID);
                        }

                        update = true;
                    }

                    // add member to room
                    if (IsCommandRoom(room.Kind) && room.Members.SafeContains(session.UserID))
                    {
                        update = true;
                    }

                    else if (status.ActiveRooms.Contains(room.RoomID))
                    {
                        // if room private check that sender is verified
                        if (room.Kind == RoomKind.Secret && !room.Verified.ContainsKey(session.UserID))
                        {
                            continue;
                        }

                        if (!room.Members.SafeContains(session.UserID))
                        {
                            ProcessMessage(room, GetNameAndLocation(session) + " joined the room");
                        }

                        room.AddMember(session.UserID);
                        update = true;
                    }

                    if (update)
                    {
                        Core.RunInGuiThread(room.MembersUpdate);
                    }
                }
            });
        }
Exemple #3
0
        public static ChatStatus Decode(G2Header root)
        {
            ChatStatus status = new ChatStatus();

            G2Protocol.ResetPacket(root);

            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Active:
                    if (child.PayloadSize % 8 == 0)
                    {
                        int offset = 0;

                        while (offset < child.PayloadSize)
                        {
                            UInt64 id = BitConverter.ToUInt64(child.Data, child.PayloadPos + offset);
                            status.ActiveRooms.Add(id);

                            offset += 8;
                        }
                    }
                    break;
                }
            }

            return(status);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public static ChatStatus Decode(G2Header root)
        {
            ChatStatus status = new ChatStatus();

            G2Protocol.ResetPacket(root);

            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Active:
                        if (child.PayloadSize % 8 == 0)
                        {
                            int offset = 0;

                            while (offset < child.PayloadSize)
                            {
                                UInt64 id = BitConverter.ToUInt64(child.Data, child.PayloadPos + offset);
                                status.ActiveRooms.Add(id);

                                offset += 8;
                            }
                        }
                        break;
                }
            }

            return status;
        }