list order_buttons (list buttons) 
{
    return llList2List (buttons, -3, -1) + llList2List (buttons, -6, -4) +
        llList2List (buttons, -9, -7) + llList2List (buttons, -12, -10);
}
 
integer g_menu_idx;

DialogPlus (key avatar, string message, list buttons, integer channel, integer CurMenu) 
{
    if (12 < llGetListLength (buttons)) 
    {
        list lbut = buttons;
        list Nbuttons = [];
        if (CurMenu == -1) 
        {
            CurMenu = 0;
            g_menu_idx = 0;
        }
        if ((Nbuttons = (llList2List (buttons, (CurMenu * 10), ((CurMenu * 10) + 9)) + ["Back", "Next"])) == ["Back", "Next"]) 
        {
            DialogPlus (avatar, message, lbut, channel,  0);
        } 
        else 
        {
            llDialog (avatar, message,  order_buttons (Nbuttons), channel);
        }
    } 
    else 
    {
        llDialog (avatar, message,  order_buttons (buttons), channel);
    }
}

integer gIntListenHandle;
integer gIntListenHandle2;
integer gIntListenHandle3;
integer gIntListenHandle7;
integer gIntListenHandle8;
integer gIntListenHandle9;
integer gIntListenHandle10;
integer gIntListenHandle12;
integer gIntListenHandle15;
integer gIntListenHandle16;
integer gIntListenHandle17;
integer gIntListenHandle18;
integer gIntListenHandle19;
integer gIntListenHandle20;
integer gIntListenHandle21;
integer gIntMinAge;
integer gIntMinHeight;
integer gIntMaxHeight;
integer gIntMaxScriptNum;
integer gIntMaxScriptMem;
integer gIntOkFly = 1;
integer gIntScanTime;
integer gIntSwitch;
integer gIntRegionAgentCount;
integer menuindex = 0;
float agelimit=60;
string surl;
string squeryBorn;
list gLstConfig;
list gLstPeopleHere;
list gLstGridBanList;
list gLstBanListIP;
list gLstBanListKeys;
list gLstBanListName;
list gLstWhiteList;
list gLstLogList;
list buttons = ["On", "Off", "Reset", "Ban by", "Setup"];
list buttons2 = ["Radar", "Name", "Key", "IP Address", "Grid"];
list buttons3 = ["Max Scripts", "Min Height", "Min Age", "Max Height", "Send To", "Script Mem", "Scan Time"];
list gLstButtons;
string gStrSendTo ;

vector LandingPoint = <128,128,50>;
vector LookAt = <0,1,0>;
key gKyOid;
key kDetect;
key kyThisAgent;
string url;
list lhttp_request;

string fnStringTrim(string src)
{
    string myTrimmedText = llDumpList2String(llParseString2List(src, [" "], []), " ");
    return myTrimmedText;
}

fnExileAgent(key kyThisAgent)
{
    llAddToLandBanList(kyThisAgent,0);
    llTeleportAgentHome(kyThisAgent);
    osTeleportAgent(kyThisAgent,gStrSendTo,LandingPoint,LookAt);
    llEjectFromLand(kyThisAgent);
}

fnWriteConfig()
{
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
       // llSay(0,llDumpList2String(gLstConfig,""));
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount ++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "autoConfig")
            {
                llRemoveInventory("autoConfig");
            }
        }
        osMakeNotecard("autoConfig", gLstConfig);  
    }
}

fnWriteBanListGrid()
{
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount ++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "banlistgrid")
            {
                llRemoveInventory("banlistgrid");
            }
        }
        osMakeNotecard("banlistgrid", gLstGridBanList);   
    }
}

fnWriteBanListIP()
{
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "banlistip")
            {
                llRemoveInventory("banlistip");
            }
        }
        osMakeNotecard("banlistip", gLstBanListIP);   
    }
}

fnWriteBanListName()
{
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "banlistname")
            {
                llRemoveInventory("banlistname");
            }
        }
        osMakeNotecard("banlistname", gLstBanListName);   
    }   
}

fnWriteBanListKey()
{
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "banlistkey")
            {
                llRemoveInventory("banlistkey");
            }
        }
        osMakeNotecard("banlistkey", gLstBanListKeys);   
    }      
}

fnWriteLog()
{
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "log")
            {
                llRemoveInventory("log");
            }
        }
        osMakeNotecard("log", gLstLogList);   
    }   
}

