ZLib -- Zarqon's useful function library

I am looking into replacing my kmail parser based off of the old registry.ash with your new one in zlib.
First I need to know if it works with messages received by players without IDs? (Like the guy in the new lab quest, and the crimbo guy)
I cannot test it at the moment, can you confirm?
 
I had a kmail from "The Council of Loathing" on my mall multi (with my new Evilometer), and the fromid for that message was 0.
 
I can't confirm at the moment, but I'm fairly certain that would probably give us another possible value for the "type" field -- possibly something like "npc" or something. So far, the only values I have observed for that field are "normal" and "giftshop".

If anyone watching this thread has an NPC message sitting in your kmail, pop this URL in your relay browser and tell us if the NPC's kmail shows up, and if so what type is it:

Code:
http://127.0.0.1:60080/api.php?what=kmail&format=php&count=100&for=registryscript
 
This is the entry for the "The Council of Loathing" kmail:
Code:
1 => array ( 'id' => '105333582', 'type' => 'normal', 'fromid' => '0', 'azunixtime' => '1304191525', 'message' => 'Dear slyz_shopkeep:

Our records indicate that you\'re in the middle of investigating the Cyrpt for us. We thought this might come in handy:
Evilometer	You acquire an item: Evilometer [use]
', 'fromname' => 'The Council of Loathing', 'localtime' => '04/30/11 02:25:25 PM', )
I guess a fromid of 0 is the only way to know a kmail is from an NPC.
 
Indeed. Constant updates can become a teeny bit annoying, true. But nothing compares to getting stuck when you "know" you have the current version, because your version numbers match -- and yet something isn't working as it should. Then, it turns out that the problem was a non-updated version number. Argh!

Also, one of the original goals of my comparison function was to allow users to set their own notification threshold. But that relies on either a stricter standardization of version schemes or someone to come up with a clever idea that has thus far eluded me.

We could lobby for a standard version numbering scheme and version checking code to support it ;-) I'm partial to x.y.x where x, y and z are all strings of digits and leading zeros are ignored unless the only digit is a zero. Version a.b.c is newer than x.y.z if one of the following is true
  • a > x
  • a == x && b > y
  • a == x && b == y and c > z

In slightly more sophisticated updating systems, the user is always told a newer version is available. The first and last cases have to have some consent or trigger from the user to update and the second case automatically updates.

Changing the first digit usually means "this is so big it might break things (or we are justified in making you pay again to get the new features) so you need to make a careful and deliberate decision to upgrade. Changing the second means things are different, better and we want all of out users using the latest. Changing the third is for trivial or specialized changes that are generally not of use to the entire user community at this time.

BTW, I am not advocating that we actually do all of this. I build systems, write code and manage development teams for a living and it is just a habit of mine to encourage good practices when I can.
 
All of those fancy version numbering systems usually come with a convenient "don't bother me until the next version" button/box/whatever. Since zarqon decided he doesn't want people to not update, the rest of the system has to change.

For a while, the frequent zlib updates kept me from using any zlib-using scripts. I've gotten past that, but I still feel like I need to figure out how to update it from the command line (a bit more difficult since I believe downloading anything here requires logging in, which would mean learning a bunch of new stuff probably).
 
First I need to know if it works with messages received by players without IDs? (Like the guy in the new lab quest, and the crimbo guy)

Player without IDs are id = 0. Their name is in fromname. I've verified this with the lab quest.
 
Looks like these kmail revamps happened not a moment too soon! Nice that we were ahead of the curve for once! :D
 
I'm using 5 scripts which use the check_version function. Instead of messing up my farm scripting with randomness I want to check all of them at one time before the rest of my script starts running so I can just update them if need be. Right now I have this


Code:
void DWS_script_updates () {
	if (check_version("ZLib","zlib",": 24",2072) == check_version("BatBrain","batbrain","1.0",6445))
		if (check_version("SmartStasis","SS","3.3",1715) == check_version("Neo's Libram Script", "NeoLibram", "1.1", 2591))
			if (check_version("Best Between Battle Script Ever","automcd","2.5",1240) == "")
				print ("Scripts are current", "red");
}


