Old CTWF rotation script query

Post here if you need help setting up your server, etc.
Post Reply
syllabear
Shutout Match Winner
Posts: 1023
Joined: Fri Oct 13, 2006 1:37 pm
Location: UK/HK

Old CTWF rotation script query

Post by syllabear »

I was looking over the old CTWF rotation script setup guide found here and wondering if it could be converted to something that would run on windows.

As far as I can tell, there are three main elements to this - the bash scripts which run the server and the map rotation, the php scripts which randomise and rotate the maps and the mysql database which stores the maps.

The first bash script was not particularly difficult to change

Code: Select all

$tron = "\tron\Armagetron Advanced Dedicated\armagetronad_dedicated.exe"
$config = "\tron\sylla\config"
$var = "\tron\sylla\var"
$log = "\tron\sylla\log\wildlog.txt"

.$tron --configdir $config --vardir $var | Tee-Object -FilePath $log
The Mysql database appears to be achievable, and I've left the php scripts alone (since these should work OK on windows?). I am currently stuck on the remaining two bash scripts. The first one currently looks like this:

Code: Select all

$log = "\tron\sylla\log\wildlog.txt"

Get-Content $log -tail 1 -wait | \tron\mapscript\mapcycle2.ps1
However I suspect the pipe function is wrong and the line of text from wildlog is not being properly fed anywhere. The second is even more of a mess

Code: Select all

while($true)
{
# I have no idea what goes after this
$line = ""
echo $line
\tron\mapscript\tron.php "$line"
}
and depending on how I use it, will just repeatedly return blank lines or open files (obviously as a consequence of it being a loop function). I appreciate this is basically a non-priority and I'll probably just look at downloading a windows compatible version of linux, but for my own personal sanity if anyone can easily highlight my mistakes for me I'd be most grateful.

EDIT: I've realised that the first powershell script is missing -wait after get-content and I've added it above.
The Halley's comet of Armagetron.
ps I'm not tokoyami

User avatar
kyle
Reverse Outside Corner Grinder
Posts: 1867
Joined: Thu Jun 08, 2006 3:33 pm
Location: Indiana, USA, Earth, Milky Way Galaxy, Universe, Multiverse
Contact:

Re: Old CTWF rotation script query

Post by kyle »

Those are super old, they evolved a lot since then. Hopefully in 2 months I'll be back, have CTWF back up and make the current script more public.

With that said, the newer scripts use GNU/Screen and python instead of bash or PHP

I don't know enough power shell to point out your issue though.

How's Syllabear these days? Is your post count still shrinking ;)
Image

User avatar
delinquent
Match Winner
Posts: 728
Joined: Sat Jul 07, 2012 3:07 am

Re: Old CTWF rotation script query

Post by delinquent »

It's a bad idea to do anything permanent in powershell on Windows. You are far better off creating a helper service, or even just a small application, that runs in the background instead, using a framework that isn't dependent on the ever-changing Windows landscape.

I despise Python, but it would suffice here. Alternatively, C# has built-in handles for constant piping, as well as log splitting. You could easily set up a daily log, rather than a never ending file. I'd also suggest you change the PHP files to something that doesn't rely on another internal host - I'm not aware of anything that can efficiently interpret PHP on-the-fly on Windows that isn't a web server. Plus, by using Python or C#, or any other OOP language, you can combine everything into one single application.

Alternatively, WSL might be an efficable solution here - but again, it's an ever-changing landscape and could stop working at a moment's notice.

syllabear
Shutout Match Winner
Posts: 1023
Joined: Fri Oct 13, 2006 1:37 pm
Location: UK/HK

Re: Old CTWF rotation script query

Post by syllabear »

Hi Kyle, glad to see you're still knocking about :) I have no idea why my post count is shrinking haha!

I am aware there are newer ways to do this, such as your advice in this thread. Regardless, I thought it would be a fun little project to try my hand at. Turns out it wasn't too fun, but I've got a (terribly unrefined) purely powershell script that does work.

Also delinquent, I already went ahead and didn't take your advice :oops: but at least I learned stuff. I do appreciate the input though, in the future I will take the sensible path!

Just in case it ends up helping, I've included a snippet of what I eventually came up with. The first step involves running the following as a background job. Wildlog.txt is referenced in my first post.

