using std::endl;
char *PACKAGE = "GameServ";
-char *VERSION = "1.1.8";
+char *VERSION = "1.2.0 +devel";
int sock;
int day;
-List<aClient> clients;
+List<aClient> clients[U_TABLE_SIZE];
void save_day();
void load_day();
int main(int argc, char *argv[])
{
char buffer[1024], buf[1024];
- int connected = 1;
+ int connected;
char *cmd, *source = NULL, *conf = "gameserv.conf";
srand(time(NULL));
+ /*
+ * This needs to be fixed to work for any number of arguments in any
+ * order
+ *
+ */
if (argc > 1)
{
if ( argc > 2 || stricmp(argv[1], "--help") == 0)
exit(2);
}
+ init_masters();
+ load_gs_dbase();
+
+ if (load_monsters() == false)
+ goto end;
+
+ shuttingdown = false;
+
+ strcpy(boss.name, "Red Dragon");
+ strcpy(boss.weapon, "Breath of Unholy Fire");
+ boss.strength = 6667;
+ boss.gold = 2000000000;
+ boss.exp = 2000000000;
+ strcpy(boss.death, "You finally snuff out the deadly murderous "\
+ "dragon's dark flames. You have freed the land of its terror "\
+ "filled reign from above!");
+
+ // This loop will retry the connection 3 times
+ for (int retry = 0; retry < 3 && !shuttingdown; retry++)
+ {
+ connected = 1;
+ load_day();
+
+ long int loadtime = time(NULL);
+ long int currentTime;
+ long int oldTime = loadtime;
+ bool loaded = false;
+
ignore_pipe();
sock = make_connection(remoteport, SOCK_STREAM, remoteserver);
if (sock == -1) {
log("Server: %s",buffer);
#endif
- init_masters();
- load_gs_dbase();
- load_day();
- long int loadtime = time(NULL);
- long int currentTime;
- long int oldTime = loadtime;
- bool loaded = false;
-
- if (load_monsters() == false)
- goto end;
-
while (connected) {
if (sock_gets(sock,buffer,sizeof(buffer)) == -1) {
connected = 0;
if (!loaded)
{
if (time(NULL) >= welcomedelay + loadtime)
+ {
loaded = true;
+ retry = 0; // Start the reconnection cycle over
+ }
}
// Save the player data every updateperiod seconds
if ((tempPtr = find((source + 1))))
{
char *nick;
+ unsigned long oldhv, newhv;
nick = strtok(NULL, " ");
+ oldhv = HASH((unsigned char *) tempPtr->getNick(),
+ U_TABLE_SIZE);
+ newhv = HASH((unsigned char *) nick, U_TABLE_SIZE);
tempPtr->setNick(nick);
+ clients[oldhv].remove(tempPtr);
+ clients[newhv].insertAtBack(tempPtr);
}
}
else
#else
notice(s_GameServ, nick, welcomemsg, nick);
#endif
-
- clients.insertAtBack(newuser);
+ unsigned long hv = HASH((unsigned char *) nick, U_TABLE_SIZE);
+ clients[hv].insertAtBack(newuser);
delete newuser;
}
#if defined(P10)
if (z == ':')
source++;
+ unsigned long hv = HASH((unsigned char *) source, U_TABLE_SIZE);
if ((quitter = find(source)))
- clients.remove(quitter);
+ clients[hv].remove(quitter);
if ((quitter = findIRCplayer(source)))
{
- quitter->setNick("!NULL!");
- quitter->stats->user = NULL; // Unidentify them
+ if (player_fight(quitter))
+ {
+ // Stop the fight on the other client
+ aClient *otherplayer = quitter->stats->battle;
+ otherplayer->stats->battle = NULL;
+ notice(s_GameServ, otherplayer->getNick(), "%s "\
+ "has quit IRC. The fight stops here.",
+ quitter->stats->name);
+ }
+ quitter->stats->battle = NULL;
+ quitter->stats->fight = NULL;
+ quitter->stats->master = NULL;
+
+ quitter->setNick("Not Playing");
+ #ifdef P10
+ quitter->setRealNick("Not Playing");
+ #endif
+ quitter->stats->client = NULL; // Unidentify them
}
if (z == ':')
else if (stricmp(dest, c_Forest) == 0)
forest(source, rest);
#endif
+ #if defined(P10)
+ } else if (stricmp(cmd, "J") == 0) {
+ #else
} else if (stricmp(cmd, "JOIN") == 0) {
+ #endif
char *channel;
+ aClient *joiner;
channel = strtok(NULL, " ");
- if (stricmp(channel, c_Forest) == 0 && is_playing(source + 1))
- raw(":%S MODE %s +v %s", c_Forest, (source + 1));
+
+ char z = source[0];
+
+ if (z == ':')
+ source++;
+
+ joiner = find(source);
+
+ if (stricmp(channel, c_Forest) == 0 && is_playing(joiner))
+ {
+ #ifdef DEBUGMODE
+ log("Player %s (IRC: %s) joined %s",
+ joiner->stats->name,
+ #ifdef P10
+ joiner->getRealNick(),
+ #else
+ joiner->getNick(),
+ #endif
+ c_Forest);
+ #endif
+ raw(":%S MODE %s +v %s", c_Forest, (source));
+ }
+
+ if (z == ':')
+ source--;
#if defined(BAHAMUT)
} else if (stricmp(cmd, "SJOIN") == 0) {
}
}
+ } // for loop for connection retry
+
end:
save_gs_dbase();
aClient *findbyrealnick(char *realnick)
{
ListNode <aClient> *newPtr;
- newPtr = clients.First();
+ unsigned long hv = HASH((unsigned char *) realnick, U_TABLE_SIZE);
+ newPtr = clients[hv].First();
aClient *client = NULL;
aClient *findbynick(char *nick)
{
ListNode <aClient> *newPtr;
- newPtr = clients.First();
+ unsigned long hv = HASH((unsigned char *) nick, U_TABLE_SIZE);
+ newPtr = clients[hv].First();
aClient *client = NULL;
ListNode <aClient> *newPtr;
aClient *p = NULL;
- for (newPtr = players.First(); newPtr; newPtr = newPtr->Next())
+ unsigned long hv = HASH((unsigned char *) nick, U_TABLE_SIZE);
+ for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
{
p = newPtr->getData();
#ifdef P10
{
ListNode <aClient> *newPtr;
Player *p = NULL;
-
- for (newPtr = players.First(); newPtr; newPtr = newPtr->Next())
+ unsigned long hv = HASH((unsigned char *) name, U_TABLE_SIZE);
+ for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
{
p = newPtr->getData()->stats;
if (stricmp(p->name, name) == 0)
aClient *findbynick(const char *nick)
{
ListNode <aClient> *newPtr;
- newPtr = clients.First();
+ unsigned long hv = HASH((unsigned char *) nick, U_TABLE_SIZE);
+ newPtr = clients[hv].First();
aClient *client = NULL;
case -1: return -1;
default:
ofstream outfile;
- outfile.open("gameserv.pid");
+ outfile.open(pidfile);
if (outfile.fail())
- cerr << "Unable to open gameserv.pid" << endl;
+ cerr << "Unable to open " << pidfile << endl;
outfile << pid << endl;
outfile.close();