Feature - Implemented whichplace Relay Overrides

Bale

Minion
Jick's place.php thing, while no doubt wonderfully effective for refactoring the game on the back end, is troublesome to the usefulness of KoLmafia's relay override scripts. Things like manor.php use to be just fine. Now we need to have a relay for place.php since its address is place.php?whichplace=spookyraven1 and could make it difficult for the user to also have an override for place.php?whichplace=KOLHS, just to name two scripts I use. I've got them sorted out by using a place.php override that does this:

PHP:
import "manor.ash";
import "kolhs.ash";

void main() {
	switch(form_field("whichplace")) {
	case "spookyraven1": main@manor();
		break;
	case "KOLHS": main@kolhs();
		break;
	}
}

Let's face it, this solution is kinda kludgy. I would like to propose a better solution KoLmafia could implement. I believe someone mentioned this idea in some thread somewhere, but pardon me for not giving proper credit to the original proposal.

In the relay directory should be a subdirectory /relay/whichplace and in that subdirectory, an override called spookyraven1.ash would be applied as a relay override to place.php?whichplace=spookyraven1. If we did this, all place.php locations could play nicely with each other, without troubling the user to untangle the knot of overrides as I did in the previous example.
 

heeheehee

Developer
Staff member
Ooh, a similar feature would be sweet for choice.php (whichchoice).

Also this feature would be awesome.
 

ckb

Minion
Staff member
Also:
shop.php (whichshop)
store.php (whichstore)
peevpee.php (place)

Also, I third the awesomeness of this feature.
Also, There are probably more I am forgetting... I'll keep poking my brain and the game to see if I can find more.
 

lostcalpolydude

Developer
Staff member
If there are going to be 10 different cases where this applies, then the idea of using subfolders seems less appealing.
 

fronobulax

Developer
Staff member
Better organization of scripts is a bad thing?

If the definition of "better" requires a directory structure that makes sense to some and is counter intuitive to others, may, or may not, have to deal with operating system file system quirks to work reliably everywhere, and adds another layer that has to be checked and verified when things appear to break, then "bad" might be an appropriate description.
 

heeheehee

Developer
Staff member
Wouldn't something like this suffice? (very roughly)
Code:
String[] DIR_NAMES = new HashSet({ "whichplace", "choice", "whichshop", ... });

...

if (DIR_NAMES.contains(path)) {
     load from that directory >.>
}

edit: frono, OS and file system quirks *should* be handled by Java libraries for the most part, not the end developer :|
 

fronobulax

Developer
Staff member
edit: frono, OS and file system quirks *should* be handled by Java libraries for the most part, not the end developer :|

I agree in theory. In practice if you know a library that gets it all right, let me know. Programmers forget to use the defined path separator but I have not seen good library support for blanks in path or file names or for dealing with the bugs that occur because the operating system allows ./whichPlace and ./whichplace but the programmer was case insensitive. I shudder to think of the matching if we have to match a portion of the KoL URL to a directory name.

All the issues can be handled but in the context of this particular problem I have to ask if there is a better way to deal with it besides the file system.
 

Bale

Minion
How about just automagically loading spookyraven1.ash for whichplace=spookyraven1?

While I'm not opposed to that, I fear it might eventually cause a problem if a whichplace value was used for something else, especially if mafia eventually implements whichshop or whichstore. If we put all the whichplace overrides in their own directory then we don't have to worry about the possibility of some whichshop and whichplace eventually having the same value.


If new folders are used, then the command to wipe the relay folder needs to not touch those folders too.

I think you are thinking of the /images folder.
 

Nappa

Member
Disclaimer: I don't know anything about the technical implementation of mafia and its script handling. But how about a metadata based approach? Scripters add metadata about where they want to run their script. Scan any present scripts in the relay dir for available metadata. Cache this and use it to determine what stuff to run. You can then avoid using exact filenames or folders altogether, and have 'fancyrelay.ash' run when loading place.php?whichplace=plains.php if you want.
 

lostcalpolydude

Developer
Staff member
Disclaimer: I don't know anything about the technical implementation of mafia and its script handling. But how about a metadata based approach? Scripters add metadata about where they want to run their script. Scan any present scripts in the relay dir for available metadata. Cache this and use it to determine what stuff to run. You can then avoid using exact filenames or folders altogether, and have 'fancyrelay.ash' run when loading place.php?whichplace=plains.php if you want.

That would likely result in poor results when someone unknowingly has two scripts that want to run on place.php?whichplace=plains.php, something that currently can't be a problem.
 

fronobulax

Developer
Staff member
Disclaimer: I don't know anything about the technical implementation of mafia and its script handling. But how about a metadata based approach? Scripters add metadata about where they want to run their script. Scan any present scripts in the relay dir for available metadata. Cache this and use it to determine what stuff to run. You can then avoid using exact filenames or folders altogether, and have 'fancyrelay.ash' run when loading place.php?whichplace=plains.php if you want.

I like the out of the box thinking but I would hate to add "how to create relay script metadat" to the learning curve of aspiring relay script authors.

As for the name collision potential, I'm not sure we can prevent it without imposing a lot of constraints on Kol ( *snicker* ) or authors so I might vote for detecting it and pushing the problem back on the user who could then choose to rename scripts, petition the authors to change something or merely choose which one each time the relay is invoked.
 

ckb

Minion
Staff member
Perhaps Mafia could parse some extended filenames of relay scripts, instead of a folder structure.
So place.ash will apply to all place.php hits, but place.whichplace.spookyraven1.ash will apply only to place.php?whichplace=spookyraven1

It seems like this would leave the current functionality in place, but also allow for specific overides for whichplaces and the like. In the case of both a generic place.ash AND a specific place.whichplace.spookyraven1.ash, the specific should always win.
 

ckb

Minion
Staff member
I am bumping this because it would still be really sweet. Also, my choice.ash override is getting huge, and a way to split it would be nice.
 

lostcalpolydude

Developer
Staff member
I think I mostly have something written where you can have place.plains.ash, choice.720.ash, and so on, all in the /relay folder. I won't be able to test it for at least a few days. The only hardcoded thing is the list of fields to check for, "place", "whichchoice", and so on. I haven't actually tested any of this, and it will be at least a few days before I get to that (and with the changes I've made to the code just since starting this post, it needs testing).
 
Top