I try to write a script.

This is the place where you can find everything related to the dedicated server, control scripts and community tools.

Moderators: Pit Crew, TM-Patrol

Post Reply
User avatar
lgrfbs-sweden
smooth traffic navigator
smooth traffic navigator
Posts: 200
Joined: 15 Apr 2007 15:48
Owned TM-games: TMN
Location: Sweden
Contact:

I try to write a script.

Post by lgrfbs-sweden » 21 Mar 2008 18:16

Hi, I run in some problems with this code, can anyone see if I done some big errors in there.
The script shall only dump the nickname, login & number of player to a file.

Code: Select all

<?php
// Count the players for the systembar graph.
// Version: 0.0.0.0
// Beta: 0.0.0.3
// Date: 2008-03-21
// _____________________________________________________

Aseco::registerEvent('onStartup', 'init_sp');
Aseco::registerEvent("onPlayerConnect", "PlayerPlus");
Aseco::registerEvent("onPlayerDisconnect", "PlayerMinus");

// Setup -------------------------
$SaveFolder="/home/subfil/Aseco/plugins/stat-players";
$SaveToFile=$SaveFolder."/No_of_players.txt"; 
// Only a filename will put the file in same folder as the script is in.
//--------------------------------
// the "$aseco->console_text" do not work here, use "print" instead.
print "plugin.players.lgrfbs.php} start ------------------------------\n";
print "plugin.players.lgrfbs.php} Write to:".$SaveToFile."\n";





function init_sp(&$aseco){
 $aseco->console_text ("plugin.players.lgrfbs.php} init_sp.");
 if (!is_dir($SaveFolder))
 {
  $aseco->console_text ("plugin.players.lgrfbs.php} Make a dir for the files.");
  mkdir('stat-players', 0777);
  $aseco->console_text ('plugin.players.lgrfbs.php} Done.');
 }
}





function PlayerPlus(&$aseco, $player){
 $aseco->console_text ('plugin.players.lgrfbs.php} PlayerPlus');
 $Gamers=0;
 $nickname = $player->nickname;
 $aseco->console_text ('plugin.players.lgrfbs.php} Nick:'.$nickname);
 $login= $player->login;
 $aseco->console_text ('plugin.players.lgrfbs.php} Login:'.$login);
               
 // exist file?
 if (file_exists($SaveToFile)) 
 {
  $aseco->console_text ("plugin.players.lgrfbs.php} The file".$SaveToFile." exists");


  // Read the file number of Gamers
  $Index=0;
  $aseco->console_text ('plugin.players.lgrfbs.php} open file for reading.');
  $fh = fopen($SaveToFile, 'r');
  // while ( $line = fgets($fh, 1000) ) 
  //  {
  while(!feof($fh))
  {
   $Index=$Index+1;
   $line=fgets($fh);
   if ($Index==1){}
   if ($Index==2){$Gamers=$line;}
   $aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
   $aseco->console_text ("plugin.players.lgrfbs.php} ".$Index);
   $aseco->console_text ("plugin.players.lgrfbs.php} ".$line);
  }
  $aseco->console_text ("plugin.players.lgrfbs.php} Close file.");
  fclose($fh);
 } else {
 $aseco->console_text ("plugin.players.lgrfbs.php} The file ".$SaveToFile." does not exist");
 }
  

 // Add a player to ...
 $Gamers=$Gamers+1;
 $aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);


 // Write new data into file
 $Data_01="Player: ". $login." Nick:".$nickname;
 $aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
 $aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
 $fhh = fopen($SaveToFile, 'w');// or die("can't open file");
  fwrite($fhh, $Data_01."\n");
  fwrite($fhh, $Gamers."\n");
 fclose($fhh);
}





function PlayerMinus(&$aseco, $Player){
$aseco->console_text ("plugin.players.lgrfbs.php} PlayerMinus");
 $nickname = $player->nickname;
 $aseco->console_text ("plugin.players.lgrfbs.php} Nick:".$nickname);
 $login= $player->login;
 $aseco->console_text ("plugin.players.lgrfbs.php} Login:".$login);
// Read the file
//
// 
// Subd a player to ...
// $Gamers=$Gamers-1;
// if ($Gamers<0){$Gamers=0;}
//
// Write new data into file
// open (MYFILE, '>No_of_players.txt');
//  print MYFILE $Data_01."\n";
// close (MYFILE);
}
// the "$aseco->console_text" do not work here, use "print" instead.
print "plugin.players.lgrfbs.php} End --------------------------------\n";
?>
what are working:
* the folder is create with the right property.
* The script can read the Nickname & login.
* Debug text show up in the aseco.log file.

what are not working for me:
write the file "No_of_players.txt" in the create folder.
Admin On:Image
My server:lgrfbs server / XASECO plugins
Image

User avatar
w1lla
TM-Patrol
TM-Patrol
Posts: 1466
Joined: 23 May 2007 07:20
Owned TM-games: TMU, TMN, TMF
Manialink(s): intr
Location: Venray

