( search forums )
Help needed with autobalance script
Soldat Forums - Server Talk - Server Help
Leo
January 24, 2006, 9:05 pm
This is from mar77a:

 Quote:Okey i dont know what is wron with this code, i need someone that is smart and knows PHP to check what's wrong with this:

so, the code is composed of three files:
config.inc.php
<?

$servip = "24.232.139.227"; // Server IP
$servport = "23073"; // Server Port
$servpwd = "hola"; // Server Admin Password
$refresh = "30"; // Refresh interval in seconds

?>

function.php

<?

function GetSoldatInfo(&$sock) {
if (!$sock) return false;
$info = array(
'gamemode' => 0,
'teammode' => false,
'pointmode' => false,
'players' => 0,
'spectators' => 0,
'map' => '',
'timelimit' => 0,
'currenttime' => 0,
'timeleft' => 0,
'limit' => 0,
'player' => array(),
'spectator' => array(),
'team' => array()
);

// Temporary array for players
$players = array();
for ($i = 0; $i < 32; $i++)

// Get player names
for ($i = 0; $i < 32; $i++)

// Get player teams
for ($i = 0; $i < 32; $i++)

// Get player kills
for ($i = 0; $i < 32; $i++)

// Get player deaths
for ($i = 0; $i < 32; $i++)

// Get player pings
for ($i = 0; $i < 32; $i++)

// Get player IDs
for ($i = 0; $i < 32; $i++)

// Get player IPs
for ($i = 0; $i < 32; $i++)

// Get team scores
for ($i = 1; $i < 5; $i++)

// Get map name
$data = fread($sock, 17);
$len = ord($data[0]);
$info['map'] = substr($data, 1, $len);

// Get time limit & current time, and form timeleft
$data = unpack("V", fread($sock, 4));
$timelimit = $data[1];
$info['timelimit'] = $timelimit;
$data = unpack("V", fread($sock, 4));
$currenttime = $data[1];
$info['currenttime'] = $timelimit - $currenttime;
$timeleft = $currenttime;
$temp = (floor($timeleft / 60) % 60);
$info['timeleft'] = floor($timeleft / 3600) . ':' .
($temp < 10 ? '0' : '') . $temp;

// Get kill limit
$data = unpack("v", fread($sock, 2));
$limit = $data[1];
$info['limit'] = $limit;

// Get gamestyle
$data = fread($sock, 1);
$gamestyle = ord($data);
$info['gamemode'] = $gamestyle;
if ($gamestyle == 2 || $gamestyle == 3 || $gamestyle ==
5 || $gamestyle == 6)
if ($gamestyle != 2)

foreach ($players as $player)

return $info;
}

?>

script.php

<?

// PASS IP PORT

include("function.php");
include("config.inc.php");

if(!$servip || !$servport || !$servpwd || !$refresh){
die("Configuration required. (1x00f)");
}

$s = @fsockopen($servip, $servport);

if(!$s){
echo "Couldn't conect to server.";
exit;
}else{

$info = array();

fwrite($s, "$servpwd\r\n");

fwrite($s, "REFRESH\r\n");

while(1) {

$data = trim(fgets($s, 1024));

if(eregi("password", $data)){
echo "Wrong admin password.";
exit;
}

if($data == "REFRESH"){

$info = GetSoldatInfo($s);

break;

}

}

if(!$info){

die("Error: Couldn't retrieve data from server.");

}else{

$numplayers = count($info['player']);

if($numplayers > 0) else


echo "\n<br>- Refresh in $refresh seconds - ";
fclose($s);
}
}


?>


Leo
January 25, 2006, 3:01 pm
I am gonna pay 15 ? for this together with another small script I need. Contact me if you're interested.
Cancelled, I am broke :P

FliesLikeABrick
January 25, 2006, 4:12 pm
I'll try and write a perl script to do it if I have some free time. Maybe I'll get to it this weekend after U13 is back online

Leo
January 25, 2006, 6:46 pm
Alright, please keep in mind, you or anyone else that want to try that I can not execute scripts locally on server. It must run on another place and connect to the Soldat dedicated.

FliesLikeABrick
January 25, 2006, 8:50 pm
yeah, doesn't matter as long as you have the admin connection enabled

SERIAL KILLeR
January 25, 2006, 10:06 pm
i think the Extended Soldat Admin can do that

FliesLikeABrick
January 25, 2006, 10:08 pm
heh yeah it looks like it does

Leo
January 26, 2006, 4:39 am
People.... you think I have not tried everything before I ask for help ? ESA has a lot of bugs with the most important one, it crashes my servers. MSAT also has an autobalance feature but I have no idea on how to work this program, it's confusing. I only need one feature: autobalance, better to be done by an internal check by the server, if the script is running, and not by a command.

FliesLikeABrick
January 26, 2006, 4:48 am
Alright, I will try and get around to working on it for you then

Leo
February 5, 2006, 8:11 pm
Ehmm.... any news on this ??

Deleted User
February 5, 2006, 10:11 pm
Hmm...This would really be great,
hope you can find any free time to do this.

