Dedicated server callbacks?

Moderator: NADEO

User avatar
Leigham
Posts: 26
Joined: 16 Aug 2011, 23:27
Location: World inside my head

Re: Dedicated server callbacks?

Post by Leigham »

Not sure if I'm understanding, but the easiest way I can see is to make a new array with all the logins but the one you want. So something like

Code: Select all

 foreach ($array as $login) { 
if ($login != $targetlogin) {
$newarray[] = $login;
}
}
$array = $newarray;
Apologies for the awful formatting. Typed it straight into the message box :)
"If you can't find something nice to say, come sit next to me."

SFT Servers
svens
Posts: 97
Joined: 15 Jun 2010, 11:06
Location: Bern, CH
Contact:

Re: Dedicated server callbacks?

Post by svens »

Manually copying an array in PHP is a bad idea. It's better to just unset() the right entry.

Something like this will get the job done:

Code: Select all

if (($index = array_search($login, $array)) !== false) {
	unset($array[$index]);
}
Note that after this operation there will be a "hole" in the array indexes. For example if your array is

Code: Select all

[0] => "Login A",
[1] => "Login B",
[2] => "Login C"
After you remove "Login B" from it, it will look like this:

Code: Select all

[0] => "Login A",
[2] => "Login C"
To "fix" this one could use array_values() afterwards:

Code: Select all

$array = array_values($array);
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post by adder »

works now
thanks svens & Leigham
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post by adder »

I have yet another question :yes:

i have this code

Code: Select all

<?php
// Trackrating.plugin
// date: 20/05/12
// version 0.5

$connect->query('GetCurrentMapInfo');
$mapinfocb = $connect->getResponse();

if ($donewithfunctiontrim != TRUE) {
	function trim_value(&$value) { //remove unwanted \r\n from admins.list
		$value = trim($value); 
	}
	$donewithfunctiontrim = TRUE;
}

//check if the vote file's exist
$plusvotefile="inc\Lists\gvote\\".$mapinfocb['UId'].".plus.list";
$minvotefile="inc\Lists\gvote\\".$mapinfocb['UId'].".min.list";
$votedatafile="inc\Lists\gvote\\".$mapinfocb['UId'].".vote";
if (!file_exists($plusvotefile)) {
	$ourFileHandle = fopen($plusvotefile, 'w') or die("can't open file");
	fclose($ourFileHandle);
}
if (!file_exists($votedatafile)) {
	$ourFileHandle = fopen($votedatafile, 'w') or die("can't open file");
	$stringData1 = 0;
	$stringData2 = 0;
	fwrite($ourFileHandle, $stringData1."\r\n".$stringData2);
	fclose($ourFileHandle);
}
if (!file_exists($minvotefile)) {
	$ourFileHandle = fopen($minvotefile, 'w') or die("can't open file");
	fclose($ourFileHandle);
}

//plugin starts
$alreadyvoteplus = file("inc\Lists\gvote\\".$mapinfocb['UId'].".plus.list");
array_walk($alreadyvoteplus, 'trim_value'); // use function: trim_value to "clean" the file
$alreadyvotemin = file("inc\Lists\gvote\\".$mapinfocb['UId'].".min.list");
array_walk($alreadyvotemin, 'trim_value'); // use function: trim_value to "clean" the file
$filenamecurrtrack = file("inc\Lists\gvote\\".$mapinfocb['UId'].".vote");
array_walk($filenamecurrtrack, 'trim_value'); // use function: trim_value to "clean" the file

