public static void FakeRejoinSequence(AresClient client, bool features) { if (!client.Cloaked) { LinkLeaf.LinkUser other = null; if (ServerCore.Linker.Busy) { foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves) { other = leaf.Users.Find(x => x.Vroom == client.Vroom && x.Name == client.Name && x.Link.Visible); if (other != null) { other.LinkCredentials.Visible = false; break; } } } UserPool.AUsers.ForEachWhere(x => x.SendPacket(other == null ? TCPOutbound.Join(x, client) : TCPOutbound.UpdateUserStatus(x, client)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined); UserPool.WUsers.ForEachWhere(x => x.QueuePacket(other == null ? ib0t.WebOutbound.JoinTo(x, client.Name, client.Level) : ib0t.WebOutbound.UpdateTo(x, client.Name, client.Level)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined); } client.SharedFiles.Clear(); client.LoggedIn = true; client.SendPacket(TCPOutbound.Ack(client)); if (features) { client.SendPacket(TCPOutbound.MyFeatures(client)); client.SendPacket(TCPOutbound.FavIcon()); } client.SendPacket(TCPOutbound.UserlistBot(client)); UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.Userlist(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Cloaked && !x.Quarantined); UserPool.WUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.Userlist(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Cloaked && !x.Quarantined); if (ServerCore.Linker.Busy) { foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves) { leaf.Users.ForEachWhere(x => client.SendPacket(TCPOutbound.Userlist(client, x)), x => x.Vroom == client.Vroom && x.Link.Visible); } } client.SendPacket(TCPOutbound.UserListEnd()); client.SendPacket(TCPOutbound.OpChange(client)); if (features) { client.SendPacket(TCPOutbound.SupportsVoiceClips()); client.SendPacket(TCPOutbound.Url(client, Settings.Get <String>("link", "url"), Settings.Get <String>("text", "url"))); } client.SendPacket(Avatars.Server(client)); client.SendPacket(TCPOutbound.PersonalMessageBot(client)); if (client.CustomClient) { UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.VoiceChatUserSupport(client, x)), x => (x.VoiceChatPrivate || x.VoiceChatPublic) && !x.Cloaked && !x.Quarantined); } UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.Avatar(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && x.Avatar.Length > 0 && !x.Cloaked && !x.Quarantined); UserPool.WUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.Avatar(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Cloaked && !x.Quarantined); if (ServerCore.Linker.Busy) { foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves) { leaf.Users.ForEachWhere(x => client.SendPacket(TCPOutbound.Avatar(client, x)), x => x.Vroom == client.Vroom && x.Link.Visible && x.Avatar.Length > 0); } } UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.PersonalMessage(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && x.PersonalMessage.Length > 0 && !x.Cloaked && !x.Quarantined); UserPool.WUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.PersonalMessage(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Cloaked && !x.Quarantined); if (client.IsCbot) { UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.CustomFont(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && x.Font.Enabled); } if (ServerCore.Linker.Busy) { foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves) { leaf.Users.ForEachWhere(x => client.SendPacket(TCPOutbound.PersonalMessage(client, x)), x => x.Vroom == client.Vroom && x.Link.Visible && x.PersonalMessage.Length > 0); } } if (client.Avatar.Length > 0) { if (!client.Cloaked) { UserPool.AUsers.ForEachWhere(x => x.SendPacket(TCPOutbound.Avatar(x, client)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined); UserPool.WUsers.ForEachWhere(x => x.QueuePacket(WebOutbound.AvatarTo(x, client.Name, client.Avatar)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.Extended); if (ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready) { ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafAvatar(ServerCore.Linker, client)); } } } if (!String.IsNullOrEmpty(client.PersonalMessage)) { if (!client.Cloaked) { UserPool.AUsers.ForEachWhere(x => x.SendPacket(TCPOutbound.PersonalMessage(x, client)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined); UserPool.WUsers.ForEachWhere(x => x.QueuePacket(WebOutbound.PersMsgTo(x, client.Name, client.PersonalMessage)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.Extended); if (ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready) { ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafPersonalMessage(ServerCore.Linker, client)); } } } if (client.Font.Enabled) { if (!client.Cloaked) { UserPool.AUsers.ForEachWhere(x => x.SendPacket(TCPOutbound.CustomFont(x, client)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && x.IsCbot); AresFont f = (AresFont)client.Font; UserPool.WUsers.ForEachWhere(x => x.QueuePacket(WebOutbound.FontTo(x, client.Name, f.oldN, f.oldT)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined); } } if (features) { if (client.SocketConnected) { IdleManager.Set(client); } Events.Joined(client); } }
private static void Login(AresClient client, TCPPacketReader packet, ulong time, bool relogin) { if (client.LoggedIn) { return; } client.FastPing = relogin; client.Guid = packet; client.FileCount = packet; ushort org_files = client.FileCount; byte crypto = packet; client.DataPort = packet; client.NodeIP = packet; client.NodePort = packet; packet.SkipBytes(4); client.OrgName = packet.ReadString(client); Helpers.FormatUsername(client); client.Name = client.OrgName; client.Version = packet.ReadString(client); client.Ares = client.Version.StartsWith("Ares 2.") || client.Version.StartsWith("Ares_2."); client.IsCbot = client.Version.StartsWith("cb0t "); client.CustomClient = true; // everyone can be custom client client.LocalIP = packet; packet.SkipBytes(4); client.Browsable = ((byte)packet) > 2 && Settings.Get <bool>("files"); client.CurrentUploads = packet; client.MaxUploads = packet; client.CurrentQueued = packet; client.Age = packet; client.Sex = packet; client.Country = packet; client.Region = packet.ReadString(client); if (client.Region.Length > 30) { client.Region = client.Region.Substring(0, 30); } client.FileCount = client.Browsable && client.Version.StartsWith("Ares") ? client.FileCount : (ushort)0; if (client.FileCount == 0) { client.Browsable = false; } // new proto data if (packet.Remaining > 0) { byte vc = packet; client.VoiceChatPublic = ((vc & 1) == 1); client.VoiceChatPrivate = ((vc & 2) == 2); client.VoiceOpusChatPublic = ((vc & 4) == 4); client.VoiceOpusChatPrivate = ((vc & 8) == 8); client.SupportsHTML = ((vc & 16) == 16); if (client.VoiceOpusChatPublic) { client.VoiceChatPublic = true; } if (client.VoiceOpusChatPrivate) { client.VoiceChatPrivate = true; } } // maybe add encryption in next cbot? client.Encryption.Mode = crypto == 250 ? EncryptionMode.Encrypted : EncryptionMode.Unencrypted; IPAddress p_check = new IPAddress(client.ExternalIP.GetAddressBytes()); client.OriginalIP = p_check; if (client.Version.StartsWith("cb0t")) { ObSalt.GetSalt(client); // client doesn't support file sharing, so protect their external ip from idiots! } client.Captcha = !Settings.Get <bool>("captcha"); if (!client.Captcha) { client.Captcha = CaptchaManager.HasCaptcha(client); } if (client.Encryption.Mode == EncryptionMode.Encrypted) { client.Encryption.Key = Crypto.CreateKey; client.Encryption.IV = Crypto.CreateIV; client.SendPacket(TCPOutbound.CryptoKey(client)); } // Use Original IP here // Fixes issue #30 https://github.com/AresChat/sb0t/issues/30 if ((UserPool.AUsers.FindAll(x => x.OriginalIP.Equals(client.OriginalIP)).Count + UserPool.WUsers.FindAll(x => x.OriginalIP.Equals(client.OriginalIP)).Count) > 5) { Events.Rejected(client, RejectedMsg.TooManyClients); throw new Exception("too many clients from this ip"); } if (UserHistory.IsJoinFlooding(client, time)) { Events.Rejected(client, RejectedMsg.TooSoon); throw new Exception("joined too quickly"); } IClient hijack = UserPool.AUsers.Find(x => (x.Name == client.Name || x.OrgName == client.OrgName) && x.ID != client.ID && x.LoggedIn); if (hijack == null) { hijack = UserPool.WUsers.Find(x => (x.Name == client.Name || x.OrgName == client.OrgName) && x.ID != client.ID && x.LoggedIn); } if (hijack != null) { if (hijack.OriginalIP.Equals(client.OriginalIP)) // Possible issue with using masked ip lets use orginal instead { if (!hijack.WebClient) { ((AresClient)hijack).Disconnect(true); } else { ((ib0t.ib0tClient)hijack).Disconnect(); } client.Name = client.OrgName; client.FastPing = true; } else { Events.Rejected(client, RejectedMsg.NameInUse); throw new Exception("name in use"); } } UserHistory.AddUser(client, time); if (BanSystem.IsBanned(client)) { if (!Helpers.IsLocalHost(client)) { if (hijack != null && hijack is AresClient) { ((AresClient)hijack).SendDepart(); } Events.Rejected(client, RejectedMsg.Banned); throw new Exception("banned user"); } } if (client.LocalIP.ToString() == "6.6.6.6" || client.LocalIP.ToString() == "7.8.7.8" || org_files == 6969) { if (hijack != null && hijack is AresClient) { ((AresClient)hijack).SendDepart(); } Events.Rejected(client, RejectedMsg.Banned); throw new Exception("spam bot"); } if (Settings.Get <bool>("age_restrict")) { if (client.Age > 0) { if ((byte)Settings.Get <int>("age_restrict_value") > client.Age) { if (hijack != null && hijack is AresClient) { ((AresClient)hijack).SendDepart(); } Events.Rejected(client, RejectedMsg.UnderAge); throw new Exception("under aged user"); } } } if (Helpers.IsUnacceptableGender(client)) { if (hijack != null && hijack is AresClient) { ((AresClient)hijack).SendDepart(); } Events.Rejected(client, RejectedMsg.UnacceptableGender); throw new Exception("unacceptable gender"); } if (Proxies.Check(p_check, client.DNS)) { if (!Helpers.IsLocalHost(client)) { if (Events.ProxyDetected(client)) { if (hijack != null && hijack is AresClient) { ((AresClient)hijack).SendDepart(); } Events.Rejected(client, RejectedMsg.Proxy); throw new Exception("proxy detected"); } } } client.Quarantined = !client.Captcha && Settings.Get <int>("captcha_mode") == 1; if (!Events.Joining(client)) { if (!Helpers.IsLocalHost(client)) { if (hijack != null && hijack is AresClient) { ((AresClient)hijack).SendDepart(); } Events.Rejected(client, RejectedMsg.UserDefined); throw new Exception("user defined rejection"); } } IgnoreManager.LoadIgnores(client); if (Helpers.IsLocalHost(client)) { client.Captcha = true; client.Quarantined = false; client.Registered = true; client.Owner = true; } if (hijack != null) { if (hijack.Cloaked) { hijack = null; } } if (!client.Quarantined) { if (hijack == null || !(hijack is AresClient)) { LinkLeaf.LinkUser other = null; if (ServerCore.Linker.Busy) { foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves) { other = leaf.Users.Find(x => x.Vroom == client.Vroom && x.Name == client.Name && x.Link.Visible); if (other != null) { other.LinkCredentials.Visible = false; break; } } } UserPool.AUsers.ForEachWhere(x => x.SendPacket(other == null ? TCPOutbound.Join(x, client) : TCPOutbound.UpdateUserStatus(x, client)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined); UserPool.WUsers.ForEachWhere(x => x.QueuePacket(other == null ? ib0t.WebOutbound.JoinTo(x, client.Name, client.Level) : ib0t.WebOutbound.UpdateTo(x, client.Name, client.Level)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined); } client.LoggedIn = true; client.SendPacket(TCPOutbound.Ack(client)); client.SendPacket(TCPOutbound.MyFeatures(client)); client.SendPacket(TCPOutbound.FavIcon()); client.SendPacket(TCPOutbound.TopicFirst(client, Settings.Topic)); client.SendPacket(TCPOutbound.UserlistBot(client)); UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.Userlist(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && !x.Cloaked); UserPool.WUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.Userlist(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && !x.Cloaked); if (ServerCore.Linker.Busy) { foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves) { leaf.Users.ForEachWhere(x => client.SendPacket(TCPOutbound.Userlist(client, x)), x => x.Vroom == client.Vroom && x.Link.Visible && !x.Cloaked); } } client.SendPacket(TCPOutbound.UserListEnd()); client.SendPacket(TCPOutbound.OpChange(client)); client.SendPacket(TCPOutbound.SupportsVoiceClips()); client.SendPacket(TCPOutbound.Url(client, Settings.Get <String>("link", "url"), Settings.Get <String>("text", "url"))); client.SendPacket(TCPOutbound.PersonalMessageBot(client)); client.SendPacket(Avatars.Server(client)); if (client.CustomClient) { UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.VoiceChatUserSupport(client, x)), x => (x.VoiceChatPrivate || x.VoiceChatPublic) && !x.Quarantined && !x.Cloaked); } UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.Avatar(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && x.Avatar.Length > 0 && !x.Quarantined && !x.Cloaked); UserPool.WUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.Avatar(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && !x.Cloaked); if (ServerCore.Linker.Busy) { foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves) { leaf.Users.ForEachWhere(x => client.SendPacket(TCPOutbound.Avatar(client, x)), x => x.Vroom == client.Vroom && x.Link.Visible && x.Avatar.Length > 0 && !x.Cloaked); } } UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.PersonalMessage(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && x.PersonalMessage.Length > 0 && !x.Quarantined && !x.Cloaked); UserPool.WUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.PersonalMessage(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && !x.Quarantined && !x.Cloaked); if (ServerCore.Linker.Busy) { foreach (LinkLeaf.Leaf leaf in ServerCore.Linker.Leaves) { leaf.Users.ForEachWhere(x => client.SendPacket(TCPOutbound.PersonalMessage(client, x)), x => x.Vroom == client.Vroom && x.Link.Visible && x.PersonalMessage.Length > 0 && !x.Cloaked); } } FloodControl.Remove(client); if (client.SocketConnected) { IdleManager.Set(client); } if (ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready) { ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafJoin(ServerCore.Linker, client)); } Events.Joined(client); if (client.Owner) { client.Level = ILevel.Host; } if (client.IsCbot) { UserPool.AUsers.ForEachWhere(x => client.SendPacket(TCPOutbound.CustomFont(client, x)), x => x.LoggedIn && x.Vroom == client.Vroom && x.Font.Enabled && !x.Cloaked); } } else { if (hijack != null && hijack is AresClient) { ((AresClient)hijack).SendDepart(); } client.LoggedIn = true; client.SendPacket(TCPOutbound.Ack(client)); client.SendPacket(TCPOutbound.MyFeatures(client)); client.SendPacket(TCPOutbound.FavIcon()); client.SendPacket(TCPOutbound.TopicFirst(client, Settings.Topic)); client.SendPacket(TCPOutbound.UserlistBot(client)); client.SendPacket(TCPOutbound.UserListEnd()); client.SendPacket(TCPOutbound.PersonalMessageBot(client)); client.SendPacket(Avatars.Server(client)); CaptchaItem cap = Captcha.Create(); client.CaptchaWord = cap.Word; Events.CaptchaSending(client); client.SendPacket(TCPOutbound.NoSuch(client, String.Empty)); foreach (String str in cap.Lines) { client.SendPacket(TCPOutbound.NoSuch(client, str)); } client.SendPacket(TCPOutbound.NoSuch(client, String.Empty)); FloodControl.Remove(client); } }