PDA

View Full Version : New Look to Client.cpp


Edgar1898
12-31-2002, 12:06 AM
I recoded Client.cpp from the beginning to make the code flow better and to get rid of the 10000 mile long if then else loop that it had. What I do was replaced that with a switch that sent you to the function that holds the commands. There are 8 functions each of them represents a status on the server. (Normal,Privuser,Vprivuser,Questtroupe,GM,LeadGM,S erverOP, and VHServerOp). Each other these functions contains only the information for their status. It starts at the highest level that you can access, then is flows downhill from there until it gets to a Normal User. Let me explain: Your a GM and you use the command #kill (somemob) instead of having to go through every command trying to find the one it was looking for (like the old version did), it simply calls the function for that status group, and it retrieves it much faster since it has about 80% less information to sort through. If the command is a lower status command, it then goes down a step in the status chain to the next rung, and it looks for it there, and so on until it gets to the lowest one. Since most users dont have access to the large list of commands at the top there was no reason to have them search through it. Okies Im done rambling on hehe time to goto bed :) Anyways to sum it up this will save quite a bit of time and overhead by using this method.

Add the following to client.h:
bool NormalUser(const char* message, const char* targetname);
bool PrivUser(const char* message, const char* targetname);
bool VeryPrivUser(const char* message, const char* targetname);
bool QuestTroupe(const char* message, const char* targetname);
bool NormalGM(const char* message, const char* targetname);
bool LeadGM(const char* message, const char* targetname);
bool ServerOP(const char* message, const char* targetname);
bool VHServerOP(const char* message, const char* targetname);

blackhawk
12-31-2002, 01:13 AM
C:\eqemusrc\zone\client.cpp(2357) : error C2248: 'RunQuery' : cannot access protected member declared in class 'Database'
C:\eqemusrc\zone\../common/database.h(263) : see declaration of 'RunQuery'
C:\eqemusrc\zone\client.cpp(2862) : error C2248: 'RunQuery' : cannot access protected member declared in class 'Database'
C:\eqemusrc\zone\../common/database.h(263) : see declaration of 'RunQuery'
C:\eqemusrc\zone\client.cpp(2890) : error C2248: 'RunQuery' : cannot access protected member declared in class 'Database'
C:\eqemusrc\zone\../common/database.h(263) : see declaration of 'RunQuery'
C:\eqemusrc\zone\client.cpp(2922) : error C2248: 'RunQuery' : cannot access protected member declared in class 'Database'
C:\eqemusrc\zone\../common/database.h(263) : see declaration of 'RunQuery'

Edgar1898
12-31-2002, 09:19 AM
Oh oops I forgot to add another change I made. Change the following in database.h:


protected:
void AddLootDropToNPC(int32 lootdrop_id, ItemList* itemlist);
bool RunQuery(const char* query, int32 querylen, char* errbuf = 0, MYSQL_RES** result = 0, int32* affected_rows = 0, int32* errnum = 0, bool retry = true);

move

bool RunQuery(const char* query, int32 querylen, char* errbuf = 0, MYSQL_RES** result = 0, int32* affected_rows = 0, int32* errnum = 0, bool retry = true); from protected to public. If you dont want to do that then just go into Client.cpp and delete the following:

else if ((strcasecmp(sep.arg[0], "#listpetition") == 0) && CheckAccess(cmdlevel, 100)) {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
int blahloopcount=0;
if (database.RunQuery(query, MakeAnyLenString(&query, "SELECT dib, charname, accountname from petitions order by dib"), errbuf, &result))
{
delete[] query;
cout << this->GetName() << " looking at petitionlist" << endl;
while ((row = mysql_fetch_row(result))) {
if (blahloopcount==0) {
blahloopcount=1;
Message(13," ID : Character Name , Account Name");
}
else
Message(15, " %s: %s , %s ",row[0],row[1],row[2]);
}
mysql_free_result(result);
}
}
else if ((strcasecmp(sep.arg[0], "#viewpetition") == 0) && CheckAccess(cmdlevel, 100)) {
if (sep.arg[1][0] == 0) {
Message(0, "Usage: #viewpetition (petition number) Type #listpetition for a list");
} else {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
int queryfound = 0;
MYSQL_RES *result;
MYSQL_ROW row;
Petition* newpet;
Message(13," ID : Character Name , Petition Text");
if (database.RunQuery(query, MakeAnyLenString(&query, "SELECT dib, charname, petitiontext from petitions order by dib"), errbuf, &result))
{
delete[] query;

while ((row = mysql_fetch_row(result))) {
if (strcasecmp(row[0],sep.argplus[1])== 0) {
queryfound=1;
Message(15, " %s: %s , %s ",row[0],row[1],row[2]);
}
}
cout << this->GetName() << " looking at petition Number " << sep.argplus[1] << endl;
if (queryfound==0)
Message(13,"There was an error in your request: ID not found! Please check the Id and try again.");
mysql_free_result(result);
}
}
}
else if ((strcasecmp(sep.arg[0], "#petitioninfo") == 0) && CheckAccess(cmdlevel, 100)) {
if (sep.arg[1][0] == 0) {
Message(0, "Usage: #petitioninfo (petition number) Type #listpetition for a list");
} else {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
int queryfound = 0;
MYSQL_RES *result;
MYSQL_ROW row;
Petition* newpet;
if (database.RunQuery(query, MakeAnyLenString(&query, "SELECT dib, charname, accountname, zone, charclass, charrace, charlevel from petitions order by dib"), errbuf, &result))
{
delete[] query;
while ((row = mysql_fetch_row(result))) {
if (strcasecmp(row[0],sep.argplus[1])== 0) {
queryfound=1;
Message(13," ID : %s Character Name: %s Account Name: %s Zone: %s Character Class: %s Character Race: %s Character Level: %s",row[0],row[1],row[2],row[3],row[4],row[5],row[6]) ;
}
}
cout << this->GetName() << " looking at petition information Number " << sep.argplus[1] << endl;
if (queryfound==0)
Message(13,"There was an error in your request: ID not found! Please check the Id and try again.");
mysql_free_result(result);
}
}
}
else if ((strcasecmp(sep.arg[0], "#delpetition") == 0) && CheckAccess(cmdlevel, 100)) {
if (sep.arg[1][0] == 0 || strcasecmp(sep.arg[1],"*")==0)
Message(0, "Usage: #delpetition (petition number) Type #listpetition for a list");
else {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
int queryfound = 0;
MYSQL_RES *result;
MYSQL_ROW row;
Petition* newpet;
//char* blah32;
//strcpy(blah32,sep.argplus[1]);
//char* querystring;
//querystring=strcat("DELETE from petitions where dib=",blah32);
Message(13,"Attempting to delete petition number: %i",atoi(sep.argplus[1]));
if (database.RunQuery(query, MakeAnyLenString(&query, "DELETE from petitions where dib=%i",atoi(sep.argplus[1])), errbuf, &result)) {
delete[] query;
cout << this->GetName() << " deleting petition Number " << sep.argplus[1] << endl;
}
//mysql_free_result(result); // If uncommented crashes zone. :/
}
}



Just do one or the other though. I recommend keeping the petition commands so you can handle petitions :P

Edgar1898
12-31-2002, 11:16 AM
Use this version instead, it includes a fix for gms zoning into cshome.

Joolz
01-06-2003, 12:59 AM
All you have done is split the if statement into little bits. The cascading down routine is probably more in-efficient than the long if-then-else.

Edgar1898
01-06-2003, 04:55 AM
Not really, its still more efficient because with the old client.cpp, if the command was near the bottom it had to go through everyone of the statements before it. Now it only goes through the statements if it needs to.