Re: I try to write a script.

Post by w1lla » 21 Mar 2008 20:26

Hi there fixed the code so that it writes the .txt but it wont add data in it butif u look in the aseco logs its says that it opens so u online need to find a way to write it supposedly its fwrite but that online adds the lines but for some help i can give u a link to this http://nl3.php.net/fwrite

Code: Select all

<?php
// Count the players for the systembar graph.
// Version: 0.0.0.0
// Beta: 0.0.0.3a
// Date: 2008-03-21
//edited by w1lla
// _____________________________________________________

Aseco::registerEvent('onStartup', 'init_sp');
Aseco::registerEvent("onPlayerConnect", "PlayerPlus");
Aseco::registerEvent("onPlayerDisconnect", "PlayerMinus");

// Setup -------------------------
$SaveFolder="/home/subfil/Aseco/plugins/stat-players";
$SaveToFile="No_of_players.txt"; 
// Only a filename will put the file in same folder as the script is in.
//--------------------------------
// the "$aseco->console_text" do not work here, use "print" instead.
print "plugin.players.lgrfbs.php} start ------------------------------\n";
print "plugin.players.lgrfbs.php} Write to: ".No_of_players.txt."\n";





function init_sp(&$aseco){
$aseco->console_text ("plugin.players.lgrfbs.php} init_sp.");
if (!is_dir($SaveFolder))
{
  $aseco->console_text ("plugin.players.lgrfbs.php} Make a dir for the files.");
  mkdir('stat-players', 0777);
  $aseco->console_text ('plugin.players.lgrfbs.php} Done.');
}
}

function PlayerPlus(&$aseco, $player){
$aseco->console_text ('plugin.players.lgrfbs.php} PlayerPlus');
$Gamers=0;
$nickname = $player->nickname;
$aseco->console_text ('plugin.players.lgrfbs.php} Nick:'.$nickname);
$login= $player->login;
$aseco->console_text ('plugin.players.lgrfbs.php} Login:'.$login);
   
// Write new data into file
$Data_01="Player: ". $login." Nick:".$nickname;
$aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
$aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
$fp = fopen(No_of_players.txt, 'a'); //or die("can't open No_of_players.txt");
  fwrite($fp,No_of_players.txt, $Data_01."a");
  fwrite($fp,No_of_players.txt, $Gamers."a");
fclose($fp);
   
// exist file?
if (file_exists(No_of_players.txt)) 
{
  $aseco->console_text ("plugin.players.lgrfbs.php} The file ".No_of_players.txt." exists");

  // Read the file number of Gamers
  $Index=0;
  $aseco->console_text ('plugin.players.lgrfbs.php} open file for reading.');
  $fp = fopen(No_of_players.txt, 'r');
   while ( $line = fgets($fp, 1000) ) 
  //  {
  while(!feof($fp))
  {
   $Index=$Index+1;
   $line=fgets($fp);
   if ($Index==1){}
   if ($Index==2){$Gamers=$line;}
   $aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
   $aseco->console_text ("plugin.players.lgrfbs.php} ".$Index);
   $aseco->console_text ("plugin.players.lgrfbs.php} ".$line);
  }
$aseco->console_text ("plugin.players.lgrfbs.php} The file ".No_of_players.txt." does not exist");
}
  

// Add a player to ...
$Gamers=$Gamers+1;
$aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
}

function PlayerMinus(&$aseco, $Player){
$aseco->console_text ("plugin.players.lgrfbs.php} PlayerMinus");
$nickname = $player->nickname;
$aseco->console_text ("plugin.players.lgrfbs.php} Nick:".$nickname);
$login= $player->login;
$aseco->console_text ("plugin.players.lgrfbs.php} Login:".$login);

// Read the file

// Subd a player to ...
$Gamers=$Gamers-1;
if ($Gamers<0){$Gamers=0;}
$aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);

// Write new data into file
$Data_01="Player: ". $login." Nick:".$nickname;
$aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
$aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
$fp = fopen(No_of_players.txt, 'a'); //or die("can't open No_of_players.txt");
  fwrite($fp,No_of_players.txt, $Data_01."a");
  fwrite($fp,No_of_players.txt, $Gamers."a");
fclose($fp);
}
// the "$aseco->console_text" do not work here, use "print" instead.
print "plugin.players.lgrfbs.php} End --------------------------------\n";
?>

Code: Select all

tmnforever is nations and united makes it special. tmnforever has united. I need united!

User avatar
lgrfbs-sweden
smooth traffic navigator
smooth traffic navigator
Posts: 200
Joined: 15 Apr 2007 15:48
Owned TM-games: TMN
Location: Sweden
Contact:

Re: I try to write a script.

Post by lgrfbs-sweden » 22 Mar 2008 10:41

