Author Topic: [BL SOURCE CODE/REFERENCE] ServerLoadSaveFile_Start/Tick/End/Color Data  (Read 4306 times)

All code here is BL source code, decompiled from the various DSO's in base/. I am posting these for reference for modders, one at a time to make sure I don't expose anything too sensitive.



ServerLoadSaveFile_Start, _Tick, _End, _ProcessColorData

https://puu.sh/voLGP/62d10ad1af.txt
« Last Edit: April 18, 2017, 06:58:55 PM by Mocha »


registerInputEvent + registerOutputEvent

function registerOutputEvent(%class, %name, %parameterList, %appendClient)
{
if (%appendClient $= "")
{
%appendClient = 1;
}
$OutputEvent_Count[%class] = mFloor($OutputEvent_Count[%class]);
%i = 0;
while(%i < $OutputEvent_Count[%class])
{
if ($OutputEvent_Name[%class,%i] $= %name)
{
echo("registerOutputEvent() - Output event " @ %name @ " already registered on class " @ %class @ " - overwriting.");
$OutputEvent_Name[%class,%i] = %name;
$OutputEvent_parameterList[%class,%i] = %parameterList;
verifyOutputParameterList(%class, %i);
$OutputEvent_AppendClient[%class,%i] = mFloor(%appendClient);
return;
}
%i = %i + 1.0;
}
%i = mFloor($OutputEvent_Count[%class]);
$OutputEvent_Name[%class,%i] = %name;
$OutputEvent_parameterList[%class,%i] = %parameterList;
verifyOutputParameterList(%class, %i);
$OutputEvent_AppendClient[%class,%i] = mFloor(%appendClient);
$OutputEvent_Count[%class] = $OutputEvent_Count[%class] + 1.0;
if (strstr($OutputEvent_ClassList, %class) == -1.0)
{
if ($OutputEvent_ClassList $= "")
{
$OutputEvent_ClassList = %class;
}
else
{
$OutputEvent_ClassList = $OutputEvent_ClassList @ %class;
}
}
}

function registerInputEvent(%class, %name, %targetList, %adminOnly)
{
%adminOnly = mFloor(%adminOnly);
$InputEvent_Count[%class] = mFloor($InputEvent_Count[%class]);
%i = 0;
while(%i < $InputEvent_Count[%class])
{
if ($InputEvent_Name[%class,%i] $= %name)
{
$InputEvent_Name[%class,%i] = %name;
$InputEvent_TargetList[%class,%i] = %targetList;
$InputEvent_AdminOnly[%class,%i] = %adminOnly;
return;
}
%i = %i + 1.0;
}
%i = mFloor($InputEvent_Count[%class]);
$InputEvent_Name[%class,%i] = %name;
$InputEvent_TargetList[%class,%i] = %targetList;
$InputEvent_AdminOnly[%class,%i] = %adminOnly;
$InputEvent_Count[%class] = $InputEvent_Count[%class] + 1.0;
if (strstr($InputEvent_ClassList, %class) == -1.0)
{
if ($InputEvent_ClassList $= "")
{
$InputEvent_ClassList = %class;
}
else
{
$InputEvent_ClassList = $InputEvent_ClassList @ %class;
}
}
}



serverCmdMessageSent

