예제 #1
0
파일: Network.php 프로젝트: xety/marsbot
 /**
  * Build the private packet to send it in the socket.
  *
  * @return string
  */
 protected function _buildPrivatePacket()
 {
     $packet = ['v' => ['n' => Configure::read('Bot.username'), 'p' => Configure::read('Bot.password')]];
     return Xml::build($packet);
 }
예제 #2
0
파일: Response.php 프로젝트: xety/marsbot
 /**
  * When an user tickle the bot, you must send back this packet to display
  * the bot's powers and others information about the bot.
  *
  * @param \Mars\Network\Server $server The server instance.
  * @param int $id The user id.
  *
  * @return bool
  */
 public function answerTickle(Server $server, $id)
 {
     $server->Socket->write(Xml::build(['z' => ['d' => $id, 'u' => Configure::read('Bot.id') . '_0', 't' => '/a_NF']]));
     return true;
 }
예제 #3
0
파일: Server.php 프로젝트: xety/marsbot
 /**
  * Handle the response from the socket.
  *
  * @param bool|string $response The response from the socket.
  *
  * @return void
  */
 protected function _handleResponse($response)
 {
     if ($response != false) {
         $length = strlen($response);
         while ($response[$length - 1] != '>' && $response[$length - 1] != chr(0)) {
             $response .= $this->Socket->read();
             $length = strlen($response);
         }
         $packets = [];
         preg_match_all("/<([\\w]+)[^>]*>/", $response, $packets, PREG_SET_ORDER);
         foreach ($packets as $packet) {
             $packet[0] = Xml::toArray(Xml::build(Xml::repair($packet[0])));
             debug($packet);
             $this->PacketManager->{'on' . Inflector::camelize($packet[1])}($packet[0]);
         }
     }
 }
예제 #4
0
파일: Room.php 프로젝트: xety/marsbot
 /**
  * Build the join packet (J2).
  *
  * - Order attributes :
  * cb,Y,l5,l4,l3,l2,q,y,k,k3,d1,z,p,c,b,r,f,e,u,m,d0,d[i],dO,sn,dx,dt,N,n,a,h,v
  *
  * @param array $connection The connection array.
  * @param array $network The login array.
  * @param int $room The room id.
  *
  * @return string The packet generated.
  *
  * @throws \Mars\Network\Exception\RoomException When the $connection and/or $network variables are empty.
  */
 protected function _buildJoinPacket(array $connection = [], array $network = [], $room = null)
 {
     if (empty($connection) || empty($network)) {
         throw new RoomException('The connection and/or network variable(s) can not be empty to build the J2 packet.', E_WARNING);
     }
     if (is_null($room)) {
         $room = $this->config()['room'];
     }
     $j2 = ['j2' => ['cb' => $connection['y']['c']]];
     if (isset($connection['y']['au'])) {
         $j2['j2']['Y'] = 2;
     }
     $j2['j2'] += ['l5' => '65535', 'l4' => rand(10, 500), 'l3' => rand(10, 500), 'l2' => 0, 'q' => 1, 'y' => $connection['y']['i'], 'k' => $network['v']['k1'], 'k3' => $network['v']['k3']];
     if (isset($network['v']['d1'])) {
         $j2['j2']['d1'] = $network['v']['d1'];
     }
     $j2['j2'] += ['z' => 12, 'p' => 0, 'c' => $room, 'r' => '', 'f' => 0, 'e' => 1, 'u' => $network['v']['i'], 'd0' => $network['v']['d0']];
     for ($x = 2; $x <= 15; $x++) {
         if (isset($network['v']['d' . $x])) {
             $j2['j2']['d' . $x] = $network['v']['d' . $x];
         }
     }
     if (isset($network['v']['dO'])) {
         $j2['j2']['dO'] = $network['v']['dO'];
     }
     if (isset($network['v']['dx'])) {
         $j2['j2']['dx'] = $network['v']['dx'];
     }
     if (isset($network['v']['dt'])) {
         $j2['j2']['dt'] = $network['v']['dt'];
     }
     $j2['j2'] += ['N' => $network['v']['n'], 'n' => Configure::read('Bot.name'), 'a' => Configure::read('Bot.avatar'), 'h' => Configure::read('Bot.home'), 'v' => 0];
     return Xml::build($j2);
 }