public function verifyClient(TeamspeakAccount $tsAccount, MinecraftAccount $mcAccount) { //unauthenticate any accounts with the same MC name but not the same UUID $mcqb = $this->entityManager->createQueryBuilder(); $mcqb->select('mcAccount')->from('PublicUHCTeamspeakAuthBundle:MinecraftAccount', 'mcAccount')->where($mcqb->expr()->andX($mcqb->expr()->eq('mcAccount.name', ':name'), $mcqb->expr()->neq('mcAccount.uuid', ':uuid')))->setParameter('name', $mcAccount->getName())->setParameter('uuid', $mcAccount->getUUID()); $accounts = $mcqb->getQuery()->getResult(Query::HYDRATE_OBJECT); /** @var $account MinecraftAccount */ foreach ($accounts as $account) { /** @var $authentication Authentication */ foreach ($account->getAuthentications()->getValues() as $authenitcation) { $this->unauthenticate($authenitcation); } } //verify the client $tsUUID = $tsAccount->getUUID(); $this->setDescriptionForUUID($mcAccount->getName(), $tsUUID); //attempt to remove them from the group first try { $this->removeUUIDFromGroup($tsUUID, $this->groupID); } catch (\TeamSpeak3_Exception $ex) { } $this->addUUIDToGroup($tsUUID, $this->groupID); $authenitcation = new Authentication(); $authenitcation->setMinecraftAccount($mcAccount)->setTeamspeakAccount($tsAccount); $this->entityManager->persist($authenitcation); $tsAccount->getCodes()->clear(); $mcAccount->getCodes()->clear(); $this->entityManager->flush(); $playerIcon = $this->mcHelper->getIconForUsername($mcAccount->getName()); $this->setIconForUUID($tsUUID, $playerIcon); }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln("<info>Starting server on port {$this->server->getPort()}... You can stop the server with Ctrl+C.</info>"); $this->logger->info('Starting auth server on port ' . $this->server->getPort()); //setup a loop to keep the connection alive $this->loop->addPeriodicTimer($this->keepAlive, function () { $this->em->getConnection()->executeQuery('DO 1'); }); $this->server->on('login_success', function ($username, $uuid, DisconnectPacket $packet) use($output) { $qb = $this->em->createQueryBuilder(); $qb->select('account')->from('PublicUHCTeamspeakAuthBundle:MinecraftAccount', 'account')->where('account.uuid = :uuid')->setParameter('uuid', $uuid); try { /** @var $account MinecraftAccount */ $account = $qb->getQuery()->getSingleResult(); } catch (NoResultException $ex) { $output->writeln("<info>New account created for {$username} ({$uuid})</info>"); $this->logger->info("New minecraft account created for {$username} ({$uuid})"); $account = new MinecraftAccount(); } $account->setName($username)->setUUID($uuid)->setUpdatedAt(new DateTime('now')); $code = new MinecraftCode(); $code->setAccount($account); $codes = $account->getCodes(); $codes->clear(); $codes->add($code); $this->em->persist($account); $this->em->persist($code); $this->em->flush(); //detach so changes to db externally will affet the account if it's used again //also stops memory leaking due to references being kept $this->em->detach($account); $this->em->detach($code); $output->writeln("<comment>USERNAME: {$username} UUID: {$uuid} CODE: {$code->getCode()}</comment>"); $this->logger->info("USERNAME: {$username} UUID: {$uuid} CODE: {$code->getCode()}"); $packet->setReason('Your code is ' . $code->getCode()); }); $description = $this->description; $imageData = base64_encode(file_get_contents($this->faviconLocation)); $favicon = 'data:image/png;base64,' . $imageData; $this->server->on('status_request', function (StatusResponsePacket $packet) use($description, $favicon) { $packet->setDescription($description)->setMaxPlayers(-1)->setOnlineCount(-1)->setVersion('1.8+')->setFavicon($favicon); }); $this->server->start(); }