Beispiel #1
0
        /// <summary>
        /// Creates a packet with the following data
        /// </summary>
        /// <param name="Data">Byte, Byte[], Int16, Int32, Int64, UInt32, String, Boolean, or Double</param>
        /// <returns>New packet created with the data</returns>
        public static Packet New(params object[] Data)
        {
            Packet pak = new Packet(null);

            foreach (object data in Data)
            {
                switch (data.GetType().Name)
                {
                    case "Byte": pak.Write((Byte)data); break;
                    case "Byte[]": pak.Write((Byte[])data); break;
                    case "Int16": pak.Write((Int16)data); break;
                    case "Int32": pak.Write((Int32)data); break;
                    case "Int64": pak.Write((Int64)data); break;
                    case "UInt32": pak.Write((UInt32)data); break;
                    case "String": pak.Write((String)data); break;
                    case "Boolean": pak.Write((Boolean)data); break;
                    case "Double": pak.Write((Double)data); break;
                    default: throw new ArgumentException("Unknown Type: " + data.GetType().Name);
                }
            }

            return pak;
        }
Beispiel #2
0
        public void SendData(byte[] data)
        {
            if (SoundInMuted)
                    return;
                else
                {
                    Packet pak = new Packet(null);
                    pak.Write(0x03);
                    pak.Write(CallID);
                    pak.Write(data.Length);
                    pak.Write(data);

                    UdpConnection.Send(pak.ToArray(), pak.Length);
                }
        }
Beispiel #3
0
        public static void HandleMemberInfoRequest(SocketConnection conn, Packet pak)
        {
            int MemberID = 0;

            if (conn.ConnectionData.ContainsKey("Member"))
            {
                try
                {
                    Packet pak2 = new Packet(null);
                    pak2.Write(Packets.PAK_SRV_MEMINFORESP);

                    MemberID = pak.Readint();
                    Member mem = conn.ConnectionData["Member"] as Member;
                    Member member;
                    if (ServerSocket.Instance.MemberConnections.ContainsKey(MemberID))
                        member = ServerSocket.Instance.MemberConnections[MemberID].ConnectionData["Member"] as Member;
                    else
                        member = new Member(MemberID, conn.SqlConnection);
                    if (member.IsValid)
                    {
                        pak2.Write(true);
                        pak2.Write(MemberID);
                        pak2.Write(member.Nickname);
                        pak2.Write(member.MemberData);
                        pak2.Write(member.Authority);
                        pak2.Write(member.StatusCode);
                        pak2.Write(mem.PendingFriends.Contains(MemberID.ToString()));
                        pak2.Write(member.FirstName);
                        pak2.Write(member.LastName);
                        pak2.Write(member.IsPremiumIM);
                        pak2.Write(member.NameFontColor);
                        pak2.Write(member.StatusFontColor);
                    }
                    else
                        pak2.Write(false);

                    conn.SendPacket(pak2);
                }
                catch (Exception ex) { Console.WriteLine(ex.ToString()); }
            }

            Console.WriteLine("HandleMemberInfoRequest({0}); SqlState: {1}", MemberID, conn.SqlConnection.State);
        }
Beispiel #4
0
        public static void HandleFriendListRequest(SocketConnection conn, Packet pak)
        {
            if (conn.ConnectionData.ContainsKey("Member"))
            {
                Packet pak2 = new Packet(null);
                Member mem = (Member)conn.ConnectionData["Member"];

                pak2.Write(Packets.PAK_SRV_FRNDLSTRESP);
                int FriendCount = 0;
                foreach (string FriendID in mem.Friends)
                    try { Convert.ToInt32(FriendID); FriendCount++; }
                    catch { }
                foreach (string FriendID in mem.PendingFriends)
                    try { Convert.ToInt32(FriendID); FriendCount++; }
                    catch { }

                pak2.Write(FriendCount);

                foreach (string FriendID in mem.Friends)
                    try { pak2.Write(Convert.ToInt32(FriendID)); }
                    catch { }
                foreach (string FriendID in mem.PendingFriends)
                    try { pak2.Write(Convert.ToInt32(FriendID)); }
                    catch { }

                conn.SendPacket(pak2);

                Console.WriteLine("HandleFriendListRequest({0});", mem.Friends.Count);
            }
        }