fnPopulateConfigList()
{
    gLstConfig = [];
    if (llGetInventoryType("autoConfig") == -1)
    {
        gLstConfig = [4,140,180,25,"hg.osgrid.org:80:Lbsa Plaza",400000,5];
        osMakeNotecard("autoConfig", gLstConfig);
    }
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "autoConfig")
            {
                string notecard = "autoConfig";
                integer intNCLength;
                intNCLength=osGetNumberOfNotecardLines(notecard);
                integer q;
                for ( q=0;q<intNCLength;q++)
                {
                    gLstConfig =  gLstConfig + [osGetNotecardLine(notecard,q)];
                }
                gIntMinAge = llList2Integer(gLstConfig,0);   
                gIntMinHeight = llList2Integer(gLstConfig,1);
                gIntMaxHeight = llList2Integer(gLstConfig,2);
                gIntMaxScriptNum = llList2Integer(gLstConfig,3);
                gStrSendTo = llList2String(gLstConfig,4);                               
                gIntMaxScriptMem = llList2Integer(gLstConfig,5);
                gIntScanTime = llList2Integer(gLstConfig,6);  
               //llSay(0, llDumpList2String(gLstConfig,""));                      
            }
        }   
    }   
}

fnPopulateLogList()
{
    gLstLogList = [];
    if (llGetInventoryType("log") == -1)
    {
        osMakeNotecard("log", gLstLogList);
    }
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "log")
            {
                string notecard = "log";
                integer intNCLength;
                intNCLength=osGetNumberOfNotecardLines(notecard);
                integer q;
                for ( q=0;q<intNCLength;q++)
                {
                    gLstLogList =  gLstLogList + [osGetNotecardLine(notecard,q)];
                }           
            }
        }   
    }   
}

fnPopulateBanListGrid()
{
    gLstGridBanList = [];
    if (llGetInventoryType("banlistgrid") == -1)
    {
        osMakeNotecard("banlistgrid", gLstGridBanList);
    }
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "banlistgrid")
            {
                string notecard = "banlistgrid";
                integer intNCLength;
                intNCLength=osGetNumberOfNotecardLines(notecard);
                integer q;
                for ( q=0;q<intNCLength;q++)
                {
                    string strThisGrid = osGetNotecardLine(notecard,q);
                    strThisGrid = fnStringTrim(strThisGrid);
                    if ((strThisGrid == "") || (strThisGrid == " "))
                    {}
                    else
                    {
                        gLstGridBanList =  gLstGridBanList + [osGetNotecardLine(notecard,q)];
                    }
                }           
            }
        }   
    }
}

fnPopulateBanListIP()
{
    if (llGetInventoryType("banlistip") == -1)
    {
        osMakeNotecard("banlistip", gLstBanListIP);
    }
    gLstBanListIP = [];
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "banlistip")
            {
                string notecard = "banlistip";
                integer intNCLength;
                intNCLength=osGetNumberOfNotecardLines(notecard);
                integer q;
                for ( q=0;q<intNCLength;q++)
                {
                    string strThisIP = osGetNotecardLine(notecard,q);
                    strThisIP = fnStringTrim(strThisIP);
                    if ((strThisIP == "") || (strThisIP == " "))
                    {}
                    else
                    {
                        gLstBanListIP =  gLstBanListIP + [osGetNotecardLine(notecard,q)];
                    }
                }           
            }
        }   
    }
}

fnPopulateBanListKeys()
{
    if (llGetInventoryType("banlistkeys") == -1)
    {
        osMakeNotecard("banlistkeys", gLstBanListKeys);
    }
    gLstBanListKeys = [];
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "banlistkeys")
            {
                string notecard = "banlistkeys";
                integer intNCLength;
                intNCLength=osGetNumberOfNotecardLines(notecard);
                integer q;
                for ( q=0;q<intNCLength;q++)
                {
                    string strThisKey = osGetNotecardLine(notecard,q);
                    strThisKey = fnStringTrim(strThisKey);
                    if ((strThisKey == "") || (strThisKey == " "))
                    {}
                    else
                    {
                        gLstBanListKeys =  gLstBanListKeys + [osGetNotecardLine(notecard,q)];
                    }
                }           
            }
        }   
    }
}

