コード例 #1
0
ファイル: Event.php プロジェクト: bennysuh/workerman-game
 /**
  * 有消息时
  * @param int $uid
  * @param string $message
  */
 public static function onMessage($uid, $message)
 {
     $message_data = json_decode($message, true);
     // 向所有人发送
     if ($message_data['to_uid'] == 'all') {
         return GateWay::sendToAll($message);
     } else {
         return GateWay::sendToUid($message_data['to_uid'], $message);
     }
 }
コード例 #2
0
ファイル: Event.php プロジェクト: bennysuh/myself-wokerman
 /**
  * 有消息时触发该方法
  * @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));
 }