Yay for balanced publics.

FliesLikeABrick
February 6, 2006, 1:59 am
no, sorry... school is breaking me :-/ I'll try and find someone else to look into it if i can't

mar77a
February 6, 2006, 9:04 pm
oh dang, i guess i can do this but i dont have internet on my computer, you can wait like 2 weeks if you still want to.

Leo
February 7, 2006, 4:26 pm
That would be nice mar77a. If someone else make it before I'll tell you.

Deleted User
February 11, 2006, 5:15 pm
I am running a CTF server with player limit at 12.
I have problems with teams just like Leo. I checked your server and I agree.

Please we who have CTF servers need an autobalace script!


sgt. dinler

mar77a
February 14, 2006, 9:08 pm
Im getting internet on thursday, the question is, Leo, did that no-multi-run stuff worked with the player validator script?

Leo
February 14, 2006, 10:07 pm
 Quote:Originally posted by mar77aIm getting internet on thursday, the question is, Leo, did that no-multi-run stuff worked with the player validator script?


Some failures now and then but in general it's doing it's job.

bja888
February 18, 2006, 5:06 am
Dude! Great minds think alike...
I'm working on a server admin panel that features that and other very useful commands like shuffle teams. I call it Soldat Democracy (or soldom). Ran for the people by the people :) The only problem though, I cant get connected the server 100%. Once I can do that though, it wont take me very long to get it working.
http://www.soldatforums.com/topic.asp?topic_id=31894

Program requires .net framework 1.1 or later :)
Be sure you have it.



mar77a
February 22, 2006, 5:14 pm
[MAIN POST]

Leo
February 22, 2006, 5:30 pm
I am using it and it works fine.I have it run like a cron job every 2 minutes. The only thing it needs is to switch people with lowest score.

bja888
February 22, 2006, 8:48 pm
grrrrrrr. php is sooo unstructured....

bja888
February 23, 2006, 5:36 am
mar77a, without knowing it (or maybe you did) you provided the missing link for my admin program. I can now retrieve name, team and kills but still working on the rest. For now though there is a small problem. Your script pulls 25 bytes of data 32 times. Max char length by max players. I was originally trying to pull all the data for each player on each read. Now that I fallowed suit, missing players give some really f***ed up results. Even worse, there is no pattern or similar elements to override the read value to an empty string. Same with the kills value but strangely enough not the team value...

Have you noticed this as well? Do you think you could be having the same problem?
Post the output of the script so I can have a look at it. My server only runs ASP.NET so I can not run it.

mar77a
February 23, 2006, 12:40 pm
i thougth missing players gave empty strings (?)

bja888
February 23, 2006, 3:21 pm
I wish... every 25 bytes is drffrent. Some come out to be empty other come out to be random crap. See if you can modify that script to give palyer output.

mar77a
February 23, 2006, 3:48 pm
It works in PHP, i¿ve already tested it: http://m00.u13.net

Leo
February 23, 2006, 5:53 pm
That's all nice but how about modifing the script to switch the players with low score ? I have checked this post already twice for no reason :P

mar77a
February 23, 2006, 6:05 pm
I know, that's the reason i posted the hole stuff, maybe you should change the topic title...

Leo
February 23, 2006, 6:19 pm
 Quote:Originally posted by mar77aI know, that's the reason i posted the hole stuff, maybe you should change the topic title...


To what ?

mar77a
February 23, 2006, 6:21 pm
Help with PHP Script. An put the script in the main post

bja888
February 24, 2006, 12:25 am
I hate php, I'll have a look at it though... While your php script might be a temp solution. My Program will have more options.

Leo
February 24, 2006, 5:39 am
Since I have the option to run a .php soldat admin script like a cron job I prefer them over any other kind of program. Why ? because I "fire and forget" them. I do not need to be 24/7 connected to my server. ;)

bja888
February 24, 2006, 6:10 am
This is the way I see it, correct me if I am wrong...

1) I server side language (such as php) will only run when the page is accessed.
Thus, in order to maintain you must keep at least one browser window open at all times.
2) The web is stateless environment.
Thus you cannot keep variables like who is the last person that joined. You also cannot detect those people who switch over to the winning team.
3) I could be wrong but you can put a program in the icon tray.
It would be much easier to let the soldat admin run in the background.

Leo
February 24, 2006, 6:18 am
 Quote:Originally posted by bja888This is the way I see it, correct me if I am wrong...

1) I server side language (such as php) will only run when the page is accessed.
Thus, in order to maintain you must keep at least one browser window open at all times.
2) The web is stateless environment.
Thus you cannot keep variables like who is the last person that joined. You also cannot detect those people who switch over to the winning team.
3) I could be wrong but you can put a program in the icon tray.
It would be much easier to let the soldat admin run in the background.


1.Since I rend a web server for my forums I have the current script run like a cron job every 2 minutes. The script connect to server and check if the teams are even. If they are not it switches the players and then disconnect. No need to keep a web page open at all times.
2. If you could make it switces the players with lowest score it would be nice.
3. My servers are 24/7 online and I am not.

