It's C++, based off of iago and DarkMinion's code, but it's pretty close to what I assume you want:
void h_socket::waitEvents()
{
long clientToken = GetTickCount();
char serverToken[4] = "";
char mpqFile[256] = "";
char checksumFormula[256];
char buffer[20000] = "";
char exeinfo[256] = "";
unsigned long version;
unsigned long checksum;
unsigned long *prodVal;
unsigned long *publicVal;
unsigned long *privateVal;
PacketBuffer pbuff;
send(s, "\x1", 1, 0);
pbuff.insert((int)0x00);
pbuff.insert(PLATID_IX86);
pbuff.insert(CLIENT_STAR);
pbuff.insert((int)0xcd);
pbuff.insert((int)0x00);
pbuff.insert((int)0x00);
pbuff.insert((int)0x00);
pbuff.insert((int)0x00);
pbuff.insert((int)0x00);
pbuff.insert("USA");
pbuff.insert("United States");
pbuff.sendpacket(s, 0x50);
while(bncsConnected)
{
DWORD waitresult = WaitForSingleObject(events[0], 10);
if(waitresult == WAIT_OBJECT_0)
{
int buflen = 0;
int packetlen = 0;
char packetdata[5000] = "";
int recvlen = recv(s, buffer + buflen, sizeof(buffer) - buflen, 0);
if(!recvlen || recvlen == SOCKET_ERROR)
{
bncsConnected = false;
Disconnect();
h_timestamp();
printf("socket closed; recvlen %i\n", recvlen);
break;
}
buflen += recvlen;
while((int)buflen >= 4 && bncsConnected && (unsigned char)buffer[0] == 0xff)
{
char packetid = buffer[1];
packetlen = *(unsigned short *)(buffer + 2);
memcpy(packetdata, buffer, packetlen);
switch(packetid)
{
case SID_NULL:
pbuff.sendpacket(s, SID_NULL);
break;
case SID_PING:
pbuff.insert((int)(*(unsigned long *)(buffer + 4)));
pbuff.sendpacket(s, 0x25);
break;
case SID_AUTH_INFO:
h_timestamp();
if(*(unsigned long *)(packetdata + 4) == 0)
{
printf("Logon type is broken SHA-1\n");
}else if(*(unsigned long *)(packetdata + 4) == 1) {
printf("Logon type is NLS 1; this should not be! Aborting logon\n");
Disconnect();
} else if(*(unsigned long *)(packetdata + 4) == 2) {
printf("Logon type is NLS 2\n");
}
strcpy(serverToken, packetdata + 8);
strcpy(mpqFile, packetdata + 24);
strcpy(checksumFormula, packetdata + 37);
h_timestamp();
printf("Server Token: 0x");
hexStr(4, serverToken);
printf("\n");
h_timestamp();
printf("MPQ File: %s\n", mpqFile);
h_timestamp();
printf("Checksum Formula: %s\n", checksumFormula);
pbuff.clear();
pbuff.insert((int)clientToken);
h_timestamp();
if(!CheckRevision(
".\\star\\starcraft.exe",
".\\star\\storm.dll",
".\\star\\battle.snp",
checksumFormula,
&version,
&checksum,
exeinfo,
mpqFile
))
{
printf("CheckRevision() call failed; invalid hashes\n");
Disconnect();
break;
}
printf("CheckRevision() call passed\n");
pbuff.insert(version);
pbuff.insert(checksum);
pbuff.insert((int)1);
pbuff.insert((int)0);
h_timestamp();
if(DecodeCDKey(cfg.cdkey, prodVal, publicVal, privateVal) == false)
{
printf("CD-Key decode failed\n");
Disconnect();
break;
}
printf("CD-Key decode passed\n");
pbuff.insert((int)strlen(cfg.cdkey));
pbuff.insert(*(unsigned long *)prodVal);
pbuff.insert(*(unsigned long *)publicVal);
pbuff.insert((int)0);
pbuff.insert(*(unsigned long *)privateVal);
break;
default:
hexDump(packetlen, packetdata);
}
ZeroMemory(buffer, 20000);
ZeroMemory(packetdata, 5000);
packetlen = 0;
}
}
}
return;
}