Example #1
0
 protected function _createRoom()
 {
     $userName = Dura::user()->getName();
     $userId = Dura::user()->getId();
     $userIcon = Dura::user()->getIcon();
     $roomHandler = new Dura_Model_RoomHandler();
     $roomModel = $roomHandler->create();
     $roomModel->name = $this->input['name'];
     $roomModel->update = time();
     $roomModel->limit = $this->input['limit'];
     $roomModel->host = $userId;
     $roomModel->language = $this->input['language'];
     $users = $roomModel->addChild('users');
     $users->addChild('name', $userName);
     $users->addChild('id', $userId);
     $users->addChild('icon', $userIcon);
     $users->addChild('update', time());
     if (Dura::$language != $this->input['language']) {
         $langFile = DURA_TRUST_PATH . '/language/' . $this->input['language'] . '.php';
         Dura::$catalog = (require $langFile);
     }
     $talk = $roomModel->addChild('talks');
     $talk->addChild('id', md5(microtime() . mt_rand()));
     $talk->addChild('uid', 0);
     $talk->addChild('name', $userName);
     $talk->addChild('message', "{1} logged in.");
     $talk->addChild('icon', '');
     $talk->addChild('time', time());
     $id = md5(microtime() . mt_rand());
     if (!$roomHandler->save($id, $roomModel)) {
         throw new Exception(t("Data Error: Room creating failed."));
     }
     Dura_Class_RoomSession::create($id);
     Dura::redirect('room');
 }
Example #2
0
 protected function _login()
 {
     if ($this->_isLogin()) {
         return;
     }
     if (count($this->roomModel->users) >= (int) $this->roomModel->limit) {
         Dura::trans(t("Room is full.", 'lounge'));
     }
     $unsetUsers = array();
     $offset = 0;
     $changeHost = false;
     foreach ($this->roomModel->users as $user) {
         if ($user->update < time() - DURA_CHAT_ROOM_EXPIRE) {
             $userName = (string) $user->name;
             $this->_npcDisconnect($userName);
             if ($this->_isHost($user->id)) {
                 $changeHost = true;
             }
             $unsetUsers[] = $offset;
         }
         $offset++;
     }
     foreach ($unsetUsers as $unsetUser) {
         unset($this->roomModel->users[$unsetUser]);
     }
     $userName = Dura::user()->getName();
     $userId = Dura::user()->getId();
     $userIcon = Dura::user()->getIcon();
     foreach ($this->roomModel->users as $user) {
         if ($userName == (string) $user->name and $userIcon == (string) $user->icon) {
             Dura::trans(t("Same name user exists. Please rename or change icon.", 'lounge'));
         }
     }
     $users = $this->roomModel->addChild('users');
     $users->addChild('name', $userName);
     $users->addChild('id', $userId);
     $users->addChild('icon', $userIcon);
     $users->addChild('update', time());
     if ($changeHost) {
         $this->_moveHostRight();
     }
     $this->_npcLogin($userName);
     $this->roomHandler->save($this->id, $this->roomModel);
     Dura_Class_RoomSession::create($this->id);
     Dura::redirect('room');
 }