fnPopulateBanListName()
{
    if (llGetInventoryType("banlistname") == -1)
    {
        osMakeNotecard("banlistname", gLstBanListName);
    }
    gLstBanListName = [];
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "banlistname")
            {
                string notecard = "banlistname";
                integer intNCLength;
                intNCLength=osGetNumberOfNotecardLines(notecard);
                integer q;
                for ( q=0;q<intNCLength;q++)
                {
                    string strThisName = osGetNotecardLine(notecard,q);
                    strThisName = fnStringTrim(strThisName);
                    if ((strThisName == "") || (strThisName == " "))
                    {}
                    else
                    {
                        gLstBanListName =  gLstBanListName + [osGetNotecardLine(notecard,q)];
                    }
                }           
            }
        }   
    }
}

fnPopulateWhiteList()
{
    if (llGetInventoryType("whitelist") == -1)
    {
        osMakeNotecard("whitelist", gLstWhiteList);
    }
    gLstWhiteList = [];
    integer intInvNum = llGetInventoryNumber(INVENTORY_NOTECARD);
    if (intInvNum != 0)
    {
        integer intCount;
        for (intCount = 0; intCount < intInvNum;intCount++)
        {
            if (llGetInventoryName(INVENTORY_NOTECARD, intCount) == "whitelist")
            {
                string notecard = "whitelist";
                integer intNCLength;
                intNCLength=osGetNumberOfNotecardLines(notecard);
                integer q;
                for ( q=0;q<intNCLength;q++)
                {
                    string strThisName = osGetNotecardLine(notecard,q);
                    strThisName = fnStringTrim(strThisName);
                    if ((strThisName == "") || (strThisName == " "))
                    {}
                    else
                    {
                        gLstWhiteList =  gLstWhiteList + [osGetNotecardLine(notecard,q)];
                    }
                }           
            }
        }   
    }
}


