Exemplo n.º 1
0
 public bool Equals(MarsChannel other)
 {
     if (other is null)
     {
         return(false);
     }
     return(ExternalIp.ToString() == other.ExternalIP && Name == other.Name);
 }
Exemplo n.º 2
0
 public string ToPlainText()
 {
     return(string.Format("Chatroom:{0}:{1}|{2}", ExternalIp.ToString(), Port, Name));
     //future?
     //return string.Format("Chatroom:{0}:{1}|{2}", string.IsNullOrEmpty(Domain) ? ExternalIp.ToString() : Domain, Port, Name);
 }
Exemplo n.º 3
0
        /*
         * NOTICE -- Occurs before "LoggedIn" is set to true. "AresServer.SendPacket" will fail
         */
        private bool AllowedJoin(Record record)
        {
            if (this.Guid.Equals(Guid.Empty))
            {
                return(Rejected(new Announce(Errors.InvalidLogin), RejectReason.InvalidLogin));
            }

            //let onjoincheck run for host but ignore its return
            if (!server.PluginHost.OnJoinCheck(this) && !LocalHost)
            {
                return(Rejected(new Error(Errors.Rejected), RejectReason.Plugins));
            }

            // check bans
            if (!LocalHost)
            {
                if (server.History.Bans.Contains((s) => s.Equals(record)))
                {
                    return(Rejected(new Error(Errors.Banned), RejectReason.Banned));
                }

                if (server.History.RangeBans.Contains((s) => s.IsMatch(ExternalIp.ToString())))
                {
                    return(Rejected(new Error(Errors.RangeBanned), RejectReason.RangeBanned));
                }
            }

            //check name hijacking
            int count = 1;

            foreach (var user in server.Users)
            {
                if (user != this)
                {
                    if (user.Name == Name)
                    {
                        return(Rejected(new Announce(Errors.NameTaken), RejectReason.NameTaken));
                    }

                    else if (user.ExternalIp.Equals(Socket.RemoteEndPoint.Address))
                    {
                        count++;
                    }
                }

                if (count > server.Config.MaxClones)
                {
                    return(Rejected(new Error(String.Format(Errors.Clones, Socket.RemoteEndPoint.Address)), RejectReason.TooManyBots));
                }
            }
            //Disconnect ghosts after the Name hijack check
            //this prevents an infinite loop in case you open 2 tabs to the same room with the same name
            //the second join will not boot the first one, this can cause a delay in ghost detection but it's minimal
            foreach (var user in server.Users)
            {
                if (user != this && user.Guid.Equals(this.Guid))
                {
                    user.Disconnect();
                }
            }

            return(true);
        }
Exemplo n.º 4
0
 public bool Equals(MarsChannel other)
 {
     return(ExternalIp.ToString() == other.ExternalIP && Port == (ushort)other.Port);
 }
Exemplo n.º 5
0
        /*
         * NOTICE -- Occurs before "LoggedIn" is set to true. "AresServer.SendPacket" will fail
         */
        private bool AllowedJoin(IRecord record)
        {
            if (this.Guid.Equals(Guid.Empty))
            {
                socket.SendAsync(new Announce(Errors.InvalidLogin));
                server.PluginManager.OnJoinRejected(this, RejectReason.InvalidLogin);

                Disconnect();
                return(false);
            }

            //let onjoincheck run for host but ignore its return
            if (!server.PluginManager.OnJoinCheck(this) && !LocalHost)
            {
                socket.SendAsync(new Announce(Errors.Rejected));
                server.PluginManager.OnJoinRejected(this, RejectReason.Plugins);

                Disconnect();
                return(false);
            }

            // check bans
            if (!LocalHost)
            {
                if (server.History.Bans.Contains((s) => s.Equals(record)))
                {
                    socket.SendAsync(new Error(Errors.Banned));
                    server.PluginManager.OnJoinRejected(this, RejectReason.Banned);

                    Disconnect();
                    return(false);
                }

                if (server.History.RangeBans.Contains((s) => s.IsMatch(ExternalIp.ToString())))
                {
                    socket.SendAsync(new Error(Errors.RangeBanned));
                    server.PluginManager.OnJoinRejected(this, RejectReason.RangeBanned);

                    Disconnect();
                    return(false);
                }

                if (DnsEntry != null && server.History.DnsBans.Contains((s) => s.IsMatch(DnsEntry.HostName)))
                {
                    socket.SendAsync(new Error(Errors.DnsBanned));
                    server.PluginManager.OnJoinRejected(this, RejectReason.DnsBanned);

                    Disconnect();
                    return(false);
                }
            }

            //check name hijacking
            int count = 1;

            foreach (var user in server.Users)
            {
                if (user != this)
                {
                    if (user.Name == Name)
                    {
                        socket.SendAsync(new Announce(Errors.NameTaken));
                        server.PluginManager.OnJoinRejected(this, RejectReason.NameTaken);

                        Disconnect();
                        return(false);
                    }
                    else if (user.ExternalIp.Equals(socket.RemoteEndPoint.Address))
                    {
                        count++;
                    }
                }

                if (count > server.Config.MaxClones)
                {
                    socket.SendAsync(new Error(String.Format(Errors.Clones, socket.RemoteEndPoint.Address)));
                    server.PluginManager.OnJoinRejected(this, RejectReason.TooManyBots);

                    Disconnect();
                    return(false);
                }
            }

            //Disconnect ghosts after the Name hijack check
            foreach (var user in server.Users)
            {
                if (user != this && user.Guid.Equals(this.Guid))
                {
                    user.Disconnect();
                }
            }

            return(true);
        }