hlswmaster-ng/mod_halflife.cpp

63 lines
1.5 KiB
C++
Raw Normal View History

2006-02-05 16:44:38 +01:00
#include <string.h>
2006-03-05 02:28:19 +01:00
#include "modhelper.h"
2006-02-05 16:44:38 +01:00
#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";
2006-03-06 20:13:26 +01:00
static const char reply1[] = "m\x00";
static const char reply2[] = "I\x07";
2006-02-05 16:44:38 +01:00
void ModHalfLife::scan(MultiSock* msock)
{
2006-03-05 02:28:19 +01:00
ModHelper::send(msock, port_arr, scanmsg1, strlen(scanmsg1));
ModHelper::send(msock, port_arr, scanmsg2, strlen(scanmsg2));
ModHelper::send(msock, port_arr, scanmsg3, strlen(scanmsg3));
2006-02-05 16:44:38 +01:00
}
2006-03-06 20:13:26 +01:00
int ModHalfLife::parse(NetPkt* pkt, GameList* glist)
2006-02-05 16:44:38 +01:00
{
2006-03-06 20:13:26 +01:00
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;
2006-02-05 16:44:38 +01:00
}