Log in

View Full Version : ZoneNumbers


AndMetal
08-31-2008, 04:53 AM
I am not sure if where all this is used in the code

It looks like the only place it is referenced is in zone/command.cpp (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/command.cpp?revision=1.52&view=markup#l_3828), and it is commented out, and has been at least since the code was moved (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/zone/command.cpp?revision=1.1&view=markup#l_3854) to the current CVS system sometime over 3 years ago.

Thankfully, the zone names are loaded from the database in common/database.cpp (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/common/database.cpp?revision=1.59&view=markup#l_1111):

1111 bool Database::LoadZoneNames() {
1112 char errbuf[MYSQL_ERRMSG_SIZE];
1113 char *query = 0;
1114 MYSQL_RES *result;
1115 MYSQL_ROW row;
1116 query = new char[256];
1117 strcpy(query, "SELECT MAX(zoneidnumber) FROM zone");
1118
1119 if (RunQuery(query, strlen(query), errbuf, &result)) {
1120 safe_delete_array(query);
1121 row = mysql_fetch_row(result);
1122 if (row && row[0])
1123 {
1124 max_zonename = atoi(row[0]);
1125 zonename_array = new char*[max_zonename+1];
1126 for(unsigned int i=0; i<max_zonename; i++) {
1127 zonename_array[i] = 0;
1128 }
1129 mysql_free_result(result);
1130
1131 MakeAnyLenString(&query, "SELECT zoneidnumber, short_name FROM zone");
1132 if (RunQuery(query, strlen(query), errbuf, &result)) {
1133 safe_delete_array(query);
1134 while((row = mysql_fetch_row(result))) {
1135 zonename_array[atoi(row[0])] = new char[strlen(row[1]) + 1];
1136 strcpy(zonename_array[atoi(row[0])], row[1]);
1137 Sleep(0);
1138 }
1139 mysql_free_result(result);
1140 }
1141 else {
1142 cerr << "Error in LoadZoneNames query '" << query << "' " << errbuf << endl;
1143 safe_delete_array(query);
1144 return false;
1145 }
1146 }
1147 else {
1148 mysql_free_result(result);
1149 }
1150 }
1151 else {
1152 cerr << "Error in LoadZoneNames query '" << query << "' " << errbuf << endl;
1153 safe_delete_array(query);
1154 return false;
1155 }
1156 return true;
1157 }


Which can then be called using Database::GetZoneID (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/common/database.cpp?revision=1.59&view=markup#l_1159), Database::GetZoneName (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/common/database.cpp?revision=1.59&view=markup#l_1171), or Database::GetZoneLongName (http://eqemulator.cvs.sourceforge.net/eqemulator/EQEmuCVS/Source/common/database.cpp?revision=1.59&view=markup#l_1009).

Although it doesn't look like this was really a major deal (and can probably be removed from the main source), it's things like these that can really help the code, so definitely a good catch in general :-)