#endif
-List<aClient> players;
+// this will be hash.cpp start
+// thank you wcampbel
+unsigned long HASH(const unsigned char *name, int size_of_table);
+List<aClient> players[U_TABLE_SIZE];
+// this will be hash.cpp end
+
Monster *monsters[LEVELS][MONSTERS]; // Monsters per level. Total = MONSTERS * LEVELS
Monster boss; // The boss monster
int strnicmp(const char *s1, const char *s2, size_t len);
// String Functions
-
/********** Password functions **********/
bool passcmp(char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one
/********** GameServ Booleans **********/
+bool shuttingdown;
bool is_playing(char *u); // True if the given nickname in the clients list is playing.
bool is_playing(aClient *user);
ts = strtok(NULL, "\1");
notice(s_GameServ, source, "\1PING %s\1", ts);
} else if (stricmp(cmd, "\1VERSION\1") == 0) {
- notice(s_GameServ, source, "\1VERSION %s %s +devel\1", PACKAGE, VERSION);
+ notice(s_GameServ, source, "\1VERSION %s %s\1", PACKAGE, VERSION);
} else if (stricmp(cmd, "SEARCH") == 0) {
cmd = strtok(NULL, " ");
do_list(source);
} else if (stricmp(cmd, "LOGOUT") == 0) {
do_logout(source);
- #ifdef DEBUGMODE
- } else if (stricmp(cmd, "PRINT") == 0) {
- cout << "Printing the clients list:" << endl;
- clients.print();
- cout << "\nPrinting the players list:" << endl;
- players.print();
- #endif
} else if (stricmp(cmd, "REGISTER") == 0) {
do_register(source);
} else if (stricmp(cmd, "IDENTIFY") == 0) {
#else
raw("SQUIT %s :leaving: %s used the Shutdown command.", servername, source);
#endif
+ shuttingdown = true;
}
} else if (stricmp(cmd, "SAVE") == 0) {
aClient *user;
void do_list(char *u)
{
ListNode<aClient> *temp;
- temp = players.First();
- if (!players.isEmpty())
+ bool header = false;
+ for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
+ {
+ temp = players[x].First();
+ if (!players[x].isEmpty())
{
- notice(s_GameServ, u, "People Playing:");
+ if (!header)
+ {
+ notice(s_GameServ, u, "People Playing:");
+ header = true;
+ }
while(temp)
{
#ifdef P10
temp = temp->Next();
}
- notice(s_GameServ, u, "End of List");
}
- else
+ }
+ if (!header)
notice(s_GameServ, u, "No one is playing");
+ else
+ notice(s_GameServ, u, "End of List");
+
}
void do_logout(char *u)
{
ListNode<aClient> *it;
aClient *temp;
- it = players.Find(user);
+ unsigned long hv = HASH((unsigned char *) user->stats->name,
+ U_TABLE_SIZE);
+ it = players[hv].Find(user);
if (!it)
{
notice(s_GameServ, user->getNick(), "Fatal error. Contact "\
user->stats->user = user; // Set the backwards pointer
strcpy(user->stats->password, crypt(password, salt));
strcpy(user->stats->name, name);
- players.insertAtBack(user);
+ unsigned long hv = HASH((unsigned char *) name, U_TABLE_SIZE);
+ players[hv].insertAtBack(user);
notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->name, password);
notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!");
log("Nickname %s registered player %s.", u, user->stats->name);
}
else {
ListNode<aClient> *temp;
- temp = players.Find(p);
+ unsigned long hv = HASH((unsigned char *) p->stats->name,
+ U_TABLE_SIZE);
+ temp = players[hv].Find(p);
if (!temp)
{
notice(s_GameServ, u, "Fatal error. Contact %S Admin. Buf: %s",
int save_gs_dbase()
{
- ListNode<aClient> *ptr = players.First();
+ ListNode<aClient> *ptr;
Player *it;
ofstream outfile;
return 0;
}
+ for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
+ {
+ ptr = players[x].First();
while(ptr)
{
it = ptr->getData()->stats;
<< ' ' << it->inventory.Strength() << ' ' << it->inventory.Defense() << ' ' << it->inventory.HP() << endl;
ptr = ptr->Next();
}
+ }
outfile.close();
return 1;
}
if (tempname)
p->inventory.setHP(stringtoint(tempname));
temp->stats->user = NULL;
- players.insertAtBack(temp);
+ unsigned long hv = HASH((unsigned char *) temp->stats->name, U_TABLE_SIZE);
+ players[hv].insertAtBack(temp);
delete temp;
}
delete [] buf;
{
ListNode <aClient> *it;
Player *p;
-
- it = players.First();
+ for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
+ {
+ it = players[x].First();
while (it)
{
refresh(p);
it = it->Next();
}
+ }
}
void refresh(Player *p)
ListNode <aClient> *it;
Player *p;
- it = players.First();
+ for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
+ {
+ it = players[x].First();
while (it)
{
reset(p);
it = it->Next();
}
+ }
}
void reset(Player *p)
delete [] buf;
return true;
}
+
+// this will be hash.cpp start
+// thank you wcampbel
+unsigned long HASH(const unsigned char *name, int size_of_table)
+{
+ unsigned long h = 0, g;
+
+ while (*name)
+ {
+ #ifdef P10
+ h = (h << 4) + (*name++); // Case sensitive for numerics
+ #else
+ h = (h << 4) + tolower(*name++);
+ #endif
+ if ((g = (h & 0xF0000000)))
+ h ^= g >> 24;
+ h &= ~g;
+ }
+ return h % size_of_table;
+}
+
+// this will be hash.cpp end