#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
+
//#include <sys/types.h>
//#include <sys/wait.h>
//#include <errno.h>
-using std::ofstream;
-using std::ifstream;
-using std::cerr;
-using std::endl;
+using namespace std;
char *PACKAGE = "GameServ";
-char *VERSION = "1.2.4 +devel";
+char *VERSION = "1.3.2 +devel";
int sock;
long lastrefresh;
+long lastrollover;
List<aClient> clients[U_TABLE_SIZE];
void save_lastrefresh();
void load_lastrefresh();
+void load_lastrollover();
+void save_lastrollover();
void prettyIntro();
void check_idles();
int main(int argc, char *argv[])
{
- char buffer[1024], buf[1024];
- memset(buffer, 0, 1024);
- memset(buf, 0, 1024);
- int connected;
- long lastidlecheck;
- char *cmd, *source = NULL, *conf;
- srand(time(NULL));
- conf = new char[16];
- strcpy(conf, "gameserv.conf");
-
+ char buffer[1024], buf[1024];
+ memset(buffer, 0, 1024);
+ memset(buf, 0, 1024);
+ int connected;
+ long lastidlecheck;
+ char *cmd, *source = NULL, *conf;
+ srand(time(NULL));
+ conf = new char[16];
+ strcpy(conf, "gameserv.conf");
+
/*
* 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)
{
- cout << "Usage: gameserv [options] [configfile]" << endl;
- cout << "Options:" << endl;
- cout << "--help Displays this help dialogue" << endl;
- return 1;
+ if ( argc > 2 || stricmp(argv[1], "--help") == 0)
+ {
+ cout << "Usage: gameserv [options] [configfile]" << endl;
+ cout << "Options:" << endl;
+ cout << "--help Displays this help dialogue" << endl;
+ return 1;
+ }
+ delete []conf;
+ conf = argv[1];
}
- delete []conf;
- conf = argv[1];
- }
-
+
prettyIntro();
-
+
if (load_config_file(conf))
- {
- cout << "Config file loaded ok...\n"
- << "Turning into a daemon" << endl;
- }
+ {
+ cout << "Config file loaded ok...\n"
+ << "Turning into a daemon" << endl;
+ }
else
exit(2);
-
- if (argc <= 1)
+
+ if (argc <= 1)
delete []conf;
-
- // Turn into a daemon
- if (daemon(1,0) < 0)
+
+ // Turn into a daemon
+ if (daemon(1,0) < 0)
{
- perror("Could not turn into a daemon");
- exit(3);
+ perror("Could not turn into a daemon");
+ exit(3);
}
-
- init_masters();
+ if (load_items() == 0)
+ {
+ log("Error loading items");
+ goto end;
+ }
+
+ if (load_store() == 0)
+ {
+ log("Error loading store");
+ goto end;
+ }
+ if (load_tavern() == 0)
+ {
+ log("Error loading tavern");
+ goto end;
+ }
+
load_gs_dbase();
loadNews(newsdata, todaysnews);
-
+
+
+ if (load_masters() == false)
+ {
+ log("Error loading masters");
+ goto end;
+ }
+
if (load_monsters() == false)
- {
- log("Error loading monsters");
- goto end;
- }
-
+ {
+ log("Error loading monsters");
+ goto end;
+ }
+
+ if (!load_dragon())
+ {
+ log("Error loading dragon");
+ goto end;
+ }
+
if (load_levels() == false)
- {
- log("Error loading levels");
- goto end;
- }
-
- shuttingdown = false;
-
- char ignoreservers[32][256];
- char *currentserver;
- currentserver = strtok(ignoreserverslist, " ");
- for (int server = 0; server < 32 && currentserver != NULL; server++)
{
- strncpy(ignoreservers[server], currentserver, 255);
- log("Placing %s on the server ignore list", currentserver);
- currentserver = strtok(NULL, " ");
+ log("Error loading levels");
+ goto end;
}
-
- boss.name = "Red Dragon";
- boss.weapon = "Breath of Unholy Fire";
- boss.strength = 2500;
- boss.gold = 2000000000;
- boss.exp = 2000000000;
- boss.maxhp = 6667;
- boss.hp = 6667;
- 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_lastrefresh();
-
-
- long int loadtime = time(NULL);
- long int currentTime;
- long int oldTime = loadtime;
-
- lastidlecheck = loadtime;
-
- #ifdef DEBUGMODE
- log("Setting primary Idle Check timestamp: %ld", lastidlecheck);
- #endif
- bool loaded = false;
-
- ignore_pipe();
- sock = make_connection(remoteport, SOCK_STREAM, remoteserver);
- if (sock == -1) {
- fprintf(stderr,"make_connection failed.\n");
- unload_config_file();
- return -1;
- }
- log("%S socket connected.");
-
+
+ shuttingdown = false;
+
+ char ignoreservers[32][256];
+ char *currentserver;
+ currentserver = strtok(ignoreserverslist, " ");
+ for (int server = 0; server < 32 && currentserver != NULL; server++)
+ {
+ strncpy(ignoreservers[server], currentserver, 255);
+ log("Placing %s on the server ignore list", currentserver);
+ currentserver = strtok(NULL, " ");
+ }
+
+ // This loop will retry the connection 3 times
+ for (int retry = 0; retry < 3 && !shuttingdown; retry++)
+ {
+ connected = 1;
+ load_lastrefresh();
+ load_lastrollover();
+
+ long int loadtime = time(NULL);
+ long int currentTime;
+ long int oldTime = loadtime;
+
+ lastidlecheck = loadtime;
+
+#ifdef DEBUGMODE
+ log("Setting primary Idle Check timestamp: %ld", lastidlecheck);
+#endif
+ bool loaded = false;
+
+ ignore_pipe();
+ sock = conn(remoteserver, remoteport, localhost, 0);
+ // sock = make_connection(remoteport, SOCK_STREAM, remoteserver);
+ if (sock == -1) {
+ fprintf(stderr,"make_connection failed.\n");
+ unload_config_file();
+ return -1;
+ }
+ log("%S socket connected.");
+
#ifdef UNREAL
- raw("PROTOCTL NICKv2 VHP");
- raw("PASS :%s", remotepass);
- raw("SERVER %s 1 :%s", servername, servername);
- raw("NICK %S 1 %d %S %s %s %d +w%s %s :%s v%s", time(NULL), gshost,
- servername, time(NULL), (isBOper() ? "o" : ""), gshost, PACKAGE, VERSION);
- raw(":%S JOIN %s", c_Forest);
- raw(":%S MODE %s +tn", c_Forest);
+ raw("PASS :%s", remotepass);
+ raw("SERVER %s 1 :%s", servername, servername);
+ raw("NICK %S 1 %d %s %s %s %d :%s v%s", time(NULL), gsident, gshost,
+ servername, time(NULL), PACKAGE, VERSION);
+ raw(":%S JOIN %s", c_Forest);
+ raw(":%S MODE %s +tn", c_Forest);
#elif defined(BAHAMUT)
- raw("PASS %s :TS", remotepass);
- raw("SERVER %s 1 :%s", servername, servername);
- raw("NICK %S 1 %d +w%s %s %s %s 0 :GameServ", time(NULL), (isBOper() ? "o" : ""),
- gsident, gshost, servername);
- raw(":%s SJOIN %d %d %s +nt :@%S", servername, time(NULL), time(NULL), c_Forest);
+ raw("PASS %s :TS", remotepass);
+ raw("SERVER %s 1 :%s", servername, servername);
+ raw("NICK %S 1 %d +w%s %s %s %s 0 :GameServ", time(NULL), (isBOper() ? "o" : ""),
+ gsident, gshost, servername);
+ raw(":%s SJOIN %d %d %s +nt :@%S", servername, time(NULL), time(NULL), c_Forest);
#elif defined(HYBRID)
- raw("PASS %s :TS", remotepass);
- raw("SERVER %s 1 :%s", servername, servername);
- raw("NICK %S 1 %d +w%s %s %s %s :GameServ", time(NULL), (isBOper() ? "o" : ""),
- gsident, gshost, servername);
- raw(":%s SJOIN %ld %s +nt :@%S", servername, time(NULL), c_Forest);
+ raw("PASS %s :TS", remotepass);
+ raw("SERVER %s 1 :%s", servername, servername);
+ raw("NICK %S 1 %d +w%s %s %s %s :GameServ", time(NULL), (isBOper() ? "o" : ""),
+ gsident, gshost, servername);
+ raw(":%s SJOIN %ld %s +nt :@%S", servername, time(NULL), c_Forest);
#elif defined(ULTIMATE2)
- raw("PASS %s :TS", remotepass);
- raw("SERVER %s 1 :%s", servername, servername);
- raw("NICK %S 1 %d %s %s %s 0 :GameServ",
- time(NULL), gsident, gshost, servername);
- if (isBOper())
+ raw("PASS %s :TS", remotepass);
+ raw("SERVER %s 1 :%s", servername, servername);
+ raw("NICK %S 1 %d %s %s %s 0 :GameServ",
+ time(NULL), gsident, gshost, servername);
+ if (isBOper())
raw(":%S mode %S +o");
- raw(":%S JOIN %s", c_Forest);
+ raw(":%S JOIN %s", c_Forest);
#elif defined(P10)
- // Server numeric is: [] <-- must be unique
- raw("PASS :%s", remotepass);
- raw("SERVER %s 1 %d %d P10 []AAF :%s", servername, time(NULL), time(NULL), servername);
- raw("[] N %S 1 %d %s %s %s DAqAoB %s :%S", time(NULL), gsident, gshost,
- (isBOper() ? "+o" : ""), gsnum);
- raw("[] B %s %d +tn %s:o", c_Forest, time(NULL) - 864000, gsnum);
+ // Server numeric is: [] <-- must be unique
+ raw("PASS :%s", remotepass);
+ raw("SERVER %s 1 %d %d P10 []AAF :%s", servername, time(NULL), time(NULL), servername);
+ raw("[] N %S 1 %d %s %s %s DAqAoB %s :%S", time(NULL), gsident, gshost,
+ (isBOper() ? "+o" : ""), gsnum);
+ raw("[] B %s %d +tn %s:o", c_Forest, time(NULL) - 864000, gsnum);
#endif
-
+
#if defined(P10)
- raw("%s T %s :%s", gsnum, c_Forest, c_ForestTopic);
- raw("[] EB"); // End burst
+ raw("%s T %s :%s", gsnum, c_Forest, c_ForestTopic);
+ raw("[] EB"); // End burst
#else
- #ifndef HYBRID
- #if defined(ULTIMATE2)
- raw(":%s MODE %s +o %S %ld", servername, c_Forest,
- time(NULL));
- #else
- raw(":%S MODE %s +o %S", c_Forest);
- #endif
- #endif
- raw(":%S TOPIC %s :%s", c_Forest, c_ForestTopic);
+#ifndef HYBRID
+#if defined(ULTIMATE2)
+ raw(":%s MODE %s +o %S %ld", servername, c_Forest,
+ time(NULL));
+#else
+ raw(":%S MODE %s +o %S", c_Forest);
#endif
-
- sock_gets(sock,buffer,sizeof(buffer)-1); /* -1 added thanks to
- David Duchene <dave@ltd.com> for pointing out the possible
- buffer overflow resulting from the linefeed added below. */
-
-
- #ifdef DEBUGMODE
+#endif
+ raw(":%S TOPIC %s :%s", c_Forest, c_ForestTopic);
+#endif
+
+#ifndef P10
+ if (isUseNickServ())
+ {
+ raw(":%S PRIVMSG %s :IDENTIFY %s", nsname, nspass);
+ }
+#endif
+ sock_gets(sock,buffer,sizeof(buffer)-1); /* -1 added thanks to
+ David Duchene <dave@ltd.com> for pointing out the possible
+ buffer overflow resulting from the linefeed added below. */
+
+
+#ifdef DEBUGMODE
log("Server: %s",buffer);
- #endif
-
- while (connected) {
- if (sock_gets(sock,buffer,sizeof(buffer)) == -1) {
- connected = 0;
- }
- strcpy(buf, buffer);
-
- #if !defined(P10)
- if (buffer[0] == ':')
- {
- source = strtok(buf, " ");
- cmd = strtok(NULL, " ");
- }
- else
- cmd = strtok(buf, " ");
- #else
- source = strtok(buf, " ");
- cmd = strtok(NULL, " ");
- #endif
-
- #ifdef DEBUGMODE
- log("Server: %s", buffer);
- #endif
-
- // Wait N seconds then we're loaded.
- if (!loaded)
- {
- if (time(NULL) >= welcomedelay + loadtime)
- {
- loaded = true;
- retry = 0; // Start the reconnection cycle over
- }
- }
- else
- {
- long TIME = time(NULL);
- if (TIME - lastidlecheck >= idlecheckperiod)
- {
- check_idles();
- lastidlecheck = TIME;
- }
- }
-
- // Refresh players and clear news if the time is up
- currentTime = time(NULL);
- if (currentTime - lastrefresh >= refreshperiod)
- {
- refreshall();
- clearNews(todaysnews);
- saveNews(newsdata, todaysnews);
- lastrefresh = currentTime;
- save_lastrefresh();
- notice(s_GameServ, c_Forest, "Refreshing all players "\
- "and resetting news!");
- }
-
- // Save the player data every updateperiod seconds
- currentTime = time(NULL);
- if (currentTime - oldTime >= updateperiod)
- {
- oldTime = currentTime;
- log("Saving to %s", playerdata);
-
- save_gs_dbase();
- saveNews(newsdata, todaysnews);
+#endif
+
+ while (connected)
+ {
+ if (sock_gets(sock,buffer,sizeof(buffer)) == -1)
+ {
+ connected = 0;
+ }
+ strcpy(buf, buffer);
+
+#if !defined(P10)
+ if (buffer[0] == ':')
+ {
+ source = strtok(buf, " ");
+ cmd = strtok(NULL, " ");
+ }
+ else
+ cmd = strtok(buf, " ");
+#else
+ source = strtok(buf, " ");
+ cmd = strtok(NULL, " ");
+#endif
+
+#ifdef DEBUGMODE
+ log("Server: %s", buffer);
+#endif
+
+ // Wait N seconds then we're loaded.
+ if (!loaded)
+ {
+ if (time(NULL) >= welcomedelay + loadtime)
+ {
+ loaded = true;
+ retry = 0; // Start the reconnection cycle over
+ }
+ }
+ else
+ {
+ long TIME = time(NULL);
+ if (TIME - lastidlecheck >= idlecheckperiod)
+ {
+ check_idles();
+ lastidlecheck = TIME;
+ }
+ }
- // Send notice to the channel of the update
- if (isSavedNotice())
- notice(s_GameServ, c_Forest, "%S player data saved");
- }
+ // Refresh players and clear news if the time is up
+ currentTime = time(NULL);
+ if (isRolloverForestFights())
+ {
+ if (currentTime - lastrollover >= rolloverperiod)
+ {
+ rolloverall();
+ lastrollover = currentTime;
+ save_lastrollover();
+ notice(s_GameServ, c_Forest, "Adding %d forest fights to all players!", numrolloverfights);
+ }
+ }
+
+ if (currentTime - lastrefresh >= refreshperiod)
+ {
+ refreshall();
+ clearNews(todaysnews);
+ saveNews(newsdata, todaysnews);
+ lastrefresh = currentTime;
+ save_lastrefresh();
+ notice(s_GameServ, c_Forest, "Refreshing all players "\
+ "and resetting news!");
+ }
- #if !defined(P10)
+ // Save the player data every updateperiod seconds
+ if (currentTime - oldTime >= updateperiod)
+ {
+ oldTime = currentTime;
+ log("Saving to %s", playerdata);
+
+ save_gs_dbase();
+ saveNews(newsdata, todaysnews);
+ if (isSavedNotice())
+ {
+ // Send notice to the channel of the update
+ notice(s_GameServ, c_Forest, "%S player data saved");
+ }
+ }
+
+
+#if !defined(P10)
if (stricmp(cmd, "PING") == 0) {
char *timestamp;
timestamp = strtok(NULL, "");
}
logout(quitter);
-
+ delete quitter;
+
if (z == ':')
source--;
{
#ifdef DEBUGMODE
log("Player %s (IRC: %s) joined %s",
- joiner->stats->name.getString(),
+ joiner->stats->getName().c_str(),
#ifdef P10
joiner->getRealNick(),
#else
end:
save_gs_dbase();
+ save_dragon();
saveNews(newsdata, todaysnews);
delete_monsters();
- delete_masters();
#ifdef DEBUGMODE
log("<CLOSED>");
if (!is_playing(p))
return NULL;
- unsigned long hv = iHASH((unsigned char *) p->stats->name.getString());
+ unsigned long hv = iHASH((unsigned char *) p->stats->getName().c_str());
for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
{
aClient *findplayer(const char *name)
{
- ListNode <aClient> *newPtr;
- Player *p = NULL;
- unsigned long hv = iHASH((unsigned char *) name);
- for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
+ ListNode <aClient> *newPtr;
+ Player *p = NULL;
+ unsigned long hv = iHASH((unsigned char *) name);
+ for (newPtr = players[hv].First(); newPtr; newPtr = newPtr->Next())
{
- p = newPtr->getData()->stats;
- if (stricmp(p->name.getString(), name) == 0)
+ p = newPtr->getData()->stats;
+ if (stricmp(p->getName().c_str(), name) == 0)
return newPtr->getData();
- p = NULL;
+ p = NULL;
}
- return NULL;
+ return NULL;
}
void check_idles()
for (newPtr = players[x].First(); newPtr; newPtr = newPtr->Next())
{
p = newPtr->getData()->stats;
- switch(p->level)
+ switch(p->getLevel())
{
case 1:
if ((time(NULL) - p->lastlogin) / 86400 >= level1expire)
void prettyIntro()
{
-cout << endl;
-cout << " GGGG AAA MM MM EEEEEEE SSSSS EEEEEEE RRRRRR VV VV " << endl;
-cout << " GG GG AAAAA MMM MMM EE SS EE RR RR VV VV " << endl;
-cout << "GG AA AA MM MM MM EEEEE SSSSS EEEEE RRRRRR VV VV " << endl;
-cout << "GG GGG AAAAAAA MM MM EE SS EE RR RR VV VV " << endl;
-cout << "G G AA AA MM MM EEEEEEE SSSSS EEEEEEE RR RR VVV" << endl;
-cout << " GGGGG V\n\n" << endl;
-cout << "Version: " << VERSION << endl;
+ cout << endl;
+ cout << " GGGG AAA MM MM EEEEEEE SSSSS EEEEEEE RRRRRR VV VV " << endl;
+ cout << " GG GG AAAAA MMM MMM EE SS EE RR RR VV VV " << endl;
+ cout << "GG AA AA MM MM MM EEEEE SSSSS EEEEE RRRRRR VV VV " << endl;
+ cout << "GG GGG AAAAAAA MM MM EE SS EE RR RR VV VV " << endl;
+ cout << "G G AA AA MM MM EEEEEEE SSSSS EEEEEEE RR RR VVV" << endl;
+ cout << " GGGGG V\n\n" << endl;
+ cout << "Version: " << VERSION << endl;
+ cout << "http://www.gameserv.us - http://www.sourceforge.net/projects/gameservirc" << endl;
}
void load_lastrefresh()
#endif
// Just a safety measure... tho no one should
- // get anywhere near the time as their refreshperiod
+ // get anywhere near the actual time as their refreshperiod
if (refreshperiod >= mytime)
+ {
+ log("Refresh period is greater than or equal to the actual time... setting it to 86400");
refreshperiod = 86400;
-
+ }
+
lastrefresh = mytime - (mytime % refreshperiod);
+
refreshall();
save_lastrefresh();
return;
}
infile >> lastrefresh;
+
infile.close();
if (lastrefresh < 0)
goto generate;
}
+void load_lastrollover()
+{
+ ifstream infile;
+ infile.open(".gsrollover");
+ if (infile.fail())
+ {
+#ifdef DEBUGMODE
+ log("Error opening .gsrollover");
+#endif
+
+ generate:
+ long mytime = time(NULL);
+#ifdef DEBUGMODE
+ log("Generating new rollover time");
+#endif
+ lastrollover = mytime;
+ return;
+ }
+ infile >> lastrollover;
+
+ infile.close();
+ if (lastrollover < 0)
+ goto generate;
+}
+
void save_lastrefresh()
{
ofstream outfile;
log("Error creating new file .gsrefresh");
return;
}
- outfile << lastrefresh << endl;
+ outfile << lastrefresh << endl << lastrollover;
+
+ outfile.close();
+}
+void save_lastrollover()
+{
+ ofstream outfile;
+
+ outfile.open(".gsrollover");
+
+ if (outfile.fail())
+ {
+ log("Error creating new file .gsrollover");
+ return;
+ }
+ outfile << lastrollover << endl;
outfile.close();
}