SPADS plugin development

SPADS plugin development

SpringRTS Perl Autohost for Dedicated Server

Moderators: Moderators, Lobby Developers, SPADS AutoHost

Post Reply
Teabag
Posts: 28
Joined: 26 May 2016, 19:11

SPADS plugin development

Post by Teabag » 27 Jan 2018, 17:18

What is the best way to pull data from the spads config files?

I have working code but it requires "use strict;" to be removed to be usable outside of the initial subroutine.

Code: Select all

sub getmodName {
    my $hostingPresets=getSpadsConf()->{etcDir}.'/hostingPresets.conf';
    open( my $fh, '<', $hostingPresets ) or die "Can't open $hostingPresets: $!";
    while ( my $modName = <$fh> ) {
        if ( $modName =~ s/modName:// ) {
			print $modName;
        }
    }
    close $fh;
}
0 x

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

Re: SPADS plugin development

Post by bibim » 27 Jan 2018, 21:24

You don't need to re-parse SPADS configuration files for that, you can directly access the in-memory data structure containing the configuration data.

For example, to get the value of the "modName" hosting setting:

Code: Select all

getSpadsConfFull()->{hSettings}{modName}
1 x

Teabag
Posts: 28
Joined: 26 May 2016, 19:11

Re: SPADS plugin development

Post by Teabag » 28 Jan 2018, 10:45

Thank you this works well.

also, is SPADS able to detect when the game has started? i know you can "onSpringStart" but i am unable to find a trigger point for when the game has actually started.
a work around im using is onSpringStart + addTimer
0 x

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

Re: SPADS plugin development

Post by bibim » 28 Jan 2018, 14:02

Sure, you just need to set up a callback on the "SERVER_STARTPLAYING" event received on the autohost interface, like this:

Code: Select all

addSpringCommandHandler( { SERVER_STARTPLAYING => sub { slog('The game has just started!',3); } } );
1 x

Teabag
Posts: 28
Joined: 26 May 2016, 19:11

Re: SPADS plugin development

Post by Teabag » 01 Feb 2018, 13:12

Thanks these were a huge help, also other events on this page:
https://raw.githubusercontent.com/sprin ... erface.cpp

at the moment i am trying to increase the number of commands the CustomAliases plugin will allow on a single aliase. so far i have got it to read multiple commands from CustomAliases.conf file
but i am having trouble with issuing the command, it takes the first or last command only depending on the format of the second part.

this part is functioning:

Code: Select all