function serverCmdMessageSent(%client, %text)
{
   %trimText = trim(%text);
   if (%client.lastChatText $= %trimText)
   {
      %chatDelta = (getSimTime() - %client.lastChatTime) / getTimeScale();
      if (%chatDelta < 15000.0)
      {
         %client.spamMessageCount = $SPAM_MESSAGE_THRESHOLD;
         messageClient(%client, '', '\c4Do not repeat yourself.');
      }
   }
   %client.lastChatTime = getSimTime();
   %client.lastChatText = %trimText;
   %player = %client.Player;
   if (isObject(%player))
   {
      %player.playThread(3, talk);
      %player.schedule(strlen(%text) * 50.0, playThread, 3, root);
   }
   %text = chatWhiteListFilter(%text);
   %text = StripMLControlChars(%text);
   %text = trim(%text);
   if (strlen(%text) <= 0.0)
   {
      return;
   }
   if ($Pref::Server::MaxChatLen > 0.0)
   {
      if (strlen(%text) >= $Pref::Server::MaxChatLen)
      {
         %text = getSubStr(%text, 0, $Pref::Server::MaxChatLen);
      }
   }
   %protocol = "http://";
   %protocolLen = strlen(%protocol);
   %urlStart = strpos(%text, %protocol);
   if (%urlStart == -1.0)
   {
      %protocol = "https://";
      %protocolLen = strlen(%protocol);
      %urlStart = strpos(%text, %protocol);
   }
   if (%urlStart == -1.0)
   {
      %protocol = "ftp://";
      %protocolLen = strlen(%protocol);
      %urlStart = strpos(%text, %protocol);
   }
   if (%urlStart != -1.0)
   {
      %urlEnd = strpos(%text, " ", %urlStart + 1.0);
      %skipProtocol = 0;
      if (%protocol $= "http://")
      {
         %skipProtocol = 1;
      }
      if (%urlEnd == -1.0)
      {
         %fullUrl = getSubStr(%text, %urlStart, strlen(%text) - %urlStart);
         %url = getSubStr(%text, %urlStart + %protocolLen, strlen(%text) - %urlStart - %protocolLen);
      }
      else
      {
         %fullUrl = getSubStr(%text, %urlStart, %urlEnd - %urlStart);
         %url = getSubStr(%text, %urlStart + %protocolLen, %urlEnd - %urlStart - %protocolLen);
      }
      if (strlen(%url) > 0.0)
      {
         %url = strreplace(%url, "<", "");
         %url = strreplace(%url, ">", "");
         if (%skipProtocol)
         {
            %newText = strreplace(%text, %fullUrl, "<a:" @ %url @ ">" @ %url @ "</a>\c6");
         }
         else
         {
            %newText = strreplace(%text, %fullUrl, "<a:" @ %protocol @ %url @ ">" @ %url @ "</a>\c6");
         }
         echo(%newText);
         %text = %newText;
      }
   }
   if ($Pref::Server::ETardFilter)
   {
      if (!chatFilter(%client, %text, $Pref::Server::ETardList, '\c4This is a civilized game.  Please use full words.'))
      {
         return;
      }
   }
   chatMessageAll(%client, '\c7%1\c3%2\c7%3\c6: %4', %client.clanPrefix, %client.getPlayerName(), %client.clanSuffix, %text);
   echo(%client.getSimpleName(), ": ", %text);
}


QueueSO (Fixed)
function New_QueueSO(%size)
{
if (%size <= 1.0 || %size > 10000.0)
{
error("ERROR: New_QueueSO() - invalid size \'" @ %size @ "\'");
return;
}
%ret = new ScriptObject(""){
class = QueueSO;
size = %size;
head = 0;
tail = 0;
};
MissionCleanup.add(%ret);
%i = 0;
while(%i < %size)
{
%ret.val[%i] = 0;
%i = %i + 1.0;
}
return %ret;
}

function QueueSO::push(%obj, %val)
{
%obj.val[%obj.head] = %val;
%obj.head = (%obj.size % (%obj.head + 1.0));
%obj.val[%obj.head] = 0;
if (%obj.head == %obj.tail)
{
%obj.tail = (%obj.size % (%obj.tail + 1.0));
return;
}
}

function QueueSO::pop(%obj)
{
if (%obj.head != %obj.tail)
{
%obj.head = %obj.head - 1.0;
if (%obj.head < 0.0)
{
%obj.head = %obj.size - 1.0;
}
%ret = %obj.val[%obj.head];
%obj.val[%obj.head] = 0;
return %ret;
}
else
{
return 0;
}
}

function QueueSO::dumpVals(%obj)
{
%i = 0;
while(%i < %obj.size)
{
%line = %i @ ": " @ %obj.val[%i];
if (%obj.head == %i)
{
%line = %line @ " <Head";
}
if (%obj.tail == %i)
{
%line = %line @ " <Tail";
}
echo(%line);
%i = %i + 1.0;
}
}


BanManagerSO + getCurrentYear + getCurrentMinuteOfYear + getLongNumberString



