Perl Scripting Engine Plugin for FLHook
-
last week or so i been working on a FLHook plugin that provides a perl scripting engine.
Basically, embeds a perl interpreter inside hook, allowing perl scripts to register event callbacks and access FLHook’s internal functions and data just like any other plugin.
No messing around with TCP socket and eventmodePlease note this is extreme alpha, and for now pretty much worthless unless your a perl coder, or FLHook developer
Its probably unstable atm, and no perl plugins have been created.Main advantage of this would be quick and easy coding of new FLHook plugins (in perl), without the need to compile anything (just need a notepad).
Drawback would be performance (not really intended for larger servers) but no real performance testing has been done since I’m currently limited to running FLServer and Client on the same machine.
For now, running this plugin requires perl to be installed on the server (it requires some core perl modules for its calling of FLHooks functions), and recompiling will require perl source code (see the readme included)
http://yspstudios.linuxniche.net/files/freelancer/Plugin_PerlHeavy.zip
(new builds will probably be uploaded daily or more for a while)You’ll have to excuse any bad Cpp, I’m not a C/Cpp coder and this is my first real attempt at it.
Any advice or tips be much appreciatedA quick example a perl script plugin (basic text file)
# these lines are executed as the plugin is read (on FLHook startup) ConPrint "\n##################################################\n"; ConPrint "Testing perl string to wstring and function calls from inside perl\n"; ConPrint "obviously it works if you can read these lines\n"; # note the next line, we create a array (list) of 'a' to 'z' select specific elements, # then join them into a string and print it to the Console, all in 1 shot.Perl Power! ConPrint join('',(a .. z,' ')[9,20,18,19,26,0,13,14,19,7,4,17,26,15,4,17,11,26,7,0,2,10,4,17]) . "\n"; ConPrint "##################################################\n\n"; # example of hooking a callback to BaseEnter callRegister 'BaseEnter', sub{ my ($iBaseID, $iClientID) = @_; my $charname = GetCharacterName $iClientID; my $basename = HkGetBaseNickByID sprintf('%lu', $iBaseID); HkMsg $iClientID, "Welcome to $basename, $charname"; }; # like all good perl scripts, you MUST return a value (1), least FLHook thinks we failed to load 1;
-
for some reason, a few of the events refuse to hook for me with this, and i cant figure out why. FLHook reports a ‘Error: Plugin ‘perl’ does not export ….’ even though its listed in the source (i’ve coded and compiled some of these in a another plugin, and they hook fine)
ones i’ve noticed:UserCmd_Process
HkIServerImpl:: ReqAddItem
HkIServerImpl:: ReqModifyItem
HkIServerImpl:: Startup
HkIServerImpl:: LocationInfoRequest
HkIServerImpl:: BaseInfoRequest
HkIServerImpl:: CharacterInfoReq
HkIServerImpl:: SPRequestInvincibilitythe first 3 are of prime importance, expecially the UserCmd_Process any help on this would be VERY muchly appreciated
-
I used your example to create something basic (not very useful - but this is just for me to get used to this), but it’s not working…
Here’s what I’ve got:
callRegister 'ActivateCruise', sub{ my $charname = GetCharacterName $iClientID; MkFMsg $iClientID, "<tra data="\"000099x1\"" mask="\"-1\"/"><text>$charname has activated cruise engines.</text>"; };</tra>
Any idea why it’s not working?
-
assuming the plugin is working correctly (the tester.pl script is good for confirming that)
looking at the FLHook documentation, our ActivateCruise hook is passed 2 values, first is the iClientID, second XActivateCruise struct.
the XActivateCruise struct isnt passed to perl yet (structs not supported atm). But we need to capture that iClientID for your scriptcallRegister 'ActivateCruise', sub{ # catch first argument passed my $iClientID = $_[0]; my $charname = GetCharacterName $iClientID; HkFMsg $iClientID, "<tra data="\"000099x1\"" mask="\"-1\"/"><text>$charname has activated cruise engines.</text>"; };</tra>
you also typo’d the HkFMsg (in your code above you have it as MkFMsg). I wouldnt bother trying anything overly useful yet, the plugin has a long way to go still.
-
HkMsgU and HkFMsgU for universe messages
-
updated.
more seamless data type conversion (structs and lists still not fully supported),
removed some redundant functions not needed in perl (mostly data type conversion functions).
added brief documentation on FLHooks functions - whats currently working and how to access via perl.
functions that formally took a Client ID or Character name will now accept either one.
added ‘short’ versions of some functions, eg:#getting and setting a reputation - long function names my $rep = HkGetRep( $client, $faction ); HkSetRep( $client, $faction, $value ); # short function names my $rep = rep( $client, $faction ); rep( $client, $faction, $value ); ######################################### #getting current cash and adding 1000cr - long my $cash = HkGetCash( $client ); HkAddCash( $client, 1000 ); # short my $cash = cash( $client ); cash( $client, 1000 ); ```note alot of short functions have yet to be defined, and those that are the names arent final yet (subject to change later) Message functions and ConPrint now support multiple lines per call
HkMsg can be called as msg() - short form
HkMsg( $client, $line1, $line2, $line3, $etc);
still no luck on getting FLHook to recognize a few of the exported hooks… UserCmd_Process is driving me nuts since perl defiantly needs this one
-
both using official build of 1.6.0, and tried compiling myself with Visual studio 2003 on XP sp3
i had a feeling it might have been just my machine, since i couldnt see anything wrong and have exported those fine in other test plugins. Thanks alot for testing that, I’ll see if i can find a solution