63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
#include <string.h>
|
|
#include "modhelper.h"
|
|
#include "mod_halflife.h"
|
|
|
|
static struct game_ports port_arr[] = {
|
|
{ 27015, 27024, ID_HL },
|
|
{ 0,0,0 }
|
|
};
|
|
|
|
static const char scanmsg1[] = "\xff\xff\xff\xff""details";
|
|
static const char scanmsg2[] = "\xff\xff\xff\xff\x54";
|
|
static const char scanmsg3[] = "\xff\xff\xff\xff""TSource Engine Query";
|
|
|
|
static const char reply1[] = "m\x00";
|
|
static const char reply2[] = "I\x07";
|
|
|
|
void ModHalfLife::scan(MultiSock* msock)
|
|
{
|
|
ModHelper::send(msock, port_arr, scanmsg1, strlen(scanmsg1));
|
|
ModHelper::send(msock, port_arr, scanmsg2, strlen(scanmsg2));
|
|
ModHelper::send(msock, port_arr, scanmsg3, strlen(scanmsg3));
|
|
}
|
|
|
|
int ModHalfLife::parse(NetPkt* pkt, GameList* glist)
|
|
{
|
|
struct in_addr tmp;
|
|
int port, count, pos;
|
|
|
|
if (ModHelper::checkPorts(pkt, port_arr) == 0)
|
|
return PARSE_REJECT;
|
|
|
|
// check 0xFF 0xFF 0xFF 0xFF
|
|
if (!pkt->compare(0, scanmsg1, 4))
|
|
return PARSE_REJECT;
|
|
|
|
/* check for short answer without ip/port */
|
|
if (pkt->compare(4, reply1, 2)) {
|
|
glist->addGame(ID_HL, pkt);
|
|
return PARSE_ACCEPT;
|
|
}
|
|
|
|
/* second query?! */
|
|
if (pkt->compare(4, reply2, 2)) {
|
|
glist->addGame(ID_HL2, pkt);
|
|
return PARSE_ACCEPT;
|
|
}
|
|
|
|
/* parse server IP */
|
|
pos = 5;
|
|
if ((count = pkt->parse_ip(pos, &tmp)) == 0)
|
|
return PARSE_REJECT;
|
|
|
|
/* parse server port */
|
|
pos += count +1;
|
|
if ((count = pkt->parse_int(pos, &port)) == 0)
|
|
return PARSE_REJECT;
|
|
|
|
// TODO: check server IP?
|
|
//glist->add(ID_HL, &tmp, port, 0);
|
|
glist->addGame(ID_HL, pkt);
|
|
return PARSE_ACCEPT;
|
|
}
|