bool Guild::Create(Player* leader, std::string gname) { if (sGuildMgr.GetGuildByName(gname)) { return false; } WorldSession* lSession = leader->GetSession(); if (!lSession) { return false; } m_LeaderGuid = leader->GetObjectGuid(); m_Name = gname; GINFO.clear(); MOTD = "No message set."; m_Id = sObjectMgr.GenerateGuildId(); // creating data time_t now = time(0); tm local = *(localtime(&now)); // dereference and assign m_CreatedDay = local.tm_mday; m_CreatedMonth = local.tm_mon + 1; m_CreatedYear = local.tm_year + 1900; DEBUG_LOG("GUILD: creating guild %s to leader: %s", gname.c_str(), m_LeaderGuid.GetString().c_str()); // gname already assigned to Guild::name, use it to encode string for DB CharacterDatabase.escape_string(gname); std::string dbGINFO = GINFO; std::string dbMOTD = MOTD; CharacterDatabase.escape_string(dbGINFO); CharacterDatabase.escape_string(dbMOTD); CharacterDatabase.BeginTransaction(); // CharacterDatabase.PExecute("DELETE FROM guild WHERE guildid='%u'", Id); - MAX(guildid)+1 not exist CharacterDatabase.PExecute("DELETE FROM guild_member WHERE guildid='%u'", m_Id); CharacterDatabase.PExecute("INSERT INTO guild (guildid,name,leaderguid,info,motd,createdate,EmblemStyle,EmblemColor,BorderStyle,BorderColor,BackgroundColor) " "VALUES('%u','%s','%u', '%s', '%s','" UI64FMTD "','%u','%u','%u','%u','%u')", m_Id, gname.c_str(), m_LeaderGuid.GetCounter(), dbGINFO.c_str(), dbMOTD.c_str(), uint64(now), m_EmblemStyle, m_EmblemColor, m_BorderStyle, m_BorderColor, m_BackgroundColor); CharacterDatabase.CommitTransaction(); CreateDefaultGuildRanks(lSession->GetSessionDbLocaleIndex()); // Used by Eluna #ifdef ENABLE_ELUNA sEluna->OnCreate(this, leader, gname.c_str()); #endif /* ENABLE_ELUNA */ return AddMember(m_LeaderGuid, (uint32)GR_GUILDMASTER); }
bool Guild::Create(Player* leader, std::string gname) { if (sGuildMgr.GetGuildByName(gname)) return false; WorldSession* lSession = leader->GetSession(); if (!lSession) return false; m_LeaderGuid = leader->GetObjectGuid(); m_Name = gname; GINFO = ""; MOTD = "No message set."; m_Id = sObjectMgr.GenerateGuildId(); m_CreatedDate = time(0); DEBUG_LOG("GUILD: creating guild %s to leader: %s", gname.c_str(), m_LeaderGuid.GetString().c_str()); // gname already assigned to Guild::name, use it to encode string for DB CharacterDatabase.escape_string(gname); std::string dbGINFO = GINFO; std::string dbMOTD = MOTD; CharacterDatabase.escape_string(dbGINFO); CharacterDatabase.escape_string(dbMOTD); CharacterDatabase.BeginTransaction(); // CharacterDatabase.PExecute("DELETE FROM guild WHERE guildid='%u'", Id); - MAX(guildid)+1 not exist CharacterDatabase.PExecute("DELETE FROM guild_member WHERE guildid='%u'", m_Id); CharacterDatabase.PExecute("INSERT INTO guild (guildid,name,leaderguid,info,motd,createdate,EmblemStyle,EmblemColor,BorderStyle,BorderColor,BackgroundColor) " "VALUES('%u','%s','%u', '%s', '%s','" UI64FMTD "','%u','%u','%u','%u','%u')", m_Id, gname.c_str(), m_LeaderGuid.GetCounter(), dbGINFO.c_str(), dbMOTD.c_str(), uint64(m_CreatedDate), m_EmblemStyle, m_EmblemColor, m_BorderStyle, m_BorderColor, m_BackgroundColor); CharacterDatabase.CommitTransaction(); CreateDefaultGuildRanks(lSession->GetSessionDbLocaleIndex()); return AddMember(m_LeaderGuid, (uint32)GR_GUILDMASTER); }