/** * Execute SQL query * @category WoW Database Handler * @access private * @param string $safe_sql * @param int $queryType * @return mixed **/ private function _query($safe_sql, $queryType) { // Execute query and calculate execution time $make_array = array(); $query_start = microtime(true); $this->queryCount++; if ($this->driver_type == 'mysqli') { $performed_query = @mysqli_query($this->connectionLink, $safe_sql); $this->errmsg = @mysqli_error($this->connectionLink); $this->errno = @mysqli_errno($this->connectionLink); } else { $performed_query = @mysql_query($safe_sql, $this->connectionLink); $this->errmsg = @mysql_error($this->connectionLink); $this->errno = @mysql_errno($this->connectionLink); } if (!$performed_query) { WoW_Log::WriteLog('%s : unable to execute SQL query (%s). MySQL error: %s', __METHOD__, $safe_sql, $this->errmsg ? sprintf('"%s" (Error #%d)', $this->errmsg, $this->errno) : 'none'); return false; } $result = false; switch ($queryType) { case SINGLE_CELL: if ($this->driver_type == 'mysqli') { $tmp = @mysqli_fetch_array($performed_query); // this works faster than mysql_result } else { $tmp = @mysql_fetch_array($performed_query); // this works faster than mysql_result } $result = $tmp[0]; unset($tmp); break; case SINGLE_ROW: if ($this->driver_type == 'mysqli') { $result = @mysqli_fetch_assoc($performed_query); } else { $result = @mysql_fetch_assoc($performed_query); } if (is_array($result)) { foreach ($result as $rKey => $rValue) { if (is_string($rKey)) { $make_array[$rKey] = $rValue; } } $result = $make_array; } break; case MULTIPLY_ROW: $result = array(); if ($this->driver_type == 'mysqli') { while ($_result = @mysqli_fetch_assoc($performed_query)) { if (is_array($_result)) { foreach ($_result as $rKey => $rValue) { if (is_string($rKey)) { $make_array[$rKey] = $rValue; } } $result[] = $make_array; } else { $result[] = $_result; } } } else { while ($_result = @mysql_fetch_assoc($performed_query)) { if (is_array($_result)) { foreach ($_result as $rKey => $rValue) { if (is_string($rKey)) { $make_array[$rKey] = $rValue; } } $result[] = $make_array; } else { $result[] = $_result; } } } break; case OBJECT_QUERY: $result = array(); if ($this->driver_type == 'mysqli') { while ($_result = @mysqli_fetch_object($performed_query)) { $result[] = $_result; } } else { while ($_result = @mysql_fetch_object($performed_query)) { $result[] = $_result; } } break; case SQL_QUERY: $result = true; break; default: $result = false; break; } $query_end = microtime(true); $queryTime = round($query_end - $query_start, 4); WoW_Log::WriteSql('[%s ms]: %s', $queryTime, $safe_sql); $this->queryTimeGeneration += $queryTime; unset($performed_query); return $result; }
public static function GetNpcAreaInfo($entry) { $npc_coordinates = DB::World()->selectRow("SELECT `guid`, `map`, `position_x`, `position_y` FROM `creature` WHERE `id` = %d LIMIT 1", $entry); if (!is_array($npc_coordinates)) { WoW_Log::WriteLog('%s : creature #%d was not found in `creature` table!', __METHOD__, $entry); return false; } $area_data = DB::WoW()->selectRow("\n SELECT\n `a`.`id`,\n `a`.`area`,\n `b`.`name_en` AS `areaName_original`,\n `b`.`name_%s` AS `areaName_locale`\n FROM `DBPREFIX_zones` AS `a`\n JOIN `DBPREFIX_areas` AS `b` ON `b`.`id` = `a`.`area`\n WHERE `a`.`map` = %d AND `a`.`y_min` >= %d AND `a`.`y_max` <= %d AND `a`.`x_min` >= %d AND `a`.`x_max` <= %d\n LIMIT 1", WoW_Locale::GetLocale(), $npc_coordinates['map'], $npc_coordinates['position_y'], $npc_coordinates['position_y'], $npc_coordinates['position_x'], $npc_coordinates['position_x']); if (!is_array($area_data)) { WoW_Log::WriteLog('%s : area data for creature #%d (GUID: %d) was not found!', __METHOD__, $entry, $npc_coordinates['guid']); return false; } return array('entry' => $entry, 'guid' => $npc_coordinates['guid'], 'mapID' => $npc_coordinates['map'], 'zoneID' => $area_data['id'], 'areaID' => $area_data['area'], 'zoneName' => $area_data['areaName_original'], 'zoneName_loc' => $area_data['areaName_locale'], 'pos_x' => $npc_coordinates['position_x'], 'pos_y' => $npc_coordinates['position_y']); }
private static function HandleGuildFeed() { if (!self::IsCorrect()) { WoW_Log::WriteError('%s : guild was not found.', __METHOD__); return false; } if (!self::$guild_feed) { self::LoadGuildFeed(); } $feeds_data = array(); $periods = array(WoW_Locale::GetString('template_feed_sec'), WoW_Locale::GetString('template_feed_min'), WoW_Locale::GetString('template_feed_hour')); $today = date('d.m.Y'); $lengths = array(60, 60, 24); $feed_count = 0; foreach (self::$guild_feed as $event) { if ($feed_count >= 25) { break; } $date_string = date('d.m.Y', $event['date']); if ($date_string == $today) { $diff = time() - $event['date']; for ($i = 0; $diff >= $lengths[$i]; $i++) { $diff /= $lengths[$i]; } $diff = round($diff); $date_string = sprintf('%s %s %s', $diff, $periods[$i], WoW_Locale::GetString('template_feed_ago')); } $feed = array(); switch ($event['type']) { case TYPE_ACHIEVEMENT_FEED: $achievement = WoW_Achievements::GetAchievementInfo($event['data']); if (!$achievement) { WoW_Log::WriteLog('%s : wrong feed data (TYPE_ACHIEVEMENT_FEED, achievement ID: %d), ignore.', __METHOD__, $event['data']); continue; } $feed = array('type' => TYPE_ACHIEVEMENT_FEED, 'date' => $date_string, 'id' => $event['data'], 'points' => $achievement['points'], 'name' => $achievement['name'], 'desc' => $achievement['desc'], 'icon' => $achievement['iconname'], 'category' => $achievement['categoryId'], 'charName' => $event['charName'], 'gender' => $event['gender']); break; case TYPE_ITEM_FEED: $item = WoW_Items::GetItemInfo($event['data']); if (!$item) { WoW_Log::WriteLog('%s : wrong feed data (TYPE_ITEM_FEED, item ID: %d), ignore.', __METHOD__, $event['data']); continue; } $item_icon = WoW_Items::GetItemIcon($item['entry'], $item['displayid']); $data_item = null; $feed = array('type' => TYPE_ITEM_FEED, 'date' => $date_string, 'id' => $event['data'], 'name' => WoW_Locale::GetLocale() == 'en' ? $item['name'] : WoW_Items::GetItemName($item['entry']), 'data-item' => $data_item, 'quality' => $item['Quality'], 'icon' => $item_icon, 'charName' => $event['charName'], 'gender' => $event['gender']); break; case TYPE_BOSS_FEED: // Not supported here. continue; default: WoW_Log::WriteError('%s : unknown feed type (%d)!', __METHOD__, $event['type']); continue; } $feeds_data[] = $feed; $feed_count++; } self::$guild_feed_data = $feeds_data; return true; }
public static function loadFromCookieSession() { $user_data = DB::WoW()->selectRow("SELECT `email`, `sha_pass_hash` FROM `DBPREFIX_users` WHERE `cookie_session_key` = '%s' LIMIT 1", $_COOKIE['wow_session']); if (!$user_data) { WoW_Log::WriteLog('%s : cookie_session %s was not found in `DBPREFIX_users` table!', __METHOD__, $_COOKIE['wow_session']); unset($_COOKIE['wow_session']); return false; } else { self::PerformLogin($user_data['email'], $user_data['sha_pass_hash'], true, true); return true; } }
/** * @return int **/ public function GetMaxDurability() { if ($this->m_server == SERVER_MANGOS) { return $this->GetUInt32Value(ITEM_FIELD_MAXDURABILITY); } elseif ($this->m_server == SERVER_TRINITY) { return $this->tc_data['maxdurability']; // assigned in Item::LoadFromDB() } WoW_Log::WriteLog('%s : wrong server type', __METHOD__); return 0; }
/** * Generates random enchantments for $item_entry and $item_guid (if provided) * @category Items class * @access public * @param int $item_entry * @param int $owner_guid * @param int $item_guid * @return array **/ public function GetRandomPropertiesData($item_entry, $owner_guid, $item_guid = 0, $rIdOnly = false, $serverType = 1, $item = null, $item_data = null) { // I have no idea how it works but it works :D // Do not touch anything in this method (at least until somebody will explain me what the f**k am I did here). $enchId = 0; $use = 'property'; switch ($serverType) { case SERVER_MANGOS: if ($item_guid > 0) { if (is_object($item) && $item->IsCorrect()) { if (is_array($item_data) && $item_data['RandomProperty'] > 0) { $enchId = $item->GetItemRandomPropertyId(); } elseif (is_array($item_data) && $item_data['RandomSuffix'] > 0) { $suffix_enchants = $item->GetRandomSuffixData(); if (!is_array($suffix_enchants) || !isset($suffix_enchants[0]) || $suffix_enchants[0] == 0) { WoW_Log::WriteError('%s : suffix_enchants not found', __METHOD__); return false; } $enchId = DB::Wow()->selectCell("SELECT `id` FROM `DBPREFIX_randomsuffix` WHERE `ench_1` = %d AND `ench_2` = %d AND `ench_3` = %d LIMIT 1", $suffix_enchants[0], $suffix_enchants[1], $suffix_enchants[2]); $use = 'suffix'; } } else { $enchId = self::GetItemDataField(ITEM_FIELD_RANDOM_PROPERTIES_ID, 0, $owner_guid, $item_guid); } } else { $enchId = self::GetItemDataField(ITEM_FIELD_RANDOM_PROPERTIES_ID, $item_entry, $owner_guid); } break; case SERVER_TRINITY: if ($item_guid > 0) { if (is_object($item) && $item->IsCorrect()) { $enchId = $item->GetItemRandomPropertyId(); if ($enchId < 0) { $use = 'suffix'; $enchId = abs($enchId); } } else { $enchId = DB::Characters()->selectCell("SELECT `randomPropertyId` FROM `item_instance` WHERE `guid`=%d", $item_guid); } } else { $item_guid = self::GetItemGUIDByEntry($item_entry, $owner_guid); $enchId = DB::Characters()->selectCell("SELECT `randomPropertyId` FROM `item_instance` WHERE `guid`=%d", $item_guid); } break; } if ($rIdOnly == true) { return $enchId; } $return_data = array(); $table = 'randomproperties'; if ($use == 'property') { $rand_data = DB::Wow()->selectRow("SELECT `name_%s` AS `name`, `ench_1`, `ench_2`, `ench_3` FROM `DBPREFIX_randomproperties` WHERE `id`=%d", Wow_Locale::GetLocale(), $enchId); } elseif ($use == 'suffix') { $table = 'randomsuffix'; } if ($table == 'randomproperties') { if (!$rand_data) { WoW_Log::WriteLog('%s : unable to get rand_data FROM `%s_%s` for id %d (itemGuid: %d, ownerGuid: %d)', __METHOD__, $this->wow->armoryconfig['db_prefix'], $table, $enchId, $item_guid, $owner_guid); return false; } $return_data['suffix'] = $rand_data['name']; $return_data['data'] = array(); for ($i = 1; $i < 4; $i++) { if ($rand_data['ench_' . $i] > 0) { $return_data['data'][$i] = DB::Wow()->selectCell("SELECT `text_%s` FROM `DBPREFIX_enchantment` WHERE `id`=%d", Wow_Locale::GetLocale(), $rand_data['ench_' . $i]); } } } elseif ($table == 'randomsuffix') { $enchant = DB::Wow()->selectRow("SELECT `id`, `name_%s` AS `name`, `ench_1`, `ench_2`, `ench_3`, `pref_1`, `pref_2`, `pref_3` FROM `DBPREFIX_randomsuffix` WHERE `id`=%d", Wow_Locale::GetLocale(), $enchId); if (!$enchant) { return false; } $return_data['suffix'] = $enchant['name']; $return_data['data'] = array(); $item_data = DB::World()->selectRow("SELECT `InventoryType`, `ItemLevel`, `Quality` FROM `item_template` WHERE `entry`=%d", $item_entry); $points = self::GetRandomPropertiesPoints($item_data['ItemLevel'], $item_data['InventoryType'], $item_data['Quality']); $return_data = array('suffix' => $enchant['name'], 'data' => array()); $k = 1; for ($i = 1; $i < 4; $i++) { if (isset($enchant['ench_' . $i]) && $enchant['ench_' . $i] > 0) { $cur = DB::Wow()->selectCell("SELECT `text_%s` FROM `DBPREFIX_enchantment` WHERE `id` = %d", Wow_Locale::GetLocale(), $enchant['ench_' . $i]); $return_data['data'][$k] = str_replace('$i', round(floor($points * $enchant['pref_' . $i] / 10000), 0), $cur); } $k++; } } return $return_data; }
/** * Copyright (C) 2011 - 2014 Apocalypsecore <https://Apocalypsecore.tk> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA **/ WoW_Log::WriteLog('RunOnce : execute commands.'); /** * Execute necessary code (once) * @param void * @return bool **/ function ExecuteRunOnce() { //////////////////////////////////////// DB::WoW()->query("TRUNCATE TABLE `DBPREFIX_user_characters`"); return true; //////////////////////////////////////// }
public static function GetDataField($field) { if (!isset(self::$data[$field])) { WoW_Log::WriteLog('%s : field %d was not found.', __METHOD__, $field); return 0; } return self::$data[$field]; }
/** * Performs model fields parsing **/ private function ParseFields(&$query) { if (!$this->m_fields) { WoW_Log::WriteError('%s : no fields were found for Model "%s"!', __METHOD__, $this->m_storageName); return false; } $count = count($this->m_fields); $current = 0; $query['query'] .= ' '; foreach ($this->m_fields as $name => $field) { if (!is_string($name) && is_array($field)) { WoW_Log::WriteLog('%s : skipping index "%s"', __METHOD__, $name); ++$current; continue; } elseif (isset($field['locale']) && $field['locale']) { $query['query'] .= '`' . $name . '_' . $this->m_locale . '` AS `' . $this->FieldAlias($field, $name) . '`'; } elseif (isset($field['dbLocale']) && $field['dbLocale']) { $query['query'] .= '`' . $name . '_loc' . $this->m_dbLocale . '` AS `' . $this->FieldAlias($field, $name) . '`'; } elseif (isset($field['alias'])) { $query['query'] .= '`' . $name . '` AS `' . $field['alias'] . '`'; } else { $query['query'] .= '`' . $name . '`'; } ++$current; if ($current < $count) { $query['query'] .= ', '; } } $query['query'] .= ' FROM `' . $this->m_storageName . '`'; return $this; }