Which is possibly the ugliest code I've ever written. While it does check and works fine if they're all up to date, it's certainly not good code, and I have to crash it manually if one of the scripts isn't up to date. Also, if there are more then 1 outdated I'll have to crash it for everyone that's outdated.

Any ideas on how to improve this? Especially something that won't require me manually updating each new version number in my scripting when there is a new one?
 
You could try this:
PHP:
void DWS_script_updates () {
	string c;
	c += check_version("ZLib","zlib",": 24",2072);
	c += check_version("BatBrain","batbrain","1.0",6445);
	c += check_version("SmartStasis","SS","3.3",1715);
	c += check_version("Neo's Libram Script", "NeoLibram", "1.1", 2591);
	c += check_version("Best Between Battle Script Ever","automcd","2.5",1240);
	if ( c != "" ) abort("Scripts are not current");
	print ("Scripts are current", "red");
}

EDIT: As for updating the script versions, you will have to do it manually unless you want to parse the KoLmafia thread of each script and check it against the "_version_" property.

EDIT2: you could make it a little bit clearer like this:
PHP:
void DWS_script_updates () {
	string [ string ] to_check;
	to_check[ "zlib" ] = ": 24";
	to_check[ "batbrain" ] = "1.0";
	to_check[ "SS" ] = "3.3";
	to_check[ "NeoLibram" ] = "1.1";
	to_check[ "automcd" ] = "2.5";
	foreach s, v in to_check
		if ( get_property( "_version_" + s ) != v )
			abort( "Scripts are not current" );
	print ("Scripts are current", "red");
}

EDIT3: even parsing the kolmafia threads won't help you because you need to know the string anyway of the script you imported anyway.
 
Last edited:
Much better than mine but:

Code:
void DWS_script_updates () {
    string c;
    c += check_version("ZLib","zlib",": 24",2072);
    c += check_version("BatBrain","batbrain","1.0",6445);
    c += check_version("SmartStasis","SS","3.3",1715);
    c += check_version("Neo's Libram Script", "NeoLibram", "1.1", 2591);
    c += check_version("Best Between Battle Script Ever","automcd","2.5",1240);
    if ( c != "" ) abort(c);
    print ("Scripts are current", "red");
}

would this print out the normal check_version responses for all the ones that aren't current? Looking for the lazy way to get the thread links while I'm at it ;)


[edit]

I tried it out on a multi, since my main is currently farming, and my change does print out the normal response. It's a little ugly with the countdown and waiting lines still popping up, but the "upgrade" link works

Code:
Countdown: 1 second...
Waiting completed.
New Version of SmartStasis Available: 3.3
Upgrade to 3.3 now



Also, zarqon is there any way we can just make the link go straight to downloading the script instead of just opening the forum thread? I guess the script writers would have to add the full link to their script as a 5th call in the check_version function though ... We'd have to also be currently logged into the forum for the dl to start also I guess.
 
Last edited:
Simply calling check_version() will print out the version info (for the second time since those are already printed when you import the scripts anyway).
 
A lot of scripts create a _version variable in the per user mafia settings, for example _version_BalesAdventureAdvisor=1.29 in charname_prefs.txt. While there are many ways that using the variable could give an incorrect answer it seems that reading the variable might be easier than hard coding the version number of one script in another. My recollection is that running the script (or calling check_version with the appropriate parameters) will update the _version value once a day.
 
Zlib's check_version() creates a "_version_"+prop Mafia property that contains the version string parsed from the script's forum thread (the most current version). You need to compare this to the version of the script you are running, which could be provided in a variable available when you import the script, instead of being explicitly written in the check_version() call.

This would mean replacing zlib's
PHP:
check_version("ZLib","zlib",": 24",2072);
with
PHP:
string ver_zlib = ": 24"
check_version("ZLib","zlib",ver_zlib,2072);
This way you could check for:
PHP:
if ( ver_zlib != get_property("_version_zlib") ) abort();
 