thanks w1lla for the help, I have now a working version but I do not get the "fopen", "fwrite" & "fclose" to work for write to file, so I cheat with
"system('echo '.$Data_01.' > '.$SaveToFile);" but for read the file the "fopen", "fwrite" & "fclose" works fine, this is strange to me.
Admin On:Image
My server:lgrfbs server / XASECO plugins
Image

User avatar
w1lla
TM-Patrol
TM-Patrol
Posts: 1466
Joined: 23 May 2007 07:20
Owned TM-games: TMU, TMN, TMF
Manialink(s): intr
Location: Venray

Re: I try to write a script.

Post by w1lla » 23 Mar 2008 10:50

well i got a strange problem that it would give this in aseco log

Code: Select all

plugin.players.lgrfbs.php} PlayerPlus
plugin.players.lgrfbs.php} Nick:$000[GRC]$fffW1lla
plugin.players.lgrfbs.php} Login:hateitorluvitnl
plugin.players.lgrfbs.php} Data_01:Player: hateitorluvitnl Nick:$000[GRC]$fffW1lla
plugin.players.lgrfbs.php} Open - Write to file
plugin.players.lgrfbs.php} The file No_of_playerstxt exists
plugin.players.lgrfbs.php} open file for reading.
plugin.players.lgrfbs.php} The file No_of_playerstxt does not exist
plugin.players.lgrfbs.php} Gamers:1
[03/21,21:29:54] << player 3 joined the game [kungfudriver : Samson1818 : GER : 72508 : 217.232.64.92]
plugin.players.lgrfbs.php} PlayerPlus
plugin.players.lgrfbs.php} Nick:Samson1818
plugin.players.lgrfbs.php} Login:kungfudriver
plugin.players.lgrfbs.php} Data_01:Player: kungfudriver Nick:Samson1818
plugin.players.lgrfbs.php} Open - Write to file
plugin.players.lgrfbs.php} The file No_of_playerstxt exists
plugin.players.lgrfbs.php} open file for reading.
plugin.players.lgrfbs.php} The file No_of_playerstxt does not exist
plugin.players.lgrfbs.php} Gamers:1
if u could pm me the new version i will check it out

Code: Select all

tmnforever is nations and united makes it special. tmnforever has united. I need united!

User avatar
lgrfbs-sweden
smooth traffic navigator
smooth traffic navigator
Posts: 200
Joined: 15 Apr 2007 15:48
Owned TM-games: TMN
Location: Sweden
Contact:

Re: I try to write a script.

Post by lgrfbs-sweden » 23 Mar 2008 13:25

OBS this script is only one part of two, but here we go:

Code: Select all

<?php
// Count the players for the systembar graph.
// Version: 0.0.0.1
// Beta: 0.0.0.6
// Date: 2008-03-21 to 2008-03-22
//.3a edited by w1lla
//.4 lgrfbs
// _____________________________________________________

Aseco::registerEvent('onStartup', 'init_sp');
Aseco::registerEvent("onPlayerConnect", "PlayerPlus");
Aseco::registerEvent("onPlayerDisconnect", "PlayerMinus");

// Setup -------------------------
$SaveFolder="stat-players";
$SaveToFile=$SaveFolder."/No_of_players.txt"; 
//--------------------------------
// the "$aseco->console_text" do not work here, I use "print" instead.
print "plugin.players.lgrfbs.php} start ------------------------------\n";
print "plugin.players.lgrfbs.php} Write to: ".$SaveToFile."\n";





function init_sp(&$aseco){
 // Setup -------------------------
 $SaveFolder="stat-players";
 $SaveToFile=$SaveFolder."/No_of_players.txt"; 
 //--------------------------------
 $aseco->console_text ("plugin.players.lgrfbs.php} init_sp.".$SaveFolder."<");
 if (!is_dir($SaveFolder))
 {
  $aseco->console_text ('plugin.players.lgrfbs.php} Make the folder. ['.$SaveFolder.']');
  mkdir($SaveFolder, 0777);
  $aseco->console_text ('plugin.players.lgrfbs.php} Done.');
 } else {
  $aseco->console_text ('plugin.players.lgrfbs.php} The folder are allready done. - '.$SaveFolder);
 }
}