//++
if ($chatcommand[0] == "/++") {
	if (!in_array($playerchat['login'], $alreadyvoteplus, true)) {
		//update vote login list
		$fh = fopen($plusvotefile, 'a') or die("can't open file");
		$stringData = $playerchat['login'];
		fwrite($fh, $stringData."\r\n");
		fclose($fh);
		$votesplus = $filenamecurrtrack[0];
		$votesmin = $filenamecurrtrack[1];
		$newvotemin = $votesmin;
		//if player voted -- update vote list
		if (in_array($playerchat['login'], $alreadyvotemin, true)) {
			if (($index = array_search($playerchat['login'], $alreadyvotemin)) !== false) {
				unset($alreadyvotemin[$index]);
				$newvotemin = $newvotemin - 1;
				$fp = fopen($minvotefile,'w');
				foreach($alreadyvotemin as $key => $value){
					fwrite($fp,$value."\r\n");
				}
				fclose($fp);
			}
		}
		//update voting stats
		$newvoteplus = $votesplus + 1;
		$fg = fopen($votedatafile, 'w') or die("can't open file");
		$stringData1 = $newvoteplus;
		$stringData2 = $newvotemin;
		fwrite($fg, $stringData1."\r\n".$stringData2);
		fclose($fg);
		$connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffVote succesfull!','',0);
	}
	else $connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffYou already voted!','',0);	
}


//--
if ($chatcommand[0] == "/--") {
	if (!in_array($playerchat['login'], $alreadyvotemin, true)) {
		//update vote login list
		$fh = fopen($minvotefile, 'a') or die("can't open file");
		$stringData = $playerchat['login'];
		fwrite($fh, $stringData."\r\n");
		fclose($fh);
		$votesplus = $filenamecurrtrack[0];
		$votesmin = $filenamecurrtrack[1];
		$newvoteplus = $votesplus;
		//if player voted -- update vote list
		if (in_array($playerchat['login'], $alreadyvoteplus, true)) {
			if (($index = array_search($playerchat['login'], $alreadyvoteplus)) !== false) {
				unset($alreadyvoteplus[$index]);
				$newvoteplus = $newvoteplus - 1;
			}
		}
		//update voting stats
		$newvotemin = $votesmin + 1;
		$fg = fopen($votedatafile, 'w') or die("can't open file");
		$stringData1 = $newvoteplus;
		$stringData2 = $newvotemin;
		fwrite($fg, $stringData1."\r\n".$stringData2);
		fclose($fg);
		$connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffVote succesfull!','',0);
	}
	else $connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffYou already voted!','',0);	
}

but for some reason the:
$connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffVote succesfull!','',0);

doesn't work. I can't figure it out, even if i change '$adminlogin' into 'adder' (my login)
i still doesn't work.

$adminlogin is the players login

GreetZ
An eye for an eye leaves the whole world monocular.
TheM
Posts: 1379
Joined: 15 Jun 2010, 14:30
Location: Uden, Noord-Brabant, Netherlands
Contact:

Re: Dedicated server callbacks?

Post by TheM »

