Ejemplo n.º 1
0
        // Function from file: IsBanned.dm
        public static dynamic IsBanned(string key = null, dynamic address = null, string computer_id = null)
        {
            dynamic _default = null;

            bool    admin      = false;
            string  ckey       = null;
            string  ckeytext   = null;
            string  ipquery    = null;
            string  cidquery   = null;
            DBQuery query      = null;
            string  pckey      = null;
            dynamic ackey      = null;
            dynamic reason     = null;
            dynamic expiration = null;
            string  duration   = null;
            dynamic bantime    = null;
            string  bantype    = null;
            string  expires    = null;
            string  desc       = null;


            if (!Lang13.Bool(key) || !Lang13.Bool(address) || !Lang13.Bool(computer_id))
            {
                GlobalFuncs.log_access("Failed Login (invalid data): " + key + " " + address + "-" + computer_id);
                return(new ByTable()
                       .Set("reason", "invalid login data")
                       .Set("desc", "Error: Could not check ban status, Please try again. Error message: Your computer provided invalid or blank information to the server on connection (byond username, IP, and Computer ID.) Provided information for reference: Username:'******' IP:'" + address + "' Computer ID:'" + computer_id + "'. (If you continue to get this error, please restart byond or contact byond support.)")
                       );
            }

            if (String13.ParseNumber(computer_id) == 2147483648)
            {
                GlobalFuncs.log_access("Failed Login (invalid cid): " + key + " " + address + "-" + computer_id);
                return(new ByTable().Set("reason", "invalid login data").Set("desc", "Error: Could not check ban status, Please try again. Error message: Your computer provided an invalid Computer ID.)"));
            }
            admin = false;
            ckey  = String13.CKey(key);

            if (GlobalVars.admin_datums.Contains(ckey) || GlobalVars.deadmins.Contains(ckey))
            {
                admin = true;
            }

            if (GlobalFuncs.IsGuestKey(key))
            {
                if (!GlobalVars.guests_allowed)
                {
                    GlobalFuncs.log_access("Failed Login: "******" - Guests not allowed");
                    return(new ByTable().Set("reason", "guest").Set("desc", "\nReason: Guests not allowed. Please sign in with a byond account."));
                }

                if (GlobalVars.config.panic_bunker && GlobalVars.dbcon != null && GlobalVars.dbcon.IsConnected())
                {
                    GlobalFuncs.log_access("Failed Login: "******" - Guests not allowed during panic bunker");
                    return(new ByTable()
                           .Set("reason", "guest")
                           .Set("desc", "\nReason: Sorry but the server is currently not accepting connections from never before seen players or guests. If you have played on this server with a byond account before, please log in to the byond account you have played from.")
                           );
                }
            }

            if (Lang13.Bool(GlobalVars.config.extreme_popcap) && GlobalFuncs.living_player_count() >= (GlobalVars.config.extreme_popcap ?? 0) && !admin)
            {
                GlobalFuncs.log_access("Failed Login: "******" - Population cap reached");
                return(new ByTable().Set("reason", "popcap").Set("desc", "\nReason: " + GlobalVars.config.extreme_popcap_message));
            }

            if (GlobalVars.config.ban_legacy_system)
            {
                _default = GlobalFuncs.CheckBan(String13.CKey(key), computer_id, address);

                if (Lang13.Bool(_default))
                {
                    if (admin)
                    {
                        GlobalFuncs.log_admin("The admin " + key + " has been allowed to bypass a matching ban on " + _default["key"]);
                        GlobalFuncs.message_admins("<span class='adminnotice'>The admin " + key + " has been allowed to bypass a matching ban on " + _default["key"] + "</span>");
                        GlobalFuncs.addclientmessage(ckey, "<span class='adminnotice'>You have been allowed to bypass a matching ban on " + _default["key"] + "</span>");
                    }
                    else
                    {
                        GlobalFuncs.log_access("Failed Login: "******" " + computer_id + " " + address + " - Banned " + _default["reason"]);
                        return(_default);
                    }
                }
            }
            else
            {
                ckeytext = String13.CKey(key);

                if (!GlobalFuncs.establish_db_connection())
                {
                    Game13.log.WriteMsg("Ban database connection failure. Key " + ckeytext + " not checked");
                    GlobalVars.diary.WriteMsg("Ban database connection failure. Key " + ckeytext + " not checked");
                    return(_default);
                }
                ipquery  = "";
                cidquery = "";

                if (Lang13.Bool(address))
                {
                    ipquery = " OR ip = '" + address + "' ";
                }

                if (Lang13.Bool(computer_id))
                {
                    cidquery = " OR computerid = '" + computer_id + "' ";
                }
                query = GlobalVars.dbcon.NewQuery("SELECT ckey, ip, computerid, a_ckey, reason, expiration_time, duration, bantime, bantype FROM " + GlobalFuncs.format_table_name("ban") + " WHERE (ckey = '" + ckeytext + "' " + ipquery + " " + cidquery + ") AND (bantype = 'PERMABAN' OR bantype = 'ADMIN_PERMABAN' OR ((bantype = 'TEMPBAN' OR bantype = 'ADMIN_TEMPBAN') AND expiration_time > Now())) AND isnull(unbanned)");
                query.Execute();

                while (query.NextRow())
                {
                    pckey      = query.item[1];
                    ackey      = query.item[4];
                    reason     = query.item[5];
                    expiration = query.item[6];
                    duration   = query.item[7];
                    bantime    = query.item[8];
                    bantype    = query.item[9];

                    if (bantype == "ADMIN_PERMABAN" || bantype == "ADMIN_TEMPBAN")
                    {
                        if (pckey != ckey)
                        {
                            continue;
                        }
                    }

                    if (admin)
                    {
                        if (bantype == "ADMIN_PERMABAN" || bantype == "ADMIN_TEMPBAN")
                        {
                            GlobalFuncs.log_admin("The admin " + key + " is admin banned, and has been disallowed access");
                            GlobalFuncs.message_admins("<span class='adminnotice'>The admin " + key + " is admin banned, and has been disallowed access</span>");
                        }
                        else
                        {
                            GlobalFuncs.log_admin("The admin " + key + " has been allowed to bypass a matching ban on " + pckey);
                            GlobalFuncs.message_admins("<span class='adminnotice'>The admin " + key + " has been allowed to bypass a matching ban on " + pckey + "</span>");
                            GlobalFuncs.addclientmessage(ckey, "<span class='adminnotice'>You have been allowed to bypass a matching ban on " + pckey + "</span>");
                            continue;
                        }
                    }
                    expires = "";

                    if ((String13.ParseNumber(duration) ?? 0) > 0)
                    {
                        expires = " The ban is for " + duration + " minutes and expires on " + expiration + " (server time).";
                    }
                    else
                    {
                        expires = " The is a permanent ban.";
                    }
                    desc     = "\nReason: You, or another user of this computer or connection (" + pckey + ") is banned from playing here. The ban reason is:\n" + reason + "\nThis ban was applied by " + ackey + " on " + bantime + ", " + expires;
                    _default = new ByTable().Set("reason", "" + bantype).Set("desc", "" + desc);
                    GlobalFuncs.log_access("Failed Login: "******" " + computer_id + " " + address + " - Banned " + _default["reason"]);
                    return(_default);
                }
            }
            _default = Game13._internal_IsBanned(key, address, computer_id);

            if (Lang13.Bool(_default))
            {
                if (admin)
                {
                    GlobalFuncs.log_admin("The admin " + key + " has been allowed to bypass a matching host/sticky ban");
                    GlobalFuncs.message_admins("<span class='adminnotice'>The admin " + key + " has been allowed to bypass a matching host/sticky ban</span>");
                    GlobalFuncs.addclientmessage(ckey, "<span class='adminnotice'>You have been allowed to bypass a matching host/sticky ban</span>");
                    return(null);
                }
                else
                {
                    GlobalFuncs.log_access("Failed Login: "******" " + computer_id + " " + address + " - Banned " + _default["message"]);
                }
            }
            return(_default);
        }