There's code to add in a html link in check_version() but you append to the msg variable after it was printed out so the link never appears, then add a plain text version of the link afterwards.

Also might want to add an underline so it looks more like a link.
 
Last edited:
Zlib's check_version() creates a "_version_"+prop Mafia property that contains the version string parsed from the script's forum thread (the most current version). You need to compare this to the version of the script you are running, which could be provided in a variable available when you import the script, instead of being explicitly written in the check_version() call.

raaaaghgh ... slyz make brain hurt ... fianor smash ...

You totally lost me with the foreach version and everything since. While it does properly test, I have no clue how. I don't understand where that code is pulling variables or how it finds the threads at all. I tried banging in all the variables I could see to the abort call trying to make it report which one failed and got nothing useful. I tried dropping check_version() in during and after the if call and completely outside after the function, none returned anything that I could understand. As the code does properly test I'm sure it would work if I had any idea what it was doing, but for now it just makes my head hurt.

I'm using this right now

Code:
void DWS_script_updates () {
	string c;
    c += check_version("ZLib","zlib",": 24",2072);
    c += check_version("BatBrain","batbrain","1.0",6445);
    c += check_version("SmartStasis","SS","3.2",1715);
    c += check_version("Neo's Libram Script", "NeoLibram", "1.1", 2591);
    c += check_version("Best Between Battle Script Ever","automcd","2.5",1240);
    if ( c != "" ) abort(c);
    print ("Scripts are current", "red");
}

And it is giving me a usable response:

Code:
[COLOR="red"][SIZE="5"][B]New Version of SmartStasis Available: 3.3[/B][/SIZE][/COLOR]
[COLOR="blue"]Upgrade SmartStasis from 3.2 to 3.3 here: http://kolmafia.us/showthread.php?t=1715[/COLOR]
Countdown: 1 second...
Waiting completed.
[CENTER][COLOR="red"][SIZE="5"][B]New Version of SmartStasis Available: 3.3[/B][/SIZE][/COLOR]
[COLOR="blue"]Upgrade to 3.3 now[/COLOR][/CENTER]

if multiple scripts are outdated it repeats that for all of them. The "Upgrade to 3.3 now" line is a link to the thread, but the first one is not. I don't understand why the first response does not have the link and the 2nd does. It seems like they should be the same. Also if I just use the original version slyz posted that has a text print from the abort I get the non-linked version of the responses followed by the abort text.

The code in this post is effectively doing the check I want it to do and aborts the farm script before it does anything else as I wanted so for all intents and purposes what I want to do is working. I'm just not sure how it's working and the output isn't very pretty. I'm more just trying to figure out the 2nd slyz version (ow .. made my head hurt again) and what exactly is making the check_version() give different responses than anything else now I guess.


... hmm ...
for the TL;DR crowd, this codes works but it's ugly, thanks for the help slyz.
 
check_version() prints a message if your script is outdated. It also returns a string which contains almost the same message (almost). In the code you are using, the string c only serves to check if check_version() returned empty strings only. You really don't need to print it, but that's where the second message comes from.
Try using the first version I posted, with abort("Scripts are not current") instead of abort(c).

In the version with the foreach, I just create the to_check map which contains the names of the properties and the versions of each script you are currently running. If the property is different than the current version, then the script is outdated and it aborts.

There isn't any thread checking, and you wouldn't really need to add a check_version() since that is already done when you import the scripts.
 
But the problem with the version that uses the foreach is that he isn't actually importing the scripts at any point, so he isn't going to have updated properties or an automatic check_version execution yet... it'll abort every time with a "Scripts are not current!" message because those properties are going to be blank, which != the right version number.

His goal was to make an external script that checks to see if the version is correct... to do something like that 'properly' you'd need to do something like file_to_map on the scripts and search for something like checkversion( or better, checkversion(" so that it doesn't match on the function itself in zlib, which comes first so that it's properly defined when the script does its version check...
 
Back
Top