数据包&功能冲突

时间:2013-01-02 23:40:36

标签: php

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

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

谢谢。

1 个答案:

答案 0 :(得分: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期待的东西,否则这是我能给出的最佳答案。

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