Formatting

This commit is contained in:
smallmodel 2025-03-01 23:34:24 +01:00
parent 70f6ede7b8
commit d08027360f
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
4 changed files with 101 additions and 55 deletions

View file

@ -1,6 +1,6 @@
/* /*
=========================================================================== ===========================================================================
Copyright (C) 2023 the OpenMoHAA team Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code. This file is part of OpenMoHAA source code.
@ -29,9 +29,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "common/gsCommon.h" #include "common/gsCommon.h"
#include "common/gsAvailable.h" #include "common/gsAvailable.h"
static char gamemode[128]; static char gamemode[128];
static qboolean gcdInitialized = qfalse; static qboolean gcdInitialized = qfalse;
static qboolean gcdValid = qfalse; static qboolean gcdValid = qfalse;
extern GSIACResult __GSIACResult; extern GSIACResult __GSIACResult;
static const char *SECRET_GS_KEYS[] = static const char *SECRET_GS_KEYS[] =
@ -84,10 +84,10 @@ void qr_process_queries(qr_t qrec);
int qr_init( int qr_init(
qr_t *qrec, qr_t *qrec,
const char *ip, const char *ip,
int baseport, int baseport,
const char *gamename, const char *gamename,
const char *secret_key, const char *secret_key,
qr_querycallback_t qr_basic_callback, qr_querycallback_t qr_basic_callback,
qr_querycallback_t qr_info_callback, qr_querycallback_t qr_info_callback,
qr_querycallback_t qr_rules_callback, qr_querycallback_t qr_rules_callback,
@ -95,23 +95,28 @@ int qr_init(
void *userdata void *userdata
); );
const char* GS_GetGameKey(unsigned int index) { const char *GS_GetGameKey(unsigned int index)
{
return SECRET_GS_KEYS[index]; return SECRET_GS_KEYS[index];
} }
const char* GS_GetCurrentGameKey() { const char *GS_GetCurrentGameKey()
{
return GS_GetGameKey(com_target_game->integer); return GS_GetGameKey(com_target_game->integer);
} }
unsigned int GS_GetGameID(unsigned int index) { unsigned int GS_GetGameID(unsigned int index)
{
return GCD_GAME_IDS[index]; return GCD_GAME_IDS[index];
} }
unsigned int GS_GetCurrentGameID() { unsigned int GS_GetCurrentGameID()
{
return GS_GetGameID(com_target_game->integer); return GS_GetGameID(com_target_game->integer);
} }
const char* GS_GetGameName(unsigned int index) { const char *GS_GetGameName(unsigned int index)
{
if (!com_target_demo->integer) { if (!com_target_demo->integer) {
return GS_GAME_NAME[index]; return GS_GAME_NAME[index];
} else { } else {
@ -119,11 +124,13 @@ const char* GS_GetGameName(unsigned int index) {
} }
} }
const char* GS_GetCurrentGameName() { const char *GS_GetCurrentGameName()
{
return GS_GetGameName(com_target_game->integer); return GS_GetGameName(com_target_game->integer);
} }
const char* GS_GetGameVersion(unsigned int index) { const char *GS_GetGameVersion(unsigned int index)
{
if (!com_target_demo->integer) { if (!com_target_demo->integer) {
return GS_GAME_VERSION[index]; return GS_GAME_VERSION[index];
} else { } else {
@ -131,7 +138,8 @@ const char* GS_GetGameVersion(unsigned int index) {
} }
} }
const char* GS_GetCurrentGameVersion() { const char *GS_GetCurrentGameVersion()
{
return GS_GetGameVersion(com_target_game->integer); return GS_GetGameVersion(com_target_game->integer);
} }
@ -363,7 +371,7 @@ qboolean SV_InitGamespy()
return qtrue; return qtrue;
} }
void SV_CreateGamespyChallenge(char* challenge) void SV_CreateGamespyChallenge(char *challenge)
{ {
int i; int i;
@ -373,10 +381,10 @@ void SV_CreateGamespyChallenge(char* challenge)
challenge[i] = 0; challenge[i] = 0;
} }
challenge_t* FindChallengeById(int gameid) challenge_t *FindChallengeById(int gameid)
{ {
challenge_t* challenge; challenge_t *challenge;
int i; int i;
for (i = 0; i < MAX_CHALLENGES; i++) { for (i = 0; i < MAX_CHALLENGES; i++) {
challenge = &svs.challenges[i]; challenge = &svs.challenges[i];
@ -388,32 +396,37 @@ challenge_t* FindChallengeById(int gameid)
return NULL; return NULL;
} }
void AuthenticateCallback(int gameid, int localid, int authenticated, char* errmsg, void* instance) void AuthenticateCallback(int gameid, int localid, int authenticated, char *errmsg, void *instance)
{ {
challenge_t* challenge; challenge_t *challenge;
qboolean valid = qfalse; qboolean valid = qfalse;
if (localid || !Q_stricmp(errmsg, "CD Key in use")) { if (localid || !Q_stricmp(errmsg, "CD Key in use")) {
valid = qtrue; valid = qtrue;
} }
challenge = FindChallengeById(gameid); challenge = FindChallengeById(gameid);
if (valid) if (valid) {
{
challenge->cdkeyState = 2; challenge->cdkeyState = 2;
challenge->pingTime = svs.time; challenge->pingTime = svs.time;
SV_NET_OutOfBandPrint(&svs.netprofile, challenge->adr, "challengeResponse %i", challenge->challenge); SV_NET_OutOfBandPrint(&svs.netprofile, challenge->adr, "challengeResponse %i", challenge->challenge);
} } else {
else
{
char buf[32]; char buf[32];
if (!challenge) { if (!challenge) {
return; return;
} }
Com_sprintf(buf, sizeof(buf), "%d.%d.%d.%d", challenge->adr.ip[0], challenge->adr.ip[1], challenge->adr.ip[2], challenge->adr.ip[3]); Com_sprintf(
buf,
sizeof(buf),
"%d.%d.%d.%d",
challenge->adr.ip[0],
challenge->adr.ip[1],
challenge->adr.ip[2],
challenge->adr.ip[3]
);
Com_Printf("%s failed cdkey authorization\n", buf); Com_Printf("%s failed cdkey authorization\n", buf);
challenge->cdkeyState = 3; challenge->cdkeyState = 3;
// tell the client about the reason // tell the client about the reason
@ -421,28 +434,25 @@ void AuthenticateCallback(int gameid, int localid, int authenticated, char* errm
} }
} }
void RefreshAuthCallback(int gameid, int localid, int hint, char* challenge, void* instance) void RefreshAuthCallback(int gameid, int localid, int hint, char *challenge, void *instance) {}
{
}
void SV_GamespyAuthorize(netadr_t from, const char* response) void SV_GamespyAuthorize(netadr_t from, const char *response)
{ {
char buf[64]; char buf[64];
challenge_t* challenge = FindChallenge(from, qtrue); challenge_t *challenge = FindChallenge(from, qtrue);
if (!challenge) { if (!challenge) {
return; return;
} }
switch (challenge->cdkeyState) switch (challenge->cdkeyState) {
{
case CDKS_NONE: case CDKS_NONE:
challenge->cdkeyState = CDKS_AUTHENTICATING; challenge->cdkeyState = CDKS_AUTHENTICATING;
challenge->firstTime = svs.time; challenge->firstTime = svs.time;
gcd_authenticate_user( gcd_authenticate_user(
GS_GetCurrentGameID(), GS_GetCurrentGameID(),
challenge->gamespyId, challenge->gamespyId,
LittleLong(*(unsigned int*)from.ip), LittleLong(*(unsigned int *)from.ip),
challenge->gsChallenge, challenge->gsChallenge,
response, response,
AuthenticateCallback, AuthenticateCallback,
@ -453,11 +463,10 @@ void SV_GamespyAuthorize(netadr_t from, const char* response)
case CDKS_AUTHENTICATING: case CDKS_AUTHENTICATING:
// the server can't reach the authentication server // the server can't reach the authentication server
// let the client connect // let the client connect
if (svs.time - challenge->firstTime > 5000) if (svs.time - challenge->firstTime > 5000) {
{
Com_DPrintf("authorize server timed out\n"); Com_DPrintf("authorize server timed out\n");
challenge->cdkeyState = CDKS_AUTHENTICATED; challenge->cdkeyState = CDKS_AUTHENTICATED;
challenge->pingTime = svs.time; challenge->pingTime = svs.time;
SV_NET_OutOfBandPrint(&svs.netprofile, from, "challengeResponse %i", challenge->challenge); SV_NET_OutOfBandPrint(&svs.netprofile, from, "challengeResponse %i", challenge->challenge);
} }
break; break;
@ -466,7 +475,15 @@ void SV_GamespyAuthorize(netadr_t from, const char* response)
break; break;
case CDKS_FAILED: case CDKS_FAILED:
// authentication server told the cdkey was invalid // authentication server told the cdkey was invalid
Com_sprintf(buf, sizeof(buf), "%d.%d.%d.%d", challenge->adr.ip[0], challenge->adr.ip[1], challenge->adr.ip[2], challenge->adr.ip[3]); Com_sprintf(
buf,
sizeof(buf),
"%d.%d.%d.%d",
challenge->adr.ip[0],
challenge->adr.ip[1],
challenge->adr.ip[2],
challenge->adr.ip[3]
);
Com_Printf("%s failed cdkey authorization\n", buf); Com_Printf("%s failed cdkey authorization\n", buf);
// reject the client // reject the client
SV_NET_OutOfBandPrint(&svs.netprofile, from, "droperror\nServer rejected connection:\nInvalid CD Key"); SV_NET_OutOfBandPrint(&svs.netprofile, from, "droperror\nServer rejected connection:\nInvalid CD Key");

View file

@ -1,3 +1,25 @@
/*
===========================================================================
Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#pragma once #pragma once
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -1,6 +1,6 @@
/* /*
=========================================================================== ===========================================================================
Copyright (C) 2023 the OpenMoHAA team Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code. This file is part of OpenMoHAA source code.
@ -294,10 +294,10 @@ static void send_echo(qr_t qrec, struct sockaddr *sender, char *outbuf, const ch
static void send_final(qr_t qrec, struct sockaddr *sender, char *outbuf, char *validation) static void send_final(qr_t qrec, struct sockaddr *sender, char *outbuf, char *validation)
{ {
char keyvalue[256]; char keyvalue[256];
uchar encrypted_val[128]; uchar encrypted_val[128];
uchar encoded_val[200]; uchar encoded_val[200];
int keylen; int keylen;
if (*validation) { if (*validation) {
keylen = (int)strlen(validation); keylen = (int)strlen(validation);
@ -306,7 +306,7 @@ static void send_final(qr_t qrec, struct sockaddr *sender, char *outbuf, char *v
return; return;
} }
strcpy((char*)encrypted_val, validation); strcpy((char *)encrypted_val, validation);
gs_encrypt((uchar *)qrec->secret_key, (int)strlen(qrec->secret_key), encrypted_val, keylen); gs_encrypt((uchar *)qrec->secret_key, (int)strlen(qrec->secret_key), encrypted_val, keylen);
gs_encode(encrypted_val, keylen, encoded_val); gs_encode(encrypted_val, keylen, encoded_val);
@ -322,7 +322,7 @@ static void send_final(qr_t qrec, struct sockaddr *sender, char *outbuf, char *v
static void parse_query(qr_t qrec, char *query, struct sockaddr *sender) static void parse_query(qr_t qrec, char *query, struct sockaddr *sender)
{ {
query_t querytype = qtunknown; query_t querytype = qtunknown;
char buffer[MAX_KEYVALUES_LENGTH] = {0}; char buffer[MAX_KEYVALUES_LENGTH] = {0};
const char *value; const char *value;
char validation[256] = {0}; char validation[256] = {0};
@ -402,7 +402,14 @@ static void send_heartbeat(qr_t qrec, int statechanged)
sprintf(buf + strlen(buf), "\\statechanged\\%d", statechanged); sprintf(buf + strlen(buf), "\\statechanged\\%d", statechanged);
} }
sendto((SOCKET)qrec->hbsock, buf, (int)strlen(buf), 0, (const struct sockaddr *)&qrec->master_saddr, sizeof(qrec->master_saddr)); sendto(
(SOCKET)qrec->hbsock,
buf,
(int)strlen(buf),
0,
(const struct sockaddr *)&qrec->master_saddr,
sizeof(qrec->master_saddr)
);
qrec->lastheartbeat = current_time(); qrec->lastheartbeat = current_time();
} }
@ -417,8 +424,8 @@ void init_qrec(
int baseport, int baseport,
SOCKET hbsock, SOCKET hbsock,
SOCKET querysock, SOCKET querysock,
const char *gamename, const char *gamename,
const char *secret_key, const char *secret_key,
qr_querycallback_t qr_basic_callback, qr_querycallback_t qr_basic_callback,
qr_querycallback_t qr_info_callback, qr_querycallback_t qr_info_callback,
qr_querycallback_t qr_rules_callback, qr_querycallback_t qr_rules_callback,
@ -457,10 +464,10 @@ void init_qrec(
int qr_init( int qr_init(
qr_t *qrec, qr_t *qrec,
const char *ip, const char *ip,
int baseport, int baseport,
const char *gamename, const char *gamename,
const char *secret_key, const char *secret_key,
qr_querycallback_t qr_basic_callback, qr_querycallback_t qr_basic_callback,
qr_querycallback_t qr_info_callback, qr_querycallback_t qr_info_callback,
qr_querycallback_t qr_rules_callback, qr_querycallback_t qr_rules_callback,

View file

@ -1,6 +1,6 @@
/* /*
=========================================================================== ===========================================================================
Copyright (C) 2023 the OpenMoHAA team Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code. This file is part of OpenMoHAA source code.