Code: Select all

$myjob=Start-Job -ScriptBlock {Get-Content "...\tron\sylla\log\wildlog.txt" -tail 1 -wait}
You can check if it is running using

Code: Select all

Get-Job
Then when this is in the background you run a looping while script. It has recursive elements for each round since I'm dumb and don't know any better:

Code: Select all

while ($true) {
    $line = (Get-Job | Receive-Job)
    if (($line -like '*Go (round 1 o*') -and ($line -notlike '*Go (rou* `*') -and ($line -notlike '*:* Go rou*')) {
        write-output "round one"
        $maprannum = Get-Random -maximum 3
        Write-Output $maprannum
        if ($maprannum -eq 0) {
            set-content -path "...\tron\sylla\var\everytime.cfg" -value 'MAP_FILE ed/fortress/minefield-0.0.7.aamap.xml
            ROUND_CENTER_MESSAGE Round 2 - Minefield'
        }elseif ($maprannum -eq 1) {
            set-content -path "...\tron\sylla\var\everytime.cfg" -value 'MAP_FILE ed/fortress/minepillars-0.0.3.aamap.xml
            ROUND_CENTER_MESSAGE Round 2 - Mine Pillars '
        }elseif ($maprannum -eq 2) {
            set-content -path "...\tron\sylla\var\everytime.cfg" -value 'MAP_FILE ed/fortress/hairbrush-0.0.2.aamap.xml
            ROUND_CENTER_MESSAGE Round 2 - HairBrush'
        }
    }
This is followed by an elseif for each round which has maps for the following round:

Code: Select all

elseif (($line -like '*Go (round 2 o*') -and ($line -notlike '*Go (rou* `*') -and ($line -notlike '*:* Go rou*')) {
        write-output "round two"
        $maprannum = Get-Random -maximum 4
        Write-Output $maprannum
        if ($maprannum -eq 0) {
            set-content -path "...\tron\sylla\var\everytime.cfg" -value 'MAP_FILE ed/fortress/octazigzag-0.0.3.aamap.xml
            ROUND_CENTER_MESSAGE Round 3 - Octagon Wiggle'
        }elseif ($maprannum -eq 1) {
            set-content -path "...\tron\sylla\var\everytime.cfg" -value 'MAP_FILE ed/fortress/octagon-0.0.2.aamap.xml
            ROUND_CENTER_MESSAGE Round 3 - Octagon Fortress'
        }elseif ($maprannum -eq 2) {
            set-content -path "...\tron\sylla\var\everytime.cfg" -value 'MAP_FILE ed/fortress/octagoneloopy-0.0.1.aamap.xml
            ROUND_CENTER_MESSAGE Round 3 - Octa Gone Loopy'
        }elseif ($maprannum -eq 3) {
            set-content -path "...\tron\sylla\var\everytime.cfg" -value 'MAP_FILE ed/fortress/octagon_weasel-0.0.1.aamap.xml
            ROUND_CENTER_MESSAGE Round 3 - Octagon Weasel'
        }
    }
After completing every elseif for the number of rounds you want, you'll need to close }. And that's it.
The Halley's comet of Armagetron.
ps I'm not tokoyami

User avatar
aP|Nelg
Match Winner
Posts: 593
Joined: Wed Oct 22, 2014 10:22 pm
Contact:

Re: Old CTWF rotation script query

Post by aP|Nelg »

delinquent wrote:
Mon Jul 20, 2020 10:10 pm
I'd also suggest you change the PHP files to something that doesn't rely on another internal host - I'm not aware of anything that can efficiently interpret PHP on-the-fly on Windows that isn't a web server.
I've already mentioned this to you, but for anyone else reading: PHP can be run standalone without the use of a web server and it is available for Windows. I will also note that it's a semi-common choice for ArmagetronAd server scripting, though anything halfway modern will be using the ladderlog and SPAWN_SCRIPT. Unfortunately, the latter is unavailable (to my knowledge) on Windows. There you'd have to pipe input into the script(s) and feed the output into the server yourself.

Under Linux, most servers will be using bash scripts for tasks such as keeping the Armagetron process in a loop so running QUIT will restart the server. The servers run in the background with GNU Screen, with a start/stop script. (Un)fortunately I haven't messed around with running servers under Windows much, so I don't know exactly what all would be necessary there for a similar setup.

syllabear
Shutout Match Winner
Posts: 1023
Joined: Fri Oct 13, 2006 1:37 pm
Location: UK/HK

Re: Old CTWF rotation script query

Post by syllabear »

Hi Nelg, I didn't realise you had so many resources available on your website, thanks for linking!

Also as you found last night, the line

Code: Select all

if (($line -like '*Go (round 1 o*') -and ($line -notlike '*Go (rou* `*') -and ($line -notlike '*:* Go rou*'))


was not fit for purpose. The intention is to read when the round is beginning from the wildlog.txt and change the subsequent map_file. To prevent it reading when players say or use /me "Go (round 6", I use the -notlike with wildcards for the asterix (which is always output during /me) and : (which is output when anyone says anything). Unfortunately it wasn't working for when players said something for some reason, but changing it to

Code: Select all

if (($line -like '*Go (round 1 o*') -and ($line -notlike '*Go (rou* `*') -and ($line -notlike '*:*'))


seems to work.
The Halley's comet of Armagetron.
ps I'm not tokoyami

syllabear
Shutout Match Winner
Posts: 1023
Joined: Fri Oct 13, 2006 1:37 pm
Location: UK/HK

Re: Old CTWF rotation script query

Post by syllabear »

After a bit more work, I have greatly reduced the number of lines of code for the script I am using, as well as made it so the map_file and round_center_message data is retrieved from a .csv file named maplist.csv with the following columns: Round, Map, mapfile and message.

I am still yet to figure a way for the map used for the first round to be reset when the first person enters the server, or for when a second person enters the server and the match resets (in both instances, round 1 plays using whatever the last played map was).

The updated code with several #annotations which explain what is going on or can be removed to output information to the terminal to assist with troubleshooting. As before, the directories will need to be changed.

Code: Select all

$myjob=Start-Job -ScriptBlock {Get-Content "...\tron\sylla\log\wildlog.txt" -tail 1 -wait}

$masterlist = import-csv -path "...\tron\maplist.csv"
#$masterlist | format-table
#above can be used to check the csv has been imported correctly

while ($true) {
    $line = (Get-Job | Receive-Job)
    if (($line -like '*] Go (round *') -and ($line -notlike '*Go (rou* `*') -and ($line -notlike '*:*')) {
        #write-output $line 
        #checks whether $line is correctly receiving the right lines from wildlog.txt at the right time
        
        [int]$roundnum = $line -replace '.*round ([0-9]*) of.*','$1'
        #write-output $roundnum
        #checks whether $roundnum is correctly extracting the correct round number from $line
        
        if ($roundnum -eq '12') {
            [int]$roundnum = '0'
        }
        #this makes sure the script fetches maps for round 1 rather than trying to find a non-existent round 13
        
        $roundmaps = $masterlist | where-object {$_.Round -eq "$($roundnum+1)"}
        #write-output $roundmaps
        #checks whether $roundmaps has extracted the correct set of maps for the next round
        
        $numnextroundmaps = $roundmaps.Count
        #write-output $numnextroundmaps
        #checks whether $numnextroundmaps has correctly identified the number of possible maps in the next round
        
        $maprannum = Get-Random -maximum ($numnextroundmaps)
        #write-output $maprannum
        #checks to see what the random number used to pick the next map is
        
        $nextmap = $roundmaps | where-object {$_.Map -eq "$($maprannum+1)"}
        #write-output $nextmap
        #checks to see which line of csv data $nextmap has picked
        
        $mapfile = $nextmap.mapfile
        #write-output $mapfile
        #checks which map_file is being sent to everytime.cfg
        set-content -path "...\tron\sylla\var\everytime.cfg" -value $mapfile
        
        $nextmessage = $nextmap.message
        #write-output $nextmessage
        #checks to see which round_center_message is being added to everytime.cfg
        add-content -path "...\tron\sylla\var\everytime.cfg" -value $nextmessage
    }
}

EDIT: I have fixed a bit of the code which didn't take into account the rounds resetting after round 12. The correction is now inserted into the above
The Halley's comet of Armagetron.
ps I'm not tokoyami

Post Reply