[plugin] SetEngine

[plugin] SetEngine

SpringRTS Perl Autohost for Dedicated Server

Moderators: Moderators, Lobby Developers, SPADS AutoHost

Post Reply
User avatar
Jools
XTA Developer
Posts: 2804
Joined: 23 Feb 2009, 16:29

[plugin] SetEngine

Post by Jools » 30 Jan 2015, 18:53

I and Turboss were thinking about how to make spads implement a !setengine command and we almost have it working.

One obstacle for doing this is that spads needs to generate unitsync wrapper for each engine. I think this perlunitsync.so needs to be placed in same directory as spads.pl. But does it have to be this way? Would it be possible to place unitsync in same directory as each engine?

Then you could have one spads installation that can run 50 different engines by just reconfiguring some paths in the conf. But is this possible?
0 x

User avatar
bibim
Lobby Developer
Posts: 901
Joined: 06 Dec 2007, 11:12

Re: SPADS AutoHost

Post by bibim » 30 Jan 2015, 21:31

Jools wrote:I think this perlunitsync.so needs to be placed in same directory as spads.pl. But does it have to be this way?
Not necessarily. I think you can place it anywhere and configure your LD_LIBRARY_PATH to include this new path.
0 x

User avatar
Jools
XTA Developer
Posts: 2804
Joined: 23 Feb 2009, 16:29

Re: SPADS AutoHost

Post by Jools » 09 Feb 2015, 20:37

Here's a plugin I did: it adds the following command:

[setengine]
!setengine <engine version|latest>. Will attempt to download unknown versions. Needs DownloadArchives plugin 0.5 or later
!setengine 98.0.1-353-gcae510f sets engine to version 98.0.1-353-gcae510f
!setengine latest sets engine to latest version in http://springrts.com/dl/buildbot/default/develop/


It finds the current engine from the path in spadsconfig, attemps to dl a new engine if it doesn't exist (looks for libunitsync.so and spring-dedicated) ands regenerates the perl unitsync module with spadsinstaller -g flag.

Here are some settings that need to be set/changed, in the conf file:

precedingstring:engine/
followingstring:/spring-dedicated
spadsconfname:spads-dev.conf

So it only works if the path to your engines is consistent. Also some versions spring don't contain spring-dedicated, so pr-downloader won't download it for those versions.
Last edited by Jools on 10 May 2015, 14:29, edited 1 time in total.
0 x

User avatar
bibim
Lobby Developer
Posts: 901
Joined: 06 Dec 2007, 11:12

Re: SPADS AutoHost

Post by bibim » 10 Feb 2015, 14:23

Thanks for sharing!
Jools wrote:Needs DownloadArchives plugin 0.5 or later
There is a callback in the API to declare plugin dependencies: getDependencies()

There are several problems with calling "use DownloadArchives;" directly as you did:
- it could try to load the corresponding Perl module directly if it's not loaded yet through the plugin infrastructure, thus failing sooner or later
- if the module isn't found it could fail with obscure error
- if the DownloadArchives plugin is unloaded afterward, your SetEngine plugin could crash

On the other hand, if you declare the getDependencies callback in your plugin, SPADS will perform all the necessary checks for you and ensure the dependencies are always loaded. Then you just need to use the getPlugin function to access to dependencies. For example:

Code: Select all

my $p_dlArchivesPlugin=getPlugin('DownloadArchives');
slog("Found DownloadArchives ".$p_dlArchivesPlugin->getVersion(),3);
 
0 x

User avatar
Jools
XTA Developer
Posts: 2804
Joined: 23 Feb 2009, 16:29

Re: SPADS AutoHost

Post by Jools » 10 Feb 2015, 16:32

You're right. I tested it many times and it just fails with some error similar to "unable to instantiate plugin". I tested what happens and it's enough that the other module is present, it doesn't have to be loaded.

In the code, I use this way to check version:

Code: Select all

sub new {

  slog("Found DownloadArchives ".DownloadArchives::getVersion(),3);
  die ("Sorry, this program needs DownloadArchives v.0.5 or later!") unless (DownloadArchives::getVersion() 
>= 0.5);
So there is a message but it will only be output to log, not to the user.

But I will modify it to this other method of checking dependencies :)
0 x

