А здесь сам гейм мод в бегин плее подключаемся, а в прелогине закидываем чтонибуть в базу.
#include "MyGame.h"
#include "loginServer_GameMode.h"
#include "CoreMisc.h"
#include "libpq-fe.h" // postgresql header for cpp
PGconn *CONN = NULL; // create connection variable
FString PGQUERY; // query for postgresql
void AloginServer_GameMode::PreLogin(const FString& Options, const FString& Address, const TSharedPtr<const FUniqueNetId>& UniqueId, FString& ErrorMessage)
{
FString id;
FString psw;
FString eMail;
// check connection
if (PQstatus(CONN) == CONNECTION_OK)
{
// add some values
PGQUERY = "INSERT INTO users_tbl ( id, psw, email) VALUES ('" + id + "', '" + psw + "', '" + eMail + "')";
PGresult *_res = PQexec(CONN, TCHAR_TO_ANSI(*PGQUERY));
if (PQresultStatus(_res) != PGRES_COMMAND_OK)
{
PQclear(_res);
}
}
}
void AloginServer_GameMode::BeginPlay()
{
Super::BeginPlay();
FString dbIP = "127.0.0.1";
FString dbPort = "5432";
FString dbUser = "User";
FString dbPsw = "123";
// connect to db
PGQUERY = "user=" + dbUser + " password=" +dbPsw + " dbname=mydb hostaddr=" + dbIP +" port=" + dbPort + " application_name=FLoginServer";
CONN = PQconnectdb(TCHAR_TO_ANSI(*PGQUERY));
// check connection
if (PQstatus(CONN) != CONNECTION_OK)
{
PQfinish(CONN);
FString _logMsg = "ERROR: Can`t connect to DB ";
}
}