function CreateBanManager()
{
   if (isObject($BanManagerSO))
   {
      $BanManagerSO.delete();
   }
   $BanManagerSO = new ScriptObject(BanManagerSO){
   numBans = 0;
   };
   $BanManagerSO.loadBans();
}

function BanManagerSO::addBan(%this, %adminID, %victimID, %victimBL_ID, %reason, %banTime)
{
   if (%victimBL_ID == 0.0)
   {
      return;
   }
   %this.RemoveBanBL_ID(%victimBL_ID);
   if (isObject(%adminID))
   {
      %adminName = %adminID.getPlayerName();
      %adminBL_ID = %adminID.getBLID();
   }
   else
   {
      %adminName = "CONSOLE";
      %adminBL_ID = -1.0;
   }
   if (isObject(%victimID))
   {
      %victimName = %victimID.getPlayerName();
   }
   else
   {
      %brickGroup = "BrickGroup_" @ %victimBL_ID;
      if (isObject(%brickGroup))
      {
         %victimName = %brickGroup.name;
      }
   }
   if (isObject(%victimID))
   {
      %victimIP = %victimID.getRawIP();
   }
   else
   {
      %victimIP = "";
   }
   %banOverYear = 0;
   %banOverTime = 0;
   if (%banTime == -1.0)
   {
      %banOverYear = -1.0;
      %banOverTime = -1.0;
   }
   else
   {
      %currTime = getCurrentMinuteOfYear();
      %banOverYear = getCurrentYear();
      %banOverTime = %currTime + %banTime;
      if (%banOverTime > 525600.0)
      {
         %banOverYear = %banOverYear + 1.0;
         %banOverTime = %banOverTime - 525600.0;
      }
   }
   %i = %this.numBans;
   %this.adminName[%i] = %adminName;
   %this.adminBL_ID[%i] = %adminBL_ID;
   %this.victimName[%i] = %victimName;
   %this.victimBL_ID[%i] = %victimBL_ID;
   %this.victimIP[%i] = %victimIP;
   %this.Reason[%i] = %reason;
   %this.expirationYear[%i] = %banOverYear;
   %this.expirationMinute[%i] = %banOverTime;
   %this.numBans = %this.numBans + 1.0;
}

function BanManagerSO::RemoveBanBL_ID(%this, %testBL_ID)
{
   %i = 0;
   while(%i < %this.numBans)
   {
      if (%this.victimBL_ID[%i] == %testBL_ID)
      {
         %this.removeBan(%i);
         return;
      }
      %i = %i + 1.0;
   }
}

function BanManagerSO::removeBan(%this, %idx)
{
   if (%this.numBans <= %idx)
   {
      error("ERROR: BanManagerSO::RemoveBan() - ban index " @ %idx @ " does not exist. (there are only " @ %this.numBans @ " bans)");
      return;
   }
   %i = %idx + 1.0;
   while(%i < %this.numBans)
   {
      %this.adminName[%i - 1.0] = %this.adminName[%i];
      %this.adminBL_ID[%i - 1.0] = %this.adminBL_ID[%i];
      %this.victimName[%i - 1.0] = %this.victimName[%i];
      %this.victimBL_ID[%i - 1.0] = %this.victimBL_ID[%i];
      %this.victimIP[%i - 1.0] = %this.victimIP[%i];
      %this.Reason[%i - 1.0] = %this.Reason[%i];
      %this.expirationYear[%i - 1.0] = %this.expirationYear[%i];
      %this.expirationMinute[%i - 1.0] = %this.expirationMinute[%i];
      %i = %i + 1.0;
   }
   %i = %this.numBans;
   %this.adminName[%i] = "";
   %this.adminBL_ID[%i] = "";
   %this.victimName[%i] = "";
   %this.victimBL_ID[%i] = "";
   %this.victimIP[%i] = "";
   %this.Reason[%i] = "";
   %this.expirationYear[%i] = "";
   %this.expirationMinute[%i] = "";
   %this.numBans = %this.numBans - 1.0;
}

