Files
firestorm/Gameleap/code/mw4/Code/mw4print/dbexport.h
T
dicion b98cb87ef3 mw4print: MySQL export, configurable banner text
MySQL database export (dbexport.h / dbexport.cpp):
- New files dbexport.h / dbexport.cpp implement late-bound MySQL export.
  libmysql.dll is loaded at runtime via LoadLibrary/GetProcAddress so no
  MySQL SDK is required at compile time; the app runs normally if the DLL
  is absent.
- After each print job, match data is exported to a MySQL server before
  PrintDlg() is called: one row in 'match', one row per player in
  'player_result', one row per attacker/victim pair in 'pvp'.  An optional
  'event' table records every individual SRecScore entry (off by default).
  Tables are created automatically (CREATE TABLE IF NOT EXISTS) on first
  connect.
- Config stored in mw4print.ini (app directory), section [MySQLExport]:
  Enabled, Host, Port, Database, Username, Password, ExportEvents.
- Config loaded at startup (OnCreate); DB_LoadConfig() / DB_SaveConfig().
- Connection timeout set to 5 seconds so the app does not hang if the
  server is unreachable.
- libmysql.dll (MySQL Connector/C 32-bit) added to Gameleap/mw4/ so the
  deploy script copies it to MW4/ alongside mw4print.exe.

Database Settings dialog (File > Database Settings... / Ctrl+D):
- MFC dialog: enable checkbox, Host/Port/Database/Username/Password fields,
  Export Events checkbox, Test Connection button with live status label,
  OK/Cancel.  OK persists settings to mw4print.ini immediately.

Configurable banner text (File > Banner Setting...):
- The 'WWW.MECHJOCK.COM' URL string printed at the bottom of every score
  sheet is now configurable.  Stored as BannerText= in options.ini under
  [battle tech print] (same section/file as the other print layout params).
  File > Banner Setting... opens a dialog to edit it; OK saves to options.ini
  and takes effect on the next print job with no restart needed.
  Default value is the original MECHJOCK string if the key is absent.
2026-07-18 14:05:31 -05:00

60 lines
1.8 KiB
C

// dbexport.h - MySQL export interface for mw4print
//
// Connects to an external MySQL server and writes match results after each
// print job. MySQL is loaded at runtime via late binding (libmysql.dll) so
// no MySQL SDK is required at compile time.
//
// Config is stored in mw4print.ini next to the exe:
// [MySQLExport]
// Enabled=0
// Host=192.168.1.100
// Port=3306
// Database=firestorm_stats
// Username=mw4
// Password=
// ExportEvents=0 (1 = also export per-event SRecScore rows)
//
#ifndef __DBEXPORT_H__
#define __DBEXPORT_H__
// ---- Config struct -------------------------------------------------------
struct SDBConfig
{
bool bEnabled;
char szHost[256];
int nPort;
char szDatabase[64];
char szUsername[64];
char szPassword[64];
bool bExportEvents; // export individual SRecScore events (can be many rows)
};
extern SDBConfig g_dbConfig;
// ---- Public API ----------------------------------------------------------
// Load / save config from mw4print.ini in the app directory.
void DB_LoadConfig();
void DB_SaveConfig();
// Try to open a connection using current g_dbConfig, run a trivial query,
// then disconnect. Returns true on success; on failure fills pszError
// (up to nErrBufSize bytes) with the MySQL error string.
bool DB_TestConnection(char* pszError, int nErrBufSize);
// Export one completed match to the database. Called from
// CRecScoreFull::DoPrint() just before PrintDlg().
// Returns true on success.
bool DB_ExportMatch(
const CRecScoreFull& rsf,
PCRecScoreObject aRSOs[],
int nPlayers,
const int naTeams[8],
int nTeamCount,
const MWNetMissionParameters& params
);
#endif // __DBEXPORT_H__