예제 #1
0
파일: Packets.cs 프로젝트: astorks/BlazeIM
        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);
        }
예제 #2
0
파일: Packets.cs 프로젝트: astorks/BlazeIM
        public static void HandleLoginRequest(SocketConnection conn, Packet pak)
        {
            string Account = pak.Readstring();
            string PasswordHash = pak.Readstring();

            string Nickname = Member.TryLoginWithPassword(Account, PasswordHash, conn.SqlConnection);

            if (Nickname == null)
                conn.SendPacket(Packet.New(Packets.PAK_SRV_LGNRESP, false, (byte)0x01));
            else
            {
                Member mem = new Member(Account, conn.SqlConnection);

                if (ServerSocket.Instance.MemberConnections.ContainsKey(mem.ID))
                {
                    ServerSocket.Instance.MemberConnections[mem.ID].SendPacket(Packet.New(0x0));
                    conn.SendPacket(Packet.New(Packets.PAK_SRV_LGNRESP, false, (byte)0x02));
                }
                else
                {
                    mem.StatusCode = 0x01;
                    conn.ConnectionData.Add("MemberConnected", true);
                    conn.ConnectionData.Add("Member", mem);

                    foreach (string FriendIDStr in mem.Friends)
                        try
                        {
                            int FriendID = int.Parse(FriendIDStr);
                            if (ServerSocket.Instance.MemberConnections.ContainsKey(FriendID))
                                ServerSocket.Instance.MemberConnections[FriendID].SendPacket(Packet.New(Packets.PAK_SRV_NEWSTSDLVR, mem.ID, mem.StatusCode));
                        }
                        catch { }

                    ServerSocket.Instance.MemberConnections.Add(mem.ID, conn);

                    conn.SendPacket(Packet.New(Packets.PAK_SRV_LGNRESP, true, Nickname, mem.MemberData, mem.FirstName + " " + mem.LastName, mem.ID, mem.IsPremiumIM, mem.NameFontColor, mem.StatusFontColor));
                }
            }

            Console.WriteLine("HandleLoginRequest({0}, {1});", Account, PasswordHash);
        }
예제 #3
0
파일: Packets.cs 프로젝트: astorks/BlazeIM
        public static void HandleFriendDenyRequest(SocketConnection conn, Packet pak)
        {
            if (conn.ConnectionData.ContainsKey("Member"))
            {
                Member member1 = (Member)conn.ConnectionData["Member"];

                int MemberID = pak.Readint();

                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.Save();
                }
            }
        }
예제 #4
0
파일: Packets.cs 프로젝트: astorks/BlazeIM
        public static void HandleFriendRemoveRequest(SocketConnection conn, Packet pak)
        {
            if (conn.ConnectionData.ContainsKey("Member"))
            {
                Member member1 = (Member)conn.ConnectionData["Member"];
                int MemberID = pak.Readint();

                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;

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

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

                if (ServerSocket.Instance.MemberConnections.ContainsKey(MemberID))
                    ServerSocket.Instance.MemberConnections[MemberID].SendPacket(Packet.New(Packets.PAK_SRV_FRNDRMVDLVR, member1.ID));
                conn.SendPacket(Packet.New(Packets.PAK_SRV_FRNDRMVDLVR, member2.ID));
            }
        }
예제 #5
0
파일: Packets.cs 프로젝트: astorks/BlazeIM
        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);
                    }
                }
            }
        }