User avatar
Jools
XTA Developer
Posts: 2804
Joined: 23 Feb 2009, 16:29

Re: [plugin] SetEngine

Post by Jools » 03 Mar 2015, 00:13

Updated the dependency check as per advised logic.
Last edited by Jools on 10 May 2015, 14:29, edited 1 time in total.
0 x

User avatar
bibim
Lobby Developer
Posts: 901
Joined: 06 Dec 2007, 11:12

Re: [plugin] SetEngine

Post by bibim » 03 Mar 2015, 00:27

Thanks, I see you changed the way you access the dependency to check the version number, you are now using getPlugin() which is good.
However you didn't define the getDependencies() callback to declare your dependency, which would be more failproof in my opinion as I explained.
0 x

User avatar
Jools
XTA Developer
Posts: 2804
Joined: 23 Feb 2009, 16:29

Re: [plugin] SetEngine

Post by Jools » 03 Mar 2015, 01:56

Here's a new version that also declares dependencies.
Last edited by Jools on 10 May 2015, 14:28, edited 1 time in total.
0 x

User avatar
bibim
Lobby Developer
Posts: 901
Joined: 06 Dec 2007, 11:12

Re: [plugin] SetEngine

Post by bibim » 03 Mar 2015, 12:21

Nice, just one last thing I forgot to say: now that you are sure that the DownloadArchives plugin will always be loaded by SPADS before the SetEngine plugin, you should be able to remove the "use DownloadArchives;" line from the top of your plugin (using "use" on another plugin module can lead to obscure problems if any of the plugins is unloaded/reloaded).
0 x

User avatar
Jools
XTA Developer
Posts: 2804
Joined: 23 Feb 2009, 16:29

Re: [plugin] SetEngine

Post by Jools » 03 Mar 2015, 15:02

Ok, here is updated version, now it works better:
[15:52:51] <[PRO]Jools> !plugin DownloadArchives unload
[15:52:51] <[elderberry]Autohost> Unloaded plugins SetEngine,DownloadArchives.
So it is better to use this latest version of the plugin, even if the previous versions will work under normal circumstances (that is you don't do anything weird, but you should not do that anyway :) )

By the way, maybe I can take these questions here: I always get this error output when starting spads:
Subroutine AddBoxPolar::tan redefined at /usr/share/perl/5.20/Exporter.pm line 66. (like 20 times)
Use of uninitialized value in hash element at SpadsConf.pm line 771. (2 times)
I get that they are just stupid warnings, but I always have to scroll up/down when I restart spads to see relevant info, and isnt the command no warnings 'redefine'; supposed to stop those anyway?

Also one thing I don't get: why doesn't everyone just use the latest version of perl?
Last edited by Jools on 10 May 2015, 14:28, edited 1 time in total.
0 x

User avatar
bibim
Lobby Developer
Posts: 901
Joined: 06 Dec 2007, 11:12

Re: [plugin] SetEngine

Post by bibim » 03 Mar 2015, 15:39

Jools wrote:By the way, maybe I can take these questions here: I always get this error output when starting spads:
Subroutine AddBoxPolar::tan redefined at /usr/share/perl/5.20/Exporter.pm line 66. (like 20 times)
Use of uninitialized value in hash element at SpadsConf.pm line 771. (2 times)
I get that they are just stupid warnings, but I always have to scroll up/down when I restart spads to see relevant info, and isnt the command no warnings 'redefine'; supposed to stop those anyway?
There are not necessarily stupid warnings... Concerning the AddBoxPolar::tan warnings, I don't see any "tan" definition in the plugin available here, do you use a different version? Concerning the "use of uninitialized value" I think it is due to at least one of your array config files having inconsistent data in it.
Jools wrote:Also one thing I don't get: why doesn't everyone just use the latest version of perl?
All Linux distro aren't updating their Perl packages that often. And people are lazy and don't want to update themselves ;)
0 x

Post Reply

Return to “SPADS AutoHost”