-3

我回来了,这次在玩游戏时遇到了一个问题。所以我正在追踪一些数据包,并在我的来源上复制了一份。所以,函数:

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'}}"%" );
}

该数据包应该发送一堆东西,并且在该数据包中它具有{和}。而且,另一个问题是该函数也有 { 和 }。所以它给了我:

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

我怎样才能解决这个问题?

更多信息:它发送的数据包是这样的:

{'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'}}

谢谢你。

4

1 回答 1

1

如果您实际上只是想将 JSON 作为封装在百分比符号中的字符串传递,那么:

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'}}" . "%" );
}

我不知何故怀疑这实际上是你想要的,但除非你表现出sendToRoom期望的东西,否则这是我能给出的最佳答案。

另请注意,以您的方式使用“数据包”非常令人困惑。您实际上只是将字符串传递给函数。数据包一词的使用令人困惑,因为它在网络方面具有非常特定的含义。

于 2013-01-02T23:49:16.647 回答