mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-10 02:08:20 +00:00
chore: Update old character create code (#1291)
* create new character fixes Don't use persistentIds, guarantee ids are unique by using do while to generate the id * Update queries to actually use prep stmt * Update UserManager.cpp * Update UserManager.cpp
This commit is contained in:
parent
df83f0d847
commit
198b3371c5
@ -275,36 +275,36 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream xml;
|
std::stringstream xml;
|
||||||
xml << "<obj v=\"1\"><mf hc=\"" << hairColor << "\" hs=\"" << hairStyle << "\" hd=\"0\" t=\"" << shirtColor << "\" l=\"" << pantsColor;
|
xml << "<obj v=\"1\">";
|
||||||
|
|
||||||
|
xml << "<mf hc=\"" << hairColor << "\" hs=\"" << hairStyle << "\" hd=\"0\" t=\"" << shirtColor << "\" l=\"" << pantsColor;
|
||||||
xml << "\" hdc=\"0\" cd=\"" << shirtStyle << "\" lh=\"" << lh << "\" rh=\"" << rh << "\" es=\"" << eyebrows << "\" ";
|
xml << "\" hdc=\"0\" cd=\"" << shirtStyle << "\" lh=\"" << lh << "\" rh=\"" << rh << "\" es=\"" << eyebrows << "\" ";
|
||||||
xml << "ess=\"" << eyes << "\" ms=\"" << mouth << "\"/>";
|
xml << "ess=\"" << eyes << "\" ms=\"" << mouth << "\"/>";
|
||||||
|
|
||||||
xml << "<char acct=\"" << u->GetAccountID() << "\" cc=\"0\" gm=\"0\" ft=\"0\" llog=\"" << time(NULL) << "\" ";
|
xml << "<char acct=\"" << u->GetAccountID() << "\" cc=\"0\" gm=\"0\" ft=\"0\" llog=\"" << time(NULL) << "\" ";
|
||||||
xml << "ls=\"0\" lzx=\"-626.5847\" lzy=\"613.3515\" lzz=\"-28.6374\" lzrx=\"0.0\" lzry=\"0.7015\" lzrz=\"0.0\" lzrw=\"0.7126\" ";
|
xml << "ls=\"0\" lzx=\"-626.5847\" lzy=\"613.3515\" lzz=\"-28.6374\" lzrx=\"0.0\" lzry=\"0.7015\" lzrz=\"0.0\" lzrw=\"0.7126\" ";
|
||||||
xml << "stt=\"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;\"></char>";
|
xml << "stt=\"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;\"></char>";
|
||||||
|
|
||||||
xml << "<dest hm=\"4\" hc=\"4\" im=\"0\" ic=\"0\" am=\"0\" ac=\"0\" d=\"0\"/>";
|
xml << "<dest hm=\"4\" hc=\"4\" im=\"0\" ic=\"0\" am=\"0\" ac=\"0\" d=\"0\"/>";
|
||||||
|
|
||||||
xml << "<inv><bag><b t=\"0\" m=\"20\"/><b t=\"1\" m=\"40\"/><b t=\"2\" m=\"240\"/><b t=\"3\" m=\"240\"/><b t=\"14\" m=\"40\"/></bag><items><in t=\"0\">";
|
xml << "<inv><bag><b t=\"0\" m=\"20\"/><b t=\"1\" m=\"40\"/><b t=\"2\" m=\"240\"/><b t=\"3\" m=\"240\"/><b t=\"14\" m=\"40\"/></bag><items><in t=\"0\">";
|
||||||
std::string xmlSave1 = xml.str();
|
|
||||||
|
|
||||||
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t idforshirt) {
|
LWOOBJID lwoidforshirt = ObjectIDManager::GenerateRandomObjectID();
|
||||||
std::stringstream xml2;
|
LWOOBJID lwoidforpants;
|
||||||
|
|
||||||
|
do {
|
||||||
|
lwoidforpants = ObjectIDManager::GenerateRandomObjectID();
|
||||||
|
} while (lwoidforpants == lwoidforshirt); //Make sure we don't have the same ID for both shirt and pants
|
||||||
|
|
||||||
LWOOBJID lwoidforshirt = idforshirt;
|
|
||||||
GeneralUtils::SetBit(lwoidforshirt, eObjectBits::CHARACTER);
|
GeneralUtils::SetBit(lwoidforshirt, eObjectBits::CHARACTER);
|
||||||
GeneralUtils::SetBit(lwoidforshirt, eObjectBits::PERSISTENT);
|
GeneralUtils::SetBit(lwoidforshirt, eObjectBits::PERSISTENT);
|
||||||
xml2 << xmlSave1 << "<i l=\"" << shirtLOT << "\" id=\"" << lwoidforshirt << "\" s=\"0\" c=\"1\" eq=\"1\" b=\"1\"/>";
|
|
||||||
|
|
||||||
std::string xmlSave2 = xml2.str();
|
|
||||||
|
|
||||||
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t idforpants) {
|
|
||||||
LWOOBJID lwoidforpants = idforpants;
|
|
||||||
GeneralUtils::SetBit(lwoidforpants, eObjectBits::CHARACTER);
|
GeneralUtils::SetBit(lwoidforpants, eObjectBits::CHARACTER);
|
||||||
GeneralUtils::SetBit(lwoidforpants, eObjectBits::PERSISTENT);
|
GeneralUtils::SetBit(lwoidforpants, eObjectBits::PERSISTENT);
|
||||||
|
|
||||||
std::stringstream xml3;
|
xml << "<i l=\"" << shirtLOT << "\" id=\"" << lwoidforshirt << "\" s=\"0\" c=\"1\" eq=\"1\" b=\"1\"/>";
|
||||||
xml3 << xmlSave2 << "<i l=\"" << pantsLOT << "\" id=\"" << lwoidforpants << "\" s=\"1\" c=\"1\" eq=\"1\" b=\"1\"/>";
|
xml << "<i l=\"" << pantsLOT << "\" id=\"" << lwoidforpants << "\" s=\"1\" c=\"1\" eq=\"1\" b=\"1\"/>";
|
||||||
|
|
||||||
xml3 << "</in></items></inv><lvl l=\"1\" cv=\"1\" sb=\"500\"/><flag></flag></obj>";
|
xml << "</in></items></inv><lvl l=\"1\" cv=\"1\" sb=\"500\"/><flag></flag></obj>";
|
||||||
|
|
||||||
//Check to see if our name was pre-approved:
|
//Check to see if our name was pre-approved:
|
||||||
bool nameOk = IsNamePreapproved(name);
|
bool nameOk = IsNamePreapproved(name);
|
||||||
@ -322,13 +322,11 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
|||||||
Database::Get()->InsertNewCharacter(info);
|
Database::Get()->InsertNewCharacter(info);
|
||||||
|
|
||||||
//Now finally insert our character xml:
|
//Now finally insert our character xml:
|
||||||
Database::Get()->InsertCharacterXml(objectID, xml3.str());
|
Database::Get()->InsertCharacterXml(objectID, xml.str());
|
||||||
|
|
||||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::SUCCESS);
|
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::SUCCESS);
|
||||||
UserManager::RequestCharacterList(sysAddr);
|
UserManager::RequestCharacterList(sysAddr);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet) {
|
void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet) {
|
||||||
@ -466,16 +464,18 @@ void UserManager::LoginCharacter(const SystemAddress& sysAddr, uint32_t playerID
|
|||||||
|
|
||||||
uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
|
uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
|
||||||
try {
|
try {
|
||||||
std::string shirtQuery = "select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == \"character create shirt\" AND icc.color1 == ";
|
auto stmt = CDClientDatabase::CreatePreppedStmt(
|
||||||
shirtQuery += std::to_string(shirtColor);
|
"select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ? AND icc.decal == ?"
|
||||||
shirtQuery += " AND icc.decal == ";
|
);
|
||||||
shirtQuery = shirtQuery + std::to_string(shirtStyle);
|
stmt.bind(1, "character create shirt");
|
||||||
auto tableData = CDClientDatabase::ExecuteQuery(shirtQuery);
|
stmt.bind(2, static_cast<int>(shirtColor));
|
||||||
auto shirtLOT = tableData.getIntField(0, -1);
|
stmt.bind(3, static_cast<int>(shirtStyle));
|
||||||
|
auto tableData = stmt.execQuery();
|
||||||
|
auto shirtLOT = tableData.getIntField(0, 4069);
|
||||||
tableData.finalize();
|
tableData.finalize();
|
||||||
return shirtLOT;
|
return shirtLOT;
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception& ex) {
|
||||||
LOG("Failed to execute query! Using backup...");
|
LOG("Could not look up shirt %i %i: %s", shirtColor, shirtStyle, ex.what());
|
||||||
// in case of no shirt found in CDServer, return problematic red vest.
|
// in case of no shirt found in CDServer, return problematic red vest.
|
||||||
return 4069;
|
return 4069;
|
||||||
}
|
}
|
||||||
@ -483,14 +483,17 @@ uint32_t FindCharShirtID(uint32_t shirtColor, uint32_t shirtStyle) {
|
|||||||
|
|
||||||
uint32_t FindCharPantsID(uint32_t pantsColor) {
|
uint32_t FindCharPantsID(uint32_t pantsColor) {
|
||||||
try {
|
try {
|
||||||
std::string pantsQuery = "select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == \"cc pants\" AND icc.color1 == ";
|
auto stmt = CDClientDatabase::CreatePreppedStmt(
|
||||||
pantsQuery += std::to_string(pantsColor);
|
"select obj.id from Objects as obj JOIN (select * from ComponentsRegistry as cr JOIN ItemComponent as ic on ic.id = cr.component_id where cr.component_type == 11) as icc on icc.id = obj.id where lower(obj._internalNotes) == ? AND icc.color1 == ?"
|
||||||
auto tableData = CDClientDatabase::ExecuteQuery(pantsQuery);
|
);
|
||||||
auto pantsLOT = tableData.getIntField(0, -1);
|
stmt.bind(1, "cc pants");
|
||||||
|
stmt.bind(2, static_cast<int>(pantsColor));
|
||||||
|
auto tableData = stmt.execQuery();
|
||||||
|
auto pantsLOT = tableData.getIntField(0, 2508);
|
||||||
tableData.finalize();
|
tableData.finalize();
|
||||||
return pantsLOT;
|
return pantsLOT;
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception& ex) {
|
||||||
LOG("Failed to execute query! Using backup...");
|
LOG("Could not look up pants %i: %s", pantsColor, ex.what());
|
||||||
// in case of no pants color found in CDServer, return red pants.
|
// in case of no pants color found in CDServer, return red pants.
|
||||||
return 2508;
|
return 2508;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user