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'); }
protected function _roomLimit() { $roomHandler = new Dura_Model_RoomHandler(); $roomModels = $roomHandler->loadAll(); $roomExpire = time() - DURA_CHAT_ROOM_EXPIRE; $usedCapacity = 0; foreach ($roomModels as $id => $roomModel) { if (intval($roomModel->update) < $roomExpire) { $roomHandler->delete($id); continue; } $usedCapacity += (int) $roomModel->limit; } unset($roomHandler, $roomModels, $roomModel); if ($usedCapacity >= DURA_SITE_USER_CAPACITY) { Dura::trans(t("Cannot create new room any more."), 'lounge'); } $this->userMax = DURA_SITE_USER_CAPACITY - $usedCapacity; if ($this->userMax > DURA_USER_MAX) { $this->userMax = DURA_USER_MAX; } if ($this->userMax < DURA_USER_MIN) { Dura::trans(t("Cannot create new room any more."), 'lounge'); } }