function PlayerPlus(&$aseco, $player){
 // Setup -------------------------
 $SaveFolder="stat-players";
 $SaveToFile=$SaveFolder."/No_of_players.txt"; 
 //--------------------------------
 $aseco->console_text ('plugin.players.lgrfbs.php} PlayerPlus'.$SaveToFile);
 $Gamers=0;
 $nickname = $player->nickname;
 $aseco->console_text ('plugin.players.lgrfbs.php} Nick:'.$nickname);
 $login= $player->login;
 $aseco->console_text ('plugin.players.lgrfbs.php} Login:'.$login);
   
 // exist file?
 if (file_exists($SaveToFile)) 
 {
  $aseco->console_text ("plugin.players.lgrfbs.php} The file ".$SaveToFile." exists");
  // Read the file number of Gamers
  $Index=0;
  $aseco->console_text ('plugin.players.lgrfbs.php} open file for reading.');
  $fp = fopen($SaveToFile, 'r');
  while(!feof($fp))
  {
   $Index=$Index+1;
   $line=fgets($fp);
   if ($Index==1){}
   if ($Index==2){$Gamers=$line;}
   $aseco->console_text ("plugin.players.lgrfbs.php} R_Gamers:".$Gamers);
   $aseco->console_text ("plugin.players.lgrfbs.php} R_Index:".$Index);
   $aseco->console_text ("plugin.players.lgrfbs.php} R_Line:".$line);
  }
  $aseco->console_text ("plugin.players.lgrfbs.php} The file ".No_of_players.txt." does not exist");
 }
 // Add a player to ...
 $Gamers=$Gamers+1;
 $aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
 // Write new data into file
 $Data_01="Player: ". $login;//." Nick:".$nickname;
 $aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
 $aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
 //$fp = fopen(No_of_players.txt, 'a'); //or die("can't open No_of_players.txt");
 //  fwrite($fp,$SaveToFile, $Data_01."a");
 //  fwrite($fp,$SaveToFile, $Gamers."a");
 //fclose($fp);
 system('echo '.$Data_01.' > '.$SaveToFile);
 system('echo '.$Gamers.' >> '.$SaveToFile);
    
}





function PlayerMinus(&$aseco, $Player){
 // Setup -------------------------
 $SaveFolder="/home/subfil/Aseco/plugins/stat-players/";
 $SaveFolder="stat-players";
 $SaveToFile=$SaveFolder."/No_of_players.txt"; 
 //--------------------------------
 $aseco->console_text ("plugin.players.lgrfbs.php} PlayerMinus".$SaveToFile);
 // Read the file
 $Index=0;
 $aseco->console_text ('plugin.players.lgrfbs.php} open file for reading.');
 $fp = fopen($SaveToFile, 'r');
 while(!feof($fp))
 {
  $Index=$Index+1;
  $line=fgets($fp);
  if ($Index==1){}
  if ($Index==2){$Gamers=$line;}
  $aseco->console_text ("plugin.players.lgrfbs.php} R_Gamers:".$Gamers);
  $aseco->console_text ("plugin.players.lgrfbs.php} R_Index:".$Index);
  $aseco->console_text ("plugin.players.lgrfbs.php} R_Line:".$line);
 }
 $aseco->console_text ("plugin.players.lgrfbs.php} The file ".No_of_players.txt." does not exist");
 // Subd a player to ...
 $Gamers=$Gamers-1;
 if ($Gamers<0){$Gamers=0;}
 $aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
 // Write new data into file
 $Data_01="Player: ". $login;//." Nick:".$nickname;
 $aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
 $aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
 //$fp = fopen(No_of_players.txt, 'w'); //or die("can't open No_of_players.txt");
 //  fwrite($fp,No_of_players.txt, $Data_01."w");
 //  fwrite($fp,No_of_players.txt, $Gamers."w");
 //fclose($fp);
 system('echo '.$Data_01.' > '.$SaveToFile);
 system('echo '.$Gamers.' >> '.$SaveToFile);
}
// the "$aseco->console_text" do not work here, I use "print" instead.
print "plugin.players.lgrfbs.php} End --------------------------------\n";
?>
This code work as I wanted it to do, of course it can be better writed.

This is only two thing I not get.
One, how to have only one "Set up" section at the top of the script, I are not enough smart for that. so for that reason the "Set up" is repeat on more places in the script.

Two, In this: fwrite($fp,No_of_players.txt, $Gamers."w");
way put in No_of_players.txt and "w" there ?

Do you want to see the other script as run from crontab as well?
The big gaps in the code between function are ther for facilitate for editng in putty with mc.

If my English is hard to read, it is for I write by help of dictionary: http://lexin.nada.kth.se/cgi-bin/sve-eng

Ops, some debug code is still in there ...
Admin On:Image
My server:lgrfbs server / XASECO plugins
Image

User avatar
w1lla
TM-Patrol
TM-Patrol
Posts: 1466
Joined: 23 May 2007 07:20
Owned TM-games: TMU, TMN, TMF
Manialink(s): intr
Location: Venray

Re: I try to write a script.

Post by w1lla » 23 Mar 2008 14:08

Hi i added the nickname in the .txt document so it will show both login as nickname.

Code: Select all

<?php
// Count the players for the systembar graph.
// Version: 0.0.0.1
// Beta: 0.0.0.6
// Date: 2008-03-21 to 2008-03-22
//.3a edited by w1lla
//.4 lgrfbs
//.5 W1lla added the nick to the .txt file
// _____________________________________________________

Aseco::registerEvent('onStartup', 'init_sp');
Aseco::registerEvent("onPlayerConnect", "PlayerPlus");
Aseco::registerEvent("onPlayerDisconnect", "PlayerMinus");

