The online racing simulator
MTC Send...
When I go to use the Send(); on a MTC packet, Prism just flat out gives me "Press any key to continue..." no error, now warning, nothing. The code I am using is


<?php 
    
public function onPrismError($errno$errstr)
    {
        
$MTC = new IS_MTC;
        
$MTC->UCID(255)->Text('^1ERROR: ^7['.$errno.'] '.$errstr)->Sound(4)->Send();
    }
    public function 
onPrismClose()
    {
        
$MTC = new IS_MTC;
        
$MTC->UCID(255)->Text('^1FATAL ERROR. Restarting...')->Sound(4)->Send();
        
Cruise::sqlSaveAll();
    }
    public function 
__construct()
    {
        
#PHP Stuff
        
set_error_handler(array($this'onPrismError'));
        
register_shutdown_function(array($this'onPrismClose'));
?>

I ran prism with out the ->Send() and it works fine, but soon as I go to send it, it crashes...
Edit... Just realized I posted from wrong account >.<
Well you are over writing the default handlers for error and shutdown, and I am not sure if you can send a packet after an error has happened within PHP as you are using a PHP resource. This might be causing the error you are having.

Second thing you might want to try is adding a return false to onPrismError at the very end. Also adding a echo statement to see if it ever get's there might also help.

Third you know you can do this right?


<?php 
IS_MTC
()->Sound(SND_ERROR)->UCID(255)->Text('Text')->Send();
?>


<?php 
    
public function onPrismError($eNo$eStr)
    {
        
IS_MTC()->Sound(SND_ERROR)->UCID(255)->Text("^1ERROR: ^7['{$eNo}'] {$eStr}")->Send();
        return 
FALSE;
    }
    public function 
onPrismClose()
    {
        
IS_MTC()->Sound(SND_ERROR)->UCID(255)->Text('^1FATAL ERROR. Restarting...')->Send();
        
Cruise::sqlSaveAll();
    }
    public function 
__construct()
    {
        
set_error_handler(array($this'onPrismError'));
        
register_shutdown_function(array($this'onPrismClose'));
    }
?>

Quote from Dygear :<snip...>

Yep, I tried sending a /msg and it sends fine... not sure why it is only crashing for MTC...
also, it seems to work fine on shutdown... must be something to do with error... and I might have just found out what it was ... will find out in a sec

EDIT: ok, so I just put it to debug out to the console and I keep getting it to say this error: ERROR: ['2'] Invalid CRT parameters detected

EDIT2: Alright, found out that the problem is due to the error above(has to do with strftime function), the error was sending soo much that it could not keep up causing prism to crash from sending too many pps

Edit3: to prevent too many PPS I did this and it works fine...:

<?php 
    
private $stuff NULL;
    
    public function 
onPrismError($eNo$eStr$eFile$eLine)
    {
        if(
$eStr != 'Invalid CRT parameters detected'){
            if(
$this->stuff === NULL)
                
$this->stuff time() - 10;
            if((
time() - $this->stuff) >= 10){
                
$Error sprintf("^1ERROR: ^7[%d] %s. %s:%d",$eNo,$eStr,basename($eFile),$eLine);
                
IS_MTC()->Sound(SND_ERROR)->UCID(255)->Text($Error)->Send();
                
$this->stuff time();
                
console($Error);
            }
        }
        return 
FALSE;
    }
?>

Ah, ok. About that error ...

You just happened to stumble upon something that myself and Victor tried really hard to hide. This is an issue with the PHP langauge on the Windows side. It only happens on Windows, no other OS is effected by this error. Simply because of the way Windows handles streams, it causes that error the spam the error console unless handled. As we handle that error in the main PRISM code, most users don't see it. As you are hooking directly into the PHP error handler you are seeing this message. It is unfortunately not something I can work around.

This is where we first found the bug, and reported it to the PHP bug list, and this is anyone one. So at this point, it's a fairly well known PHP bug, just one that PHP is not moving quickly to fix. When we started PHPInSimMod, we wanted to push the boundaries of PHP, and as we are starting to see some of it's cracks I think we have succeeded.
Quote from Dygear :<snip>

Yep, I'm just having it ignore it all together ... since that is fixed, I shouldn't really need a error limiter now... but might be smart to keep in case Either way, It is working nicely now... that I have ignored that error...

Final Code:

<?php 
    
private $Additional = array();
    
    public function 
onPrismError($eNo$eStr$eFile$eLine)
    {
        if(
$eStr != 'Invalid CRT parameters detected'){
            if(!isset(
$this->Additional['Error']['Last']))
                
$this->Additional['Error']['Last'] = time() - 5;
            if((
time() - $this->Additional['Error']['Last']) >= 5){
                
$Error sprintf("^1> ERROR: ^7[%d] %s. %s:%d",$eNo,$eStr,basename($eFile),$eLine);
                
IS_MTC()->Sound(SND_ERROR)->UCID(255)->Text($Error)->Send(); console($Error);
                
$this->Additional['Error']['Last'] = time();
            }
        }
        return 
FALSE;
    }
    public function 
onPrismClose()
    {
        
IS_MTC()->Sound(SND_ERROR)->UCID(255)->Text('^1> FATAL ERROR. ^7Restarting...')->Send();
        
Cruise::sqlSaveAll();
    }
    public function 
__construct()
    {
        
#PHP Stuff
        
set_error_handler(array($this'onPrismError'));
        
register_shutdown_function(array($this'onPrismClose'));
?>

Example of a fatal error...(click for larger image)


Edit: Is there a PRISM function which will remove ^0 etc. from a string?
Attached images
FatalErrorEx.jpg
Quote from T3charmy :Edit: Is there a PRISM function which will remove ^0 etc. from a string?

No, not directly, but there is a PHP one.


<?php 
str_replace
($search$replace$subject);
str_replace($needle$haystack$subject);

$Text str_replace('^0'''$Text);

$Text str_replace(
    array(
'^0'),
    array(
''),
    
$Text
);
?>

Quote from Dygear :No, not directly, but there is a PHP one.


<?php 
str_replace
($search$replace$subject);
str_replace($needle$haystack$subject);

$Text str_replace('^0'''$Text);

$Text str_replace(
    array(
'^0'),
    array(
''),
    
$Text
);
?>


LateReply: ahh ok thanks

FGED GREDG RDFGDR GSFDG