Need a way to start rotation script when the new match begin
- Al's Used Cars
- On Lightcycle Grid
- Posts: 45
- Joined: Sun Dec 03, 2006 3:22 pm
- Location: Baltimore, MD
Ok, I've read the php intro, read ed's howto (http://forums.armagetronad.net/viewtopi ... p+rotation)
and have formed a definite opinion that I really need a simple example relevant to what I'm trying to do. If I can see it and work with it it may make sense to me. I can tweak it to make it correct, but something to get hands-on with would be very very useful.
Any volunteers?
need
1. a script that reads live player # (=0) and advances round
2. script that reads "match" from center_message and restarts rotation
3. script that reads total live player # and resets rotation (when 2nd live player joins)
it's a linux server, ubuntu. usual cfg, 0.3.0
and have formed a definite opinion that I really need a simple example relevant to what I'm trying to do. If I can see it and work with it it may make sense to me. I can tweak it to make it correct, but something to get hands-on with would be very very useful.
Any volunteers?
need
1. a script that reads live player # (=0) and advances round
2. script that reads "match" from center_message and restarts rotation
3. script that reads total live player # and resets rotation (when 2nd live player joins)
it's a linux server, ubuntu. usual cfg, 0.3.0
- Jonathan
- A Brave Victim
- Posts: 3391
- Joined: Thu Feb 03, 2005 12:50 am
- Location: Not really lurking anymore
I tried to put a ladderlog.txt parser together.
Edit: matchWInner works but I still think matchWinner is better.
Edit 2: the previous edit destroyed my ↓.
Edit 3: improved game.
It lasted less than 27 seconds.
Code: Select all
#!/usr/bin/php
<?php
class LadderLogProcessor {
var $fp;
var $callbacks = array(
'PLAYER_LEFT' => 'playerLeft',
'PLAYER_ENTERED' => 'playerEntered',
'PLAYER_RENAMED' => 'playerRenamed',
'ROUND_SCORE' => 'roundScore',
'DEATH_SUICIDE' => 'deathSuicide',
'DEATH_FRAG' => 'deathFrag',
'DEATH_TEAMKILL' => 'deathTeamkill',
'GAME_END' => 'gameEnd',
'NEW_ROUND' => 'newRound',
'ROUND_WINNER' => 'roundWinner',
'MATCH_WINNER' => 'matchWinner',
'NEW_MATCH' => 'newMatch'
);
function LadderLogProcessor($fp = STDIN) {
$this->fp = $fp;
}
function playerLeft(&$player, &$address) {
echo "$player from $address left\n";
}
function playerEntered(&$player, &$address) {
echo "$player from $address entered\n";
}
function playerRenamed(&$oldName, &$newName, &$address) {
echo "$oldName from $address renamed to $newName\n";
}
function roundScore(&$score, &$player, &$team) {
if(isset($team))
echo "$player from team $team has $score points\n";
else
echo "$player has $score points\n";
}
function deathSuicide(&$player) {
echo "$player committed suicide\n";
}
function deathFrag(&$prey, &$hunter) {
echo "$hunter core dumped $prey\n";
}
function deathTeamkill(&$prey, &$hunter) {
echo "$hunter core dumped teammate $prey\n";
}
function gameEnd() {
echo "game ends\n";
}
function newRound() {
echo "new round\n";
}
function roundWinner(&$team) {
echo "$team won the round\n";
}
function matchWinner(&$team) {
echo "$team won the match\n";
}
function newMatch() {
echo "new match\n";
}
function process() {
for(;;) {
$line = fgetcsv($this->fp, 128, ' ', '');
$callback = $this->callbacks[$line[0]];
if(isset($callback))
$this->$callback($line[1], $line[2], $line[3]);
}
}
}
$llp = new LadderLogProcessor();
$llp->process();
?>
↓PLAYER_ENTERED jonathan 192.168.1.176
NEW_ROUND
NEW_MATCH
DEATH_TEAMKILL latex gdb
DEATH_TEAMKILL gdb latex
DEATH_FRAG gcc jonathan
ROUND_WINNER jonathan
DEATH_FRAG jonathan gcc
ROUND_SCORE 11 jonathan jonathan
PLAYER_LEFT jonathan 192.168.1.176
GAME_END
So that's how to parse it. Next is using that information to do what you want.jonathan from 192.168.1.176 entered
new round
new match
gdb core dumped teammate latex
latex core dumped teammate gdb
jonathan core dumped gcc
jonathan won the round
gcc core dumped jonathan
jonathan from team jonathan has 11 points
jonathan from 192.168.1.176 left
game ends
Edit: matchWInner works but I still think matchWinner is better.
Edit 2: the previous edit destroyed my ↓.
Edit 3: improved game.

jonathan from 192.168.1.176 entered
new round
new match
jonathan core dumped gdb
jonathan core dumped gcc
jonathan core dumped latex
jonathan won the round
jonathan from team jonathan has 19 points
new round
jonathan from team jonathan has 0 points
jonathan from 192.168.1.176 left
game ends
Last edited by Jonathan on Fri May 25, 2007 5:15 pm, edited 1 time in total.
ˌɑrməˈɡɛˌtrɑn
There is a bug somewhere that occasionally occurs that sends "PLAYER_ENTERED ed ip" to ladderlog.txt twice for the same player.
I used to use it on ctwf to count the number of players who were on the grid so the ladders wouldn't be added to if there was <2 players aboard.
I would start the server and parser with the same script with num_players=0;
add one to it when PLAYER_ENTERED and take one away when PLAYER_LEFT.
After time, sometimes a day or more, it would become wrong. I tracked it down to
PLAYER_ENTERED ed ip
PLAYER_ENTERED ed ip
PLAYER_LEFT ed ip
being in the ladderlog.txt. Though not grouped together like that.
I never worked out why it happened and was not able to recreate it. But it did, and it messed up what I was trying to do with it.
From what you've descibed it will mess up yours too.
Depending on how busy your server is, it may not effect you, but you ought to be aware of it.
I used to use it on ctwf to count the number of players who were on the grid so the ladders wouldn't be added to if there was <2 players aboard.
I would start the server and parser with the same script with num_players=0;
add one to it when PLAYER_ENTERED and take one away when PLAYER_LEFT.
After time, sometimes a day or more, it would become wrong. I tracked it down to
PLAYER_ENTERED ed ip
PLAYER_ENTERED ed ip
PLAYER_LEFT ed ip
being in the ladderlog.txt. Though not grouped together like that.
I never worked out why it happened and was not able to recreate it. But it did, and it messed up what I was trying to do with it.
From what you've descibed it will mess up yours too.
Depending on how busy your server is, it may not effect you, but you ought to be aware of it.
- Al's Used Cars
- On Lightcycle Grid
- Posts: 45
- Joined: Sun Dec 03, 2006 3:22 pm
- Location: Baltimore, MD
I seem to be missing step one somewhere... this is a parser for "ladderlog"... how about won_matches.txt or won_rounds.txt, where it simply looks for new entries?
1. should I copy the relevant parts of the script you provided, Jonathan, and save it as a plain text file with the extension ".php" in the server's "/bin" folder?
1a. Once I do that, will it run automatically each time the server restarts, or do I need to start it with some particular command? I can add the command to the macro I currently use to start the server.
1b. It looks to me like it produces a text output. How does the text output become console input (cmd line input, or however you say it), that affects the game? As you say, the next step.
2. Hm, Ed- you said that after a certain time period, depending on traffic, the player count would be fouled up... possibly this could be a result of two players with the same IP... regardless, is there a built in command to restart the server after a certain idle period, like the command to kill it?
1. should I copy the relevant parts of the script you provided, Jonathan, and save it as a plain text file with the extension ".php" in the server's "/bin" folder?
1a. Once I do that, will it run automatically each time the server restarts, or do I need to start it with some particular command? I can add the command to the macro I currently use to start the server.
1b. It looks to me like it produces a text output. How does the text output become console input (cmd line input, or however you say it), that affects the game? As you say, the next step.
2. Hm, Ed- you said that after a certain time period, depending on traffic, the player count would be fouled up... possibly this could be a result of two players with the same IP... regardless, is there a built in command to restart the server after a certain idle period, like the command to kill it?
- wrtlprnft
- Reverse Outside Corner Grinder
- Posts: 1679
- Joined: Wed Jan 04, 2006 4:42 am
- Location: 0x08048000
- Contact:
Yes there is: DEDICATED_IDLE is the time in hours since startup the server will wait before shutting down, but only if there's no clients connected to it. If there are clients it waits for the last one to leave before shutting down.
Usually you have a script to restart the server once it quits, of course.
Usually you have a script to restart the server once it quits, of course.
There's no place like ::1
- Al's Used Cars
- On Lightcycle Grid
- Posts: 45
- Joined: Sun Dec 03, 2006 3:22 pm
- Location: Baltimore, MD
- wrtlprnft
- Reverse Outside Corner Grinder
- Posts: 1679
- Joined: Wed Jan 04, 2006 4:42 am
- Location: 0x08048000
- Contact:
you can do that as a little shell script:Put it anywhere you like, then run it withIt will restart your server if it exits without an error, meaning you can do /admin quit ingame and it will restart.
You will lose the ability to directly write commands to the console, though (use /login and /admin or everytime.cfg), and if you kill the startup script (by pressing CTRL-C on the console it's running on, for example) it may not actually terminate the server, you'll have to do that yourself if it's still running.
Oh, and if you put the QUIT command in settings_custom.cfg or about any other config file your server will keep restarting.
Code: Select all
#!/bin/sh
while <insert command you use to start your server here>
do
echo "Restarting server"
done
Code: Select all
sh /path/to/the/script.sh
You will lose the ability to directly write commands to the console, though (use /login and /admin or everytime.cfg), and if you kill the startup script (by pressing CTRL-C on the console it's running on, for example) it may not actually terminate the server, you'll have to do that yourself if it's still running.
Oh, and if you put the QUIT command in settings_custom.cfg or about any other config file your server will keep restarting.
There's no place like ::1
- Al's Used Cars
- On Lightcycle Grid
- Posts: 45
- Joined: Sun Dec 03, 2006 3:22 pm
- Location: Baltimore, MD
I feel bad:
I should have explained more distinctly that the server is a remote-admin server, and not hosted on my computer at all. I use ssh to log in through terminal for cmd line ops and cyberduck to do file manipulation.
I can come up with a routine that opens terminal and enters the reboot cmd at specified times: the trouble would be if there are players in it at the time. Instant pissed-off players.
I've been thinking over the cfg setup and think I see some ways that I can address the root issues, without having an external script. Possibly clumsy, but they may work. Has to do with timing and changing cmd line order.
have a great vacation, wrtl. Have a margarita or 4 for me.
I should have explained more distinctly that the server is a remote-admin server, and not hosted on my computer at all. I use ssh to log in through terminal for cmd line ops and cyberduck to do file manipulation.
I can come up with a routine that opens terminal and enters the reboot cmd at specified times: the trouble would be if there are players in it at the time. Instant pissed-off players.

I've been thinking over the cfg setup and think I see some ways that I can address the root issues, without having an external script. Possibly clumsy, but they may work. Has to do with timing and changing cmd line order.
have a great vacation, wrtl. Have a margarita or 4 for me.
- philippeqc
- Long Poster - Project Developer - Sage
- Posts: 1526
- Joined: Mon Jul 12, 2004 8:55 am
- Location: Stockholm
- Contact:
Simply re-reading Wrt's 2 previous post:
DEDICATED_IDLE : After this many hours without players online, the server will quit.
Reading wrt's script: As long as the server quits without error, such as an admin request or DEDICATED_IDLE timeout, print a lil message and restart the server.
No player pissed, no differences between a locally or remotely administered server, just plain results!
Is someone posting this information on the wiki?
-ph
DEDICATED_IDLE : After this many hours without players online, the server will quit.
Reading wrt's script: As long as the server quits without error, such as an admin request or DEDICATED_IDLE timeout, print a lil message and restart the server.
No player pissed, no differences between a locally or remotely administered server, just plain results!
Is someone posting this information on the wiki?
-ph
Canis meus id comedit.
- Al's Used Cars
- On Lightcycle Grid
- Posts: 45
- Joined: Sun Dec 03, 2006 3:22 pm
- Location: Baltimore, MD
this is nice and everything, but I feel it's not getting any closer to my goal of finding a way to restart rotation on cmd, without affecting any players currently in the server like a reboot would.
is there a cmd comparable to the one that resets scoring on match end that can be adapted with the same parameters?
if need be, i will recompile with a patch to provide the functionality that may be missing.
is there a cmd comparable to the one that resets scoring on match end that can be adapted with the same parameters?
if need be, i will recompile with a patch to provide the functionality that may be missing.
- Al's Used Cars
- On Lightcycle Grid
- Posts: 45
- Joined: Sun Dec 03, 2006 3:22 pm
- Location: Baltimore, MD
- philippeqc
- Long Poster - Project Developer - Sage
- Posts: 1526
- Joined: Mon Jul 12, 2004 8:55 am
- Location: Stockholm
- Contact:
Rather than counting PLAYER_ENTERED and PLAYER_LEFT, why not use a map (the data structure/collection)? Upon entry, add the player to the map. Upon leaving, remove the player from the map. Maps allows an element to be present at most once, and the second PLAYER_ENTERED would not be inserted.ed wrote:I tracked it down to
PLAYER_ENTERED ed ip
PLAYER_ENTERED ed ip
PLAYER_LEFT ed ip
-ph
Canis meus id comedit.
- Al's Used Cars
- On Lightcycle Grid
- Posts: 45
- Joined: Sun Dec 03, 2006 3:22 pm
- Location: Baltimore, MD
- Jonathan
- A Brave Victim
- Posts: 3391
- Joined: Thu Feb 03, 2005 12:50 am
- Location: Not really lurking anymore
Just to continue in PHP, maps are very easy to use there because array keys can be strings and are kept unique.
If you do that the script will have to output console commands.
Code: Select all
<?php
class PlayerCounter {
var $players = array();
function add($player) {
$this->players[$player] = 1;
}
function remove($player) {
unset($this->players[$player]);
}
function count() {
return count($this->players);
}
};
function printStats(&$pc) {
echo $pc->count()."\n";
foreach($pc->players as $name => $bogus)
echo "$name\n";
}
$pc = new PlayerCounter;
printStats($pc);
$pc->add('Jonathan');
printStats($pc);
$pc->add("Al's Used Cars");
printStats($pc);
$pc->add('Jonathan');
printStats($pc);
$pc->remove('Jonathan');
printStats($pc);
?>
Regarding map rotation, you'll have to send input to the server when you want a new map. You can pipe the script's output to the server:0
1
Jonathan
2
Jonathan
Al's Used Cars
2
Jonathan
Al's Used Cars
1
Al's Used Cars
Code: Select all
script | armagetronad-dedicated
ˌɑrməˈɡɛˌtrɑn
- philippeqc
- Long Poster - Project Developer - Sage
- Posts: 1526
- Joined: Mon Jul 12, 2004 8:55 am
- Location: Stockholm
- Contact:
Hi,
I only know maps from Java and C++, but I'm quite sure php has them.
Arrays, like maps, are collections. They allow you to store many objects and to retreive them. To retreive an object in an array, you need to know its position. Arrays are usefull when most of the positions are in use, and it is easy to deduce the position of a desired object from its key (an information used to identify the object), such as cases where the key is the position.
For cases where using an array would leave many unused position (think of storing the current players and using their social security number as the key), or where computing the position is impossible (very players would like to leave their social security numbers, leaving you to use their nick as the key, but what is the position for "ed" or "philippeqc"?), maps are quite convenient.
Lets just keep away of "how a maps does it" and just accept that from a key, a map can retreive the associated object without needing to allocate place for all the possible keys, and that keys can be nearly anything, such as numerical values, strings or objects.
Another property of maps is that it will have a one to one mapping between a given key and an object. A key cannot be reused to point to a different object.
Using this, when a player joins, you could use his nick as the key and mark him present. When the player leave, you remove the key from the map. Maps normally have a method that allow you to know the number of keys-object pairs stored, so you can always know the number of players at any time.
The problem that ed observed is the double joining of a player. This is not an issue with maps. Each time a player is marked as joining, you'd attempt to add him. If he is already there, you simply discard the new request. Even multiple leave message would not cause problem, as the map would simply give you an error message when you would try to remove an non-existant player. The count of players should remain quite accurate, as the only thing that could put it of balance is losing the leave notification of a player. It would be restored the next time this player joins.
I hope this help you.
-ph
I only know maps from Java and C++, but I'm quite sure php has them.
Arrays, like maps, are collections. They allow you to store many objects and to retreive them. To retreive an object in an array, you need to know its position. Arrays are usefull when most of the positions are in use, and it is easy to deduce the position of a desired object from its key (an information used to identify the object), such as cases where the key is the position.
For cases where using an array would leave many unused position (think of storing the current players and using their social security number as the key), or where computing the position is impossible (very players would like to leave their social security numbers, leaving you to use their nick as the key, but what is the position for "ed" or "philippeqc"?), maps are quite convenient.
Lets just keep away of "how a maps does it" and just accept that from a key, a map can retreive the associated object without needing to allocate place for all the possible keys, and that keys can be nearly anything, such as numerical values, strings or objects.
Another property of maps is that it will have a one to one mapping between a given key and an object. A key cannot be reused to point to a different object.
Using this, when a player joins, you could use his nick as the key and mark him present. When the player leave, you remove the key from the map. Maps normally have a method that allow you to know the number of keys-object pairs stored, so you can always know the number of players at any time.
The problem that ed observed is the double joining of a player. This is not an issue with maps. Each time a player is marked as joining, you'd attempt to add him. If he is already there, you simply discard the new request. Even multiple leave message would not cause problem, as the map would simply give you an error message when you would try to remove an non-existant player. The count of players should remain quite accurate, as the only thing that could put it of balance is losing the leave notification of a player. It would be restored the next time this player joins.
I hope this help you.
-ph
Canis meus id comedit.