public function init() { if (($data = cache()->get(CacheNames::SERVER_STATUS)) === FALSE) { if (config('server_status.allow') == 1) { $data['content'] = array(); $data['totalOnline'] = 0; $criteria = new CDbCriteria(array('select' => 't.name, t.id, t.fake_online, t.ip, t.port', 'scopes' => array('opened'), 'with' => array('ls' => array('select' => 'ls.ip, ls.port, ls.name', 'scopes' => array('opened'))))); $gsList = Gs::model()->findAll($criteria); if ($gsList) { foreach ($gsList as $gs) { try { $l2 = l2('gs', $gs->id)->connect(); // Кол-во игроков $online = $l2->getDb()->createCommand("SELECT COUNT(0) FROM `characters` WHERE `online` = 1")->queryScalar(); // Fake online if (is_numeric($gs->fake_online) && $gs->fake_online > 0) { $online += Lineage::fakeOnline($online, $gs->fake_online); } $data['content'][$gs->id] = array('gs_status' => Lineage::getServerStatus($gs->ip, $gs->port), 'ls_status' => isset($gs->ls) ? Lineage::getServerStatus($gs->ls->ip, $gs->ls->port) : 'offline', 'online' => $online, 'gs' => $gs); $data['totalOnline'] += $online; } catch (Exception $e) { $data[$gs->id]['error'] = $e->getMessage(); } } } if (config('server_status.cache') > 0) { cache()->set(CacheNames::SERVER_STATUS, $data, config('server_status.cache') * 60); } } } app()->controller->renderPartial('//server-status', $data); }
/** * Создание аккаунта на сайте * * @return Users */ private function _createAccount() { $transaction = db()->beginTransaction(); $login = $this->getLogin(); try { // Создаю нового юзера $user = new Users(); $user->login = $login; $user->password = $this->password; $user->email = $this->email; $user->activated = config('register.confirm_email') ? Users::STATUS_INACTIVATED : Users::STATUS_ACTIVATED; $user->role = Users::ROLE_DEFAULT; $user->ls_id = $this->gs_list[$this->gs_id]['login_id']; $user->save(FALSE); // Referer if ($this->referer != '' && $this->refererInfo) { $referals = new Referals(); $referals->referer = $this->refererInfo->getPrimaryKey(); $referals->referal = $user->getPrimaryKey(); $referals->save(FALSE); } // Удаляю реферальную куку if (isset(request()->cookies[app()->params['cookie_referer_name']])) { unset(request()->cookies[app()->params['cookie_referer_name']]); } $transaction->commit(); return $user; } catch (Exception $e) { $transaction->rollback(); // Удаляю созданный аккаунт на сервере $this->l2->getDb()->createCommand("DELETE FROM {{accounts}} WHERE login = :login LIMIT 1")->bindParam('login', $login, PDO::PARAM_STR)->execute(); user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.')); return FALSE; } }
private function total() { $ls = l2('ls', $this->_gs->login_id)->connect(); // Кол-во аккаунтов $data['countAccounts'] = (int) $ls->getCountAccounts(); $gs = l2('gs', $this->_gs_id)->connect(); // Кол-во персонажей $data['countCharacters'] = (int) $gs->getCountCharacters(); // В игре $data['countOnline'] = (int) $gs->getCountOnlineCharacters(); // Fake online if ($this->_gs->fake_online > 0) { $data['countOnline'] += Lineage::fakeOnline($data['countOnline'], $this->_gs->fake_online); } // Кол-во кланов $data['countClans'] = (int) $gs->getCountClans(); // Men $data['countMen'] = $gs->getCountMen(); // Female $data['countFemale'] = $gs->getCountWomen(); // Races $data['races'] = array('human' => $gs->getCountRaceHuman(), 'elf' => $gs->getCountRaceElf(), 'dark_elf' => $gs->getCountRaceDarkElf(), 'ork' => $gs->getCountRaceOrk(), 'dwarf' => $gs->getCountRaceDwarf()); $data['races_percentage'] = array('human' => $data['races']['human'] > 0 ? round($data['races']['human'] / $data['countCharacters'] * 100) : 0, 'elf' => $data['races']['elf'] > 0 ? round($data['races']['elf'] / $data['countCharacters'] * 100) : 0, 'dark_elf' => $data['races']['dark_elf'] > 0 ? round($data['races']['dark_elf'] / $data['countCharacters'] * 100) : 0, 'ork' => $data['races']['ork'] > 0 ? round($data['races']['ork'] / $data['countCharacters'] * 100) : 0, 'dwarf' => $data['races']['dwarf'] > 0 ? round($data['races']['dwarf'] / $data['countCharacters'] * 100) : 0); if ($gs->getChronicle() != 'interlude') { $data['races']['kamael'] = $gs->getCountRaceKamael(); $data['races_percentage']['kamael'] = $data['races']['kamael'] > 0 ? round($data['races']['kamael'] / $data['countCharacters'] * 100) : 0; } return $this->renderPartial('//stats/' . __FUNCTION__, $data, TRUE); }
echo $character['pvpkills']; ?> /<?php echo $character['pkkills']; ?> </td> <td><?php $clan_link = e($character['clan_name']); if ($this->_gs->stats_clan_info) { $clan_link = HTML::link($character['clan_name'], array('/stats/default/index', 'gs_id' => $this->_gs_id, 'type' => 'clan-info', 'clan_id' => $character['clan_id'])); } echo $character['clan_name'] == '' ? Yii::t('main', 'Не в клане') : $clan_link; ?> </td> <td><?php echo Lineage::getOnlineTime($character['onlinetime']); ?> </td> <td><?php echo $row['online'] ? '<span class="status-online" title="' . Yii::t('main', 'В игре') . '"></span>' : '<span class="status-offline" title="' . Yii::t('main', 'Не в игре') . '"></span>'; ?> </td> <td><?php echo number_format($character['maxCountItems'], 0, '', '.'); ?> </td> </tr> <?php } ?> <?php
public function getGrade() { return Lineage::getItemGrade($this->crystal_type); }
echo $row['pkkills']; ?> </td> <td><?php echo clanAllyCrest('clan', $row['clan_id'], $this->_gs->id, $row['clan_crest']); ?> <?php $clan_link = e($row['clan_name']); if ($this->_gs->stats_clan_info) { $clan_link = HTML::link($row['clan_name'], array('/stats/default/index', 'gs_id' => $this->_gs_id, 'type' => 'clan-info', 'clan_id' => $row['clan_id'])); } echo $row['clan_name'] == '' ? '-' : $clan_link; ?> </td> <td><?php echo Lineage::getOnlineTime($row['onlinetime']); ?> </td> <td><?php echo $row['online'] ? '<span class="status-online" title="' . Yii::t('main', 'В игре') . '"></span>' : '<span class="status-offline" title="' . Yii::t('main', 'Не в игре') . '"></span>'; ?> </td> </tr> <?php } ?> <?php } else { ?> <tr> <td colspan="6"><?php
<?php $i = 0; foreach ($content as $row) { ?> <tr> <th colspan="2"><?php echo Lineage::getCastleName($row['castle_id']); ?> </th> </tr> <tr class="<?php echo ++$i % 2 == 0 ? 'odd' : 'even'; ?> "> <td width="150"><?php echo Lineage::getCastleIcon($row['castle_id']); ?> </td> <td> <?php echo Yii::t('main', 'Налог'); ?> : <i><?php echo $row['tax_percent']; ?> %</i><br /> <?php echo Yii::t('main', 'Дата осады'); ?> : <i><?php echo formatDate(substr($row['sieg_date'], 0, 10));
public function actionTeleport($char_id) { $statusOn = ActiveRecord::STATUS_ON; $gsId = user()->getGsId(); $cache = new CFileCache(); $cache->init(); $dependency = new CDbCacheDependency("SELECT MAX(UNIX_TIMESTAMP(updated_at)) FROM {{gs}} WHERE id = :id AND status = :status LIMIT 1"); $dependency->params = array('id' => $gsId, 'status' => $statusOn); $gsInfo = db()->cache(3600 * 24, $dependency)->createCommand("SELECT * FROM {{gs}} WHERE id = :id AND status = :status LIMIT 1")->bindParam('status', $statusOn, PDO::PARAM_INT)->bindParam('id', $gsId, PDO::PARAM_INT)->queryRow(); if ($gsInfo === FALSE || !$gsInfo['allow_teleport']) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Телепортация отключена.')); $this->redirect(array('index')); } $userId = user()->getId(); $cacheName = strtr(CacheNames::CHARACTER_TELEPORT, array(':user_id' => $userId, ':char_id' => $char_id, ':gs_id' => $gsId)); $teleportsInfo = $cache->get($cacheName); if ($teleportsInfo !== FALSE) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Вы уже недавно были телепортированы в :city.', array(':city' => '<b>' . $teleportsInfo['city'] . '</b>'))); $this->redirect(array('index')); } try { $l2 = l2('gs', $gsId)->connect(); $charIdFieldName = $l2->getField('characters.char_id'); $command = $l2->getDb()->createCommand(); $command->where($charIdFieldName . ' = :char_id AND account_name = :account_name', array(':char_id' => $char_id, ':account_name' => user()->get('login'))); $character = $l2->characters($command)->queryRow(); if ($character === FALSE) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Персонаж не найден.')); $this->redirect(array('index')); } // Если в игре if ($character['online'] != 0) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Персонаж в игре.')); $this->redirect(array('index')); } $city = Lineage::getRandomCity(); $userName = user()->get('login'); $x = $city['coordinates'][0]['x']; $y = $city['coordinates'][0]['y']; $z = $city['coordinates'][0]['z']; // Телепорт игрока $res = $l2->getDb()->createCommand("UPDATE {{characters}} SET x = :x, y = :y, z = :z WHERE " . $charIdFieldName . " = :char_id AND account_name = :account_name LIMIT 1")->bindParam('x', $x, PDO::PARAM_STR)->bindParam('y', $y, PDO::PARAM_STR)->bindParam('z', $z, PDO::PARAM_STR)->bindParam('char_id', $char_id, PDO::PARAM_INT)->bindParam('account_name', $userName, PDO::PARAM_STR)->execute(); if ($res) { $cache->set($cacheName, array('char_id' => $char_id, 'city' => $city['name']), $gsInfo['teleport_time'] * 60); // Логирую действие юзера if (app()->params['user_actions_log']) { $log = new UserActionsLog(); $log->user_id = user()->getId(); $log->action_id = UserActionsLog::ACTION_TELEPORT_TO_TOWN; $log->params = json_encode($city); $log->save(FALSE); } user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Персонаж был телепортрован в :city.', array(':city' => '<b>' . $city['name'] . '</b>'))); $this->redirect(array('index')); } else { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.')); $this->redirect(array('index')); } } catch (Exception $e) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.')); Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__ . ' ' . __LINE__); $this->redirect(array('index')); } }
/** * Создание игрового аккаунта * * @param $login * @param $password * @param int $access_level * * @return bool */ public function insertAccount($login, $password, $access_level = 0) { return $this->_db->createCommand()->insert('accounts', array('login' => $login, 'password' => $this->_context->passwordEncrypt($password), 'accessLevel' => $access_level)); }
continue; } ?> <tr class="<?php echo $i++ % 2 == 0 ? 'odd' : 'even'; ?> "> <td><?php echo Lineage::getItemIcon($item['icon'], $item['description']); ?> </td> <td><?php echo e($item['name']); ?> <?php echo Lineage::getItemGrade($item['crystal_type']); ?> </td> <td><?php echo number_format($item['count'], 0, '', '.'); ?> </td> <td><?php echo $item['enchant_level']; ?> </td> </tr> <?php } ?> <?php
/** * Создание игрового аккаунта * * @param string $login * @param string $password * @param int $accessLevel * * @return bool */ public function insertAccount($login, $password, $accessLevel = 0) { $encodePassword = $this->_context->passwordEncrypt($password); return $this->_db->createCommand('INSERT INTO `accounts` (`login`, `password`, `access_level`) VALUES(:login, :password, :access_level)')->bindParam('login', $login, PDO::PARAM_STR)->bindParam('password', $encodePassword, PDO::PARAM_STR)->bindParam('access_level', $accessLevel, PDO::PARAM_INT)->execute(); }
echo $row['char_name']; ?> [<?php echo Lineage::getClassName($row['base_class']); ?> ][<?php echo $row['level']; ?> ]</p> </td> <td><?php echo $row['clan_level']; ?> </td> <td><?php echo $row['hasCastle'] != 0 ? Lineage::getCastleName($row['hasCastle']) : '-'; ?> </td> <td><?php echo $row['ccount']; ?> </td> <td><?php echo number_format($row['reputation_score'], 0, '', '.'); ?> </td> <td> <?php echo $row['ally_name'] != '' ? e($row['ally_name']) : '-'; ?> </td>
echo Yii::t('main', 'Заточка'); ?> </th> </tr> </thead> <tbody> <?php foreach ($bonus->bonusInfo->items as $i2 => $item) { ?> <tr> <td><?php echo ++$i2; ?> </td> <td><?php echo Lineage::getItemIcon($item->itemInfo->icon, $item->itemInfo->name); ?> </td> <td><?php echo e($item->itemInfo->name); ?> </td> <td><?php echo number_format($item->count, 0, '', '.'); ?> </td> <td><?php echo $item->enchant; ?> </td> </tr>
</ul> <?php if ($stats_types) { ?> <ul class="tabs"> <?php foreach ($stats_types as $stats_type) { ?> <li<?php echo $stats_type == $type ? ' class="active"' : ''; ?> > <?php echo HTML::link(Lineage::statsName($stats_type), array('/stats/default/index', 'gs_id' => $gs_id, 'type' => $stats_type)); ?> </li> <?php } ?> </ul> <?php echo $content; ?> <?php } ?>
/** * @param string $type gs|ls * @param int $id * * @return Lineage */ function l2($type, $id) { return Lineage::getInstance($type, $id); }
/** * Создание игрового аккаунта * * @param $login * @param $password * @param int $access_level * * @return bool */ public function insertAccount($login, $password, $access_level = 0) { $this->_db->createCommand()->insert('accounts', array('login' => $login, 'password' => $this->_context->passwordEncrypt($password), 'accessLevel' => $access_level)); $this->_db->createCommand()->insert('account_premium', array('account_name' => $login, 'premium_service' => 0, 'enddate' => 0)); }