Commit f9d6fc32 authored by jan.koester's avatar jan.koester
Browse files

some extends

parent eb5beb18
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@

int main(int argc, char *argv[]){
    try{
        HldsView hlds(argv[1], atoi(argv[2]));
        gameinfo::HldsView hlds(argv[1], atoi(argv[2]));

        HldsView::HldsData hldsdata;
        gameinfo::HldsView::HldsData hldsdata;

        hlds.refresh(hldsdata);

+3 −1
Original line number Diff line number Diff line
@@ -2,11 +2,12 @@ include(GenerateExportHeader)

list(APPEND hldsviewsrc
    hldsview.cpp
    exception.cpp
)

add_library(gameinfoplus SHARED ${hldsviewsrc})

target_link_libraries(gameinfoplus netplus)
target_link_libraries(gameinfoplus netplus::netplus)

target_compile_options(gameinfoplus PUBLIC "-fPIC")

@@ -22,6 +23,7 @@ install(TARGETS gameinfoplus EXPORT gameinfoplusTargets
install(FILES
    hldsview.h
    gameinfoplus.h
    exception.h
    "${CMAKE_CURRENT_BINARY_DIR}/gameinfoplus_export.h"
    DESTINATION include/gameinfoplus
    COMPONENT Devel
+13 −11
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#include <string>

namespace gameinfo {
    class GameInfoData{
    public:
        int         Port;
@@ -32,3 +33,4 @@ public:
        int         BotsAmount;
        int         MaxPlayers;
    };
};
+15 −8
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <netplus/exception.h>

#include "hldsview.h"
#include "exception.h"

#define A2S_HEADER_INFO 0x54
#define A2S_INFO_PAYLOAD_LEN_WITH_CHALLENGE    29
@@ -36,7 +37,7 @@ const uint8_t payload_template[A2S_INFO_PAYLOAD_LEN_WITH_CHALLENGE] = {
    'S', 'o', 'u', 'r', 'c', 'e', ' ', 'E', 'n', 'g', 'i', 'n', 'e', ' ', 'Q', 'u', 'e', 'r', 'y', '\0'
};

HldsView::HldsView(const char *addr,int port){
gameinfo::HldsView::HldsView(const char *addr,int port){
    try{
        sport = port;
        saddr = addr;
@@ -45,16 +46,18 @@ HldsView::HldsView(const char *addr,int port){
        serverSocket = new netplus::udp();
        memset(challange,0,sizeof(challange));
    }catch(netplus::NetException &exp){
        throw exp;
        GameInfoException ee;
        ee[GameInfoException::Critical] << exp.what();
        throw ee;
    }
}

HldsView::~HldsView(){
gameinfo::HldsView::~HldsView(){
    delete clientSocket;
    delete serverSocket;
}

HldsView::HldsView(const HldsView &view){
gameinfo::HldsView::HldsView(const HldsView &view){
    try{
        sport = view.sport;
        saddr = view.saddr;
@@ -62,11 +65,13 @@ HldsView::HldsView(const HldsView &view){
        serverSocket = new netplus::udp();
        memset(challange,0,sizeof(challange));
    }catch(netplus::NetException &exp){
        throw exp;
        GameInfoException ee;
        ee[GameInfoException::Critical] << exp.what();
        throw ee;
    }
};

void HldsView::refresh(HldsData &info){
void gameinfo::HldsView::refresh(HldsData &info){
    const std::lock_guard<std::mutex> lock(rlock);
    serverSocket->connect(clientSocket);
    clientSocket->setTimeout(1);
@@ -102,11 +107,13 @@ void HldsView::refresh(HldsData &info){
        }
        _parse(info,buffer,rcv);
    }catch(netplus::NetException &exp){
        throw exp.what();
        GameInfoException ee;
        ee[GameInfoException::Error] << exp.what();
        throw ee;
    }
}

void HldsView::_parse(HldsData &info,const char* data, size_t len){
void gameinfo::HldsView::_parse(HldsData &info,const char* data, size_t len){
    info.Port=sport;
    info.header=0x00;

+26 −24
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#pragma once

namespace gameinfo {
    class HldsView {
    public:
        HldsView(const char *addr,int port);
@@ -59,3 +60,4 @@ private:
        int         sport;
        std::string saddr;
    };
};