Half-Life is a Quake1 base engine mod (like Tenebrae, DarkPlaces or Telejano)
I found some similar source code from a Quake1 engine.
Here: http://www.quakeforge.net/doxygen/net__dgrm_8c-source.html#l01104
00869 if (command == CCREQ_SERVER_INFO) { 00870 if (strcmp (MSG_ReadString (net_message), "QUAKE") != 0) 00871 return NULL; 00872 00873 SZ_Clear (net_message->message); 00874 // save space for the header, filled in later 00875 MSG_WriteLong (net_message->message, 0); 00876 MSG_WriteByte (net_message->message, CCREP_SERVER_INFO); 00877 dfunc.GetSocketAddr (acceptsock, &newaddr); 00878 MSG_WriteString (net_message->message, dfunc.AddrToString (&newaddr)); 00879 MSG_WriteString (net_message->message, hostname->string); 00880 MSG_WriteString (net_message->message, sv.name); 00881 MSG_WriteByte (net_message->message, net_activeconnections); 00882 MSG_WriteByte (net_message->message, svs.maxclients); 00883 MSG_WriteByte (net_message->message, NET_PROTOCOL_VERSION); 00884 *((int *) net_message->message->data) = 00885 BigLong (NETFLAG_CTL | 00886 (net_message->message->cursize & NETFLAG_LENGTH_MASK)); 00887 dfunc.Write (acceptsock, net_message->message->data, 00888 net_message->message->cursize, &clientaddr); 00889 SZ_Clear (net_message->message);
Ok, Half-Life code will be different, has this is C and HL will be C++, and because Valve has rewriten most code (with nice results!). But maybe this will be informative for some coder hacker here :D
Here is more informative code (GPL license, the same enginemod)
char *WINS_AddrToString (struct qsockaddr *addr)
{
static char buffer[22];
int haddr; haddr = ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr);
sprintf(buffer, "%d.%d.%d.%d:%d", (haddr >> 24) & 0xff, (haddr >> 16) &
0xff, (haddr >> 8) & 0xff, haddr & 0xff, ntohs(((struct sockaddr_in
*)addr)->sin_port));
return buffer;
}//=============================================================================
int WINS_StringToAddr (char *string, struct qsockaddr *addr)
{
int ha1, ha2, ha3, ha4, hp;
int ipaddr; sscanf(string, "%d.%d.%d.%d:%d", &ha1, &ha2, &ha3, &ha4, &hp);
ipaddr = (ha1 << 24) | (ha2 << 16) | (ha3 << 8) | ha4; addr->sa_family = AF_INET;
((struct sockaddr_in *)addr)->sin_addr.s_addr = htonl(ipaddr);
((struct sockaddr_in *)addr)->sin_port = htons((unsigned short)hp);
return 0;
}Good Luck!
David Fencik escribi�:
This is a multi-part message in MIME format. -- [ Picked text/plain from multipart/alternative ] I am playing around with an old proggy I wrote a couple years ago that connected to a server and did rcon commands (good thing I comment my code). I modified it to connect to a server and issue an "info" command. Here is the packet the server sends back: Server responds with the following packet: (int32) -1 (byte) ASCII 'C' (info response, S2A_INFO) (string) net address of server (string) name of the host / server (string) name of the map (string) game directory (i.e. valve/) (string) Game description (e.g. "half-life multiplay") (byte) active client count (byte) maximum clients allowed (byte) protocol version
I am able to parse the packet and get the netaddress, name, directory, and description. I can't seem to figure out how to get the client count, maxplayers, or protocol version. In the serverprotocol.txt, it only says that they are bytes.
Here's a snippet of my code:
strcpy(netAddress, szRecvBuffer+c); c = c + strlen(netAddress) + 1; strcpy(hostName, szRecvBuffer+c); c = c + strlen(hostName) + 1; strcpy(mapName, szRecvBuffer+c); c = c + strlen(mapName) + 1; strcpy(gameDir, szRecvBuffer+c); c = c + strlen(gameDir) + 1; strcpy(gameDesc, szRecvBuffer+c); c = c + strlen(gameDesc) + 1; strcpy(clientCount, szRecvBuffer+c); c = c + strlen(clientCount) + 1;
The part where I parse the clientCount does not work.
I want to make this program ping all of my half life servers (100+), outputting some brief info, and issuing an alert when one goes down. Of course, I will share when complete.
Dave
--
_______________________________________________ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders
_______________________________________________ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders

