问题描述:

I'm back, this time working on a game and I came across a problem. So I was tracing some packets, and made a duplicate on my source. So, the function:

function handleBakeryStateUpdate( $data, $str, $clientid )

{

$client = $this->clients[ $clientid ]; //$client SHOULD ALWAYS BE A MEMBER OF THE CLIENT CLASS!

$this->sendToRoom( $client->extRoomID, "%xt%barsu%" . $client->ID . "%"{'CurrentStation':'IngredientsStation','IngredientsStation':[{'IngredientType':'Eggs','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Milk','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Hay','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Flour','TotalRequired':1,'CurrentCount':0}],'CheerStation':{'CheerCapacity':7,'CurrentCheerCount':7,'Emote':7},'MultiplierStation':{'Counter':-1,'Multiplier':'Small'}}"%" );

}

The packet is supposed to send a bunch of stuff, and in that packet it has { and }. And, the other problem is that the function also has { and }. So it gives me:

PHP Parse error: syntax error, unexpected '{' in ...

How can I fix this?

More information: The packet it is sending is all this:

{'CurrentStation':'IngredientsStation','IngredientsStation':[{'IngredientType':'Eggs','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Milk','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Hay','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Flour','TotalRequired':1,'CurrentCount':0}],'CheerStation':{'CheerCapacity':7,'CurrentCheerCount':7,'Emote':7},'MultiplierStation':{'Counter':-1,'Multiplier':'Small'}}

Thank you.

网友答案:

If you literally just want to pass the JSON as a string that's encapsulated in percent symbols, then:

function handleBakeryStateUpdate( $data, $str, $clientid )
{
    $client    = $this->clients[ $clientid ]; //$client SHOULD ALWAYS BE A MEMBER OF THE CLIENT CLASS!
    $this->sendToRoom( $client->extRoomID, "%xt%barsu%" . $client->ID . "%" . "{'CurrentStation':'IngredientsStation','IngredientsStation':[{'IngredientType':'Eggs','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Milk','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Hay','TotalRequired':1,'CurrentCount':0},{'IngredientType':'Flour','TotalRequired':1,'CurrentCount':0}],'CheerStation':{'CheerCapacity':7,'CurrentCheerCount':7,'Emote':7},'MultiplierStation':{'Counter':-1,'Multiplier':'Small'}}" . "%" );
}

I somehow doubt that's actually want you want, but unless you show what sendToRoom is expecting, that's the best answer I can give.

Also note that using "packet" the way you are is very confusing. You're really just passing a string to a function. The use of the word packet is confusing, since it has a very specific meaning when it comes to networking.

相关阅读:
Top