/* Tony Watson (aka Alascom) 12 Nov 2003 Client program to make a UDP socket connection to a CoD server to get the status of a given server and format output in HTML. Intended to be used as a CGI-Script for www.terrorist.net INSTALL: find line 51(or so) in the program, it looks like this; remoteHost = "172.16.0.100"; Edit the IP address to that of your Call of Duty server. Then compile with gcc codwatch.c -o codwatch. Copy the codwatch program to your CGI-BIN directory and it make sure its executable. The program will make UDP port 28960 connections to your server to retrieve the status of the server every 5 seconds (change META Refresh tag on line 47 if you want a different refresh rate). */ #include #include #include #include #include #include #include #include #include int getinput(int sock); int results(char * stats,int * y); int main(int argc, char *argv[]) { int udpSocket = 0, remotePort = 0, status = 0, size = 0, serverLength = 0, c = 0; struct sockaddr_in serverName = { 0 }; struct hostent *hostPtr = NULL; char *remoteHost = NULL; char mesgout[1024000] = ""; char * mesgoutptr = mesgout; char mesgin[1024000] = ""; char * mesginptr = mesgin; printf("Content-type: text/html\n\n"); printf("\n"); printf("\n"); printf("\n"); printf("

\n"); printf("CoD.TERRORIST.NET (68.74.97.98)

\n\n"); remoteHost = "172.16.0.100"; remotePort = 28960; udpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); hostPtr = gethostbyname(remoteHost); serverName.sin_family = AF_INET; serverName.sin_port = htons(remotePort); memcpy(&serverName.sin_addr, hostPtr->h_addr_list[0], hostPtr->h_length); memset(mesgout,0,strlen(mesgout)); strcpy(mesgout," getstatus "); mesgout[0]=0xff; mesgout[1]=0xff; mesgout[2]=0xff; mesgout[3]=0xff; mesgout[13]=0x0a; mesgout[14]=0x00; mesgout[15]=0x00; mesgout[16]=0x00; mesgout[17]=0x00; size=strlen(mesgout); status = connect(udpSocket, (struct sockaddr *) &serverName, sizeof(struct sockaddr_in)); size = send(udpSocket, mesgout, size,0); bzero(mesginptr,sizeof(mesgin)); getinput(udpSocket); return 0; } int getinput(int sock) { #define BUFFSIZE 1024000 struct sockaddr_in host; char buff[BUFFSIZE]; int hostsize, x, sel, i; unsigned long *pdw; unsigned char *ptr; struct timeval tv; fd_set fds; FD_ZERO(&fds); FD_SET(sock, &fds); tv.tv_sec = 10; tv.tv_usec = 0; hostsize = sizeof(host); while( (sel = select(sock+1, &fds, NULL, NULL, &tv)) > 0 ) { tv.tv_sec = 10; tv.tv_usec = 0; if ( (x = recvfrom(sock, buff, BUFFSIZE, 0, (struct sockaddr *)&host, &hostsize)) <= 0) continue; results(buff,&x); return 0; } if (sel == 0) { printf("Timeout on wait (no response for 10 seconds):\n"); } else if (sel < 0) perror("select"); return(1); } int results(char * stats,int * y) { FILE *fp; char w[32][256]; char p[32][256]; char ch; int wi=0; int pi=0; int i=0; int j=0; int x; int playerloc; int tabcount; x=*y; for (i=19;i\n"); /* ROW TABLE FORMATTING */ printf("
\n"); /* START PLAYER INFO DISPLAY */ printf("\n"); printf("\n"); printf("\n"); pi=0;j=0; for (i=playerloc+1;i<=x;i++) { if (stats[i]==0x0a) { p[pi][j]='\0';j=0;pi++; } else { p[pi][j++]=stats[i]; } } pi++; for(i=0;i\n"); tabcount=0; } printf("
PLAYERS ONLINE
KillsPingName
"); for(j=0;j"); } ch=p[i][j]; putchar(ch); } printf("
\n"); /* END OF PLAYER INFO DISPLAY */ /* ROW TABLE FORMATTING */ printf("
     \n"); /* DISPLAY SCHEDULE INFO FROM TEXT FILE */ printf("\n"); printf("\n\n
SCHEDULED GAMES
DateTimeUser
"); fp=fopen("/var/www/cgi-bin/schedule.inc","r"); while ((i=getc(fp))!=EOF) { if ((i!=0x0a)&&(i!=',')) { putc(i,stdout); } else { if (i==0x0a) { printf("
"); } if (i==',') { printf(""); } } } fclose(fp); printf("
\n"); /* END SCHEDULED GAMES DISPLAY */ /* END ROW TABLE FORMATTING */ printf("

\n"); /* HORIZONTAL TABLE FORMATTING */ printf("\n"); /* START SERVER SETTINGS DISPLAY */ printf("\n"); for(i=1;i<31;i+=2) { if (!strcmp(w[i],"g_gametype")) { if (!strcmp(w[i+1],"dm")) { printf("\n"); } if (!strcmp(w[i+1],"tdm")) { printf("\n"); } if (!strcmp(w[i+1],"re")) { printf("\n"); } if (!strcmp(w[i+1],"sd")) { printf("\n"); } if (!strcmp(w[i+1],"del")) { printf("\n"); } } else { printf("\n",w[i],w[i+1]); } } printf("\n
SERVER SETTINGS
GameTypeDeathMatch
GameTypeTeam DeathMatch
GameTypeRetrieval
GameTypeSearch & Destroy
GameTypeBehind Enemy Lines
%s%s
\n"); /* END SERVER SETTINGS DISPLAY */ /* END HORIZONTAL TABLE FORMATTING */ printf("\n"); printf("\n"); }