Ban from an area based on age

// Autoban from area if under a certain age in months
// Ordinal Malaprop
// 2006-06-13

list gCheckList = [];
integer gThisDay = 0;
integer gThisMonth = 0;
integer gThisYear = 0;

integer gAgeLimit = 3; // in months
// hardcode in keys to ignore, to save dataserver load
list gExcludeKeys = [];

check_name()
{
   if (gCheckList == []) return;
   llRequestAgentData(llList2Key(gCheckList, 0), DATA_BORN);
}

default
{
   state_entry()
   {
      gExcludeKeys += llGetOwner(); // don't check the owner
      llSensorRepeat("", NULL_KEY, AGENT, 96.0, PI, 60.0);
   }

   sensor(integer n)
   {
      integer f = 0;
      key id = NULL_KEY;
      // go through all detected avs
      do {
         id = llDetectedKey(f);
         // if actually over owner's land and not on exclude list...
         if (llOverMyLand(id) && llListFindList(gExcludeKeys, [id]) == -1) {
            // add them to the list of keys to check
            gCheckList += id;
         }
      } while (++f < n);
      list parsedDate = llParseString2List(llGetDate(), ["-"], []);
      gThisYear = (integer)llList2String(parsedDate, 0);
      gThisMonth = (integer)llList2String(parsedDate, 1);
      gThisDay = (integer)llList2String(parsedDate, 2);
      check_name();
   }

   dataserver(key queryid, string data)
   {
      // Check age based on month, for simplicity
      list parsedDate = llParseString2List(data, ["-"], []);
      integer year = (integer)llList2String(parsedDate, 0);
      integer month = (integer)llList2String(parsedDate, 1);
      integer day = (integer)llList2String(parsedDate, 2);
      integer ageInMonths = (gThisMonth - month) + (gThisYear - year) * 12;
      if (day > gThisDay) ageInMonths--;
      if (ageInMonths < gAgeLimit) {
         key id = llList2Key(gCheckList, 0);
         // inform owner
         llOwnerSay("Banning and ejecting " + llKey2Name(id));
         llAddToLandBanList(id, 24); // don't permanently ban them
         // boot them
         llEjectFromLand(id);
         // tell them why they have been booted
         llInstantMessage(id, "You are under the age limit of " + (string)gAgeLimit + " months and have been ejected from this parcel.");
      }
      gCheckList = llDeleteSubList(gCheckList, 0, 0);
      check_name();
   }
}