Jump to content

Log System Info of Players Anonymously


Recommended Posts

  • Honorable Member

Hey guyz :)

I just made a lil system to log players ram and cpu mhz into the db anonymously.

Let's start with the client.


Opena packet.hand search for

HEADER_CG_MARK_LOGIN                        = 100,

 


Add before:

HEADER_CG_SYS_INFO_BY_DISTRAUGHT = 99,

 

Go down to typedef struct command_mark_login
Add before:

 

struct sys_info_by_distraught
{
    BYTE header;
    float RAM;
    int CPU;
};

Search for this in PythonNetworkStream.h:

        bool SendSpecial(int nLen, void * pvBuf);


Add before:

bool SendSYSInfo();

Open PythonNetworkStreamPhaseGame.cpp and after

 

BOOL gs_bEmpireLanuageEnable = TRUE;


add:

//SYS INFO BY DISTRAUGHT
#define _WIN32_WINNT  0x0501
float GetRAM()
{
    MEMORYSTATUSEX memstat;
    memstat.dwLength = sizeof(memstat);
    GlobalMemoryStatusEx(&memstat);
    return (float)memstat.ullTotalPhys / (1024 * 1024 * 1024);
}
int GetCPUSpeedMHz()
{
    char Buffer[MAX_PATH];
    unsigned long BufSize = MAX_PATH;
    unsigned long ulMHz = MAX_PATH;
    HKEY hKey;
    long lError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey);
    if (lError != ERROR_SUCCESS)
        return 0;
    RegQueryValueEx(hKey, "~MHz", NULL, NULL, (LPBYTE)&ulMHz, &BufSize);
    return ulMHz;
}
bool CPythonNetworkStream::SendSYSInfo()
{
    std::ifstream check("sentsys.txt");
    if (check.good())
    {
        int i = 0;
        check >> i;
        if (i > 0) return false;
    }
    check.close();
    sys_info_by_distraught packet;
    packet.header = HEADER_CG_SYS_INFO_BY_DISTRAUGHT;
    packet.RAM = GetRAM();
    packet.CPU = GetCPUSpeedMHz();
    if (!Send(sizeof(packet), &packet))
        return false;
    std::ofstream save("sentsys.txt");
    save << "1";
    save.close();
    return SendSequence();
}
//SYS INFO END

Open PythonNetworkStreamPhaseLogin.cpp search for function SendLoginPacket.
Inside this function search for:

 

if (!Send(sizeof(LoginPacket), &LoginPacket))


add before:

SendSYSInfo();

Now look for SendLoginPacketNew function and do the same.

 

Compile client binary.

And now the server.

Open packet.h -t and search for

HEADER_CG_REFINE                = 96,


add after:

HEADER_CG_SYS_INFO_BY_DISTRAUGHT = 99,

Look for

 

typedef struct SPacketGGSetup


Add before:

struct sys_info_by_distraught
{
    BYTE header;
    float RAM;
    int CPU;
};

Open packet_info.cpp and search for

 

Set(HEADER_CG_TEXT, sizeof(TPacketCGText), "Text", false);


add before:

Add elé:

Set(HEADER_CG_SYS_INFO_BY_DISTRAUGHT, sizeof(sys_info_by_distraught), "SYSInfo", true);

Open input.h and look for CInputLogin class.
Inside search for

 

virtual int    Analyze(LPDESC d, BYTE bHeader, const char * c_pData);


Add after:

void         SaveSYSInfo(const char* data);

Open input_login.cpp-t and look for Analyze function.
Inside look for

 

case HEADER_CG_PONG:


add before:

case HEADER_CG_SYS_INFO_BY_DISTRAUGHT:
            SaveSYSInfo(c_pData);
            break;

Look for

 

int CInputLogin::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)


add before:

void CInputLogin::SaveSYSInfo(const char* data)
{
    sys_info_by_distraught* packet = (sys_info_by_distraught*)data;
    DBManager::instance().Query("INSERT INTO system_info(ram, cpu, sent_at) VALUES (%f, %d, CURDATE());", packet->RAM, packet->CPU);
    return;
}

Compile the game.

 

Run this query in the player db:

DROP TABLE IF EXISTS `system_info`;
CREATE TABLE `system_info` (
  `ram` float(12,0) DEFAULT NULL,
  `cpu` int(12) DEFAULT NULL,
  `sent_at` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

You'll find the system infos in the play/system_info table.

 

If you want players to send their RAM and CPU again, just upload a sentsys.txt file with a content of just a 0 to the main directory of the client to your patchserver.

  • Love 2

WRnRW3H.gif

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.