public static void HandleCallRequest(SocketConnection conn, Packet pak) { if (conn.ConnectionData.ContainsKey("Member")) { Member memfrom = (Member)conn.ConnectionData["Member"]; int MemberCall = pak.Readint(); int Port = pak.Readint(); string LocalAddress = pak.Readstring(); if (memfrom.Friends.Contains(Convert.ToString(MemberCall))) { if (ServerSocket.Instance.MemberConnections.ContainsKey(MemberCall)) { SocketConnection toconn = ServerSocket.Instance.MemberConnections[MemberCall]; if(conn.clientSocket.RemoteEndPoint.ToString().Split(':')[0] == toconn.clientSocket.RemoteEndPoint.ToString().Split(':')[0]) toconn.SendPacket(Packet.New(Packets.PAK_SRV_CALL_DLVR, memfrom.ID, LocalAddress, Port)); else toconn.SendPacket(Packet.New(Packets.PAK_SRV_CALL_DLVR, memfrom.ID, conn.clientSocket.RemoteEndPoint.ToString().Split(':')[0], Port)); } else { //TODO: Notify the member that the friend is offline } } else { //TODO: Notify the member that the friend is not in their list } } }
public void SocketReceivedPacket(SocketConnection conn, Packet pak) { PacketsReceived++; Console.Title = string.Format("{0} Active Connection - {1} Packets Received - {2} Packets Sent", SocketConnections.Count, PacketsReceived, PacketsSent); SocketConnection_PacketReceived_Event(conn, pak); }
static void Socket_SocketConnection_PacketReceived_Event(SocketConnection socketConnection, Packet pak) { if (pak.IsValid()) { uint Header = pak.Readuint(); switch (Header) { case Packets.PAK_CLI_LGNRQST: PacketHandlers.HandleLoginRequest(socketConnection, pak); break; case Packets.PAK_CLI_FRNDLSTRQST: PacketHandlers.HandleFriendListRequest(socketConnection, pak); break; case Packets.PAK_CLI_MEMINFORQST: PacketHandlers.HandleMemberInfoRequest(socketConnection, pak); break; case Packets.PAK_CLI_SNDMSG: PacketHandlers.HandleMessageSend(socketConnection, pak); break; case Packets.PAK_CLI_CHNGSTSRQST: PacketHandlers.HandleStatusChangeRequest(socketConnection, pak); break; case Packets.PAK_CLI_OFFLNMSGRQST: PacketHandlers.HandleOfflineMessagesRequest(socketConnection, pak); break; case Packets.PAK_CLI_FRNDADDRQST: PacketHandlers.HandleFriendAddRequest(socketConnection, pak); break; case Packets.PAK_CLI_FRNDDNYRQST: PacketHandlers.HandleFriendDenyRequest(socketConnection, pak); break; case Packets.PAK_CLI_CHNGUPDTRQST: PacketHandlers.HandleChangeUpdateRequest(socketConnection, pak); break; case Packets.PAK_CLI_FRNDRMVRQST: PacketHandlers.HandleFriendRemoveRequest(socketConnection, pak); break; case Packets.PAK_CLI_CALL_RQST: PacketHandlers.HandleCallRequest(socketConnection, pak); break; case Packets.PAK_CLI_CALL_ACC: PacketHandlers.HandleCallAccept(socketConnection, pak); break; case Packets.PAK_CLI_CALL_DNY: PacketHandlers.HandleCallDeny(socketConnection, pak); break; default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid packet from {0}, 0x{1:X}", socketConnection.IP, Header); break; } } else { //Console.ForegroundColor = ConsoleColor.Red; //Console.WriteLine("Invalid packet from {0}", socketConnection.IP); //socketConnection.clientSocket.Close(); } }
/// <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; }
public static void HandleCallDeny(SocketConnection conn, Packet pak) { if (conn.ConnectionData.ContainsKey("Member")) { Member memfrom = (Member)conn.ConnectionData["Member"]; int MemberCall = pak.Readint(); if (memfrom.Friends.Contains(Convert.ToString(MemberCall))) { if (ServerSocket.Instance.MemberConnections.ContainsKey(MemberCall)) { ServerSocket.Instance.MemberConnections[MemberCall].SendPacket(Packet.New(Packets.PAK_SRV_CALL_DNY_DLVR, memfrom.ID)); } else { //TODO: Notify the member that the friend is offline } } else { //TODO: Notify the member that the friend is not in their list } } }
void HandleFriendListResponse(ClientSocket clientSocket, Packet pak) { int FriendsCount = pak.Readint(); FriendCount = FriendsCount; for (int i = 0; i < FriendsCount; i++) { int FriendID = pak.Readint(); try { clientSocket.SendPacket(Packet.New(Packets.PAK_CLI_MEMINFORQST, FriendID)); } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } this.Dispatcher.Invoke((MethodInvoker)delegate { LoginComplete = true; BlazeGames.IM.Client.MainWindow.Instance.txt_nickname.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.txt_status.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.txt_search.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.profile_image.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.nav_bar.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.listbox1.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.btn_ProfileSettings.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.btn_AddFriend.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.btn_chat.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.btn_close.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.btn_contacts.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.btn_home.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.btn_minimize.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.btn_settings.Visibility = Visibility.Visible; SlideFade.StartAnimationIn(BlazeGames.IM.Client.MainWindow.Instance.wnd); BlazeGames.IM.Client.MainWindow.Instance.page_Login.Visibility = Visibility.Hidden; BlazeGames.IM.Client.MainWindow.Instance.page_Home.Visibility = System.Windows.Visibility.Visible; SlideFade.StartAnimationIn(BlazeGames.IM.Client.MainWindow.Instance.page_Home); BlazeGames.IM.Client.MainWindow.Instance.page_Login.btn_login.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.page_Login.Loading.Visibility = Visibility.Hidden; BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_loading.Visibility = Visibility.Hidden; BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_account.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_password.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_loading.Content = "Loading Your Account"; }, null); }
void HandleCallRequest(ClientSocket clientsocket, Packet pak) { this.Dispatcher.Invoke((MethodInvoker)delegate { int MemberID = pak.Readint(); Contact contact = Contacts[MemberID]; string UDPAddress = pak.Readstring(); int Port = pak.Readint(); NotificationWindow.ShowCallNotification(contact, UDPAddress, Port); }, null); }
void HandleCallDenyRequest(ClientSocket clientsocket, Packet pak) { this.Dispatcher.Invoke((MethodInvoker)delegate { int MemberID = pak.Readint(); Contact contact = Contacts[MemberID]; contact.CallActive = false; VCallCore.EndCall(MemberID); SoundManager.VoiceCallingSound.Stop(); NotificationWindow.RemoveCallNotification(contact); }, null); }
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(); } } }
public void SendPacket(Packet pak) { clientSocket.BeginSend(pak.ToArray(), 0, pak.Length, SocketFlags.None, new AsyncCallback(SendPacketCallback), clientSocket); }
void HandleStatusChangeDeliver(ClientSocket clientSocket, Packet pak) { this.Dispatcher.Invoke((MethodInvoker)delegate { int MemberID = pak.Readint(); Status NewStatus = (Status)pak.Readbyte(); Contact contact = Contacts[MemberID]; if (contact.status == Status.Offline && NewStatus != Status.Offline && ConfigManager.Instance.GetBool("txt_loginnotification", true) && ConfigManager.Instance.GetBool("txt_notifications", true)) NotificationWindow.ShowNotification(String.Format("{0} Has Signed In", contact.FullName), String.Format("{0} has just signed in.", contact.FullName), contact); if (contact.status != Status.Offline && NewStatus == Status.Offline && ConfigManager.Instance.GetBool("txt_logoutnotification", true) && ConfigManager.Instance.GetBool("txt_notifications", true)) { VCallCore.EndCall(contact.ID); NotificationWindow.ShowNotification(String.Format("{0} Has Signed Out", contact.FullName), String.Format("{0} has just signed out.", contact.FullName), contact); } contact.status = NewStatus; BlazeGames.IM.Client.MainWindow.Instance.page_Contacts.Draw(); }, null); }
void HandleMemberInfoResponse(ClientSocket clientSocket, Packet pak) { this.Dispatcher.Invoke((MethodInvoker)delegate { ReceivedFriendCount++; if (pak.Readbool()) { int MemberID = pak.Readint(); string MemberNickname = pak.Readstring(); string MemberStatus = pak.Readstring(); int MemberAuth = pak.Readint(); byte StatusCode = pak.Readbyte(); bool PendingRequest = pak.Readbool(); string FirstName = pak.Readstring(); string LastName = pak.Readstring(); if (!Contacts.ContainsKey(MemberID)) Contacts.Add(MemberID, new Contact(MemberID, MemberNickname, FirstName, LastName, PendingRequest, (Status)StatusCode, MemberStatus, MemberAuth)); else { Contact contact = Contacts[MemberID]; contact.NickName = MemberNickname; contact.StatusUpdate = MemberStatus; contact.Authority = MemberAuth; contact.status = (Status)StatusCode; contact.Pending = PendingRequest; contact.FirstName = FirstName; contact.LastName = LastName; contact.FullName = FirstName + " " + LastName; } if (PendingRequest && ConfigManager.Instance.GetBool("txt_newrequestnotification", true) && ConfigManager.Instance.GetBool("txt_notifications", true)) { NotificationWindow.ShowNotification("Pending Contact", String.Format("{0} has requested you be added to their contact list.", MemberNickname)); } if (ReceivedFriendCount >= FriendCount) BlazeGames.IM.Client.MainWindow.Instance.page_Contacts.Draw(); } if (ReceivedFriendCount == FriendCount) clientSocket.SendPacket(Packet.New(Packets.PAK_CLI_OFFLNMSGRQST)); }, null); }
public static void HandleStatusChangeRequest(SocketConnection conn, Packet pak) { if (conn.ConnectionData.ContainsKey("Member")) { Member mem = (Member)conn.ConnectionData["Member"]; mem.StatusCode = pak.Readbyte(); mem.Save(); 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 { } } }
public static void HandleOfflineMessagesRequest(SocketConnection conn, Packet pak) { if (conn.ConnectionData.ContainsKey("Member")) { Member mem = (Member)conn.ConnectionData["Member"]; OfflineMessage[] OfflineMessages = OfflineMessageManager.Instance.GetMessages(mem.ID); foreach (OfflineMessage msg in OfflineMessages) conn.SendPacket(Packet.New(Packets.PAK_SRV_MSGDLVR, msg.From, msg.Message)); } }
public static void HandleMessageSend(SocketConnection conn, Packet pak) { if (conn.ConnectionData.ContainsKey("Member")) { Member memfrom = (Member)conn.ConnectionData["Member"]; int MemberSendTo = pak.Readint(); string Message = pak.Readstring(); if (memfrom.Friends.Contains(Convert.ToString(MemberSendTo))) { if (ServerSocket.Instance.MemberConnections.ContainsKey(MemberSendTo)) ServerSocket.Instance.MemberConnections[MemberSendTo].SendPacket(Packet.New(Packets.PAK_SRV_MSGDLVR, memfrom.ID, Message)); else { OfflineMessageManager.Instance.NewOfflineMessage(memfrom.ID, MemberSendTo, Message); } } else { //TODO: Notify the member that the friend is not in their list } } }
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); }
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); }
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)); } }
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); } }
void HandleFriendRemoveDeliver(ClientSocket clientSocket, Packet pak) { this.Dispatcher.Invoke((MethodInvoker)delegate { int MemberID = pak.Readint(); if (Contacts.ContainsKey(MemberID)) Contacts.Remove(MemberID); BlazeGames.IM.Client.MainWindow.Instance.page_Contacts.Draw(); }, null); }
void HandleLoginResponse(ClientSocket clientSocket, Packet pak) { bool LoginValid = pak.Readbool(); if (LoginValid) { string nickname = pak.Readstring(); string StatusUpdate = pak.Readstring(); string FullName = pak.Readstring(); clientSocket.SendPacket(Packet.New(Packets.PAK_CLI_FRNDLSTRQST)); this.Dispatcher.Invoke((MethodInvoker)delegate { Account = BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_account.Text; Password = BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_password.Password; NickName = nickname; App.FullName = FullName; BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_loading.Content = "Fetching Your Contacts"; BlazeGames.IM.Client.MainWindow.Instance.txt_nickname.Text = nickname; //BlazeGames.IM.Client.MainWindow.Instance.txt_nickname.Effect = new System.Windows.Media.Effects.BlurEffect(); BlazeGames.IM.Client.MainWindow.Instance.txt_status.Text = StatusUpdate; CurrentStatus = Status.Online; BlazeGames.IM.Client.MainWindow.Instance.profile_image_source.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("https://blaze-games.com/api/image/nocompress/?nickname=" + nickname), new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore)); }, null); } else { this.Dispatcher.Invoke((MethodInvoker)delegate { byte ResponseByte = pak.Readbyte(); if (ResponseByte == 0x01) NotificationWindow.ShowNotification("Unable to login", "Blaze Games IM was unable to verify this account, please check your username and password and try again."); else if(ResponseByte == 0x02) NotificationWindow.ShowNotification("Unable to login", "This account is already connected, please sign out and try again."); else MessageBox.Show("o.O", "Login Failed"); BlazeGames.IM.Client.MainWindow.Instance.page_Login.btn_login.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.page_Login.Loading.Visibility = Visibility.Hidden; BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_loading.Visibility = Visibility.Hidden; BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_account.Visibility = Visibility.Visible; BlazeGames.IM.Client.MainWindow.Instance.page_Login.txt_password.Visibility = Visibility.Visible; }, null); } }
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); } }
void HandleMessageDeliver(ClientSocket clientSocket, Packet pak) { this.Dispatcher.Invoke((MethodInvoker)delegate { int FromMemberID = pak.Readint(); string Message = pak.Readstring(); if(BlazeGames.IM.Client.MainWindow.Instance.page_Chat.ChattingWith != null) if (BlazeGames.IM.Client.MainWindow.Instance.page_Chat.ChattingWith.ID == FromMemberID) BlazeGames.IM.Client.MainWindow.Instance.page_Chat.HandleMessage(Contacts[FromMemberID].FullName, Message); Contacts[FromMemberID].ReceiveNewMessage(Message); }, null); }
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); } } } }
void HandleUpdateChangeDeliver(ClientSocket clientSocket, Packet pak) { this.Dispatcher.Invoke((MethodInvoker)delegate { int MemberID = pak.Readint(); string NewStatusUpdate = pak.Readstring(); Contacts[MemberID].control.txt_Status.Text = NewStatusUpdate; Contacts[MemberID].StatusUpdate = NewStatusUpdate; }, null); }
void HandleCallAcceptRequest(ClientSocket clientsocket, Packet pak) { this.Dispatcher.Invoke((MethodInvoker)delegate { int MemberID = pak.Readint(); string UDPAddress = pak.Readstring(); int Port = pak.Readint(); VCallCore.StartCall(MemberID, new IPEndPoint(IPAddress.Parse(UDPAddress), Port)); SoundManager.VoiceCallingSound.Stop(); }, null); }
/// <summary> /// Splits the buffer into all the nagled packets /// </summary> /// <param name="Buffer">Buffer to create the packets with</param> /// <returns>Nagle split packets</returns> public static Packet[] SplitPackets(byte[] Buffer) { List<Packet> Packets = new List<Packet>(); MemoryStream MemoryBuffer = new MemoryStream(); BinaryReader MemoryReader = new BinaryReader(MemoryBuffer); MemoryBuffer.Seek(0, SeekOrigin.Begin); MemoryBuffer.Write(Buffer, 0, Buffer.Length); MemoryBuffer.Position = 0; int CurrentPosition = 0; while (true) { try { if(!MemoryBuffer.CanRead) break; int PacketInnerLength = MemoryReader.ReadInt32(); if (PacketInnerLength == 0 || (MemoryBuffer.Length - MemoryBuffer.Position) < PacketInnerLength) break; MemoryBuffer.Position = CurrentPosition; byte[] PacketData = MemoryReader.ReadBytes(PacketInnerLength + 8); CurrentPosition += PacketInnerLength + 8; Packet pak = new Packet(PacketData); if(pak.IsValid()) Packets.Add(pak); } catch (Exception ex) { Console.WriteLine(ex.ToString()); break; } } MemoryReader.Close(); MemoryBuffer.Close(); MemoryReader.Dispose(); MemoryBuffer.Dispose(); return Packets.ToArray(); }
public static void HandleFriendBlockRequest(SocketConnection conn, Packet pak) { if (conn.ConnectionData.ContainsKey("Member")) { Member mem = (Member)conn.ConnectionData["Member"]; } }
public void SendPacket(Packet pak) { SendBuffer(pak.ToArray()); }
public void CSocket_ClientSocketPacketReceived_Event(object sender, ClientSocket clientSocket, Packet pak) { if (pak.IsValid()) { uint PacketHeader = pak.Readuint(); switch (PacketHeader) { case Packets.PAK_SRV_LGNRESP: this.HandleLoginResponse(clientSocket, pak); break; case Packets.PAK_SRV_FRNDLSTRESP: this.HandleFriendListResponse(clientSocket, pak); break; case Packets.PAK_SRV_MEMINFORESP: this.HandleMemberInfoResponse(clientSocket, pak); break; case Packets.PAK_SRV_MSGDLVR: this.HandleMessageDeliver(clientSocket, pak); break; case Packets.PAK_SRV_NEWSTSDLVR: this.HandleStatusChangeDeliver(clientSocket, pak); break; case Packets.PAK_SRV_NEWUPDTDLVR: this.HandleUpdateChangeDeliver(clientSocket, pak); break; case Packets.PAK_SRV_FRNDRMVDLVR: this.HandleFriendRemoveDeliver(clientSocket, pak); break; case Packets.PAK_SRV_CALL_DLVR: this.HandleCallRequest(clientSocket, pak); break; case Packets.PAK_SRV_CALL_ACC_DLVR: this.HandleCallAcceptRequest(clientSocket, pak); break; case Packets.PAK_SRV_CALL_DNY_DLVR: this.HandleCallDenyRequest(clientSocket, pak); break; default: break; } } }