bja888
February 24, 2006, 11:31 am
Define "cron job".

I have been working web development for 5 years, asp for 3 and .net for 1. I have yet to find a way to execute a server script without opening it.

bja888
February 24, 2006, 11:39 am
By the way, to fix the php script you need to pass an array of players scores and their ID. At this point the only thing that is passed is the server info such as game type.

Unless you can add an array of players to the array of info. (Extreamly bad programming practice) You will have to re-structure the entire script... why are you tring to add functions to a non OOP language? wait... who made that script any way?

mar77a
February 24, 2006, 5:26 pm
I made that script, first of all, im sorry if you dont like PHP.

I have already tried sorting the array using the player's ID but hte problem is, the player that joins the last to a server doesnt always get the higher or lower id.

BTW, Leo, have you tried using the script i posted? I mean, the last version?

bja888
February 24, 2006, 6:19 pm
Actually, all you need is player ID and kills. All you need to record is the lowest value for each team. Trash the rest of the array and append that to your info array. Then count up the teams and if something is off, do something about it.

bja888
February 24, 2006, 6:20 pm
 Quote:Originally posted by mar77aI made that script, first of all, im sorry if you dont like PHP.

I have already tried sorting the array using the player's ID but hte problem is, the player that joins the last to a server doesnt always get the higher or lower id.

BTW, Leo, have you tried using the script i posted? I mean, the last version?

Wait... are yopu saying it already works?

mar77a
February 24, 2006, 6:34 pm
It works, but i dont know it it switches the guy with the lower score.

Leo
February 24, 2006, 6:57 pm
It switces the player with higher ID but as you said this player is not always the one with lowest score or the one that last joined the server.

bja888
February 24, 2006, 7:08 pm
 Quote:Originally posted by bja888Define "cron job".

I have been working web development for 5 years, asp for 3 and .net for 1. I have yet to find a way to execute a server script without opening it.


Please reply leo, I wanna make sure we are on the same page.

Leo
February 24, 2006, 7:17 pm
 Quote:Originally posted by bja888 Quote:Originally posted by bja888Define "cron job".

I have been working web development for 5 years, asp for 3 and .net for 1. I have yet to find a way to execute a server script without opening it.


Please reply leo, I wanna make sure we are on the same page.


Hmmm... what can I say ? Google cron job and you'll see what I mean.

bja888
February 24, 2006, 9:23 pm
Your hosting allows you to add services to the runtime? I bet it supports spamming too ;)

Well then you don't put the program on the server? Oh and yes, I will be working on a linux version :)

Deleted User
February 24, 2006, 11:56 pm
LOL even I knew what Cron Jobs were for when I didnt even know how to echo somthing in PHP...

Cron Jobs just allow you to execute a bash command at any minute of any day and email the output somwhere, hence why 'Cron' is short for Cronological..

GAMEOVER
February 25, 2006, 5:21 am
I put money on it we see it in ARSSE sometime *cough*KeFear

bja888
February 25, 2006, 6:12 am
Sorry, there is no money in linux systems.

Hence why I write ASP.NET and am running a legal version of windows server 2003 in the room next door. I have had to work with php in the past few months because two of my clients are running a linux host. So weather or not I know what a cron job is, really doesn't matter to me.

I'm sure you can just as easily take the linux version of the program I am writing and run that on the server.

Ether way, you should find something better to do with your time then fallowing me around the forum trying to trip me up.

Deleted User
February 25, 2006, 6:45 am
 Quote:Originally posted by bja888Sorry, there is no money in linux systems.

Somone forgot to do their homework... I guess thats why every decent dedicated server hosting company (or any internet related business) use linux.

Leo
February 25, 2006, 7:43 am
Please guys, this is not the place for you two to solve your differences. This thread has another purpose. Any help on the autobalance script ?

bja888
February 25, 2006, 6:26 pm
 Quote:Originally posted by EnEsCe Quote:Originally posted by bja888Sorry, there is no money in linux systems.

Somone forgot to do their homework... I guess thats why every decent dedicated server hosting company (or any internet related business) use linux.


This is true. Most people don't care enough about their website to make it efficient. Where as my e-commerce site (the one that show people before I build theirs) uses techniques that are not possible with a linux host. Such as precompiling the code for all the pages and placing it in the "bin" folder so It can be accessed from every page within the site with out using paths. Relative or Absolute.

Everyone and their mother offers linux hosting. I want to high school with someone who did. I even know a 14 year old who has 3 linux servers in his house. He gives out free hosting. Like I said... No money in linux systems.

Don't get me wrong, I'm going to dual partition my hard drive on my 64x computer to run windows xp 64x and fedora core 4. I do simple things in linux such as rendering but that's it.

Leo
February 26, 2006, 12:46 pm
mara, could you at least add a "/say Teams are now balanced" command after the switch ? Because people change teams and they don't know why. I get a lot of "wtf?" :)

mar77a
February 26, 2006, 2:31 pm
http://www.soldatforums.com/topic.asp?topic_id=32015