fnPeople()
{
    gLstPeopleHere = osGetAvatarList();
    integer q;
    for ( q=2;q<(llGetListLength(gLstPeopleHere));q=q+3)
    {
        kyThisAgent = llList2Key(gLstPeopleHere,q-2);
        string strThisAgent = llList2String(gLstPeopleHere,q);
        integer intF = llSubStringIndex(strThisAgent,".");
        if (intF != -1)
        {   //a hypergrid agent
            // Is hypergrid agent below minimum age to be here?
            llMessageLinked(LINK_THIS,10,strThisAgent,kyThisAgent);
            
            // break up their name into parts.
            integer intFNPos = llSubStringIndex(strThisAgent,".");
            string strFirstName = llGetSubString(strThisAgent,0,intFNPos -1);
            integer intATLoc = llSubStringIndex(strThisAgent,"@");
            string strLastName = llGetSubString(strThisAgent,intFNPos +1,intATLoc-2);
            integer intStrLength = llStringLength(strThisAgent);
            string strGridName = llGetSubString(strThisAgent,intATLoc +1,intStrLength);
            // we have their grid name! yay!
            // check to see if their grid name matches a name in the grid ban list!
            integer intGBLL = llGetListLength(gLstGridBanList);
            integer s;
            for ( s=0;s<intGBLL;s++)
            {
                string strGridSource = llList2String(gLstGridBanList,s);
                if (llSubStringIndex(strGridName, strGridSource) != -1)
                {
                    //They are on the ban list, get rid of them!
                    llOwnerSay((string)kyThisAgent);
                    llInstantMessage(kyThisAgent,"\n Your grid is banned from my region.");
                    fnExileAgent(kyThisAgent);
                    llInstantMessage(gKyOid, strFirstName + " : " + strLastName + " : " + strGridName + " was grid banned. and matched " + strGridSource);
                    gLstLogList =  gLstLogList + strFirstName + " : " + strLastName + " : " + strGridName + " was grid banned. and matched " + strGridSource;
                    fnWriteLog();
                }
            }                                          
        }
        //Not a HyperGrid Agent
        //Are they below the minimum age?
        else
        {
            llRequestAgentData(kyThisAgent, DATA_BORN);
        }
        //**************************************************************
        //  Is there name on the ban list?
        integer intBNLL = llGetListLength(gLstBanListName);
        integer st;
        for ( st=0;st<intBNLL;st++)
        {
            string strNameSource = llList2String(gLstBanListName,st);
            strNameSource = llToLower(strNameSource);
            string strLCAgent = llToLower(strThisAgent);
            if (llSubStringIndex(strLCAgent, strNameSource) != -1)
            {
                //They are on the ban name list, get rid of them!
                llOwnerSay((string)kyThisAgent);
                llInstantMessage(kyThisAgent,"Your name is on the name ban list. " + strThisAgent);
                fnExileAgent(kyThisAgent);
                llInstantMessage(gKyOid, strThisAgent + " was name banned. and matched " + strNameSource);
                gLstLogList = gLstLogList + strThisAgent + " was name banned. and matched " + strNameSource;
                fnWriteLog();
            }
        }            
        //****************************************************************
        //  Is their key on the ban list?
        integer intBKLL = llGetListLength(gLstBanListKeys);
        integer stt;
        for ( stt=0;stt<intBKLL;stt++)
        {
            key kyBanListKey = llList2Key(gLstBanListKeys,stt);
            if (kyBanListKey == kyThisAgent)
            {
                //They are on the ban name list, get rid of them!
                llOwnerSay((string)kyThisAgent);
                llInstantMessage(kyThisAgent, " \n Your Agent Key is on the Key Ban List " + (string)kyBanListKey);
                fnExileAgent(kyThisAgent);
                llInstantMessage(gKyOid, strThisAgent + " was key banned. and matched " + (string)kyBanListKey);
                gLstLogList =  gLstLogList + strThisAgent + " was key banned. and matched " + (string)kyBanListKey;
                fnWriteLog();
            }
        }
         //****************************************************************
        //  Is their ip on the ban list?
        integer intBIPLL = llGetListLength(gLstBanListIP);
        integer sr;
        for ( sr=0;sr<intBIPLL;sr++)
        {
            kyThisAgent = llList2Key(gLstPeopleHere,q-2);
            string strBLIP = llList2String(gLstBanListIP,sr);
            string strAgentIP = osGetAgentIP(llList2Key(gLstPeopleHere,q-2));
            
            if (strBLIP == strAgentIP)
            {
                //They are on the ban ip list, get rid of them!
                llOwnerSay((string)kyThisAgent);
                llInstantMessage(kyThisAgent,"\n Your IP is on the IP ban list. " + strBLIP);
                fnExileAgent(kyThisAgent);
                llInstantMessage(gKyOid, strThisAgent + " was ip banned. and matched " + strBLIP);
                gLstLogList = gLstLogList + strThisAgent + " was ip banned. and matched " + strBLIP;
                fnWriteLog();
            }
        }
         if (osIsNpc(kyThisAgent))
         {}
         else
         {  //*******************************************************************
            //  white list for dinkies & fairies
            integer intWLL = llGetListLength(gLstWhiteList);
            integer sp;
            for ( sp=0;sp<intWLL;sp++)
            {
                string strNameSource = llList2String(gLstWhiteList,sp);
                if (llSubStringIndex(strThisAgent, strNameSource) != -1)
                {
                // They are on the whitelist for ok shorty!
                }
                //********************************************************************
                //  Is their height ok?
                else if (0 < gIntMinHeight || 0 < gIntMaxHeight) 
                {
                    vector size = llGetAgentSize(kyThisAgent);
                    if (0 < gIntMinHeight && size.z*100 < (float)gIntMinHeight)
                    {
                        llInstantMessage(gKyOid, strThisAgent + " was height banned too short at: " + (string)size.z);
                        llInstantMessage(kyThisAgent,"\n You were banned for being too short at: " + (string) size.z);
                        gLstLogList =  gLstLogList + strThisAgent + " was height banned too short at: " + (string)size.z;
                        fnWriteLog();
                        fnExileAgent(kyThisAgent);
                    }
                    if (0 < gIntMaxHeight && size.z*100 > (float)gIntMaxHeight) 
                    {
                        llInstantMessage(gKyOid, strThisAgent + " was height banned too tall at: " + (string)size.z);
                        llInstantMessage(kyThisAgent,"\n You were banned for being too tall at: " + (string)size.z);
                        gLstLogList =  gLstLogList + strThisAgent + " was height banned too tall at: " + (string)size.z;
                        fnWriteLog();
                        fnExileAgent(kyThisAgent);
                    }
                }
            }
            
            //**********************************************************************
            //  Running too many scripts? 
        
            list lstScriptData = llGetObjectDetails(kyThisAgent, [OBJECT_RUNNING_SCRIPT_COUNT, OBJECT_SCRIPT_MEMORY]);
            integer intNumScripts = llList2Integer(lstScriptData,0);
            if (0 < gIntMaxScriptNum && intNumScripts > gIntMaxScriptNum) 
            {
                llInstantMessage(gKyOid, strThisAgent + " was running " + (string)intNumScripts + " scripts and was banned.");
                gLstLogList = gLstLogList + strThisAgent + " was running " + (string)intNumScripts + " scripts and was banned.";
                llInstantMessage(kyThisAgent,"\n You have been banned for running too many scripts: " + (string)intNumScripts);
                fnWriteLog();
                fnExileAgent(kyThisAgent);
            }
            integer intScriptMem = llList2Integer(lstScriptData,1);
            if (0 < gIntMaxScriptMem && intScriptMem > gIntMaxScriptMem)
            {
                llInstantMessage(gKyOid, strThisAgent + " was using " + (string)intScriptMem + " bytes of ram and was banned.");
                gLstLogList = gLstLogList + strThisAgent + " was using " + (string)intScriptMem + " bytes of ram and was banned.";
                llInstantMessage(kyThisAgent, "\n You have been banned for using too much RAM memory: " + (string)intScriptMem);
                fnWriteLog();
                fnExileAgent(kyThisAgent);
            }
            //*************************************************************************
            //  Is Agent Flying?
            integer intFlyCheck = llGetAgentInfo(kyThisAgent);
            if ((intFlyCheck & AGENT_FLYING) && (gIntOkFly == 0)) 
            {
                llInstantMessage(gKyOid, strThisAgent + " was flying and it's not allowed and was banned.");
                gLstLogList =  gLstLogList + strThisAgent + " was flying and it's not allowed and was banned.";
                llInstantMessage(kyThisAgent, "\n You were banned for flying.");
                fnWriteLog();
                fnExileAgent(kyThisAgent);
            }            
        }            
    }   
}

