示例#1
0
 public function auth()
 {
     $um = UserManager::getInstance();
     if ($user = $um->getUser($this->getAccount())) {
         if ($um->authPassword($this->getPassword(), $user['password'])) {
             $this->setUid($user['uid']);
             return true;
         }
     }
     return false;
 }
示例#2
0
 public function testClear()
 {
     /**
      * @var array $users
      * @var integer $groupId
      * @var integer $chatroomId
      */
     require __DIR__ . '/initData.php';
     $userList = [];
     foreach ($users as $user) {
         UserManager::getInstance()->removeUser($user['account']);
         $userList[] = $user['uid'];
     }
     // create group, and user to group
     GroupManager::getInstance()->removeGroupUsers($groupId, $userList);
     // create chatroom, add user to chatroom
     ChatroomManager::getInstance()->removeChatroomUsers($chatroomId, $userList);
 }
示例#3
0
 public static function getUserPresent($uid)
 {
     $ret = UserManager::getInstance()->isUserOnline(intval($uid));
     return $ret ? User::ONLINE : User::OFFLINE;
 }
示例#4
0
            $packet = new TextGroupChat();
            /* @var TextGroupChat $packet */
            $packet = $packet->getPacketFromPacket($pkt);
            $packet->from = $pkt->to;
            $packet->setSendToAll();
            $packet->setText($introduction);
            $client->sendPacket($packet);
            break;
        case Chatroom::TYPE:
            break;
    }
});
swoole_timer_add(30000, function ($interval) use($client, $infiniteCounterHandler) {
    if ($client->isAuthorized()) {
        //send online user chat packet
        $uidList = UserManager::getInstance()->getAllOnlineUsers();
        if (count($uidList) > 1) {
            $chat = new TextChat();
            $chat->from = COUNTER_UID;
            foreach ($uidList as $uid) {
                if ($uid != COUNTER_UID) {
                    $chat->to = $uid;
                    $chat->setText($infiniteCounterHandler->increase());
                    $client->sendPacket($chat);
                }
            }
        }
        /*// send groupchat
          $groupchat = new TextGroupChat();
          $groupchat->from = COUNTER_UID;
          $groupchat->setSendToAll();
示例#5
0
 public function deleteUser(User $user)
 {
     self::assertTrue(null === UserManager::getInstance()->removeUser($user));
     // user should be remove from cache
     self::assertTrue(\jegarn\manager\UserManager::getInstance()->getUser($user->username) === null);
 }
示例#6
0
 public static function getUser()
 {
     $user = ['uid' => self::$uidIndex, 'account' => 'tester_' . self::$uidIndex, 'password' => rand(100000, 999999), 'groupId' => self::getGroup(), 'chatroomId' => self::getChatroom()];
     self::$uidList[] = self::$uidIndex;
     ++self::$uidIndex;
     UserManager::getInstance()->addUser($user['uid'], $user['account'], $user['password']);
     GroupManager::getInstance()->addGroupUser($user['groupId'], $user['uid']);
     ChatroomManager::getInstance()->addChatroomUser($user['chatroomId'], $user['uid']);
     return $user;
 }