The online racing simulator
PHPInSim
(96 posts, started )
Whatever the hell it is, please, release it.. otherwise Dygear here, is going to have some sort of melt down...!
Quote from mkinnov8 :Whatever the hell it is, please, release it.. otherwise Dygear here, is going to have some sort of melt down...!

It is basically PHPInSim, but it works, and it works really well. It's done witch is a plus. But he does not want to release it yet (From the last time we spoke and that was like 2 months ago) b/c he does not want a million requests on why this does not work the way it should. I used this in SimFIA and it's rock solid, but still no release, like a year an a half later.
Quote from Dygear :It is basically PHPInSim, but it works, and it works really well. It's done witch is a plus. But he does not want to release it yet (From the last time we spoke and that was like 2 months ago) b/c he does not want a million requests on why this does not work the way it should. I used this in SimFIA and it's rock solid, but still no release, like a year an a half later.

Simple: post "no support" over it entirely and only people with a clue will use it. Hell, I'll happily post it on his behalf and say it's an anonymous contributor, remove all references to it here, and field any stupid questions and play the "theres no support" card.

Having used it myself briefly, I can actually say it's very nice You kinda need to have at least half a brain to use it though
Quote from the_angry_angel :Having used it myself briefly, I can actually say it's very nice You kinda need to have at least half a brain to use it though

Hell yes it is, and I only needed 1/4th of my brain to program to program with it. So the rest of you should only need like 1/64th of your brain.
Quote from Dygear :However, with the individual functions, there is really no good way to then take that into a plugin systems.

Why? Have you seen my solution in my php class?
Dygear, let me criticise some of your code. I support your efforts, even though I was (and maybe will continue) making my own class.