// Setup -------------------------
$SaveFolder="stat-players";
$SaveToFile=$SaveFolder."/No_of_players.txt"; 
//--------------------------------
// the "$aseco->console_text" do not work here, I use "print" instead.
print "plugin.players.lgrfbs.php} start ------------------------------\n";
print "plugin.players.lgrfbs.php} Write to: ".$SaveToFile."\n";





function init_sp(&$aseco){
// Setup -------------------------
$SaveFolder="stat-players";
$SaveToFile=$SaveFolder."/No_of_players.txt"; 
//--------------------------------
$aseco->console_text ("plugin.players.lgrfbs.php} init_sp.".$SaveFolder."<");
if (!is_dir($SaveFolder))
{
  $aseco->console_text ('plugin.players.lgrfbs.php} Make the folder. ['.$SaveFolder.']');
  mkdir($SaveFolder, 0777);
  $aseco->console_text ('plugin.players.lgrfbs.php} Done.');
} else {
  $aseco->console_text ('plugin.players.lgrfbs.php} The folder are allready done. - '.$SaveFolder);
}
}





function PlayerPlus(&$aseco, $player){
// Setup -------------------------
$SaveFolder="stat-players";
$SaveToFile=$SaveFolder."/No_of_players.txt"; 
//--------------------------------
$aseco->console_text ('plugin.players.lgrfbs.php} PlayerPlus'.$SaveToFile);
$Gamers=0;
$nickname = $player->nickname;
$aseco->console_text ('plugin.players.lgrfbs.php} Nick:'.$nickname);
$login= $player->login;
$aseco->console_text ('plugin.players.lgrfbs.php} Login:'.$login);
   
// exist file?
if (file_exists($SaveToFile)) 
{
  $aseco->console_text ("plugin.players.lgrfbs.php} The file ".$SaveToFile." exists");
  // Read the file number of Gamers
  $Index=0;
  $aseco->console_text ('plugin.players.lgrfbs.php} open file for reading.');
  $fp = fopen($SaveToFile, 'r');
  while(!feof($fp))
  {
   $Index=$Index+1;
   $line=fgets($fp);
   if ($Index==1){}
   if ($Index==2){$Gamers=$line;}
   $aseco->console_text ("plugin.players.lgrfbs.php} R_Gamers:".$Gamers);
   $aseco->console_text ("plugin.players.lgrfbs.php} R_Index:".$Index);
   $aseco->console_text ("plugin.players.lgrfbs.php} R_Line:".$line);
  }
  $aseco->console_text ("plugin.players.lgrfbs.php} The file ".No_of_players.txt." does not exist");
}
// Add a player to ...
$Gamers=$Gamers+1;
$aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
// Write new data into file
$Data_01="Player: ". $login;
$Data_02="nick: ". $nickname;
$aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
$aseco->console_text ("plugin.players.lgrfbs.php} Data_02:".$Data_02);
$aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
//$fp = fopen(No_of_players.txt, 'a'); //or die("can't open No_of_players.txt");
//  fwrite($fp,$SaveToFile, $Data_01."a");
//  fwrite($fp,$SaveToFile, $Data_02."a");
//  fwrite($fp,$SaveToFile, $Gamers."a");
//fclose($fp);
system('echo '.$Data_01.' >> '.$SaveToFile);
system('echo '.$Data_02.' >> '.$SaveToFile);
system('echo '.$Gamers.' >> '.$SaveToFile);
    
}





function PlayerMinus(&$aseco, $Player){
// Setup -------------------------
$SaveFolder="/home/subfil/Aseco/plugins/stat-players/";
$SaveFolder="stat-players";
$SaveToFile=$SaveFolder."/No_of_players.txt"; 
//--------------------------------
$aseco->console_text ("plugin.players.lgrfbs.php} PlayerMinus".$SaveToFile);
// Read the file
$Index=0;
$aseco->console_text ('plugin.players.lgrfbs.php} open file for reading.');
$fp = fopen($SaveToFile, 'r');
while(!feof($fp))
{
  $Index=$Index+1;
  $line=fgets($fp);
  if ($Index==1){}
  if ($Index==2){$Gamers=$line;}
  $aseco->console_text ("plugin.players.lgrfbs.php} R_Gamers:".$Gamers);
  $aseco->console_text ("plugin.players.lgrfbs.php} R_Index:".$Index);
  $aseco->console_text ("plugin.players.lgrfbs.php} R_Line:".$line);
}
$aseco->console_text ("plugin.players.lgrfbs.php} The file ".No_of_players.txt." does not exist");
// Subd a player to ...
$Gamers=$Gamers-1;
if ($Gamers<0){$Gamers=0;}
$aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
// Write new data into file
$Data_01="Player: ". $login;
$Data_02="nick: ". $nickname;
$aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
$aseco->console_text ("plugin.players.lgrfbs.php} Data_02:".$Data_02);
$aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
//$fp = fopen(No_of_players.txt, 'w'); //or die("can't open No_of_players.txt");
//  fwrite($fp,No_of_players.txt, $Data_01."w");
//  fwrite($fp,No_of_players.txt, $Data_02."w");
//  fwrite($fp,No_of_players.txt, $Gamers."w");
//fclose($fp);
system('echo '.$Data_01.' >> '.$SaveToFile);
system('echo '.$Data_02. '>> '.$SaveToFile);
system('echo '.$Gamers.' >> '.$SaveToFile);
}
// the "$aseco->console_text" do not work here, I use "print" instead.
print "plugin.players.lgrfbs.php} End --------------------------------\n";
?>
fwrite($fp,No_of_players.txt, $Gamers."w");
way put in No_of_players.txt and "w" there ?
Well