integer f_daysSince(string input)
{   list l = llParseString2List(input, ["-"],[]);
    integer Y = (integer)llList2String(l,0);
    integer M = (integer)llList2String(l,1);    
    integer D = (integer)llList2String(l,2);
    if(M==1 || M==2)
    {   --Y;
        M+=12;
    }
    integer A = Y/100;
    integer B = A/4;
    integer C = 2-A-B; //(or C=0 if you're using the Julian calendar)
    float E = 365.25*(Y+4716);
    float F = 30.6001*(M+1);
    integer age = C+D+(integer)E+(integer)F-1524;
//llOwnerSay("Julian Day = "+(string)age );

    l = llParseString2List(llGetDate(), ["-"],[]);
    Y = (integer)llList2String(l,0);
    M = (integer)llList2String(l,1);    
    D = (integer)llList2String(l,2);
    if(M==1 || M==2)
    {   --Y;
        M+=12;
    }
    A = Y/100;
    B = A/4;
    C = 2-A-B; //(or C=0 if you're using the Julian calendar)
    E = 365.25*(Y+4716);
    F = 30.6001*(M+1);
    return C+D+(integer)E+(integer)F-1524-age; 
}

fnInit()
{
    gIntSwitch = 1;
    fnPopulateConfigList();
    fnPopulateBanListGrid();
    fnPopulateBanListIP();
    fnPopulateBanListKeys();
    fnPopulateBanListName();        
    fnPopulateWhiteList();
    llSetTimerEvent(gIntScanTime);
    llSetText("Overwatch Sentry Server ON",<1,0,0>,1.0);
    llSetColor (<1,0,0>,0);
    llOwnerSay("On");
    fnPopulateLogList();
    llMessageLinked(LINK_SET, 0, "on", "on");
}