function BanManagerSO::saveBans(%this)
{
   %file = new FileObject(""){
   };
   %file.openForWrite("config/server/BANLIST.txt");
   %i = 0;
   while(%i < %this.numBans)
   {
      %doLine = 1;
      if (%this.expirationMinute > 0.0)
      {
         %timeLeft = %this.expirationMinute[%i] - getCurrentMinuteOfYear();
         %timeLeft = %timeLeft + (%this.expirationYear[%i] - getCurrentYear()) * 525600.0;
         if (%timeLeft <= 0.0)
         {
            %doLine = 0;
         }
      }
      if (%doLine)
      {
         %line = %this.adminName[%i];
         %line = %line TAB %this.adminBL_ID[%i];
         %line = %line TAB %this.victimName[%i];
         %line = %line TAB %this.victimBL_ID[%i];
         %line = %line TAB %this.victimIP[%i];
         %line = %line TAB %this.Reason[%i];
         %line = %line TAB %this.expirationYear[%i];
         %line = %line TAB %this.expirationMinute[%i];
         %file.writeLine(%line);
      }
      %i = %i + 1.0;
   }
   %file.close();
   %file.delete();
}

function BanManagerSO::loadBans(%this)
{
   %this.numBans = 0;
   %file = new FileObject(""){
   };
   %file.openForRead("config/server/BANLIST.txt");
   while(!%file.isEOF())
   {
      %line = %file.readLine();
      %i = %this.numBans;
      %this.adminName[%i] = getField(%line, 0);
      %this.adminBL_ID[%i] = getField(%line, 1);
      %this.victimName[%i] = getField(%line, 2);
      %this.victimBL_ID[%i] = getField(%line, 3);
      %this.victimIP[%i] = getField(%line, 4);
      %this.Reason[%i] = getField(%line, 5);
      %this.expirationYear[%i] = getField(%line, 6);
      %this.expirationMinute[%i] = getField(%line, 7);
      %this.numBans = %this.numBans + 1.0;
   }
   %file.close();
   %file.delete();
}

function BanManagerSO::dumpBans(%this)
{
   echo(%this.numBans @ " Bans:");
   echo("-----------------------------------------------------------------");
   %i = 0;
   while(%i < %this.numBans)
   {
      %line = %this.adminName[%i];
      %line = %line TAB %this.adminBL_ID[%i];
      %line = %line TAB %this.victimName[%i];
      %line = %line TAB %this.victimBL_ID[%i];
      %line = %line TAB %this.victimIP[%i];
      %line = %line TAB %this.Reason[%i];
      %line = %line TAB %this.expirationYear[%i];
      %line = %line TAB %this.expirationMinute[%i];
      echo(%line);
      %i = %i + 1.0;
   }
   echo("-----------------------------------------------------------------");
}

function BanManagerSO::sendBanList(%this, %client)
{
   %i = 0;
   while(%i < %this.numBans)
   {
      %line = %this.adminName[%i];
      %line = %line TAB %this.victimName[%i];
      %line = %line TAB %this.victimBL_ID[%i];
      %line = %line TAB %this.victimIP[%i];
      %line = %line TAB %this.Reason[%i];
      if (%this.expirationMinute[%i] == -1.0)
      {
         %line = %line TAB -1.0;
         commandToClient(%client, 'AddUnBanLine', %line, %i);
      }
      else
      {
         %timeLeft = %this.expirationMinute[%i] - getCurrentMinuteOfYear();
         %timeLeft = %timeLeft + (%this.expirationYear[%i] - getCurrentYear()) * 525600.0;
         %line = %line TAB %timeLeft;
         if (%timeLeft > 0.0)
         {
            commandToClient(%client, 'AddUnBanLine', %line, %i);
         }
      }
      %i = %i + 1.0;
   }
}