Code: Select all

'r' Open for reading only; place the file pointer at the beginning of the file.  
'r+' Open for reading and writing; place the file pointer at the beginning of the file.  
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.  
'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.  
'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.  
'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.  
'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.  
'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.  
has to do something with fopen so im not sure how its being dealt about the setup i will not edit it.

Code: Select all

tmnforever is nations and united makes it special. tmnforever has united. I need united!

User avatar
lgrfbs-sweden
smooth traffic navigator
smooth traffic navigator
Posts: 200
Joined: 15 Apr 2007 15:48
Owned TM-games: TMN
Location: Sweden
Contact:

Re: I try to write a script.

Post by lgrfbs-sweden » 23 Mar 2008 14:43

w1lla wrote:Hi i added the nickname in the .txt document so it will show both login as nickname.

Code: Select all

<?php
// Count the players for the systembar graph.
// Version: 0.0.0.1
// Beta: 0.0.0.7
// Date: 2008-03-21 to 2008-03-22
//.3a edited by w1lla
//.4 lgrfbs
//.7 W1lla added the nick to the .txt file
// _____________________________________________________
fwrite($fp,No_of_players.txt, $Gamers."w");
way put in No_of_players.txt and "w" there ?
Well

Code: Select all

'r' Open for reading only; place the file pointer at the beginning of the file.  
'r+' Open for reading and writing; place the file pointer at the beginning of the file.  
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.  
'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.  
'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.  
'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.  
'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.  
'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.  
has to do something with fopen so im not sure how its being dealt about the setup i will not edit it.
Nice to add the nickname to.
I edit the beta version numer you have .7 beta.
Yes, I read the text then I start write the script and I interpret as it apply to fopen only and then I looking at a example : http://www.tizag.com/phpT/filewrite.php at the middel of the page.
I have only writed PHP 2-5 times now, so I can have someting wrong.
http://nl3.php.net/manual/en/function.fopen.php
http://nl3.php.net/manual/en/function.fwrite.php
Admin On:Image
My server:lgrfbs server / XASECO plugins
Image

User avatar
lgrfbs-sweden
smooth traffic navigator
smooth traffic navigator
Posts: 200
Joined: 15 Apr 2007 15:48
Owned TM-games: TMN
Location: Sweden
Contact:

Re: I try to write a script.

Post by lgrfbs-sweden » 23 Mar 2008 22:44

Code: Select all

<?php
// Count the players for the systembar graph.
// Version: 0.0.0.1
// Beta: 0.0.0.9
// Date: 2008-03-21 to 2008-03-23
// Version History ----------------------------------------------
//.3a edited by w1lla
//.4 to .6 lgrfbs
//.7 W1lla added the nick to the .txt file
//.8 to .9 lgrfbs (.8 = Clean up .9 = Add more info and a new file output. Clean up loggdata.
// _____________________________________________________

Aseco::registerEvent('onStartup', 'init_sp');
Aseco::registerEvent("onPlayerConnect", "PlayerPlus");
Aseco::registerEvent("onPlayerDisconnect", "PlayerMinus");

// Setup -------------------------
$SaveFolder="stat-players";
$SaveToFile=$SaveFolder."/No_of_players.txt"; 
$SaveToFile2=$SaveFolder."/Players_live.txt"; 
//--------------------------------
// the "$aseco->console_text" do not work here, I use "print" instead.
print "plugin.players.lgrfbs.php} start ------------------------------\n";
print "plugin.players.lgrfbs.php} Write to: ".$SaveToFile."\n";





function init_sp(&$aseco){
 // Setup -------------------------
 $SaveFolder="stat-players";
 $SaveToFile=$SaveFolder."/No_of_players.txt"; 
 $SaveToFile2=$SaveFolder."/Players_live.txt"; 
 //--------------------------------
 $aseco->console_text ("plugin.players.lgrfbs.php} init_sp.");
 if (!is_dir($SaveFolder))
 {
  $aseco->console_text ('plugin.players.lgrfbs.php} Make the folder. ['.$SaveFolder.']');
  mkdir($SaveFolder, 0777);
  $aseco->console_text ('plugin.players.lgrfbs.php} Done.');
 } else {
  $aseco->console_text ('plugin.players.lgrfbs.php} The folder are allready done. - '.$SaveFolder);
 }
}





