X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/db6cc9634692c2fe4dd9b565c9b95e3ea740f892..1fe6fccdcc6c293d4d0ce7278698f5847175d4ec:/gameserv/tcpclient.cpp diff --git a/gameserv/tcpclient.cpp b/gameserv/tcpclient.cpp index d0ae5f0..86a0b84 100644 --- a/gameserv/tcpclient.cpp +++ b/gameserv/tcpclient.cpp @@ -33,15 +33,18 @@ using namespace std; char *PACKAGE = "GameServ"; -char *VERSION = "1.2.6 +devel"; +char *VERSION = "1.3.0 +devel"; int sock; long lastrefresh; +long lastrollover; List clients[U_TABLE_SIZE]; void save_lastrefresh(); void load_lastrefresh(); +void load_lastrollover(); +void save_lastrollover(); void prettyIntro(); void check_idles(); @@ -106,6 +109,17 @@ int main(int argc, char *argv[]) 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); @@ -151,7 +165,7 @@ int main(int argc, char *argv[]) { connected = 1; load_lastrefresh(); - + load_lastrollover(); long int loadtime = time(NULL); long int currentTime; @@ -165,7 +179,8 @@ int main(int argc, char *argv[]) bool loaded = false; ignore_pipe(); - sock = make_connection(remoteport, SOCK_STREAM, remoteserver); + 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(); @@ -174,11 +189,10 @@ int main(int argc, char *argv[]) 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("NICK %S 1 %d %S %s %s %d :%s v%s", time(NULL), gshost, + servername, time(NULL), PACKAGE, VERSION); raw(":%S JOIN %s", c_Forest); raw(":%S MODE %s +tn", c_Forest); #elif defined(BAHAMUT) @@ -284,6 +298,18 @@ int main(int argc, char *argv[]) // 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!", forestfights); + } + } + if (currentTime - lastrefresh >= refreshperiod) { refreshall(); @@ -296,7 +322,6 @@ int main(int argc, char *argv[]) } // Save the player data every updateperiod seconds - currentTime = time(NULL); if (currentTime - oldTime >= updateperiod) { oldTime = currentTime; @@ -877,21 +902,51 @@ 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; @@ -903,7 +958,22 @@ void save_lastrefresh() 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(); }