Guest User

Untitled

a guest
Dec 12th, 2011
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.64 KB | None | 0 0
  1.     /**
  2.      * Internal function
  3.      */
  4.     public function ParseFromArray()
  5.     {
  6.         $this->chunk = '';
  7.         // read the length byte
  8.         $length = $this->reader->next();
  9.         // just take the splice from this array
  10.         $this->_ParseFromArray($length);
  11.     }
  12.  
  13.     /**
  14.      * Internal function
  15.      */
  16.     private function _ParseFromArray($length=99999999)
  17.     {
  18.         $_begin = $this->reader->get_pointer();
  19.         while ($this->reader->get_pointer() - $_begin < $length)
  20.         {
  21.             $next = $this->reader->next();
  22.             if ($next === false)
  23.                 break;
  24.  
  25.             // now get the message type
  26.             $messtypes = $this->get_types($next);
  27.  
  28.             // now make method test
  29.             if (!isset($this->fields[$messtypes['field']]))
  30.             {
  31.                 // field is unknown so just ignore it
  32.                 // throw new Exception('Field ' . $messtypes['field'] . ' not pr
  33. esent ');
  34.                if ($messtypes['wired'] == PBMessage::WIRED_LENGTH_DELIMITED)
  35.                {
  36.                    $consume = new PBString($this->reader);
  37.                      }
  38.                else if ($messtypes['wired'] == PBMessage::WIRED_VARINT)
  39.                {
  40.                    $consume = new PBInt($this->reader);
  41.                      }
  42.                else if ($messtypes['wired'] == PBMessage::WIRED_32BIT)
  43.                {
  44.                    $consume = new PBFixedInt($this->reader);
  45.                      }
  46.                else
  47.                {
  48.                    throw new Exception('I dont understand this wired code:' . $
  49. messtypes['wired']);
  50.                }
  51.  
  52.                // perhaps send a warning out
  53.                // @TODO SEND CHUNK WARNING
  54.                $_oldpointer = $this->reader->get_pointer();
  55.                $consume->ParseFromArray();
  56.                // now add array from _oldpointer to pointer to the chunk array
  57.                $this->chunk .= $this->reader->get_message_from($_oldpointer);
  58.                continue;
  59.            }
  60.  
  61.            // now array or not
  62.            if (is_array($this->values[$messtypes['field']]))
  63.            {
  64.                $this->values[$messtypes['field']][] = new $this->fields[$messty
  65. pes['field']]($this->reader);
  66.                $index = count($this->values[$messtypes['field']]) - 1;
  67.                if ($messtypes['wired'] != $this->values[$messtypes['field']][$i
  68. ndex]->wired_type)
  69.                {
  70.                    throw new Exception('Expected type:' . $messtypes['wired'] .
  71. ' but had ' . $this->fields[$messtypes['field']]->wired_type);
  72.                }
  73.                $this->values[$messtypes['field']][$index]->ParseFromArray();
  74.            }
  75.            else
  76.            {
  77.                //echo "Called as value : " . $this->fields[$messtypes['field']]
  78. . " : " . $messtypes['wired'] . " ($index)\n";
  79.                $this->values[$messtypes['field']] = new $this->fields[$messtype
  80. s['field']]($this->reader);
  81.                if ($messtypes['wired'] != $this->values[$messtypes['field']]->w
  82. ired_type)
  83.                {
  84.                    throw new Exception('Expected type:' . $messtypes['wired'] .
  85. ' but had ' . $this->fields[$messtypes['field']]->wired_type);
  86.                }
  87.                $this->values[$messtypes['field']]->ParseFromArray();
  88.            }
  89.        }
  90.    }
  91.  
  92.    /**
  93.     * Add an array value
  94.     * @param int - index of the field
  95.     */
  96.    protected function _add_arr_value($index)
  97.    {
  98.        return $this->values[$index][] = new $this->fields[$index]();
  99.    }
  100.  
  101.    /**
  102.     * Set an array value - @TODO failure check
  103.     * @param int - index of the field
  104.     * @param int - index of the array
  105.     * @param object - the value
  106.     */
  107.    protected function _set_arr_value($index, $index_arr, $value)
  108.    {
  109.        $this->values[$index][$index_arr] = $value;
  110.    }
  111.  
  112.    /**
  113.     * Remove the last array value
  114.     * @param int - index of the field
  115.     */
  116.    protected function _remove_last_arr_value($index)
  117.    {
  118.        array_pop($this->values[$index]);
  119.    }
  120.  
  121.    /**
  122.     * Set an value
  123.     * @param int - index of the field
  124.     * @param Mixed value
  125.     */
  126.    protected function _set_value($index, $value)
  127.    {
  128.        if (gettype($value) == 'object')
  129.        {
  130.            $this->values[$index] = $value;
  131.        }
  132.        else
  133.        {
  134.            $this->values[$index] = new $this->fields[$index]();
  135.            $this->values[$index]->value = $value;
  136.        }
  137.    }
  138.  
  139.    /**
  140.     * Get a value
  141.     * @param id of the field
  142.     */
  143.    protected function _get_value($index)
  144.    {
  145.        if ($this->values[$index] == null)
  146.            return null;
  147.        return $this->values[$index]->value;
  148.    }
  149.  
  150.    /**
  151.     * Get array value
  152.     * @param id of the field
  153.     * @param value
  154.     */
  155.    protected function _get_arr_value($index, $value)
  156.    {
  157.        return $this->values[$index][$value];
  158.    }
  159.  
  160.    /**
  161.     * Get array size
  162.     * @param id of the field
  163.     */
  164.    protected function _get_arr_size($index)
  165.    {
  166.        return count($this->values[$index]);
  167.    }
  168.  
  169.    /**
  170.     * Helper method for send string
  171.     */
  172.    protected function _save_string($ch, $string)
  173.    {
  174.        $this->_d_string .= $string;
  175.        $content_length = strlen($this->_d_string);
  176.        return strlen($string);
  177.    }
  178.  
  179.    /**
  180.     * Sends the message via post request ['message'] to the url
  181.     * @param the url
  182.     * @param the PBMessage class where the request should be encoded
  183.     *
  184.     * @return String - the return string from the request to the url
  185.     */
  186.    public function Send($url, &$class = null)
  187.    {
  188.        $ch = curl_init();
  189.        $this->_d_string = '';
  190.  
  191.        curl_setopt($ch, CURLOPT_URL, $url);
  192.        curl_setopt($ch, CURLOPT_POST, true);
  193.        curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, '_save_string'));
  194.        curl_setopt($ch, CURLOPT_POSTFIELDS, 'message=' . urlencode($this->Seria
  195. lizeToString()));
  196.        $result = curl_exec($ch);
  197.  
  198.        if ($class != null)
  199.            $class->parseFromString($this->_d_string);
  200.        return $this->_d_string;
  201.    }
  202.  
  203.        /**
  204.     * Fix Memory Leaks with Objects in PHP 5
  205.     * http://paul-m-jones.com/?p=262
  206.     *
  207.     * thanks to cheton
  208.     * http://code.google.com/p/pb4php/issues/detail?id=3&can=1
  209.     */
  210.    public function __destruct()
  211.    {
  212.        if (isset($this->reader))
  213.        {
  214.            unset($this->reader);
  215.        }
  216.        if (isset($this->value))
  217.        {
  218.            unset($this->value);
  219.        }
  220.        // base128
  221.        if (isset($this->base128))
  222.        {
  223.           unset($this->base128);
  224.        }
  225.        // fields
  226.        if (isset($this->fields))
  227.        {
  228.            foreach ($this->fields as $name => $value)
  229.            {
  230.                unset($this->$name);
  231.            }
  232.            unset($this->fields);
  233.        }
  234.        // values
  235.        if (isset($this->values))
  236.        {
  237.            foreach ($this->values as $name => $value)
  238.            {
  239.                if (is_array($value))
  240.                {
  241.                    foreach ($value as $name2 => $value2)
  242.                    {
  243.                        if (is_object($value2) AND method_exists($value2, '__des
  244. truct'))
  245.                        {
  246.                            $value2->__destruct();
  247.                        }
  248.                        unset($value2);
  249.                    }
  250.                    if (isset($name2))
  251.                        unset($value->$name2);
  252.                }
  253.                else
  254.                {
  255.                    if (is_object($value) AND method_exists($value, '__destruct'
  256. ))
  257.                    {
  258.                        $value->__destruct();
  259.                    }
  260.                    unset($value);
  261.                }
  262.                unset($this->values->$name);
  263.            }
  264.            unset($this->values);
  265.        }
  266.    }
  267.  
  268. }
  269. ?>
  270.  
  271. Fatal error: Class 'PBMessage' not found in C:\TAWNEW\Sources\AocLogin\pb_proto_
  272. Endpoints.php on line 5
  273.  
  274. ===================================================
  275.  
  276.    _/_/_/              _/_/_/                _/
  277.  
  278.   _/    _/    _/_/    _/    _/    _/_/    _/_/_/_/
  279.  
  280.  _/_/_/    _/_/_/_/  _/_/_/    _/    _/    _/
  281.  
  282. _/    _/  _/        _/    _/  _/    _/    _/
  283.  
  284. _/_/_/      _/_/_/  _/_/_/      _/_/        _/_/
  285.  
  286.         An Anarchy Online Chat Automaton
  287.  
  288.                     And
  289.  
  290.          An Age of Conan Chat Automaton
  291.  
  292.         v.0.6.8 - PHP 5.3.1
  293.  
  294.                 OS: Windows_NT
  295.  
  296.        Your operating system is detected as 32bit
  297.  
  298. ===================================================
  299.  
  300.  
  301.  
Advertisement
Add Comment
Please, Sign In to add comment