function PlayerPlus(&$aseco, $player){
 // Setup -------------------------
 $SaveFolder="stat-players";
 $SaveToFile=$SaveFolder."/No_of_players.txt"; 
 $SaveToFile2=$SaveFolder."/Players_live.txt"; 
 $LiveFile="0";
 //--------------------------------
 $aseco->console_text ('plugin.players.lgrfbs.php} PlayerPlus ');
 $id=$player->id;
 $login=$player->login;
 $nickname=$player->nickname;
 $country=$player->nation;
 $ladder=$player->ladderrank;
  // Debug code
 $aseco->console_text ('plugin.players.lgrfbs.php} - Debug Info --------');
 $aseco->console_text ('plugin.players.lgrfbs.php} ........ID:'.$id);
 $aseco->console_text ('plugin.players.lgrfbs.php} ......Nick:'.$nickname);
 $aseco->console_text ('plugin.players.lgrfbs.php} .....Login:'.$login);
 $aseco->console_text ('plugin.players.lgrfbs.php} ....Nation:'.$country);
 $aseco->console_text ('plugin.players.lgrfbs.php} Ladderrank:'.$ladder);
 $aseco->console_text ('plugin.players.lgrfbs.php} ---------------------');
 //--------------------------------

 $Gamers=0;
 $nickname = $player->nickname;
 //$aseco->console_text ('plugin.players.lgrfbs.php} Nick:'.$nickname);
 $login= $player->login;
 //$aseco->console_text ('plugin.players.lgrfbs.php} Login:'.$login);
   
 // exist file?
 if (file_exists($SaveToFile)) 
 {
  $aseco->console_text ("plugin.players.lgrfbs.php} The file ".$SaveToFile." exists");
  // Read the file number of Gamers
  $Index=0;
  //Debug Code
  //$aseco->console_text ('plugin.players.lgrfbs.php} open file for reading.');
  $fp = fopen($SaveToFile, 'r');
  while(!feof($fp))
  {
   $Index=$Index+1;
   $line=fgets($fp);
   if ($Index==1){}
   if ($Index==2){$Gamers=$line;}
   //Debug code
   //$aseco->console_text ("plugin.players.lgrfbs.php} R_Gamers:".$Gamers);
   //$aseco->console_text ("plugin.players.lgrfbs.php} R_Index:".$Index);
   //$aseco->console_text ("plugin.players.lgrfbs.php} R_Line:".$line);
  }
  // Debug Code
  //$aseco->console_text ("plugin.players.lgrfbs.php} The file ".$SaveToFile." does not exist");
 }
 // Add a player to ...
 $Gamers=$Gamers+1;
 // $aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
 // Write new data into file
 $Data_01="Player: ". $login;//." Nick:".$nickname;
 //$aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
 //$aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
 //$fp = fopen(No_of_players.txt, 'a'); //or die("can't open No_of_players.txt");
 //  fwrite($fp,$SaveToFile, $Data_01."a");
 //  fwrite($fp,$SaveToFile, $Gamers."a");
 //fclose($fp);
 system('echo '.$Data_01.' > '.$SaveToFile);
 system('echo '.$Gamers.' >> '.$SaveToFile);
 system('echo '.$nickname.' >> '.$SaveToFile);

 // Loggfile -live-
 if ($LiveFile=="1")
 {
  $D = date("Y-m-d h:i:s");
  system('echo ------- '.$D.' --------- >> '.$SaveToFile2);
  system('echo ID:'.$id.' >> '.$SaveToFile2);
  system('echo Nick:'.$nickname.' >> '.$SaveToFile2);
  system('echo Login:'.$login.' >> '.$SaveToFile2);
  system('echo Nation:'.$country.' >> '.$SaveToFile2);
  system('echo Ladderrank:'.$ladder.' >> '.$SaveToFile2);
  system('echo ------------------------------------- >> '.$SaveToFile2);
 }

 // more info can be puted here under.
 $aseco->console_text ('plugin.players.lgrfbs.php} PlayerPlus end ------------------------------------------');
}





