/** * 发送信息请求 */ function cmd_message($client_id, $msg) { $resMsg = $msg; $resMsg['cmd'] = 'fromMsg'; if (strlen($msg['data']) > self::MESSAGE_MAX_LEN) { $this->sendErrorMessage($client_id, 102, 'message max length is ' . self::MESSAGE_MAX_LEN); return; } //表示群发 if ($msg['rid'] > 0) { //广播组 $this->broadcastRoomsJson($client_id, $msg['rid'], $resMsg); //保存聊天记录 $this->getSwooleServer()->task(serialize(array('cmd' => 'addRoomsHistory', 'msg' => $msg, 'fd' => $client_id, 'rid' => $msg['rid'])), self::WORKER_HISTORY_ID); } elseif ($msg['room_id'] == 0) { if (self::ONLY_ROOM_CHAT == 1) { $resMsg['msg'] = 'send failed! only group chat.'; $this->sendJson($msg['from'], $resMsg); } else { $this->sendJson($msg['to'], $resMsg); $this->store->addHistory($client_id, $msg['data']); $this->sendJson($msg['from'], $resMsg); } } }
/** * 登录 * @param $client_id * @param $msg */ function cmd_login($client_id, $msg) { $info['name'] = Filter::escape($msg['name']); $info['avatar'] = Filter::escape($msg['avatar']); //回复给登录用户 $resMsg = array('cmd' => 'login', 'fd' => $client_id, 'name' => $msg['name'], 'avatar' => $msg['avatar']); //把会话存起来 $this->users[$client_id] = $resMsg; $this->store->login($client_id, $resMsg); $this->sendJson($client_id, $resMsg); //广播给其它在线用户 $resMsg['cmd'] = 'newUser'; //将上线消息发送给所有人 $this->broadcastJson($client_id, $resMsg); //用户登录消息 $loginMsg = array('cmd' => 'fromMsg', 'from' => 0, 'channal' => 0, 'data' => $msg['name'] . "上线了"); $this->broadcastJson($client_id, $loginMsg); }
/** * 登录 * @param $client_id * @param $msg */ function cmd_login($client_id, $msg) { $uid = $msg['uid']; $user = $this->ustore->getUser($uid); //回复给登录用户 $resMsg = array('cmd' => 'login', 'fd' => $client_id, 'uid' => $uid, 'name' => $user['name'], 'avatar' => $user['avatar']); //把会话存起来 $this->users[$client_id] = $resMsg; $this->store->login($client_id, $resMsg); $this->sendJson($client_id, $resMsg); //广播给其它在线用户 $resMsg['cmd'] = ''; //将上线消息发送给所有人 $this->broadcastJson($client_id, $resMsg); //用户登录消息 $loginMsg = array('cmd' => 'fromMsg', 'from' => 0, 'channal' => 0, 'data' => $user['name'] . "上线了"); $this->broadcastJson($client_id, $loginMsg); }