May I ask you why you want to use a notice (this is an message at the left top of the screen (please let me know if I'm wrong))?
I would suggest to use SendServerMessageToLogin ;)
Furthermore, you'll have to use

Code: Select all

$connect->query('*****', $adminlogin, '$z>>$fffVote succesfull!', '', 0);
If you use '$adminlogin', it'll send the message to the login called $adminlogin (which isn't on your server, since $ can't be used in your login).
Global moderator | Dutch moderator | Laddermoderator | ManiaWiki moderator
Server Manager/webmaster of Smurfen.net, join us on Canyon, Valley and Royal!
ESL (Game) Staff Head for TrackMania (Stadium, Canyon and Valley).
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post by adder »

in some other code, I have this

Code: Select all

$connect->query('SendNoticeToLogin','$adminlogin','$z>>$fffYou banned$f00 '.$chatcommand[1].'$z$fff!','',0);
and it send a chat message, but only to a specific login.
Also the '$admindlogin' works just fine

I've got no time to try it out atm,
but I'll do it tomorrow :)
An eye for an eye leaves the whole world monocular.
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post by adder »

Code: Select all

	else $connect->query('SendServerMessageToLogin',$adminlogin,'$z>>$fffYou already voted!');	
this does nothing

Fixed:

Code: Select all

$connect->query('ChatSendServerMessageToLogin','$z>>$fffYou added$f00 '.$chatcommand[1].'$z$ As adminfff!',"$adminlogin");
It needs chat in front, and the login to receive at last
An eye for an eye leaves the whole world monocular.
User avatar
adder
Posts: 138
Joined: 06 May 2012, 17:34
Location: Belgium

Re: Dedicated server callbacks?

Post by adder »

Hello

I want to write a array into a file like show on the picture:
picture
I have this as code (its far from finished, i does like nothing atm)

Code: Select all

<?php
/*****************************
		Localrecords.plugin
		version: 0.1b
		date: 26/05/12
		Author: adder
*****************************/
$connect->query('GetCurrentMapInfo');
$mapinfocb = $connect->getResponse();
$amountofrecs = $setting['amountofrecs'];
$count = 0;

$recordsfile="inc\Lists\localrecords\\".$mapinfocb['UId'].".record.list";
if (!file_exists($recordsfile)) {
	$ourFileHandle = fopen($recordsfile, 'w') or die("can't open file");
	$datatoputinform = "9999999999|login";
	while ($count <= $amountofrecs) {
	fwrite($ourFileHandle,$datatoputinform."\r\n");
	$count++;
	}
	fclose($ourFileHandle);
}

if ($donewithfunctiontrim != TRUE) {
	function trim_value(&$value) { //remove unwanted \r\n from admins.list
		$value = trim($value); 
	}
	$donewithfunctiontrim = TRUE;
}

//plugin start


$playerfinish['uid'] = $cb[1][0];
$playerfinish['login'] = $cb[1][1];
$playerfinish['timee'] = $cb[1][2];
$connect->query('GetPlayerInfo', $playerfinish['login']);
$playerdata = $connect->getResponse();
$playerfinish['nickname'] = $playerdata['NickName'];
$seconds = $playerfinish['timee'] / 1000;
$minutes = floor($playerfinish['timee'] / (1000 * 60));

$currentrecords = file("inc\Lists\localrecords\\".$mapinfocb['UId'].".record.list");
array_walk($currentrecords, 'trim_value'); // use function: trim_value to "clean" the file

$count = 0;
while ($count <= $amountofrecs) {
	$record["$count"] = explode("|", $currentrecords["$count"]);
	$count++;
}

$arraybanaan = array(array("0" => $cb[1][2], "1" => $cb[1][1]));
$arraykiwi = array("0" => $cb[1][2], "1" => $cb[1][1]);
$result = array_merge($record, $arraybanaan);
sort($result);
$recordnumber = array_search($arraykiwi, $result);
$connect->query('ChatSendServerMessage', "you drove".$recordnumber);
$count = $amountofrecs;
while ($count != 0) {
	implode(",", $result["$count"]);
	$count = $count - 1;
}
print_r($result);
$fp = fopen($recordsfile,"w+");
foreach($result as $key => $value){
fwrite($fp,$value."\r\n");
}
fclose($fp);
?>
but this returns:

Code: Select all

Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
Array
inside my file

GrtZ
An eye for an eye leaves the whole world monocular.
lambda
Posts: 6
Joined: 19 Jun 2010, 21:31
Location: Slovenia

Re: Dedicated server callbacks?

Post by lambda »

Try to use this function:

Code: Select all

	// function print array data to file
	function print_to_file ($data){
 		ob_start(); 
		print_r ($data); 
		$done = ob_get_flush (); 
		$txt = fopen ('print_to_file.txt', 'w'); 
		fwrite ($txt, $done); 
		fclose ($txt);
	}
instead:

Code: Select all

print_r ($result);


use this:

Code: Select all

print_to_file ($result);
The_Big_Boo
Posts: 1026
Joined: 15 Jun 2010, 15:46

Re: Dedicated server callbacks?

Post by The_Big_Boo »

lambda wrote:

Code: Select all

ob_start(); 
print_r ($data); 
$done = ob_get_flush ();
Tip: this can be done with a single call to print_r ;)

Code: Select all

$done = print_r($data, true);
OS: Win 7 Pro x64
RAM: 2x4GB Corsair @ 1600MHz
CPU: Intel i5 760 @ 3.6GHz
Mobo: Asus P7P55D-E
GPU: NVidia GTX 760 2GB
HDD: WD Black 1TB
Sound: VIA VT1828S (onboard)
Peripherals: Razer DeathAdder - Razer DeathStalker - Logitech F310
Post Reply

Return to “Dedicated Server”

Who is online

Users browsing this forum: No registered users and 1 guest