default
{
    on_rez(integer p) 
    {
        llResetScript();
    }
    
    changed(integer c) 
    {
        if (CHANGED_OWNER & c) 
        {
            llResetScript();
        }  
        if (CHANGED_INVENTORY & c & gIntSwitch)
        {
            llResetScript();
        }      
    }
   
    state_entry()
    {
        gKyOid = llGetOwner();
        gStrSendTo = llGetObjectDesc();        
        fnInit();
    }
    
    touch_start(integer p)
    {
        if (llDetectedKey(0) == gKyOid)
        {
            llSetTimerEvent(120);
            gIntListenHandle = llListen(5000, "", "", "");
            DialogPlus (gKyOid, "Main Controls", buttons, 5000,0);
        }
        else
        {
            llInstantMessage(gKyOid,llKey2Name(llDetectedKey(0)) + " is messing with your security orb. ");
        }
    }
    
    dataserver(key queryid, string data) 
    {
        //check to see if agent is below minimum age.
      //  llSay(0, "You were born on: " + data);
        integer age = f_daysSince(data);
        if (age < gIntMinAge)
        {
            llInstantMessage(gKyOid, llKey2Name(kyThisAgent) + " is  " + (string)age + " days old and was banned.");
            gLstLogList = gLstLogList + llKey2Name(kyThisAgent) + " is " + (string)age + " days old and was banned.";
            llInstantMessage(kyThisAgent,"\n You have been banned.  You must be " + (string)gIntMinAge);
            fnWriteLog();
            fnExileAgent(kyThisAgent);
        }
        
    }
    
    link_message(integer sender_num, integer iage, string snme, key id)
    {
        if (id != llGetOwner())
        {
            if( iage==-999999)
            {
                llResetScript();
            }
            if(iage==0 || snme=="" || llKey2Name(id)=="" )
            {
                return;
            }
            agelimit=llSqrt(iage*iage);
            surl= llGetSubString(snme,llSubStringIndex(snme,"@")+1,-1)+"/";
            squeryBorn="<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_user_info</methodName><params><param><value><struct><member><name>userID</name><value><string>"+(string) id+"</string></value></member></struct></value></param></params></methodCall>";
            lhttp_request = lhttp_request+llHTTPRequest("http://"+surl, [HTTP_METHOD, "POST"],squeryBorn);
            lhttp_request=lhttp_request+id;
        }
    }
    
    http_response(key request_id, integer status, list metadata, string body)
    {
        string txt;
        integer age;
        integer iRequest=llListFindList(lhttp_request,[request_id]);
        if( iRequest==-1) return ; 
        kDetect=llList2Key(lhttp_request,iRequest+1);
        lhttp_request=llDeleteSubList(lhttp_request,iRequest,iRequest+1);
        if (status != 200 ) 
        { 
            llMessageLinked( 1,-333,"-1" ,NULL_KEY);
             return ;
        }
        txt =llGetSubString(body,llSubStringIndex(body,"<i4>1")+4,-1);
        txt=llGetSubString(txt,0,llSubStringIndex(txt,"</i4>")-1);
        if(llStringLength(txt)>9 ) 
        {
            age=llGetUnixTime( )- (integer)txt;
            age=age/86400;
            llSetText("Age "+ (string) (age),<1.,1.,1.>,1.0);
            if((age<gIntMinAge && age>-1) | (age > 9999))
            {
                llInstantMessage(gKyOid, llKey2Name(kyThisAgent) + " is  " + (string)age + " days old and was banned.");
                gLstLogList = gLstLogList + llKey2Name(kyThisAgent) + " is " + (string)age + " days old and was banned.";
                llInstantMessage(kyThisAgent,"\n You have been banned.  You must be " + (string)gIntMinAge);
                fnWriteLog();
                fnExileAgent(kyThisAgent);
            }
        }
        
        if(!llGetListLength(lhttp_request))
        {
             llResetScript();
        }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        if (channel == 3000)
        {
            string gNameSelected = message;
            if (gNameSelected !="" && gNameSelected != "Next" && gNameSelected != "Back")
            {
                integer q;
                for (q=2;q<llGetListLength(gLstPeopleHere);q=q+3)
                {
                    integer intGnameSelectedLen = llStringLength(gNameSelected);
                    string strTempName = llList2String(gLstPeopleHere,q);
                    string strShortTempName = llGetSubString(strTempName,0,intGnameSelectedLen-1);
                    if (gNameSelected == strShortTempName)
                    {
                        key keyName = llList2Key(gLstPeopleHere,q-2);
                        llEjectFromLand(keyName);
                        llAddToLandBanList(keyName,0);
                        gLstBanListKeys = gLstBanListKeys + [keyName];
                        gLstBanListName = gLstBanListName + [llKey2Name(keyName)];
                        gLstBanListIP = gLstBanListIP + [osGetAgentIP(keyName)];
                        fnWriteBanListKey();
                        fnWriteBanListName();
                        fnWriteBanListIP();                        
                    }
                }
            }
        }
        else if (channel == 4000)
        {
            if (message == "Name")
            {
                llTextBox(gKyOid, "Please Enter the name to ban...", 7000);
                gIntListenHandle7 = llListen( 7000, "", "", "");     
            }
            if (message == "IP Address")
            {
                llTextBox(gKyOid, "Please Enter the name to ban...", 8000);
                gIntListenHandle8 = llListen(8000,"","","");
            }
            if (message == "Key")
            {
                llTextBox(gKyOid, "Please Enter the name to ban...", 9000);
                gIntListenHandle9 = llListen(9000,"","","");          
            }
            if (message == "Grid")
            {
                llTextBox(gKyOid, "Please Enter the grid to ban...", 10000);
                gIntListenHandle10 = llListen(10000,"","","");
            }
            if (message == "Radar")
            {
                gLstPeopleHere = osGetAvatarList();
                integer i=0;
                integer q;
                for (q=2;q<(llGetListLength(gLstPeopleHere));q=q+3)
                {
                    integer intF = llSubStringIndex(llList2String(gLstPeopleHere,q),"@");
                    if (intF == -1)
                    {
                        gLstButtons = gLstButtons + [llList2String(gLstPeopleHere,q)];
                        i=i+1;
                    }
                    else
                    {
                        string strName = llGetSubString(llList2String(gLstPeopleHere,q),0,intF - 1);
                        gLstButtons = gLstButtons + [strName];
                        i=i+1;                        
                    }
                }           
                gIntListenHandle3 = llListen(3000,"","","");
                llSetTimerEvent(120);
                DialogPlus(gKyOid," \n",gLstButtons,3000,0);
            }
        }
        else if (channel == 5000)
        {
            fnPopulateBanListGrid();
            fnPopulateBanListIP();
            fnPopulateBanListKeys();
            fnPopulateBanListName();        
            if (message == "Ban by")
            {
                llSetTimerEvent(120);
                gIntListenHandle2 = llListen(4000, "", "", "");
                DialogPlus (gKyOid, "Ban by", buttons2, 4000,0);
            }
            if (message == "Setup")
            {
                llSetTimerEvent(120);
                gIntListenHandle12 = llListen(12000,"","","");
                DialogPlus (gKyOid, "Please Set Values:", buttons3,12000,0);
            }
            if (message == "Reset")
            {
                llResetScript();
            }
            
            if (message == "Off")
            {
                gIntSwitch = 0;
                llSetTimerEvent(0);
                llSetColor(<0,0,1>,0);
                llSetText("Overwatch Sentry Server OFF",<0,0,1>,1.0);
                llOwnerSay("Off");
                fnWriteLog();
                llMessageLinked(LINK_SET, 0, "off", "off");
            }
            if (message == "On")
            {
                gIntSwitch = 1;
                llSetTimerEvent(gIntScanTime);
                llSetText("Overwatch Sentry Server ON",<1,0,0>,1.0);
                llSetColor (<1,0,0>,0);
                llOwnerSay("On");
                fnInit();
                llMessageLinked(LINK_SET, 0, "on", "on");
            }
        }
        else if (channel == 7000)
        {
             gLstBanListName = gLstBanListName + [message];
             fnWriteBanListName();
        }
        else if (channel == 8000)
        {
            gLstBanListIP = gLstBanListIP + [message];
            fnWriteBanListIP();            
        }
        else if (channel == 9000)
        {
            gLstBanListKeys = gLstBanListKeys + [message];
            fnWriteBanListKey();
        }
        else if (channel == 10000)
        {
            gLstGridBanList = gLstGridBanList + [message];
            fnWriteBanListGrid();
        }
        else if (channel == 12000)
        {
            if (message == "Min Age")
            {
                llTextBox(gKyOid,"Please Enter Min Age in days. \n Current Value: "+(string)gIntMinAge,15000);
                 gIntListenHandle15 = llListen( 15000, "",gKyOid, "");    
            }
            if (message == "Min Height")
            {
                llTextBox(gKyOid,"Please Enter Min Height in CM.  Ex: 100 - 180\n Current Value: "+(string)gIntMinHeight,16000);
                 gIntListenHandle16 = llListen( 16000, "", gKyOid, "");       
            }
            if (message == "Max Height")
            {
                llTextBox(gKyOid,"Please Enter Max Height in CM.  Ex: 180-250\n Current Value: "+(string)gIntMaxHeight,17000);
                 gIntListenHandle17 = llListen( 17000 ,"",gKyOid, "");    
            }
            if (message == "Max Scripts")
            {
                llTextBox(gKyOid,"Please Enter Max Num of Scripts.\n Current Value: "+(string)gIntMaxScriptNum, 18000);
                 gIntListenHandle18 = llListen( 18000, "",gKyOid, "");    
            }
            if (message == "Send To")
            {
                llTextBox(gKyOid,"Where To Send Bandits?  ex: hg.osgrid.org:8002\n Current: "+gStrSendTo,19000);
                 gIntListenHandle19 = llListen( 19000, "",gKyOid, "");    
            }
            if (message == "Script Mem")
            {
                llTextBox(gKyOid,"How Much Memory Agent Can Use?  ex: 400000\n Current Value: "+gIntMaxScriptMem,20000);
                 gIntListenHandle20 = llListen( 20000, "", gKyOid, "");    
            }
            if (message == "Scan Time")
            {
                llTextBox(gKyOid,"How Fast Should I Scan In Seconds?  ex: 5\n Current Value: "+(string)gIntScanTime,21000);
                 gIntListenHandle21 = llListen( 21000, "", gKyOid, "");    
            }
        }
        else if (channel == 15000)
        {
            gIntMinAge = (integer)message;
            gLstConfig = llListInsertList(gLstConfig,[gIntMinAge],0);
            gLstConfig = llDeleteSubList(gLstConfig,1,1);
            fnWriteConfig();
        }
        else if (channel == 16000)
        {
            gIntMinHeight = (integer)message;
            gLstConfig = llListInsertList(gLstConfig,[gIntMinHeight],1);
            gLstConfig = llDeleteSubList(gLstConfig,2,2);
            fnWriteConfig();
        }
        else if (channel == 17000)
        {
            gIntMaxHeight = (integer)message;
            gLstConfig = llListInsertList(gLstConfig,[gIntMaxHeight],2);
            gLstConfig = llDeleteSubList(gLstConfig,3,3);
            fnWriteConfig();
        }
        else if (channel == 18000)
        {
            gIntMaxScriptNum = (integer)message;
            gLstConfig = llListInsertList(gLstConfig,[gIntMaxScriptNum],3);
            gLstConfig = llDeleteSubList(gLstConfig,4,4);
            fnWriteConfig();
        }
        else if (channel == 19000)
        {
            llSetObjectDesc(message);
            gLstConfig = llListInsertList(gLstConfig,[message],4);
            gLstConfig = llDeleteSubList(gLstConfig,5,5);
            fnWriteConfig();
        }
        else if (channel == 20000)
        {
            gIntMaxScriptMem = (integer)message;
            gLstConfig = llListInsertList(gLstConfig,[gIntMaxScriptMem],5);
            gLstConfig = llDeleteSubList(gLstConfig,6,6);
            fnWriteConfig();
        }
        else if (channel == 21000)
        {
            gIntScanTime = (integer)message;
            gLstConfig = llListInsertList(gLstConfig,[gIntScanTime],6);
            gLstConfig = llDeleteSubList(gLstConfig,7,7);
            fnWriteConfig();
        }
    } 
    
    timer()
    {
        fnPeople();
        if (gIntListenHandle)
        {
            llListenRemove(gIntListenHandle);
        }
        if (gIntListenHandle2)
        {
            llListenRemove(gIntListenHandle2);
        }
        if (gIntListenHandle3)
        {
            llListenRemove(gIntListenHandle3);
        }
        if (gIntListenHandle7)
        {
            llListenRemove(gIntListenHandle7);
        }
        if (gIntListenHandle8)
        {
            llListenRemove(gIntListenHandle8);
        }
        if (gIntListenHandle9)
        {
            llListenRemove(gIntListenHandle9);
        }
        if (gIntListenHandle10)
        {
            llListenRemove(gIntListenHandle10);
        }
        if (gIntListenHandle12)
        {
            llListenRemove(gIntListenHandle12);
        }
        if (gIntListenHandle15)
        {
            llListenRemove(gIntListenHandle15);
        }
        if (gIntListenHandle16)
        {
            llListenRemove(gIntListenHandle16);
        }
        if (gIntListenHandle17)
        {
            llListenRemove(gIntListenHandle17);
        }
        if (gIntListenHandle18)
        {
            llListenRemove(gIntListenHandle18);
        }
        if (gIntListenHandle19)
        {
            llListenRemove(gIntListenHandle19);
        }
        if (gIntListenHandle20)
        {
            llListenRemove(gIntListenHandle20);
        }
        if (gIntListenHandle21)
        {
            llListenRemove(gIntListenHandle21);
        }
    }
}