예제 #1
0
파일: Event.php 프로젝트: eseawind/qian_dao
 /**
  * 当用户断开连接时触发的方法
  * @param integer $client_id 断开连接的用户id
  * @return void
  */
 public static function onClose($client_id)
 {
     // 广播 xxx 退出了
     GateWay::sendToAll(TextProtocol::encode("{$_SESSION['name']}[{$client_id}] logout"));
 }
예제 #2
0
 /**
  * 有消息时触发该方法
  * @param int $uid 发消息的uid
  * @param string $message 消息
  * @return void
  */
 public static function onMessage($uid, $message)
 {
     $message_data = TextProtocol::decode($message);
     // 判断是否是私聊,私聊数据格式 uid:xxxxx
     $explode_array = explode(':', $message, 2);
     if (count($explode_array) > 1) {
         $to_uid = (int) $explode_array[0];
         GateWay::sendToUid($uid, TextProtocol::encode($_SESSION['name'] . "[{$uid}] said said to [{$to_uid}] :" . $explode_array[1]));
         return GateWay::sendToUid($to_uid, TextProtocol::encode($_SESSION['name'] . "[{$uid}] said to You :" . $explode_array[1]));
     }
     // 群聊
     return GateWay::sendToAll(TextProtocol::encode($_SESSION['name'] . "[{$uid}] said :" . $message));
 }