public function dispatchReceivePacket(Packet $packet, Session $session) { if ($session->isAuth()) { return true; } /* @var \jegarn\session\SwooleSession $session * @var AuthPacket $pkt */ if ($pkt = AuthPacket::getPacketFromPacket($packet)) { if ($pkt->auth()) { $session->setUserId($pkt->getUid()); $session->setAuth(true); $session->setSessionId(TextUtil::generateGUID()); SessionManager::getInstance()->addSession($session); $pkt->setStatus(AuthPacket::STATUS_AUTH_SUCCESS); } else { $pkt->setStatus(AuthPacket::STATUS_AUTH_FAILED); Logger::addInfo('auth failed(fd:' . $session->getFd() . ')'); } } else { $pkt = new AuthPacket(); $pkt->setPacket($packet); $pkt->setStatus(AuthPacket::STATUS_NEED_AUTH); Logger::addInfo('auth needed(fd:' . $session->getFd() . ')'); } ServerManager::getInstance()->send($session, $pkt->getReversedPacket()); return false; }
public function register() { if (null === $this->serverId) { $this->serverId = TextUtil::generateGUID(); } Cache::getInstance()->hSet($this->registerKey, $this->serverId, $this->config['host'] . ':' . $this->config['port']); $this->modifyServerInfo(); }