The online racing simulator
#1 - Racon
Tutorial 2: Hello player
// [Hello player] /////////////////////////////////////////////////////////////

Now, let's make a program to greet every player that connects to the server
that we're on. We'll hook the NCN packet by defining a 'PIE_NCN' function and
use the PName field from the data parameter.

helloplayer.php:

<?php 

function PIE_NCN($data)
  {
    
PIE_say('Hello '.$data['PName']);
  }
  
?>

Command line:

> pie tutorials\helloplayer.php





// [Host hello player] ////////////////////////////////////////////////////////

Notice that this program is speaking as you - this is because the program is
in local mode. If we want a server to greet people, we must use host mode and
connect to the server instead of your client.

To connect to a server, we need the IP address, port number and admin
password of the server (these can be found in your host control panel), we
must add our IP address to the access whitelist (access control tab), and we
must set the correct flag settings (specifically, we must ensure that
ISF_LOCAL flag is not set). We can add these settings to our PIE script in two
ways:

Method 1: We'll add these settings to a config file, and use the original
helloplayer.php file unchanged. Please note that you cannot use constants in a
.cfg file. We will use the value 0 for 'flags'.

helloplayer.php file:


<?php 

function PIE_NCN($data)
  {
    
PIE_say('Hello '.$data['PName']);
  }
  
?>

host.cfg: (set your own host/port/adminpass)

flags=0
host=1.2.3.4
port=54321
adminpass=secretpassword

command line:

> pie tutorials\helloplayer.php host.cfg





Method 2: We'll copy the helloplayer.php file to hosthelloworld.php, and set
the settings we need with the 'PIE_settings' function. Here we can use our
InSim flag constants, if required.

hosthelloplayer.php: (set your own host/port/adminpass)


<?php 

function PIE_settings()
  {
    return array(
'flags'      => 0,
                 
'host'       => '1.2.3.4',
                 
'port'       => 54321,
                 
'adminpass'  => 'secretpassword');
  }

function 
PIE_NCN($data)
  {
    
PIE_say('Hello '.$data['PName']);
  }

?>

command line:

> pie tutorials\hosthelloplayer.php

Attached images
image4.jpg
image3.jpg

FGED GREDG RDFGDR GSFDG