uint32 ChatHandler::extractSpellIdFromLink(char* text) { // number or [name] Shift-click form |color|Henchant:recipe_spell_id|h[prof_name: recipe_name]|h|r // number or [name] Shift-click form |color|Hglyph:glyph_slot_id:glyph_prop_id|h[%s]|h|r // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r // number or [name] Shift-click form |color|Htalent:talent_id, rank|h[name]|h|r // number or [name] Shift-click form |color|Htrade:spell_id, skill_id, max_value, cur_value|h[name]|h|r int type = 0; char* param1_str = NULL; char* idS = extractKeyFromLink(text, spellKeys, &type, ¶m1_str); if (!idS) return 0; uint32 id = atoul(idS); switch (type) { case SPELL_LINK_SPELL: return id; case SPELL_LINK_TALENT: { // talent TalentEntry const* talentEntry = sTalentStore.LookupEntry(id); if (!talentEntry) return 0; uint32 rank = param1_str ? atol(param1_str) : 0u; if (rank >= MAX_TALENT_RANK) return 0; return talentEntry->RankID[rank]; } case SPELL_LINK_ENCHANT: case SPELL_LINK_TRADE: return id; case SPELL_LINK_GLYPH: { uint32 glyph_prop_id = param1_str ? atoul(param1_str) : 0; GlyphPropertiesEntry const* glyphPropEntry = sGlyphPropertiesStore.LookupEntry(glyph_prop_id); if (!glyphPropEntry) return 0; return glyphPropEntry->SpellId; } } // unknown type? return 0; }
ObjectGuid ChatHandler::extractGuidFromLink(char* text) { int type = 0; // |color|Hcreature:creature_guid|h[name]|h|r // |color|Hgameobject:go_guid|h[name]|h|r // |color|Hplayer:name|h[name]|h|r char* idS = extractKeyFromLink(text, guidKeys, &type); if (!idS) return ObjectGuid::Empty; switch (type) { case SPELL_LINK_PLAYER: { std::string name = idS; if (!normalizePlayerName(name)) return ObjectGuid::Empty; if (Player* player = ObjectAccessor::FindPlayerByName(name)) return player->GetGUID(); if (ObjectGuid guid = sObjectMgr->GetPlayerGUIDByName(name)) return guid; return ObjectGuid::Empty; } case SPELL_LINK_CREATURE: { ObjectGuid::LowType lowguid = atoul(idS); if (CreatureData const* data = sObjectMgr->GetCreatureData(lowguid)) return ObjectGuid(HighGuid::Unit, data->id, lowguid); else return ObjectGuid::Empty; } case SPELL_LINK_GAMEOBJECT: { ObjectGuid::LowType lowguid = atoul(idS); if (GameObjectData const* data = sObjectMgr->GetGOData(lowguid)) return ObjectGuid(HighGuid::GameObject, data->id, lowguid); else return ObjectGuid::Empty; } } // unknown type? return ObjectGuid::Empty; }
qboolean CheckID( char *id ) { int i; //TiM - screw it if we haven't got a valid ID yet if ( atoul( id ) == SECURITY_PID ) return qfalse; for( i = 0; i < numIDFilters; i++ ) { if ( atoul(id) == idFilters[i].playerID ) return qtrue; } return qfalse; }
static bool HandleGameObjectActivateCommand(ChatHandler* handler, char const* args) { if (!*args) return false; char* id = handler->extractKeyFromLink((char*)args, "Hgameobject"); if (!id) return false; ObjectGuid::LowType guidLow = atoul(id); if (!guidLow) return false; GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow); if (!object) { handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow); handler->SetSentErrorMessage(true); return false; } uint32_t const autoCloseTime = object->GetGOInfo()->GetAutoCloseTime() ? 10000u : 0u; // Activate object->SetLootState(GO_READY); object->UseDoorOrButton(autoCloseTime, false, handler->GetSession()->GetPlayer()); handler->PSendSysMessage("Object activated!"); return true; }
static bool HandleQuestReward(ChatHandler* handler, char const* args) { Player* player = handler->getSelectedPlayer(); if (!player) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // .quest reward #entry // number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r char* cId = handler->extractKeyFromLink((char*)args, "Hquest"); if (!cId) return false; uint32 entry = atoul(cId); Quest const* quest = sObjectMgr->GetQuestTemplate(entry); // If player doesn't have the quest if (!quest || player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE) { handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry); handler->SetSentErrorMessage(true); return false; } player->RewardQuest(quest, 0, player); return true; }
unsigned int atoui(const char *num) { #if !LONG_IS_INT // XXX fail #else return atoul(num); #endif }
static bool HandleAchievementAddCommand(ChatHandler* handler, char const* args) { if (!*args) return false; uint32 achievementId = atoi((char*)args); if (!achievementId) { if (char* id = handler->extractKeyFromLink((char*)args, "Hachievement")) achievementId = atoul(id); if (!achievementId) return false; } Player* target = handler->getSelectedPlayer(); if (!target) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } if (AchievementEntry const* achievementEntry = sAchievementStore.LookupEntry(achievementId)) target->CompletedAchievement(achievementEntry); return true; }
void G_ProcessIDBans( void ) { fileHandle_t f; int fileLen; char buffer[16000]; char *token, *filePtr; idFilter_t id; fileLen = trap_FS_FOpenFile( "RPG-X_Banned_Players.txt", &f, FS_READ ); if ( !f || !fileLen ) return; trap_FS_Read( buffer, fileLen, f ); if ( !buffer[0] ) return; buffer[fileLen] = '\0'; trap_FS_FCloseFile( f ); COM_BeginParseSession(); filePtr = buffer; while ( 1 ) { token = COM_Parse( &filePtr ); if ( !token[0] ) break; if ( !Q_stricmp( token, "{" ) ) { memset( &id, 0, sizeof( id ) ); token = COM_ParseExt( &filePtr, qtrue ); if ( !token[0] ) continue; //parse player id id.playerID = atoul( token ); token = COM_ParseExt( &filePtr, qtrue ); if ( !token[0] ) continue; //parse player name Q_strncpyz( id.playerName, token, sizeof( id.playerName ) ); token = COM_ParseExt( &filePtr, qtrue ); if ( !token[0] ) continue; //parse ban reason Q_strncpyz( id.banReason, token, sizeof( id.banReason ) ); AddID( &id ); } } G_Printf( "%i ban entries were successfully loaded.\n", numIDFilters ); }
bool LFGuildManager::LoadDatabase() { std::string query = "SELECT `type`,`name`,`comment`, " "`fromlevel`, `tolevel`, `classes`, " "`aacount`, `timezone`, `timeposted` FROM `lfguild`"; auto results = database.QueryDatabase(query); if (!results.Success()) { return false; } for (auto row = results.begin(); row != results.end(); ++row) { uint32 type = atoul(row[0]); if(type == 0) { PlayerLookingForGuild p(row[1], row[2], atoul(row[3]), atoul(row[5]), atoul(row[6]), atoul(row[7]), atoul(row[8])); Players.push_back(p); continue; } GuildLookingForPlayers g(row[1], row[2], atoul(row[3]), atoul(row[4]), atoul(row[5]), atoul(row[6]), atoul(row[7]), atoul(row[8])); Guilds.push_back(g); } return true; }
int main(int argv, char **argc) { char buf[MAX_SIZE],*pbuf=buf; int count = atoul(argc[1]); if (count >= MAX_SIZE) count = MAX_SIZE-1; while (count--) *pbuf++=getchar(); *pbuf=0; }
static bool HandleQuestRemove(ChatHandler* handler, const char* args) { Player* player = handler->getSelectedPlayer(); if (!player) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // .removequest #entry' // number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r char* cId = handler->extractKeyFromLink((char*)args, "Hquest"); if (!cId) return false; uint32 entry = atoul(cId); Quest const* quest = sObjectMgr->GetQuestTemplate(entry); if (!quest) { handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry); handler->SetSentErrorMessage(true); return false; } QuestStatus oldStatus = player->GetQuestStatus(entry); // remove all quest entries for 'entry' from quest log for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot) { uint32 logQuest = player->GetQuestSlotQuestId(slot); if (logQuest == entry) { player->SetQuestSlot(slot, 0); // we ignore unequippable quest items in this case, its' still be equipped player->TakeQuestSourceItem(logQuest, false); if (quest->HasFlag(QUEST_FLAGS_FLAGS_PVP)) { player->pvpInfo.IsHostile = player->pvpInfo.IsInHostileArea || player->HasPvPForcingQuest(); player->UpdatePvPState(); } } } player->RemoveActiveQuest(entry, false); player->RemoveRewardedQuest(entry); sScriptMgr->OnQuestStatusChange(player, entry); sScriptMgr->OnQuestStatusChange(player, quest, oldStatus, QUEST_STATUS_NONE); handler->SendSysMessage(LANG_COMMAND_QUEST_REMOVED); return true; }
ObjectGuid::LowType ChatHandler::extractLowGuidFromLink(char* text, HighGuid& guidHigh) { int type = 0; // |color|Hcreature:creature_guid|h[name]|h|r // |color|Hgameobject:go_guid|h[name]|h|r // |color|Hplayer:name|h[name]|h|r char* idS = extractKeyFromLink(text, guidKeys, &type); if (!idS) return 0; switch (type) { case GUID_LINK_PLAYER: { guidHigh = HighGuid::Player; std::string name = idS; if (!normalizePlayerName(name)) return 0; if (Player* player = ObjectAccessor::FindPlayerByName(name)) return player->GetGUID().GetCounter(); ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(name); return guid.GetCounter(); } case GUID_LINK_CREATURE: { guidHigh = HighGuid::Unit; ObjectGuid::LowType lowguid = atoul(idS); return lowguid; } case GUID_LINK_GAMEOBJECT: { guidHigh = HighGuid::GameObject; ObjectGuid::LowType lowguid = atoul(idS); return lowguid; } } // unknown type? return 0; }
static bool HandleLfgGroupInfoCommand(ChatHandler* handler, char const* args) { Player* playerTarget; ObjectGuid guidTarget; std::string nameTarget; ObjectGuid parseGUID(HighGuid::Player, uint32(atoul(args))); if (sObjectMgr->GetPlayerNameByGUID(parseGUID, nameTarget)) { playerTarget = ObjectAccessor::FindPlayer(parseGUID); guidTarget = parseGUID; } else if (!handler->extractPlayerTarget((char*)args, &playerTarget, &guidTarget, &nameTarget)) return false; Group* groupTarget = NULL; if (playerTarget) groupTarget = playerTarget->GetGroup(); else { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GROUP_MEMBER); stmt->setUInt32(0, guidTarget.GetCounter()); PreparedQueryResult resultGroup = CharacterDatabase.Query(stmt); if (resultGroup) groupTarget = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32()); } if (!groupTarget) { handler->PSendSysMessage(LANG_LFG_NOT_IN_GROUP, nameTarget.c_str()); handler->SetSentErrorMessage(true); return false; } ObjectGuid guid = groupTarget->GetGUID(); std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid)); handler->PSendSysMessage(LANG_LFG_GROUP_INFO, groupTarget->isLFGGroup(), state.c_str(), sLFGMgr->GetDungeon(guid)); Group::MemberSlotList const& members = groupTarget->GetMemberSlots(); for (Group::MemberSlotList::const_iterator itr = members.begin(); itr != members.end(); ++itr) { Group::MemberSlot const& slot = *itr; Player* p = ObjectAccessor::FindPlayer((*itr).guid); if (p) GetPlayerInfo(handler, p); else handler->PSendSysMessage("%s is offline.", slot.name.c_str()); } return true; }
void PlayerTaxi::LoadTaxiMask(std::string const& data) { Tokenizer tokens(data, ' '); uint8 index = 0; for (Tokenizer::const_iterator iter = tokens.begin(); index < TaxiMaskSize && iter != tokens.end(); ++iter, ++index) { // load and set bits only for existing taxi nodes m_taximask[index] = sTaxiNodesMask[index] & atoul(*iter); } }
static bool HandleGameObjectSetStateCommand(ChatHandler* handler, char const* args) { // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r char* id = handler->extractKeyFromLink((char*)args, "Hgameobject"); if (!id) return false; ObjectGuid::LowType guidLow = atoul(id); if (!guidLow) return false; GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow); if (!object) { handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow); handler->SetSentErrorMessage(true); return false; } char* type = strtok(nullptr, " "); if (!type) return false; int32 objectType = atoi(type); if (objectType < 0) { if (objectType == -1) object->SendObjectDeSpawnAnim(object->GetGUID()); else if (objectType == -2) return false; return true; } char* state = strtok(nullptr, " "); if (!state) return false; int32 objectState = atoi(state); if (objectType < 4) object->SetByteValue(GAMEOBJECT_BYTES_1, objectType, objectState); else if (objectType == 4) { WorldPacket data(SMSG_GAMEOBJECT_CUSTOM_ANIM, 8+4); data << object->GetGUID(); data << (uint32)(objectState); object->SendMessageToSet(&data, true); } handler->PSendSysMessage("Set gobject type %d state %d", objectType, objectState); return true; }
bool PlayerTaxi::LoadTaxiDestinationsFromString(const std::string& values, uint32 team) { ClearTaxiDestinations(); Tokenizer tokens(values, ' '); auto iter = tokens.begin(); if (iter != tokens.end()) m_flightMasterFactionId = atoul(*iter); ++iter; for (; iter != tokens.end(); ++iter) { uint32 node = atoul(*iter); AddTaxiDestination(node); } if (m_TaxiDestinations.empty()) return true; // Check integrity if (m_TaxiDestinations.size() < 2) return false; for (size_t i = 1; i < m_TaxiDestinations.size(); ++i) { uint32 cost; uint32 path; sObjectMgr->GetTaxiPath(m_TaxiDestinations[i - 1], m_TaxiDestinations[i], path, cost); if (!path) return false; } // can't load taxi path without mount set (quest taxi path?) if (!sObjectMgr->GetTaxiMountDisplayId(GetTaxiSource(), team, true)) return false; return true; }
static bool HandleQuestAdd(ChatHandler* handler, char const* args) { Player* player = handler->getSelectedPlayerOrSelf(); if (!player) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // .addquest #entry' // number or [name] Shift-click form |color|Hquest:quest_id:quest_level|h[name]|h|r char* cId = handler->extractKeyFromLink((char*)args, "Hquest"); if (!cId) return false; uint32 entry = atoul(cId); Quest const* quest = sObjectMgr->GetQuestTemplate(entry); if (!quest || DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, entry, nullptr)) { handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry); handler->SetSentErrorMessage(true); return false; } // check item starting quest (it can work incorrectly if added without item in inventory) ItemTemplateContainer const& itc = sObjectMgr->GetItemTemplateStore(); auto itr = std::find_if(std::begin(itc), std::end(itc), [quest](ItemTemplateContainer::value_type const& value) { return value.second.StartQuest == quest->GetQuestId(); }); if (itr != std::end(itc)) { handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, itr->first); handler->SetSentErrorMessage(true); return false; } if (player->IsActiveQuest(entry)) return false; // ok, normal (creature/GO starting) quest if (player->CanAddQuest(quest, true)) player->AddQuestAndCheckCompletion(quest, nullptr); return true; }
static bool HandleEventInfoCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r char* id = handler->extractKeyFromLink((char*)args, "Hgameevent"); if (!id) return false; uint32 eventId = atoul(id); GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap(); if (eventId >= events.size()) { handler->SendSysMessage(LANG_EVENT_NOT_EXIST); handler->SetSentErrorMessage(true); return false; } GameEventData const& eventData = events[eventId]; if (!eventData.isValid()) { handler->SendSysMessage(LANG_EVENT_NOT_EXIST); handler->SetSentErrorMessage(true); return false; } GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList(); bool active = activeEvents.find(eventId) != activeEvents.end(); char const* activeStr = active ? handler->GetTrinityString(LANG_ACTIVE) : ""; std::string startTimeStr = TimeToTimestampStr(eventData.start); std::string endTimeStr = TimeToTimestampStr(eventData.end); uint32 delay = sGameEventMgr->NextCheck(eventId); time_t nextTime = time(nullptr) + delay; std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(nullptr) + delay) : "-"; std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE); std::string lengthStr = secsToTimeString(eventData.length * MINUTE); handler->PSendSysMessage(LANG_EVENT_INFO, eventId, eventData.description.c_str(), activeStr, startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(), nextStr.c_str()); return true; }
static bool HandleQuestAdd(ChatHandler* handler, const char* args) { Player* player = handler->getSelectedPlayerOrSelf(); if (!player) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // .addquest #entry' // number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r char* cId = handler->extractKeyFromLink((char*)args, "Hquest"); if (!cId) return false; uint32 entry = atoul(cId); Quest const* quest = sObjectMgr->GetQuestTemplate(entry); if (!quest) { handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry); handler->SetSentErrorMessage(true); return false; } // check item starting quest (it can work incorrectly if added without item in inventory) ItemTemplateContainer const* itc = sObjectMgr->GetItemTemplateStore(); ItemTemplateContainer::const_iterator result = std::find_if(itc->begin(), itc->end(), [quest](ItemTemplateContainer::value_type const& value) { return value.second.GetStartQuest() == quest->GetQuestId(); }); if (result != itc->end()) { handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, result->second.GetId()); handler->SetSentErrorMessage(true); return false; } // ok, normal (creature/GO starting) quest if (player->CanAddQuest(quest, true)) player->AddQuestAndCheckCompletion(quest, NULL); return true; }
//delete object by selection or guid static bool HandleGameObjectDeleteCommand(ChatHandler* handler, char const* args) { // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r char* id = handler->extractKeyFromLink((char*)args, "Hgameobject"); if (!id) return false; ObjectGuid::LowType guidLow = atoul(id); if (!guidLow) return false; Player const* const player = handler->GetSession()->GetPlayer(); // force respawn to make sure we find something player->GetMap()->ForceRespawn(SPAWN_TYPE_GAMEOBJECT, guidLow); GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow); if (!object) { handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow); handler->SetSentErrorMessage(true); return false; } ObjectGuid ownerGuid = object->GetOwnerGUID(); if (ownerGuid) { Unit* owner = ObjectAccessor::GetUnit(*player, ownerGuid); if (!owner || !ownerGuid.IsPlayer()) { handler->PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE, ownerGuid.GetCounter(), guidLow); handler->SetSentErrorMessage(true); return false; } owner->RemoveGameObject(object, false); } object->SetRespawnTime(0); // not save respawn time object->Delete(); object->DeleteFromDB(); handler->PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE, object->GetSpawnId()); return true; }
static void convert_args(int argc, cmd_args *argv) { int i; for (i = 0; i < argc; i++) { unsigned long u = atoul(argv[i].str); argv[i].u = u; argv[i].p = (void*)u; argv[i].i = atol(argv[i].str); if (!strcmp(argv[i].str, "true") || !strcmp(argv[i].str, "on")) { argv[i].b = true; } else if (!strcmp(argv[i].str, "false") || !strcmp(argv[i].str, "off")) { argv[i].b = false; } else { argv[i].b = (argv[i].u == 0) ? false : true; } } }
int StrToNumber(char *str , unsigned int * pulValue) { /*判断是否16进制的字符串*/ if ( *str == '0' && (*(str+1) == 'x' || *(str+1) == 'X') ) { if (*(str+2) == '\0') { return -1; } else { return atoulx(str+2,pulValue); } } else { return atoul(str,pulValue); } }
static bool HandleEventStopCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r char* id = handler->extractKeyFromLink((char*)args, "Hgameevent"); if (!id) return false; uint32 eventId = atoul(id); GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap(); if (eventId < 1 || uint32(eventId) >= events.size()) { handler->SendSysMessage(LANG_EVENT_NOT_EXIST); handler->SetSentErrorMessage(true); return false; } GameEventData const& eventData = events[eventId]; if (!eventData.isValid()) { handler->SendSysMessage(LANG_EVENT_NOT_EXIST); handler->SetSentErrorMessage(true); return false; } GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList(); if (activeEvents.find(eventId) == activeEvents.end()) { handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, eventId); handler->SetSentErrorMessage(true); return false; } sGameEventMgr->StopEvent(eventId, true); return true; }
void cmd_gdb(int argc, char **argv) { struct iframe *interrupt_frame = NULL; unsigned int local_regfile[GDB_REGISTER_FILE_COUNT]; if (argc > 1) { // we want to work under a particular iframe. if(strlen(argv[1]) > 2 && argv[1][0] == '0' && argv[1][1] == 'x') interrupt_frame = (struct iframe*)atoul(argv[1]); else dprintf("warning: iframe used is not valid, using local stack.\n"); } if (interrupt_frame) { dbg_make_register_file(local_regfile, interrupt_frame); } else { memcpy(local_regfile, dbg_register_file, sizeof(unsigned int) * GDB_REGISTER_FILE_COUNT); } gdb_state_machine(local_regfile); }
static void dump_port_info(int argc, char **argv) { int i; if(argc < 2) { dprintf("port: not enough arguments\n"); return; } // if the argument looks like a hex number, treat it as such if(strlen(argv[1]) > 2 && argv[1][0] == '0' && argv[1][1] == 'x') { unsigned long num = atoul(argv[1]); if(is_kernel_address(num)) { // XXX semi-hack // one can use either address or a port_id, since KERNEL_BASE > MAX_PORTS assumed _dump_port_info((struct port_entry *)num); return; } else { unsigned slot = num % MAX_PORTS; if(ports[slot].id != (int)num) { dprintf("port 0x%lx doesn't exist!\n", num); return; } _dump_port_info(&ports[slot]); return; } } // walk through the ports list, trying to match name for(i=0; i<MAX_PORTS; i++) { if (ports[i].name != NULL) if(strcmp(argv[1], ports[i].name) == 0) { _dump_port_info(&ports[i]); return; } } }
bool LFGuildManager::LoadDatabase() { char errbuf[MYSQL_ERRMSG_SIZE]; char* query = 0; MYSQL_RES *result; MYSQL_ROW row; if (!database.RunQuery(query,MakeAnyLenString(&query, "SELECT `type`,`name`,`comment`, `fromlevel`, `tolevel`, `classes`, `aacount`, `timezone`, `timeposted` FROM `lfguild`"),errbuf,&result)){ _log(QUERYSERV__ERROR, "Failed to load LFGuild info from database. %s %s", query, errbuf); safe_delete_array(query); return false; } safe_delete_array(query); while((row = mysql_fetch_row(result))) { uint32 type = atoul(row[0]); if(type == 0) { PlayerLookingForGuild p(row[1], row[2], atoul(row[3]), atoul(row[5]), atoul(row[6]), atoul(row[7]), atoul(row[8])); Players.push_back(p); } else { GuildLookingForPlayers g(row[1], row[2], atoul(row[3]), atoul(row[4]), atoul(row[5]), atoul(row[6]), atoul(row[7]), atoul(row[8])); Guilds.push_back(g); } } mysql_free_result(result); return true; }
static bool HandleListCreatureCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r char* id = handler->extractKeyFromLink((char*)args, "Hcreature_entry"); if (!id) return false; uint32 creatureId = atoul(id); if (!creatureId) { handler->PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, creatureId); handler->SetSentErrorMessage(true); return false; } CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(creatureId); if (!cInfo) { handler->PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, creatureId); handler->SetSentErrorMessage(true); return false; } char* countStr = strtok(NULL, " "); uint32 count = countStr ? atoul(countStr) : 10; if (count == 0) return false; QueryResult result; uint32 creatureCount = 0; result = WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'", creatureId); if (result) creatureCount = (*result)[0].GetUInt64(); if (handler->GetSession()) { Player* player = handler->GetSession()->GetPlayer(); result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u", player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), creatureId, count); } else result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u", creatureId, count); if (result) { do { Field* fields = result->Fetch(); ObjectGuid::LowType guid = fields[0].GetUInt64(); float x = fields[1].GetFloat(); float y = fields[2].GetFloat(); float z = fields[3].GetFloat(); uint16 mapId = fields[4].GetUInt16(); if (handler->GetSession()) handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, std::to_string(guid).c_str(), std::to_string(guid).c_str(), cInfo->Name.c_str(), x, y, z, mapId); else handler->PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, std::to_string(guid).c_str(), cInfo->Name.c_str(), x, y, z, mapId); } while (result->NextRow()); } handler->PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE, creatureId, creatureCount); return true; }
static bool HandleListItemCommand(ChatHandler* handler, char const* args) { if (!*args) return false; char const* id = handler->extractKeyFromLink((char*)args, "Hitem"); if (!id) return false; uint32 itemId = atoul(id); if (!itemId) { handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId); handler->SetSentErrorMessage(true); return false; } ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId); if (!itemTemplate) { handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId); handler->SetSentErrorMessage(true); return false; } char* countStr = strtok(NULL, " "); uint32 count = countStr ? atoul(countStr) : 10; if (count == 0) return false; PreparedQueryResult result; // inventory case uint32 inventoryCount = 0; PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_COUNT_ITEM); stmt->setUInt32(0, itemId); result = CharacterDatabase.Query(stmt); if (result) inventoryCount = (*result)[0].GetUInt64(); stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY); stmt->setUInt32(0, itemId); stmt->setUInt32(1, count); result = CharacterDatabase.Query(stmt); if (result) { do { Field* fields = result->Fetch(); ObjectGuid itemGuid = ObjectGuid::Create<HighGuid::Item>(fields[0].GetUInt64()); uint32 itemBag = fields[1].GetUInt32(); uint8 itemSlot = fields[2].GetUInt8(); ObjectGuid ownerGuid = ObjectGuid::Create<HighGuid::Player>(fields[3].GetUInt64()); uint32 ownerAccountId = fields[4].GetUInt32(); std::string ownerName = fields[5].GetString(); char const* itemPos = 0; if (Player::IsEquipmentPos(itemBag, itemSlot)) itemPos = "[equipped]"; else if (Player::IsInventoryPos(itemBag, itemSlot)) itemPos = "[in inventory]"; else if (Player::IsBankPos(itemBag, itemSlot)) itemPos = "[in bank]"; else itemPos = ""; handler->PSendSysMessage(LANG_ITEMLIST_SLOT, itemGuid.ToString().c_str(), ownerName.c_str(), ownerGuid.ToString().c_str(), ownerAccountId, itemPos); } while (result->NextRow()); uint32 resultCount = uint32(result->GetRowCount()); if (count > resultCount) count -= resultCount; else if (count) count = 0; } // mail case uint32 mailCount = 0; stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_COUNT_ITEM); stmt->setUInt32(0, itemId); result = CharacterDatabase.Query(stmt); if (result) mailCount = (*result)[0].GetUInt64(); if (count > 0) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_ITEMS_BY_ENTRY); stmt->setUInt32(0, itemId); stmt->setUInt32(1, count); result = CharacterDatabase.Query(stmt); } else result = PreparedQueryResult(NULL); if (result) { do { Field* fields = result->Fetch(); ObjectGuid::LowType itemGuid = fields[0].GetUInt64(); ObjectGuid::LowType itemSender = fields[1].GetUInt64(); ObjectGuid::LowType itemReceiver = fields[2].GetUInt64(); uint32 itemSenderAccountId = fields[3].GetUInt32(); std::string itemSenderName = fields[4].GetString(); uint32 itemReceiverAccount = fields[5].GetUInt32(); std::string itemReceiverName = fields[6].GetString(); char const* itemPos = "[in mail]"; handler->PSendSysMessage(LANG_ITEMLIST_MAIL, std::to_string(itemGuid).c_str(), itemSenderName.c_str(), std::to_string(itemSender).c_str(), itemSenderAccountId, itemReceiverName.c_str(), std::to_string(itemReceiver).c_str(), itemReceiverAccount, itemPos); } while (result->NextRow()); uint32 resultCount = uint32(result->GetRowCount()); if (count > resultCount) count -= resultCount; else if (count) count = 0; } // auction case uint32 auctionCount = 0; stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_AUCTIONHOUSE_COUNT_ITEM); stmt->setUInt32(0, itemId); result = CharacterDatabase.Query(stmt); if (result) auctionCount = (*result)[0].GetUInt64(); if (count > 0) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_AUCTIONHOUSE_ITEM_BY_ENTRY); stmt->setUInt32(0, itemId); stmt->setUInt32(1, count); result = CharacterDatabase.Query(stmt); } else result = PreparedQueryResult(NULL); if (result) { do { Field* fields = result->Fetch(); ObjectGuid itemGuid = ObjectGuid::Create<HighGuid::Item>(fields[0].GetUInt64()); ObjectGuid owner = ObjectGuid::Create<HighGuid::Player>(fields[1].GetUInt64()); uint32 ownerAccountId = fields[2].GetUInt32(); std::string ownerName = fields[3].GetString(); char const* itemPos = "[in auction]"; handler->PSendSysMessage(LANG_ITEMLIST_AUCTION, itemGuid.ToString().c_str(), ownerName.c_str(), owner.ToString().c_str(), ownerAccountId, itemPos); } while (result->NextRow()); } // guild bank case uint32 guildCount = 0; stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_BANK_COUNT_ITEM); stmt->setUInt32(0, itemId); result = CharacterDatabase.Query(stmt); if (result) guildCount = (*result)[0].GetUInt64(); stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_BANK_ITEM_BY_ENTRY); stmt->setUInt32(0, itemId); stmt->setUInt32(1, count); result = CharacterDatabase.Query(stmt); if (result) { do { Field* fields = result->Fetch(); ObjectGuid itemGuid = ObjectGuid::Create<HighGuid::Item>(fields[0].GetUInt64()); ObjectGuid guildGuid = ObjectGuid::Create<HighGuid::Guild>(fields[1].GetUInt64()); std::string guildName = fields[2].GetString(); char const* itemPos = "[in guild bank]"; handler->PSendSysMessage(LANG_ITEMLIST_GUILD, itemGuid.ToString().c_str(), guildName.c_str(), guildGuid.ToString().c_str(), itemPos); } while (result->NextRow()); uint32 resultCount = uint32(result->GetRowCount()); if (count > resultCount) count -= resultCount; else if (count) count = 0; } if (inventoryCount + mailCount + auctionCount + guildCount == 0) { handler->SendSysMessage(LANG_COMMAND_NOITEMFOUND); handler->SetSentErrorMessage(true); return false; } handler->PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE, itemId, inventoryCount + mailCount + auctionCount + guildCount, inventoryCount, mailCount, auctionCount, guildCount); return true; }
static bool HandleQuestComplete(ChatHandler* handler, const char* args) { Player* player = handler->getSelectedPlayerOrSelf(); if (!player) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // .quest complete #entry // number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r char* cId = handler->extractKeyFromLink((char*)args, "Hquest"); if (!cId) return false; uint32 entry = atoul(cId); Quest const* quest = sObjectMgr->GetQuestTemplate(entry); // If player doesn't have the quest if (!quest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE) { handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry); handler->SetSentErrorMessage(true); return false; } for (uint32 i = 0; i < quest->Objectives.size(); ++i) { QuestObjective const& obj = quest->Objectives[i]; switch (obj.Type) { case QUEST_OBJECTIVE_ITEM: { uint32 curItemCount = player->GetItemCount(obj.ObjectID, true); ItemPosCountVec dest; uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, obj.ObjectID, obj.Amount - curItemCount); if (msg == EQUIP_ERR_OK) { Item* item = player->StoreNewItem(dest, obj.ObjectID, true); player->SendNewItem(item, obj.Amount - curItemCount, true, false); } break; } case QUEST_OBJECTIVE_MONSTER: { if (CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(obj.ObjectID)) for (uint16 z = 0; z < obj.Amount; ++z) player->KilledMonster(creatureInfo, ObjectGuid::Empty); break; } case QUEST_OBJECTIVE_GAMEOBJECT: { for (uint16 z = 0; z < obj.Amount; ++z) player->KillCreditGO(obj.ObjectID); break; } case QUEST_OBJECTIVE_MIN_REPUTATION: { uint32 curRep = player->GetReputationMgr().GetReputation(obj.ObjectID); if (curRep < uint32(obj.Amount)) if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(obj.ObjectID)) player->GetReputationMgr().SetReputation(factionEntry, obj.Amount); break; } case QUEST_OBJECTIVE_MAX_REPUTATION: { uint32 curRep = player->GetReputationMgr().GetReputation(obj.ObjectID); if (curRep > uint32(obj.Amount)) if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(obj.ObjectID)) player->GetReputationMgr().SetReputation(factionEntry, obj.Amount); break; } case QUEST_OBJECTIVE_MONEY: { player->ModifyMoney(obj.Amount); break; } } } if (sWorld->getBoolConfig(CONFIG_QUEST_ENABLE_QUEST_TRACKER)) // check if Quest Tracker is enabled { // prepare Quest Tracker datas PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_QUEST_TRACK_GM_COMPLETE); stmt->setUInt32(0, quest->GetQuestId()); stmt->setUInt64(1, player->GetGUID().GetCounter()); // add to Quest Tracker CharacterDatabase.Execute(stmt); } player->CompleteQuest(entry); return true; }
DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, std::string name, uint32 guid) { uint32 charcount = AccountMgr::GetCharactersCount(account); if (charcount >= 10) return DUMP_TOO_MANY_CHARS; FILE* fin = fopen(file.c_str(), "r"); if (!fin) return DUMP_FILE_OPEN_ERROR; char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20]; // make sure the same guid doesn't already exist and is safe to use bool incHighest = true; if (guid != 0 && guid < sObjectMgr->_hiCharGuid) { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_GUID); stmt->setUInt32(0, guid); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (result) guid = sObjectMgr->_hiCharGuid; // use first free if exists else incHighest = false; } else guid = sObjectMgr->_hiCharGuid; // normalize the name if specified and check if it exists if (!normalizePlayerName(name)) name.clear(); if (ObjectMgr::CheckPlayerName(name, true) == CHAR_NAME_SUCCESS) { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME); stmt->setString(0, name); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (result) name.clear(); // use the one from the dump } else name.clear(); // name encoded or empty snprintf(newguid, 20, "%u", guid); snprintf(chraccount, 20, "%u", account); snprintf(newpetid, 20, "%u", sObjectMgr->GeneratePetNumber()); snprintf(lastpetid, 20, "%s", ""); std::map<uint32, uint32> items; std::map<uint32, uint32> mails; char buf[32000] = ""; typedef std::map<uint32, uint32> PetIds; // old->new petid relation typedef PetIds::value_type PetIdsPair; PetIds petids; uint8 gender = GENDER_NONE; uint8 race = RACE_NONE; uint8 playerClass = 0; uint8 level = 1; SQLTransaction trans = CharacterDatabase.BeginTransaction(); while (!feof(fin)) { if (!fgets(buf, 32000, fin)) { if (feof(fin)) break; ROLLBACK(DUMP_FILE_BROKEN); } std::string line; line.assign(buf); // skip empty strings size_t nw_pos = line.find_first_not_of(" \t\n\r\7"); if (nw_pos == std::string::npos) continue; // skip logfile-side dump start notice, the important notes and dump end notices if ((line.substr(nw_pos, 16) == "== START DUMP ==") || (line.substr(nw_pos, 15) == "IMPORTANT NOTE:") || (line.substr(nw_pos, 14) == "== END DUMP ==")) continue; // add required_ check /* if (line.substr(nw_pos, 41) == "UPDATE character_db_version SET required_") { if (!CharacterDatabase.Execute(line.c_str())) ROLLBACK(DUMP_FILE_BROKEN); continue; } */ // determine table name and load type std::string tn = gettablename(line); if (tn.empty()) { TC_LOG_ERROR("misc", "LoadPlayerDump: Can't extract table name from line: '%s'!", line.c_str()); ROLLBACK(DUMP_FILE_BROKEN); } DumpTableType type = DumpTableType(0); uint8 i; for (i = 0; i < DUMP_TABLE_COUNT; ++i) { if (tn == dumpTables[i].name) { type = dumpTables[i].type; break; } } if (i == DUMP_TABLE_COUNT) { TC_LOG_ERROR("misc", "LoadPlayerDump: Unknown table: '%s'!", tn.c_str()); ROLLBACK(DUMP_FILE_BROKEN); } // change the data to server values switch (type) { case DTT_CHARACTER: { if (!changenth(line, 1, newguid)) // characters.guid update ROLLBACK(DUMP_FILE_BROKEN); if (!changenth(line, 2, chraccount)) // characters.account update ROLLBACK(DUMP_FILE_BROKEN); race = uint8(atoul(getnth(line, 4).c_str())); playerClass = uint8(atoul(getnth(line, 5).c_str())); gender = uint8(atoul(getnth(line, 6).c_str())); level = uint8(atoul(getnth(line, 7).c_str())); if (name.empty()) { // check if the original name already exists name = getnth(line, 3); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHECK_NAME); stmt->setString(0, name); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (result) if (!changenth(line, 37, "1")) // characters.at_login set to "rename on login" ROLLBACK(DUMP_FILE_BROKEN); } else if (!changenth(line, 3, name.c_str())) // characters.name ROLLBACK(DUMP_FILE_BROKEN); const char null[5] = "NULL"; if (!changenth(line, 69, null)) // characters.deleteInfos_Account ROLLBACK(DUMP_FILE_BROKEN); if (!changenth(line, 70, null)) // characters.deleteInfos_Name ROLLBACK(DUMP_FILE_BROKEN); if (!changenth(line, 71, null)) // characters.deleteDate ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_CHAR_TABLE: { if (!changenth(line, 1, newguid)) // character_*.guid update ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_EQSET_TABLE: { if (!changenth(line, 1, newguid)) ROLLBACK(DUMP_FILE_BROKEN); // character_equipmentsets.guid char newSetGuid[24]; snprintf(newSetGuid, 24, UI64FMTD, sObjectMgr->GenerateEquipmentSetGuid()); if (!changenth(line, 2, newSetGuid)) ROLLBACK(DUMP_FILE_BROKEN); // character_equipmentsets.setguid break; } case DTT_INVENTORY: { if (!changenth(line, 1, newguid)) // character_inventory.guid update ROLLBACK(DUMP_FILE_BROKEN); if (!changeGuid(line, 2, items, sObjectMgr->_hiItemGuid, true)) ROLLBACK(DUMP_FILE_BROKEN); // character_inventory.bag update if (!changeGuid(line, 4, items, sObjectMgr->_hiItemGuid)) ROLLBACK(DUMP_FILE_BROKEN); // character_inventory.item update break; } case DTT_MAIL: // mail { if (!changeGuid(line, 1, mails, sObjectMgr->_mailId)) ROLLBACK(DUMP_FILE_BROKEN); // mail.id update if (!changenth(line, 6, newguid)) // mail.receiver update ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_MAIL_ITEM: // mail_items { if (!changeGuid(line, 1, mails, sObjectMgr->_mailId)) ROLLBACK(DUMP_FILE_BROKEN); // mail_items.id if (!changeGuid(line, 2, items, sObjectMgr->_hiItemGuid)) ROLLBACK(DUMP_FILE_BROKEN); // mail_items.item_guid if (!changenth(line, 3, newguid)) // mail_items.receiver ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_ITEM: { // item, owner, data field:item, owner guid if (!changeGuid(line, 1, items, sObjectMgr->_hiItemGuid)) ROLLBACK(DUMP_FILE_BROKEN); // item_instance.guid update if (!changenth(line, 3, newguid)) // item_instance.owner_guid update ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_ITEM_GIFT: { if (!changenth(line, 1, newguid)) // character_gifts.guid update ROLLBACK(DUMP_FILE_BROKEN); if (!changeGuid(line, 2, items, sObjectMgr->_hiItemGuid)) ROLLBACK(DUMP_FILE_BROKEN); // character_gifts.item_guid update break; } case DTT_PET: { //store a map of old pet id to new inserted pet id for use by type 5 tables snprintf(currpetid, 20, "%s", getnth(line, 1).c_str()); if (*lastpetid == '\0') snprintf(lastpetid, 20, "%s", currpetid); if (strcmp(lastpetid, currpetid) != 0) { snprintf(newpetid, 20, "%u", sObjectMgr->GeneratePetNumber()); snprintf(lastpetid, 20, "%s", currpetid); } std::map<uint32, uint32> :: const_iterator petids_iter = petids.find(atoi(currpetid)); if (petids_iter == petids.end()) { petids.insert(PetIdsPair(atoi(currpetid), atoi(newpetid))); } if (!changenth(line, 1, newpetid)) // character_pet.id update ROLLBACK(DUMP_FILE_BROKEN); if (!changenth(line, 3, newguid)) // character_pet.owner update ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_PET_TABLE: // pet_aura, pet_spell, pet_spell_cooldown { snprintf(currpetid, 20, "%s", getnth(line, 1).c_str()); // lookup currpetid and match to new inserted pet id std::map<uint32, uint32> :: const_iterator petids_iter = petids.find(atoi(currpetid)); if (petids_iter == petids.end()) // couldn't find new inserted id ROLLBACK(DUMP_FILE_BROKEN); snprintf(newpetid, 20, "%d", petids_iter->second); if (!changenth(line, 1, newpetid)) ROLLBACK(DUMP_FILE_BROKEN); break; } default: TC_LOG_ERROR("misc", "Unknown dump table type: %u", type); break; } fixNULLfields(line); trans->Append(line.c_str()); } CharacterDatabase.CommitTransaction(trans); // in case of name conflict player has to rename at login anyway sWorld->AddCharacterNameData(ObjectGuid(HIGHGUID_PLAYER, guid), name, gender, race, playerClass, level); sObjectMgr->_hiItemGuid += items.size(); sObjectMgr->_mailId += mails.size(); if (incHighest) ++sObjectMgr->_hiCharGuid; fclose(fin); return DUMP_SUCCESS; }