예제 #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
파일: UserTest.php 프로젝트: lscgzwd/jegarn
 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;
 }