Beispiel #5
0
        public static void HandleFriendAddRequest(SocketConnection conn, Packet pak)
        {
            if (conn.ConnectionData.ContainsKey("Member"))
            {
                Member member1 = (Member)conn.ConnectionData["Member"];
                string FriendSearch = pak.Readstring();

                int MemberID = Member.FindMember(FriendSearch, conn.SqlConnection);
                if (MemberID == -1 || MemberID == member1.ID)
                    return;

                Member member2;
                if (ServerSocket.Instance.MemberConnections.ContainsKey(MemberID))
                    member2 = ServerSocket.Instance.MemberConnections[MemberID].ConnectionData["Member"] as Member;
                else
                    member2 = new Member(MemberID, conn.SqlConnection);

                if (!member2.IsValid || member1.Friends.Contains(member2.ID.ToString()))
                    return;

                if (member1.PendingFriends.Contains(member2.ID.ToString()))
                {
                    member1.PendingFriends.Remove(member2.ID.ToString());

                    member1.Friends.Add(member2.ID.ToString());
                    member2.Friends.Add(member1.ID.ToString());

                    member1.Save();
                    member2.Save();

                    Packet pak2 = new Packet(null);
                    pak2.Write(Packets.PAK_SRV_MEMINFORESP);

                    if (member2.IsValid)
                    {
                        pak2.Write(true);
                        pak2.Write(member2.ID);
                        pak2.Write(member2.Nickname);
                        pak2.Write(member2.MemberData);
                        pak2.Write(member2.Authority);
                        pak2.Write(member2.StatusCode);
                        pak2.Write(false);
                        pak2.Write(member2.FirstName);
                        pak2.Write(member2.LastName);
                        pak2.Write(member2.IsPremiumIM);
                        pak2.Write(member2.NameFontColor);
                        pak2.Write(member2.StatusFontColor);
                    }
                    else
                        pak2.Write(false);

                    conn.SendPacket(pak2);

                    if (ServerSocket.Instance.MemberConnections.ContainsKey(MemberID))
                    {
                        SocketConnection conn2 = ServerSocket.Instance.MemberConnections[MemberID];

                        Packet pak3 = new Packet(null);
                        pak3.Write(Packets.PAK_SRV_MEMINFORESP);

                        if (member1.IsValid)
                        {
                            pak3.Write(true);
                            pak3.Write(member1.ID);
                            pak3.Write(member1.Nickname);
                            pak3.Write(member1.MemberData);
                            pak3.Write(member1.Authority);
                            pak3.Write(member1.StatusCode);
                            pak3.Write(false);
                            pak3.Write(member1.FirstName);
                            pak3.Write(member1.LastName);
                            pak3.Write(member1.IsPremiumIM);
                            pak3.Write(member1.NameFontColor);
                            pak3.Write(member1.StatusFontColor);
                        }
                        else
                            pak3.Write(false);

                        conn2.SendPacket(pak3);
                    }
                }
                else if (member2.PendingFriends.Contains(member1.ID.ToString())) { }
                else
                {
                    member2.PendingFriends.Add(member1.ID.ToString());
                    member2.Save();

                    if (ServerSocket.Instance.MemberConnections.ContainsKey(MemberID))
                    {
                        SocketConnection conn2 = ServerSocket.Instance.MemberConnections[MemberID];

                        Packet pak2 = new Packet(null);
                        pak2.Write(Packets.PAK_SRV_MEMINFORESP);

                        if (member1.IsValid)
                        {
                            pak2.Write(true);
                            pak2.Write(member1.ID);
                            pak2.Write(member1.Nickname);
                            pak2.Write(member1.MemberData);
                            pak2.Write(member1.Authority);
                            pak2.Write(member1.StatusCode);
                            pak2.Write(true);
                            pak2.Write(member1.FirstName);
                            pak2.Write(member1.LastName);
                            pak2.Write(member1.IsPremiumIM);
                            pak2.Write(member1.NameFontColor);
                            pak2.Write(member1.StatusFontColor);
                        }
                        else
                            pak2.Write(false);

                        conn2.SendPacket(pak2);
                    }
                }
            }
        }