MCPcopy Create free account
hub / github.com/EQEmu/EQEmu / HandleGenerateRandomNamePacket

Method HandleGenerateRandomNamePacket

world/client.cpp:642–703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

640}
641
642bool Client::HandleGenerateRandomNamePacket(const EQApplicationPacket *app) {
643 char newName[17] = {0};
644 bool unique = false;
645
646 while (!unique) {
647 std::string cons = "bcdfghjklmnpqrstvwxyz";
648 std::string vows = "aeou";
649 std::string allVows = "aeiou";
650 std::vector<std::string> endPhon = {"a", "e", "i", "o", "u", "os", "as", "us", "is", "y", "an", "en", "in", "on", "un"};
651
652 std::random_device rd;
653 std::mt19937 gen(rd());
654
655 std::uniform_int_distribution<int> lenDist(5, 10);
656 std::uniform_int_distribution<int> firstCharDist(0, 1);
657 std::uniform_int_distribution<int> consDist(0, cons.size() - 1);
658 std::uniform_int_distribution<int> vowDist(0, vows.size() - 1);
659 std::uniform_int_distribution<int> allVowDist(0, allVows.size() - 1);
660 std::uniform_int_distribution<int> endPhonDist(0, endPhon.size() - 1);
661
662 int len = 0;
663 memset(newName, 0, sizeof(newName));
664
665 if (firstCharDist(gen) == 0) {
666 newName[len++] = vows[vowDist(gen)];
667 newName[len++] = cons[consDist(gen)];
668 } else {
669 newName[len++] = cons[consDist(gen)];
670 newName[len++] = allVows[allVowDist(gen)];
671 }
672
673 newName[0] = toupper(newName[0]);
674
675 while (len < lenDist(gen) - 1) {
676 if (len % 2 == 0) {
677 newName[len++] = cons[consDist(gen)];
678 } else {
679 newName[len++] = allVows[allVowDist(gen)];
680 }
681 }
682
683 std::string end = endPhon[endPhonDist(gen)];
684 for (char c : end) {
685 if (len < 10) newName[len++] = c;
686 }
687
688 if (database.CheckNameFilter(newName)) {
689 std::string query = StringFormat("SELECT `name` FROM `character_data` WHERE `name` = '%s'", newName);
690 auto res = database.QueryDatabase(query);
691 if (res.Success() && res.RowCount() == 0) {
692 unique = true;
693 }
694 }
695 }
696
697 NameGeneration_Struct* ngs = (NameGeneration_Struct*)app->pBuffer;
698 memset(ngs->name, 0, 64);
699 strcpy(ngs->name, newName);

Callers

nothing calls this directly

Calls 6

StringFormatFunction · 0.85
CheckNameFilterMethod · 0.80
QueryDatabaseMethod · 0.80
SuccessMethod · 0.80
sizeMethod · 0.45
RowCountMethod · 0.45

Tested by

no test coverage detected