mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-27 12:22:27 +00:00
Refactor HandleRandomNameGeneratorPacket
This commit is contained in:
parent
a8400803cc
commit
1e088ca2ba
167
world/client.cpp
167
world/client.cpp
@ -524,6 +524,91 @@ bool Client::HandleApproveNamePacket(const EQApplicationPacket *app)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::HandleRandomNameGeneratorPacket(const EQApplicationPacket *app)
|
||||
{
|
||||
// creates up to a 10 char name
|
||||
char vowels[18]="aeiouyaeiouaeioe";
|
||||
char cons[48]="bcdfghjklmnpqrstvwxzybcdgklmnprstvwbcdgkpstrkd";
|
||||
char rndname[17]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
char paircons[33]="ngrkndstshthphsktrdrbrgrfrclcr";
|
||||
int rndnum=MakeRandomInt(0, 75),n=1;
|
||||
bool dlc=false;
|
||||
bool vwl=false;
|
||||
bool dbl=false;
|
||||
|
||||
if (rndnum>63) {
|
||||
// rndnum is 0 - 75 where 64-75 is cons pair, 17-63 is cons, 0-16 is vowel
|
||||
rndnum=(rndnum-61)*2; // name can't start with "ng" "nd" or "rk"
|
||||
rndname[0]=paircons[rndnum];
|
||||
rndname[1]=paircons[rndnum+1];
|
||||
n=2;
|
||||
}
|
||||
else if (rndnum>16) {
|
||||
rndnum-=17;
|
||||
rndname[0]=cons[rndnum];
|
||||
}
|
||||
else {
|
||||
rndname[0]=vowels[rndnum];
|
||||
vwl=true;
|
||||
}
|
||||
|
||||
int namlen=MakeRandomInt(5, 10);
|
||||
for (int i=n;i<namlen;i++)
|
||||
{
|
||||
dlc=false;
|
||||
if (vwl) {
|
||||
//last char was a vowel
|
||||
// so pick a cons or cons pair
|
||||
rndnum=MakeRandomInt(0, 62);
|
||||
if (rndnum>46) {
|
||||
// pick a cons pair
|
||||
if (i>namlen-3) {
|
||||
// last 2 chars in name?
|
||||
// name can only end in cons pair "rk" "st" "sh" "th" "ph" "sk" "nd" or "ng"
|
||||
rndnum=MakeRandomInt(0, 7)*2;
|
||||
}
|
||||
else {
|
||||
// pick any from the set
|
||||
rndnum=(rndnum-47)*2;
|
||||
}
|
||||
|
||||
rndname[i]=paircons[rndnum];
|
||||
rndname[i+1]=paircons[rndnum+1];
|
||||
dlc=true; // flag keeps second letter from being doubled below
|
||||
i+=1;
|
||||
}
|
||||
else {
|
||||
// select a single cons
|
||||
rndname[i]=cons[rndnum];
|
||||
}
|
||||
}
|
||||
else {
|
||||
// select a vowel
|
||||
rndname[i]=vowels[MakeRandomInt(0, 16)];
|
||||
}
|
||||
|
||||
vwl=!vwl;
|
||||
if (!dbl && !dlc)
|
||||
{
|
||||
// one chance at double letters in name
|
||||
if (!MakeRandomInt(0, i+9)) {
|
||||
// chances decrease towards end of name
|
||||
rndname[i+1]=rndname[i];
|
||||
dbl=true;
|
||||
i+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rndname[0]=toupper(rndname[0]);
|
||||
NameGeneration_Struct* ngs = (NameGeneration_Struct*)app->pBuffer;
|
||||
memset(ngs->name,0,64);
|
||||
strcpy(ngs->name,rndname);
|
||||
|
||||
QueuePacket(app);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
const WorldConfig *Config=WorldConfig::get();
|
||||
EmuOpcode opcode = app->GetOpcode();
|
||||
@ -569,87 +654,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
}
|
||||
case OP_RandomNameGenerator:
|
||||
{
|
||||
// creates up to a 10 char name
|
||||
char vowels[18]="aeiouyaeiouaeioe";
|
||||
char cons[48]="bcdfghjklmnpqrstvwxzybcdgklmnprstvwbcdgkpstrkd";
|
||||
char rndname[17]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
char paircons[33]="ngrkndstshthphsktrdrbrgrfrclcr";
|
||||
int rndnum=MakeRandomInt(0, 75),n=1;
|
||||
bool dlc=false;
|
||||
bool vwl=false;
|
||||
bool dbl=false;
|
||||
if (rndnum>63)
|
||||
{ // rndnum is 0 - 75 where 64-75 is cons pair, 17-63 is cons, 0-16 is vowel
|
||||
rndnum=(rndnum-61)*2; // name can't start with "ng" "nd" or "rk"
|
||||
rndname[0]=paircons[rndnum];
|
||||
rndname[1]=paircons[rndnum+1];
|
||||
n=2;
|
||||
}
|
||||
else if (rndnum>16)
|
||||
{
|
||||
rndnum-=17;
|
||||
rndname[0]=cons[rndnum];
|
||||
}
|
||||
else
|
||||
{
|
||||
rndname[0]=vowels[rndnum];
|
||||
vwl=true;
|
||||
}
|
||||
int namlen=MakeRandomInt(5, 10);
|
||||
for (int i=n;i<namlen;i++)
|
||||
{
|
||||
dlc=false;
|
||||
if (vwl) //last char was a vowel
|
||||
{ // so pick a cons or cons pair
|
||||
rndnum=MakeRandomInt(0, 62);
|
||||
if (rndnum>46)
|
||||
{ // pick a cons pair
|
||||
if (i>namlen-3) // last 2 chars in name?
|
||||
{ // name can only end in cons pair "rk" "st" "sh" "th" "ph" "sk" "nd" or "ng"
|
||||
rndnum=MakeRandomInt(0, 7)*2;
|
||||
}
|
||||
else
|
||||
{ // pick any from the set
|
||||
rndnum=(rndnum-47)*2;
|
||||
}
|
||||
rndname[i]=paircons[rndnum];
|
||||
rndname[i+1]=paircons[rndnum+1];
|
||||
dlc=true; // flag keeps second letter from being doubled below
|
||||
i+=1;
|
||||
}
|
||||
else
|
||||
{ // select a single cons
|
||||
rndname[i]=cons[rndnum];
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // select a vowel
|
||||
rndname[i]=vowels[MakeRandomInt(0, 16)];
|
||||
}
|
||||
vwl=!vwl;
|
||||
if (!dbl && !dlc)
|
||||
{ // one chance at double letters in name
|
||||
if (!MakeRandomInt(0, i+9)) // chances decrease towards end of name
|
||||
{
|
||||
rndname[i+1]=rndname[i];
|
||||
dbl=true;
|
||||
i+=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rndname[0]=toupper(rndname[0]);
|
||||
NameGeneration_Struct* ngs = (NameGeneration_Struct*)app->pBuffer;
|
||||
memset(ngs->name,0,64);
|
||||
strcpy(ngs->name,rndname);
|
||||
|
||||
// char names[8][64] = { "How", "About", "You", "Think", "Of", "Your", "Own", "Name" };
|
||||
// //Could have parts of the random name in this struct and they compile together
|
||||
// NameGeneration_Struct* ngs = (NameGeneration_Struct*)app->pBuffer;
|
||||
// strncpy(ngs->name,"Notcreated",64);
|
||||
|
||||
QueuePacket(app);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
case OP_CharacterCreateRequest: {
|
||||
|
||||
@ -93,6 +93,7 @@ private:
|
||||
|
||||
bool HandleLoginInfoPacket(const EQApplicationPacket *app);
|
||||
bool HandleApproveNamePacket(const EQApplicationPacket *app);
|
||||
bool HandleRandomNameGeneratorPacket(const EQApplicationPacket *app);
|
||||
|
||||
ClientListEntry* cle;
|
||||
Timer CLE_keepalive_timer;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user