Here is your code for message sending:
$MSO = new MSO();
$MSO->UCID = $UCID
$MSO->PLID = $PLID
$MSO->UserType = MSO_USER;
$MSO->Msg = "Welcome to the Race, {$PName}^9 ({$UName})!";
// Setup Option 2 - Array, Fast, and Short, but Ugly.
$MSO = new MSO(array(
'UCID' => $UCID,
'PLID' => $PLID,
'UserType' => MSO_USER;
'Msg' => "Welcome to the Race, {$PName}^9 ({$UName})!"
);

In this code you repeat MSO so many times. Maybe do something about that? The 2nd option isn't that ugly, but still you repeat some names. The 3rd way is almost the same as 2nd, just written a bit differently: you m,oved array parsing from constructor to send method.

Think of it: any time you send a message to a connection, you need to supply all the 3 parameters: UCID, message text and message type. You need to remember them exactly and to put them in the right place: in case of an associative array you have to give them proper indexes. In case of a special method you need to supply them in a proper order. This is the same in it's essence. But what is easier to code: this

$MCO = new MCO(array("UCID" => $UCID, "PLID" => $PLID, "Message" => $myMessageText));

(BTW, you'll need to keep and pass global variables for the connection, right? That's why I made my plugins as objects that have links to the connection class and $connection resourse Id)

or this (let it be, as you prefer, a call of class method):

MSO::send($UCID, $PLID, $myMessageText);

As you see, the code is still readable, unless you step away from naming conventions and write something like

MSO::send($sdkjslkj, $saadasda, $mmmmmm);

In my opinion, there is no need to type the array keys to remind to yourself another time what parameters are supplied. You just have keep your variables names neat and also, anyway there is the function definition there in the code. If you don't know what parameters to supply, go there and read it. No need to repeat partso of the function definition in the code, right?

I'm not a guru in programming, but I've tried the "nice" style like that in option 1, and it appeared to be too labour-intensive to code. With years I've got an idea that the less you repeat pieces of code, the better.

Of course, it is my opinion, you may choose whatever way you prefer.
Sorry to butt in again Something like this work?


<?php 
$mso 
= new MSO($uclid$plidMSO_USER$msg);
$mso->send($conn);
?>


<?php 
class MSO {
 var 
$uclid;
 var 
$plid;
 var 
$usertype;
 var 
$msg

 
function __construct($uclid$plid$usertype$msg) {
  foreach(
get_object_vars($this) as $i => $v) {
   
$this->$i = $$i;
  }
 }
 function 
send($conn) {
  
// to do
 
}
}
?>

NotAnIllusion: why make an object in this example? I guess after you send it, it is disposable.

When somebody uses objects for a template class, it is needed to avoid carrying all the bunch of variables in parameters. But here you don't re-pass them anywhere.

send_MSO($conn, $uclid, $plid, MSO_USER, $msg)!

Ok, I see a sense to create classes for incoming packets, but why do that for those outgoing? (Don't take me wrong, I don't want to be a pain in the a**. I'm not a good programmer, so take these questions not like rhethoric, but like my curiosity )
I dont know if its possible in php, but in C# you can create something called a "utility class". This class is used to make methods that normal do something quick and fast. You also dont need to make an instance of them, you can use them directly. If you could use them in php wouldnt it be easier?

For exmple you could do normally

$MSO = new MSO(etc etc)

in a utility class, iirc you just access it directly, so it would be something like this

MSO.blah(etc etc)

Yes, you can call a class method in PHP:

myClass::myMethod(...)

Here what I'm curious about is: does it make sense to make a class without making its instances, instead of just having standalone functions?
Quote from detail :Yes, you can call a class method in PHP:

myClass::myMethod(...)

Here what I'm curious about is: does it make sense to make a class without making its instances, instead of just having standalone functions?

All depends on what it does tbh... if it was a big method id just leave it as a standard class and make instances of it. If it was a quick and small job id make it a utility class, to save the hassel of making the instance.
Quote from detail :NotAnIllusion: why make an object in this example? I guess after you send it, it is disposable.

It was just a response to the object method shown, I haven't considered the actual point of using objects, just that there just happened to be one there
Quote from the_angry_angel :You kinda need to have at least half a brain to use it though

Well thats me out, but at least those with half a brain would get to create useful things
Quote from detail :I see a sense to create classes for incoming packets, but why do that for those outgoing?

Why would you want to separate how you interface with incoming packets from how you interface with outgoing packets?
Style 1 - OOP, But Long.

<?php 
php

class myPluginName {
    public function 
register_plugin() {
        
$this->name 'Simple Example Plugin';
        
$this->author 'Mark \'Dygear\' Tomlin';
        
$this->version '0.Example1.1';
        
$this->functions = array(
            
'client_connect' => array('ISP_NCN'),
        );
    }
    public function 
client_connect($packet) {
        
extract($packet); # Extracts packet data into symbol table.
        
$MSO = new MSO();
        
$MSO->UCID $UCID
        $MSO
->PLID $PLID
        $MSO
->UserType MSO_USER;
        
$MSO->Msg "Welcome to the Race, {$PName}^9 ({$UName})!"
        
$MSO->send();
    }
}

?>

Style 2 - Array, Fast, and Short, but Ugly.

<?php 
php

class myPluginName {
    public function 
register_plugin() {
        
$this->name 'Simple Example Plugin';
        
$this->author 'Mark \'Dygear\' Tomlin';
        
$this->version '0.Example1.2';
        
$this->functions = array(
            
'client_connect' => array('ISP_NCN'),
        );
    }
    public function 
client_connect($packet) {
        
extract($packet); # Extracts packet data into symbol table.
        
$MSO = new MSO(array(
            
'UCID' => $UCID,
            
'PLID' => $PLID,
            
'UserType' => MSO_USER;
            
'Msg' => "Welcome to the Race, {$PName}^9 ({$UName})!"
        
);
        
$InSim->send($MSO);
    }
}

?>

Style 3 - OOP, Arrays and it's own send method built in!

<?php 
php

class myPluginName {
    public function 
register_plugin() {
        
$this->name 'Simple Example Plugin';
        
$this->author 'Mark \'Dygear\' Tomlin';
        
$this->version '0.Example1.3';
        
$this->functions = array(
            
'client_connect' => array('ISP_NCN'),
        );
    }
    public function 
client_connect($packet) {
        
extract($packet); # Extracts packet data into symbol table.
        
MSO::send(
            array(
                
'UCID' => $UCID,
                
'PLID' => $PLID,
                
'UserType' => MSO_USER,
                
'Msg' => "Welcome to the Race, {$PName}^9 ({$UName})!"
            
)
        );
    }
}

?>

That's how that post was meant to be read, but I understand how that could be confusing.
@filur: because to send a packet, i need only to pack(...) and send, and to receive a packet I need to socket_read, unpack, decode into my structures, then call a function. I've written a very lightweight app and didn't make length check and other routines that could be common for both outgoing and incoming packets.

@Dygear: I understood you very well, it didn't confuse me. What I talk about is the repetition of names in the following expression:


<?php 
MSO
::send(
            array(
                
'UCID' => $UCID,
                
'PLID' => $PLID,
                
'UserType' => MSO_USER,
                
'Msg' => "Welcome to the Race, {$PName}^9 ({$UName})!"
            
)
        );
?>

I meant that you better design MSO::send to work like this:

<?php 
MSO
::send($UCID$PLIDMSO_USER"Welcome to the Race, {$PName}^9 ({$UName})!");
?>

You have to remember the order the args come in. Number one reason I don't like it so much.

You guys don't know this, but I don't write programs in an IDE, they tend to get into my way most of the time. I write all of my programs in NotePad2, it's notepad with syntax highlighting of some languages.

With that said, I will consider your style send function.
Keep in mind all functions in php have an order of input parameters
Dygear - Hows the progress going now?
Quote from detail :because to send a packet, i need only to pack(...) and send, and to receive a packet I need to socket_read, unpack, decode ...

That's not quite what i meant by interfacing.


function sensibleMethod(MSO $msopacket) {
// programmer thinks "i'm interfacing with a packet object that corresponds to the insim spec"
echo $msopacket->UName;

// programmer wants to send a packet
$mypacket = new MST();
// programmer thinks "i'm interfacing with a packet object that corresponds to the insim spec"
$mypacket->Msg = 'Hello, ' . $msopacket->UName;

// programmer wants to send another packet
$myotherpacket = new MTC();
// programmer thinks "i'm interfacing with a packet object that corresponds to the insim spec"
$myotherpacket->UCID = $msopacket->UCID;
// etc ..
}

function confusingMethod(MSO $packet) {
// programmer thinks "i'm interfacing with a packet object that corresponds to the insim spec"
echo $packet->UName;

// programmer wants to send a packet
// programmer thinks "ok so now i'm supposed to interface with send_mst()"
send_mst( ... );

// programmer wants to send another packet
// programmer thinks "ok so now i'm supposed to interface with send_mtc()"

etc..
}

function sensibleProxyPacketDispatch(InSimPacket $packet) {
foreach ($this->clients as $client) {
$packet->sendTo($client);
}
}

function horribleProxyPacketDispatch(InSimPacket $packet) {
if ($packet instanceof MSO) {
send_mso( ... );
}
elseif ($packet instanceof NPL) {
send_npl( ... );
}

... and on and on
}

I have been doing (ambulance) rotations all week end, so I've not done much work on anything. Update soon
Plus with the added disagreement on how to handle packets, I've held off on it. I happen to be in an ambulance as I type this.
Quote from Dygear :Plus with the added disagreement on how to handle packets, I've held off on it. I happen to be in an ambulance as I type this.

You shouldnt worry about the disagreement tbh. Do it how you want to do it, The people that moan wont use it, so ****' em
That was pretty funny, I was in the ambulance hopping from WiFi connection to WiFi connection while surfing the forum.

Quote from mcgas001 :You shouldnt worry about the disagreement tbh. Do it how you want to do it, The people that moan wont use it, so ****' em

There people who are going to use this tho, are going to be in this forum, posting these messages. I have to speak to my user base.
Yes, but dont do it another way. just because your told its better. If you like one way, Do it. Also its a PHP script, If they want it that way they can change it themself.

PHPInSim
(96 posts, started )
FGED GREDG RDFGDR GSFDG