function PlayerMinus(&$aseco, $Player){
 // Setup -------------------------
 $SaveFolder="/home/subfil/Aseco/plugins/stat-players/";
 $SaveFolder="stat-players";
 $SaveToFile=$SaveFolder."/No_of_players.txt"; 
 //--------------------------------
 $aseco->console_text ("plugin.players.lgrfbs.php} PlayerMinus");

 //--------------------------------
 $id=$player->id;
 $login=$player->login;
 $nickname=$player->nickname;
 $country=$player->nation;
 $ladder=$player->ladderrank;
  // Debug code
 //$aseco->console_text ('plugin.players.lgrfbs.php} - Debug Info --------');
 //$aseco->console_text ('plugin.players.lgrfbs.php} ........ID:'.$id);
 //$aseco->console_text ('plugin.players.lgrfbs.php} ......Nick:'.$nickname);
 //$aseco->console_text ('plugin.players.lgrfbs.php} .....Login:'.$login);
 //$aseco->console_text ('plugin.players.lgrfbs.php} ....Nation:'.$country);
 //$aseco->console_text ('plugin.players.lgrfbs.php} Ladderrank:'.$ladder);
 //$aseco->console_text ('plugin.players.lgrfbs.php} ---------------------');
 //--------------------------------

 // Read the file
 $Index=0;
 //$aseco->console_text ('plugin.players.lgrfbs.php} open file for reading.');
 $fp = fopen($SaveToFile, 'r');
 while(!feof($fp))
 {
  $Index=$Index+1;
  $line=fgets($fp);
  if ($Index==1){}
  if ($Index==2){$Gamers=$line;}
  // Debug Code
  //$aseco->console_text ("plugin.players.lgrfbs.php} R_Gamers:".$Gamers);
  //$aseco->console_text ("plugin.players.lgrfbs.php} R_Index:".$Index);
  //$aseco->console_text ("plugin.players.lgrfbs.php} R_Line:".$line);
 }
 //$aseco->console_text ("plugin.players.lgrfbs.php} The file ".$SaveToFile." does not exist");
 // Subd a player to ...
 $Gamers=$Gamers-1;
 if ($Gamers<0){$Gamers=0;}
 //$aseco->console_text ("plugin.players.lgrfbs.php} Gamers:".$Gamers);
 // Write new data into file
 $Data_01="Player: ". $login;//." Nick:".$nickname;
 //$aseco->console_text ("plugin.players.lgrfbs.php} Data_01:".$Data_01);
 //$aseco->console_text ("plugin.players.lgrfbs.php} Open - Write to file");
 //$fp = fopen(No_of_players.txt, 'w'); //or die("can't open No_of_players.txt");
 //  fwrite($fp,No_of_players.txt, $Data_01."w");
 //  fwrite($fp,No_of_players.txt, $Gamers."w");
 //fclose($fp);
 system('echo '.$Data_01.' > '.$SaveToFile);
 system('echo '.$Gamers.' >> '.$SaveToFile);
 $aseco->console_text ('plugin.players.lgrfbs.php} PlayerMinus end ------------------------------------------');
}
// the "$aseco->console_text" do not work here, I use "print" instead.
print "plugin.players.lgrfbs.php} End --------------------------------\n";
?>
if someone want to use the code as ground for other things its okey, but use a new filename :wink:
Admin On:Image
My server:lgrfbs server / XASECO plugins
Image

User avatar
w1lla
TM-Patrol
TM-Patrol
Posts: 1466
Joined: 23 May 2007 07:20
Owned TM-games: TMU, TMN, TMF
Manialink(s): intr
Location: Venray

Re: I try to write a script.

Post by w1lla » 24 Mar 2008 07:53

big respect ;) lgrfbs u implemented some nice things but i also came across some errors

Code: Select all

$LiveFile="0";
must be

Code: Select all

$LiveFile="1";
to make the livefile and no of players work. thats what i found with a quick look so more info will come

Code: Select all

tmnforever is nations and united makes it special. tmnforever has united. I need united!

User avatar
lgrfbs-sweden
smooth traffic navigator
smooth traffic navigator
Posts: 200
Joined: 15 Apr 2007 15:48
Owned TM-games: TMN
Location: Sweden
Contact:

Re: I try to write a script.

Post by lgrfbs-sweden » 24 Mar 2008 09:29

thanks for that w1lla
The bug was that I not writed a commentary about this in the code, I do not need the live-file(logfile) at the moment so I seted it to "off".

Next time I edit the file I will commentary all as needed in it.
Admin On:Image
My server:lgrfbs server / XASECO plugins
Image

User avatar
w1lla
TM-Patrol
TM-Patrol
Posts: 1466
Joined: 23 May 2007 07:20
Owned TM-games: TMU, TMN, TMF
Manialink(s): intr
Location: Venray

Re: I try to write a script.

Post by w1lla » 25 Mar 2008 13:56

well today i started to look at the script quite nice indeed i tested the live players part and added some stuff to it what would be nice. If you have interest pm.

Code: Select all

tmnforever is nations and united makes it special. tmnforever has united. I need united!

User avatar
Pimp McPhalanx
pedestrian
pedestrian
Posts: 8
Joined: 13 Apr 2007 19:29

Re: I try to write a script.

Post by Pimp McPhalanx » 31 Mar 2008 15:34

What exactly is the purpose of this script? Is it just to record players or are you planning to do more with it?
Opperpimp!

User avatar
w1lla
TM-Patrol
TM-Patrol
Posts: 1466
Joined: 23 May 2007 07:20
Owned TM-games: TMU, TMN, TMF
Manialink(s): intr
Location: Venray

Re: I try to write a script.

Post by w1lla » 31 Mar 2008 16:52

well it just a plugin that writes all data of player collected like rang nations ladderscore.

Code: Select all

tmnforever is nations and united makes it special. tmnforever has united. I need united!

Post Reply