if($aliasDef=~/^([^\(]+)\(([^\(]+)\)\(([^\(]+)\)\(([^\(]+)\)\(([^\)]+)\)$/) {
	my ($aliasName,$aliasCmd1,$aliasCmd2,$aliasCmd3,$aliasCmd4,)=($1,$2,$3,$4,$5);
	my @aliasCmdTokens1=split(/ /,$aliasCmd1);
	my @aliasCmdTokens2=split(/ /,$aliasCmd2);
	my @aliasCmdTokens3=split(/ /,$aliasCmd3);
	my @aliasCmdTokens4=split(/ /,$aliasCmd4);
second part (original):

Code: Select all

$aliases{$aliasName}=\@aliasCmdTokens;
any suggestions as to the best way to format this?
0 x

Teabag
Posts: 28
Joined: 26 May 2016, 19:11

Re: SPADS plugin development

Post by Teabag » 24 Feb 2018, 10:12

Hi, Is there a direct way of switching map?

this works but print duplicate text:

Code: Select all

::executeCommand($source,$user,['set','map',$ReqMap]);

Code: Select all

[09:01:21] * DarkEnergy * Map changed by DarkEnergy: Comet Catcher Redux v3.1
[09:01:21] * DarkEnergy * Map is already set to "Comet Catcher Redux v3.1"
is there a better way of doing this?
0 x

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

Re: SPADS plugin development

Post by bibim » 01 Mar 2018, 15:24

Teabag wrote:Thanks these were a huge help, also other events on this page:
https://raw.githubusercontent.com/sprin ... erface.cpp

at the moment i am trying to increase the number of commands the CustomAliases plugin will allow on a single aliase. so far i have got it to read multiple commands from CustomAliases.conf file
but i am having trouble with issuing the command, it takes the first or last command only depending on the format of the second part.

this part is functioning:

Code: Select all

if($aliasDef=~/^([^\(]+)\(([^\(]+)\)\(([^\(]+)\)\(([^\(]+)\)\(([^\)]+)\)$/) {
	my ($aliasName,$aliasCmd1,$aliasCmd2,$aliasCmd3,$aliasCmd4,)=($1,$2,$3,$4,$5);
	my @aliasCmdTokens1=split(/ /,$aliasCmd1);
	my @aliasCmdTokens2=split(/ /,$aliasCmd2);
	my @aliasCmdTokens3=split(/ /,$aliasCmd3);
	my @aliasCmdTokens4=split(/ /,$aliasCmd4);
second part (original):

Code: Select all

$aliases{$aliasName}=\@aliasCmdTokens;
any suggestions as to the best way to format this?
I'm not very sure about what you are trying to do, and especially how you are trying to do it.
My guess is that you are trying to implement "SPADS commands chaining", and trying to use it with aliases the way it's done in the CustomAliases plugin. But it's not that simple, this alias system is made for one-to-one mapping of alias and commands, you can't map one alias to a chain of commands directly.

You have multiple ways to do what I guess you want to do. I would suggest this one which seems the easiest one:
First you declare a new SPADS command (!chainCommands for example), which would basically take the commands passed as parameters and execute them sequentially using the "executeCommand" function. If needed, you can follow this tutorial which explains how to implement new SPADS commands in SPADS plugins.
Then you just use the existing CustomAliases plugin without any modification, and map some aliases to the !chainCommands command with the SPADS commands you want to chain as parameters.
0 x

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

Re: SPADS plugin development

Post by bibim » 01 Mar 2018, 15:28

Teabag wrote:Hi, Is there a direct way of switching map?

this works but print duplicate text:

Code: Select all

::executeCommand($source,$user,['set','map',$ReqMap]);

Code: Select all

[09:01:21] * DarkEnergy * Map changed by DarkEnergy: Comet Catcher Redux v3.1
[09:01:21] * DarkEnergy * Map is already set to "Comet Catcher Redux v3.1"
is there a better way of doing this?
This shouldn't print duplicate text.
Are you sure it's not your code which is made a way the function is called multiple times?
Can you provide the full code of your plugin?
0 x

Teabag
Posts: 28
Joined: 26 May 2016, 19:11

Re: SPADS plugin development

Post by Teabag » 03 Mar 2018, 08:54

Originally i was trying to increase the number of commands the customaliases plugin would accept so that i could set custom mapboxes with a single command, but decided to run them directly using 'executeCommand'

The duplicate text issue was an error within my pluginCmd.conf file, both issues have now been resolved

however it would be useful if you know a way to switch map without using 'executeCommand'
similar to how 'applyPreset($ReqPreset);' switches preset directly.
0 x

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

Re: SPADS plugin development

Post by bibim » 26 Mar 2018, 14:27

Teabag wrote:however it would be useful if you know a way to switch map without using 'executeCommand'
similar to how 'applyPreset($ReqPreset);' switches preset directly.
Why do you want to switch map without using "executeCommand" ?
There are multiple answers to your question, depending on the parts of the map switching functionality you want to avoid...

If you want the simplest way to switch map (without performing any check/conversion on the map name, ignoring any map preset, without triggering the auto-restore default preset functionality, without broadcasting any message announcing the map change etc.), then I guess you can do something like that:

Code: Select all

getSpadsConf()->{map}="new map";
::applySettingChange('map');
0 x

Teabag
Posts: 28
Joined: 26 May 2016, 19:11

Re: SPADS plugin development

Post by Teabag » 26 Mar 2018, 21:17

Thanks i will try this. my reasoning is to control the output text when switching map, so i can stack multiple actions with output text that better describes what actions have been performed
0 x

Teabag
Posts: 28
Joined: 26 May 2016, 19:11

Re: SPADS plugin development

Post by Teabag » 20 Apr 2018, 21:26

Thanks this works well.
Do you have something similar for applying bsettings?

this works, they are set in !bsettings but not applied

Code: Select all

getSpadsConfFull()->{bSettings}{mo_ffa}=($mo_ffa);
this part does not apply bsettings

Code: Select all

::applySettingChange('mo_ffa');	
0 x

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

Re: SPADS plugin development

Post by bibim » 25 Apr 2018, 11:39

Teabag wrote:my reasoning is to control the output text when switching map, so i can stack multiple actions with output text that better describes what actions have been performed
What type of actions? If the actions only consist in changing some global/hosting/battle settings, then you can already do all that using presets and/or map presets (map presets are presets which are automatically called when map is changed to some specific configured maps).
Teabag wrote:Do you have something similar for applying bsettings?

this works, they are set in !bsettings but not applied

Code: Select all

getSpadsConfFull()->{bSettings}{mo_ffa}=($mo_ffa);
this part does not apply bsettings

Code: Select all

::applySettingChange('mo_ffa');	
Battle settings don't work the same way as global settings, you have to call sendBattleSetting() to apply the changes instead of applySettingChange(). But as I said, it seems you are trying to re-implement the map preset functionality using plugins, which would be a waste of time as this functionality already exists in SPADS. If you want a custom message on top of that functionality you can just make a very basic plugin which would print this message when the map is changed for example.
0 x

User avatar
Silentwings
Moderator
Posts: 3577
Joined: 25 Oct 2008, 00:23

Re: SPADS plugin development

Post by Silentwings » 25 Apr 2018, 14:13

@Teabag: Re our pm chat, maybe you are looking for the setting rotationEndGame, which can specify (when map rotation is in use) if the next map in the rotation is chosen at random or as the next item in the list.
0 x

Post Reply

Return to “SPADS AutoHost”