function BanManagerSO::isBanned(%this, %testBL_ID)
{
   if (%testBL_ID == 0.0)
   {
      return;
   }
   %i = 0;
   while(%i < %this.numBans)
   {
      if (%this.victimBL_ID[%i] == %testBL_ID)
      {
         if (%this.expirationYear[%i] == -1.0)
         {
            return 1 TAB %this.Reason[%i];
         }
         else
         {
            if (%this.expirationYear[%i] < getCurrentYear())
            {
               echo("BanManagerSO::isBanned() - ban expired last year, removing");
               %this.removeBan(%i);
               %i = %i - 1.0;
            }
            else
            {
               if (%this.expirationYear[%i] == getCurrentYear())
               {
                  if (%this.expirationMinute[%i] < getCurrentMinuteOfYear())
                  {
                     echo("BanManagerSO::isBanned() - ban expired, removing");
                     %this.removeBan(%i);
                     %i = %i - 1.0;
                  }
                  else
                  {
                     return 1 TAB %this.Reason[%i];
                  }
               }
               else
               {
                  return 1 TAB %this.Reason[%i];
               }
            }
         }
      }
      %i = %i + 1.0;
   }
   return 0;
}

function getCurrentYear()
{
   return mFloor(getSubStr(getDateTime(), 6, 2));
}

function getCurrentMinuteOfYear()
{
   %time = getDateTime();
   %month = mFloor(getSubStr(%time, 0, 2));
   %day = mFloor(getSubStr(%time, 3, 2));
   %year = mFloor(getSubStr(%time, 6, 2));
   %hour = mFloor(getSubStr(%time, 9, 2));
   %minute = mFloor(getSubStr(%time, 12, 2));
   %dayOfYear = getDayOfYear(%month, %day);
   %currTime = %minute;
   %currTime = %currTime + %hour * 60.0;
   %currTime = %currTime + %dayOfYear * 60.0 * 24.0;
   return %currTime;
}

function getLongNumberString(%val)
{
   %val = 1000003;
   echo("  val = ", (10 % %val));
   %ret = "";
   %i = 0;
   while(%i < 100.0)
   {
      %ret = (10 % %val) @ %ret;
      %val = mFloor(%val / 10.0);
      if (%val <= 0.0)
      {
      }
      else
      {
         %i = %i + 1.0;
      }
   }
   return %ret;
}
« Last Edit: April 18, 2017, 06:42:32 PM by Mocha »

What is the point of this topic?

The code doesn't even make any sense.

>Using an array instead of circular linked list for a queue

Why, you're just limiting yourself :(

>Using an array instead of circular linked list for a queue

Why, you're just limiting yourself :(
this is merely blockland source code

this is merely blockland source code

It's not though. All the array variables are messed up:


function New_QueueSO(%size)
{
   if (%size <= 1.0 || %size > 10000.0)
   {
      error("ERROR: New_QueueSO() - invalid size '" @ %size @ "'");
      return;
   }
   %ret = new ScriptObject()
   {
      size = %size;
      head = 0;
      tail = 0;
   };
   MissionCleanup.add(%ret);
   %i = 0;
   while(%i < %size)
   {
      %ret.val = %i;
      %i = %i + 1.0;
   }
   return %ret;
}

function QueueSO::push(%obj, %val)
{
   %obj.val = %obj.head;
   %obj.head = %obj.size % %obj.head + 1.0;
   %obj.val = %obj.head;
   if (%obj.head == %obj.tail)
   {
      %obj.tail = %obj.size % %obj.tail + 1.0;
   }
   return 0;
}

function QueueSO::pop(%obj)
{
   return (%obj.head != %obj.tail) ? %obj.head : 0;
}

function QueueSO::dumpVals(%obj)
{
   %i = 0;
   while(%i < %obj.size)
   {
      %line = %i @ %obj.val;
      if (%obj.head == %i)
      {
         %line = %line @ " <Head";
      }
      if (%obj.tail == %i)
      {
         %line = %line @ " <Tail";
      }
      echo(%line);
      %i = %i + 1.0;
   }
   return %i @ ": ";
}


I will update with the accurate source code when I get it.

I mean, cool but

What is the point of this topic?

Is it for informational purposes? Can you at least put in the original topic that it's default Blockland Source Code? (when you actually use default source code). Maybe even a little description for people who don't understand why you just posted this.

[CODE/REFERENCE] Cup



you figure out the rest

Also I wonder who's alt this is


Doubt it, could be wrong though. The code is from someone and it looks like he copied it and pasted it here.