#include <stdio.h>
#include <unistd.h>
#include <string.h>
-#include <iostream.h>
-#include <fstream.h>
-#include <iomanip.h>
+#include <fstream>
#include <stdlib.h>
+using std::ofstream;
+using std::ifstream;
+
char *PACKAGE = "GameServ";
-char *VERSION = "1.1.2";
+char *VERSION = "1.1.7";
int sock;
long timestamp;
void save_timestamp();
void load_timestamp();
-int main(int argc, char *argv[])
+int main()
{
char buffer[1024], buf[1024];
int connected = 1;
char *cmd, *source = NULL;
srand(time(NULL));
- load_config_file();
- if (argc == 1) {
- argc = 3;
- argv[1] = remoteserver;
- argv[2] = remoteport;
- }
- if (argc != 3) {
- fprintf(stderr,"Usage: tcpclient host port\n");
- fprintf(stderr,"where host is the machine which is running the\n");
- fprintf(stderr,"tcpserver program, and port is the port it is\n");
- fprintf(stderr,"listening on.\n");
- exit(EXIT_FAILURE);
- }
+ load_config_file(); // default = gameserv.conf
+
ignore_pipe();
- sock = make_connection(argv[2], SOCK_STREAM, argv[1]);
+ sock = make_connection(remoteport, SOCK_STREAM, remoteserver);
if (sock == -1) {
fprintf(stderr,"make_connection failed.\n");
unload_config_file();
raw("NICK %S 1 %d +o %s %s %s 0 :GameServ", time(NULL), gsident, gshost,
servername);
raw(":%s SJOIN %d %d %s +mnt :@%S", servername, time(NULL), time(NULL), 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 DAqAoB %s :%S", time(NULL), gsident, gshost, gsnum);
+ raw("[] B %s %d +tnm %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
+#else
raw(":%S MODE %s +o %S", c_Forest);
raw(":%S TOPIC %s :%s", c_Forest, c_ForestTopic);
+#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. */
- printf("Server: %s\n",buffer);
- init_monsters();
+ #ifdef DEBUGMODE
+ log("Server: %s",buffer);
+ #endif
+
init_masters();
load_gs_dbase();
load_timestamp();
- int loadtime = time(NULL);
+ 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;
}
strcpy(buf, buffer);
+ #if !defined(P10)
if (buffer[0] == ':')
{
source = strtok(buf, " ");
}
else
cmd = strtok(buf, " ");
+ #else
+ source = strtok(buf, " ");
+ cmd = strtok(NULL, " ");
+ #endif
- cout << "Server: " << buffer << endl << flush;
+ #ifdef DEBUGMODE
+ log("Server: %s", buffer);
+ #endif
- // Wait five seconds then we're loaded.
+ // Wait N seconds then we're loaded.
if (!loaded)
{
- if (time(NULL) >= 5 + loadtime)
+ if (time(NULL) >= welcomedelay + loadtime)
loaded = true;
}
+ // Save the player data every updateperiod seconds
+ currentTime = time(NULL);
+ if (currentTime - oldTime >= updateperiod)
+ {
+ oldTime = currentTime;
+ save_gs_dbase();
+ }
+
+
+ #if !defined(P10)
if (stricmp(cmd, "PING") == 0) {
char *timestamp;
timestamp = strtok(NULL, "");
raw("PONG %s", timestamp);
+ #else
+ if (stricmp(cmd, "G") == 0) {
+ char *timestamp;
+ timestamp = strtok(NULL, " ");
+ raw("[] Z [] %s 0 %s", timestamp + 1, timestamp);
+ #endif
+ #ifdef P10
+ } else if (stricmp(cmd, "EB") == 0) {
+ raw("[] EA");
+ #endif
} else if (stricmp(cmd, "VERSION") == 0) {
char *server;
server = strtok(NULL, " ");
server++;
-//351 GameServ Unreal3.2-beta18. irc.the-irc.org :FhiXOo [Linux shell.the-irc.org
-//2.4.16-010stab017.17.777-smp #1 SMP Wed Mar 19 16:25:17 MSK 2003 i686 unknown=2303]
-
raw(":%s 351 %s %s %s. %s", servername, source+1, PACKAGE, VERSION, servername);
+ #if !defined(P10)
} else if (strncmp(cmd, "NICK", 4) == 0) {
if (buffer[0] == ':')
{
else
{
char *nick;
+ #else
+ } else if (stricmp(cmd, "N") == 0 && strlen(source) == 2) {
+ {
+ char *nick;
+
+ for (int x = 0; x < 6; x++)
+ nick = strtok(NULL, " ");
+
+ if (nick[0] == '+')
+ {
+ #ifdef DEBUGMODE
+ log ("aClient has modes");
+ #endif
+
+ // Searching for the +r mode (extra parameter)
+ for (unsigned int count = 1; count < strlen(nick); count++)
+ {
+ if (nick[count] == 'r')
+ {
+ nick = strtok(NULL, " ");
+ break;
+ }
+ }
+ nick = strtok(NULL, " ");
+ }
+ #endif
aClient *newuser;
+
nick = strtok(NULL, " ");
+
newuser = new aClient(nick);
if (loaded)
- notice(s_GameServ, nick, "Hello, %s! This network utilizes a services package called GameServ. For info on how to play the game, type /msg %S help.", source + 1);
+ notice(s_GameServ, nick, welcomemsg, nick);
clients.insertAtBack(newuser);
delete newuser;
}
+ #if defined(P10)
+ } else if (stricmp(cmd, "Q") == 0) {
+ #else
} else if (stricmp(cmd, "QUIT") == 0) {
+ #endif
aClient *quitter;
- if ((quitter = find(source + 1)))
+ char z = source[0];
+
+ if (z == ':')
+ source++;
+
+ if ((quitter = find(source)))
clients.remove(quitter);
- if ((quitter = findplayer(source + 1)))
- quitter->setNick("NULL");
+ if ((quitter = findIRCplayer(source)))
+ {
+ quitter->setNick("!NULL!");
+ quitter->stats->user = NULL; // Unidentify them
+ }
+
+ if (z == ':')
+ source--;
+ #if defined(P10)
+ } else if (stricmp(cmd, "P") == 0) {
+ char *rest, *dest;
+ char *longname;
+ longname = new char[strlen(s_GameServ) + strlen(servername) + 2];
+
+ sprintf(longname, "%S@%s", servername);
+
+ dest = strtok(NULL, " ");
+ rest = strtok(NULL, "");
+ if (stricmp(dest, gsnum) == 0 || stricmp(dest, longname) == 0)
+ {
+ delete [] longname;
+ gameserv(source, rest);
+ }
+ else if (stricmp(dest, c_Forest) == 0)
+ {
+ delete [] longname;
+ forest(source, rest);
+ }
+ #else
} else if (stricmp(cmd, "PRIVMSG") == 0) {
char *rest, *dest;
dest = strtok(NULL, " ");
gameserv(source, rest);
else if (stricmp(dest, c_Forest) == 0)
forest(source, rest);
+ #endif
} else if (stricmp(cmd, "JOIN") == 0) {
char *channel;
channel = strtok(NULL, " ");
#endif
} else {
- // cout << "Unrecognized Message: cmd = " << cmd << setw(30) << "source = " <<
- // source << endl;
+ #ifdef DEBUGMODE
+ log("Unrecognized Message: cmd = %s source = %s", cmd, source);
+ #endif
}
}
+
+ end:
+
save_gs_dbase();
save_timestamp();
+
delete_monsters();
delete_masters();
- printf("<CLOSED>\n");
+ #ifdef DEBUGMODE
+ log("<CLOSED>");
+ #endif
+
close(sock);
unload_config_file();
return 0;
while (newPtr)
{
client = newPtr->getData();
- if (stricmp(client->getNick(), nick) == 0)
+ #ifdef P10
+ log("Comparing %s with %s", client->getNick(), nick);
+ if (strcmp(client->getNick(), nick) == 0)
+ #else
+ if (stricmp(client->getNick(), nick) == 0)
+ #endif
return client;
client = NULL;
newPtr = newPtr->Next();
return client;
}
+aClient *findIRCplayer(const char *nick)
+{
+ ListNode <aClient> *newPtr;
+ aClient *p = NULL;
+
+ for (newPtr = players.First(); newPtr; newPtr = newPtr->Next())
+ {
+ p = newPtr->getData();
+ #ifdef P10
+ if (strcmp(p->getNick(), nick) == 0)
+ #else
+ if (stricmp(p->getNick(), nick) == 0)
+ #endif
+ return p;
+ p = NULL;
+ }
+ return NULL;
+}
aClient *findplayer(const char *name)
{
ListNode <aClient> *newPtr;
while (newPtr)
{
client = newPtr->getData();
- if (stricmp(client->getNick(), nick) == 0)
+ #ifdef P10
+ if (strcmp(client->getNick(), nick) == 0)
+ #else
+ if (stricmp(client->getNick(), nick) == 0)
+ #endif
return client;
client = NULL;
newPtr = newPtr->Next();
if (infile.fail())
{
- cout << "Error opening .gstimestamp" << endl;
- cout << "Generating new timestamp" << endl;
+ #ifdef DEBUGMODE
+ log("Error opening .gstimestamp");
+ #endif
+
generate:
+ #ifdef DEBUGMODE
+ log("Generating new timestamp");
+ #endif
timestamp = midnight();
save_timestamp();
return;
if (outfile.fail())
{
- cout << "Error creating new file." << endl;
+ log("Error creating new file .gstimestamp");
return;
}