开发者

Code failing for 'co.uk' domains

I a开发者_Go百科m using a class to sitelocked a swf to sertand domains. it's work alright for domain names like 'mydomain.com, mydomain.eu, mydomain.org' ext,.

But when I add this to a domain like 'mydomain.co.uk' this doesn't work. And even when the domain is allowed into the swf file, the sitelock class will still block this domain. Anything I can change into this class to fix this issue?

Code below:

package
{
    import flash.display.Stage;
    import flash.net.*;
    import flash.external.ExternalInterface;

    public class SiteLock
    {
        private static var stage:Stage;

        private static var allowLocal:Boolean = false;

        private static var acceptedSites:Array = [];

        private static var deniedSites:Array = [];


        public function SiteLock():void
        {
        }

        public static function registerStage(_stage:Stage):void
        {
            SiteLock.stage = _stage;
            trace("[SiteLock] Stage registered");
        }

        public static function allowSites(sitesArray:Array):void
        {
            SiteLock.acceptedSites = sitesArray.concat();
            trace("[SiteLock] Accepted sites: " + SiteLock.acceptedSites);
        }

        public static function denySites(sitesArray:Array):void
        {
            SiteLock.deniedSites = sitesArray.concat();
            trace("[SiteLock] Denied sites: " + SiteLock.deniedSites);
        }

        public static function allowLocalPlay(permission:Boolean=true):void
        {
            SiteLock.allowLocal = permission;
        }

        public static function checkURL(destroy:Boolean=false):Boolean
        {

            var url:String = SiteLock.stage.loaderInfo.url;
            var urlStart:Number = url.indexOf("://") + 3;
            var urlEnd:Number = url.indexOf("/",urlStart);
            var domain:String = url.substring(urlStart,urlEnd);
            var LastDot:Number = domain.lastIndexOf(".") - 1;
            var domEnd:Number = domain.lastIndexOf(".",LastDot) + 1;
            domain = domain.substring(domEnd,domain.length);
            var protocol:String = url.substring(0,url.indexOf(":"));
            trace("[SiteLock] " + protocol == "file" ? "The .swf is locally hosted.":"This .swf is hosted at " + domain);



            if (SiteLock.acceptedSites.length != 0 && SiteLock.acceptedSites.indexOf(domain) == -1 && protocol != "file" || protocol == "file" && ! SiteLock.allowLocal || SiteLock.deniedSites.length != 0 && SiteLock.deniedSites.indexOf(domain) != -1 && protocol != "file")
            {
                trace("[SiteLock] This .swf is hosted illegally");
                Redirect();
            //}
                if (destroy)
                {
                    throw new Error("Sorry, I just have to present this great error now!");
                    while (SiteLock.stage.numChildren > 0)
                    {
                        SiteLock.stage.removeChild(SiteLock.stage.getChildAt(0));
                    }
                    //throw error for debugger version
                    throw new Error("This game is hosted illegally. If you find this game here, please contact webmaster", 9001);
                }
                return false;
            }
            else
            {
                return true;
            }
        }

        public static function Redirect():void
        {
            var url:String = "http://google.nl";
            var urlLink:URLRequest = new URLRequest(url);
            navigateToURL(urlLink,"_top");
        }

        public static function isLocal():Boolean
        {

            var url:String = SiteLock.stage.loaderInfo.url;
            var urlStart:Number = url.indexOf("://") + 3;
            var urlEnd:Number = url.indexOf("/",urlStart);
            var domain:String = url.substring(urlStart,urlEnd);
            var LastDot:Number = domain.lastIndexOf(".") - 1;
            var domEnd:Number = domain.lastIndexOf(".",LastDot) + 1;
            domain = domain.substring(domEnd,domain.length);
            var protocol:String = url.substring(0,url.indexOf(":"));
            return protocol == "file";
        }
    }


}


I'd imagine that it's related to searching for the last '.' to find the top level domain, which will tell you the top level domain is '.uk' and not '.co.uk'

Bear in mind you can't really work out the top level domain in a reliable manner this way. Consider these domain names:

www.mydomain.com
myotherdomain.co.uk

They both have 2 dots, but one belongs to .com, and the other to .co.uk

Your best bet is to find the full domain and test if the string ends with '.com', '.co.uk', '.org' or whatever


I would start by organizing the if statement by placing parentheses to create AND sections between the OR operators

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