mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
Update gamespy.cpp to use new logger
This commit is contained in:
parent
8b0f27604c
commit
ad33f3d79f
@ -54,7 +54,7 @@
|
|||||||
#include "descent.h"
|
#include "descent.h"
|
||||||
#include "gamespy.h"
|
#include "gamespy.h"
|
||||||
#include "gamespyutils.h"
|
#include "gamespyutils.h"
|
||||||
#include "mono.h"
|
#include "log.h"
|
||||||
#include "multi.h"
|
#include "multi.h"
|
||||||
#include "networking.h"
|
#include "networking.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
@ -130,7 +130,7 @@ int gspy_Init() {
|
|||||||
|
|
||||||
if (SOCKET_ERROR == gspy_socket) {
|
if (SOCKET_ERROR == gspy_socket) {
|
||||||
int lerror = WSAGetLastError();
|
int lerror = WSAGetLastError();
|
||||||
mprintf(0, "Unable to init gamespy socket! (%d)\n", lerror);
|
LOG_WARNING.printf("Unable to init gamespy socket! (%d)", lerror);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SOCKADDR_IN sock_addr{};
|
SOCKADDR_IN sock_addr{};
|
||||||
@ -147,17 +147,17 @@ int gspy_Init() {
|
|||||||
} else {
|
} else {
|
||||||
gspy_listenport = GAMESPY_LISTENPORT;
|
gspy_listenport = GAMESPY_LISTENPORT;
|
||||||
}
|
}
|
||||||
mprintf(0, "Using port %d for gamespy requests.\n", gspy_listenport);
|
LOG_INFO.printf("Using port %d for gamespy requests.", gspy_listenport);
|
||||||
sock_addr.sin_port = htons(gspy_listenport);
|
sock_addr.sin_port = htons(gspy_listenport);
|
||||||
if (bind(gspy_socket, (SOCKADDR *)&sock_addr, sizeof(sock_addr)) == SOCKET_ERROR) {
|
if (bind(gspy_socket, (SOCKADDR *)&sock_addr, sizeof(sock_addr)) == SOCKET_ERROR) {
|
||||||
mprintf(0, "Couldn't bind gamespy socket (%d)!\n", WSAGetLastError());
|
LOG_WARNING.printf("Couldn't bind gamespy socket (%d)!", WSAGetLastError());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// make the socket non-blocking
|
// make the socket non-blocking
|
||||||
make_nonblocking(gspy_socket);
|
make_nonblocking(gspy_socket);
|
||||||
CFILE *cfp = cfopen(cfgpath, "rt");
|
CFILE *cfp = cfopen(cfgpath, "rt");
|
||||||
if (cfp) {
|
if (cfp) {
|
||||||
mprintf(0, "Found a gamespy config file!\n");
|
LOG_INFO << "Found a gamespy config file!";
|
||||||
char hostn[MAX_HOSTNAMELEN];
|
char hostn[MAX_HOSTNAMELEN];
|
||||||
|
|
||||||
for (auto &server : gspy_server) {
|
for (auto &server : gspy_server) {
|
||||||
@ -188,10 +188,10 @@ int gspy_Init() {
|
|||||||
if (INADDR_NONE == inet_addr(hostn)) {
|
if (INADDR_NONE == inet_addr(hostn)) {
|
||||||
// This is a name we must resolve
|
// This is a name we must resolve
|
||||||
HOSTENT *he;
|
HOSTENT *he;
|
||||||
mprintf(0, "Resolving hostname for gamespy: %s\n", hostn);
|
LOG_DEBUG.printf("Resolving hostname for gamespy: %s", hostn);
|
||||||
he = gethostbyname(hostn);
|
he = gethostbyname(hostn);
|
||||||
if (!he) {
|
if (!he) {
|
||||||
mprintf(0, "Unable to resolve %s\n", hostn);
|
LOG_WARNING.printf("Unable to resolve %s", hostn);
|
||||||
// gspy_server[i].sin_addr.S_un.S_addr = INADDR_NONE;
|
// gspy_server[i].sin_addr.S_un.S_addr = INADDR_NONE;
|
||||||
INADDR_SET_SUN_SADDR(&server.sin_addr, INADDR_NONE);
|
INADDR_SET_SUN_SADDR(&server.sin_addr, INADDR_NONE);
|
||||||
} else {
|
} else {
|
||||||
@ -206,8 +206,7 @@ int gspy_Init() {
|
|||||||
uint32_t resolved_addr;
|
uint32_t resolved_addr;
|
||||||
INADDR_GET_SUN_SADDR(&server.sin_addr, &resolved_addr);
|
INADDR_GET_SUN_SADDR(&server.sin_addr, &resolved_addr);
|
||||||
if (resolved_addr != INADDR_NONE) {
|
if (resolved_addr != INADDR_NONE) {
|
||||||
mprintf(0, "Sending gamespy heartbeats to %s:%d\n", inet_ntoa(server.sin_addr),
|
LOG_INFO.printf("Sending gamespy heartbeats to %s:%d", inet_ntoa(server.sin_addr), htons(server.sin_port));
|
||||||
htons(server.sin_port));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,7 +249,7 @@ void gspy_DoFrame() {
|
|||||||
uint32_t resolved_addr;
|
uint32_t resolved_addr;
|
||||||
INADDR_GET_SUN_SADDR(&server.sin_addr, &resolved_addr);
|
INADDR_GET_SUN_SADDR(&server.sin_addr, &resolved_addr);
|
||||||
if (resolved_addr != INADDR_NONE) {
|
if (resolved_addr != INADDR_NONE) {
|
||||||
mprintf(0, "Sending heartbeat to %s:%d\n", inet_ntoa(server.sin_addr), htons(server.sin_port));
|
LOG_DEBUG.printf("Sending heartbeat to %s:%d", inet_ntoa(server.sin_addr), htons(server.sin_port));
|
||||||
gspy_DoHeartbeat(&server);
|
gspy_DoHeartbeat(&server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,12 +260,12 @@ void gspy_DoFrame() {
|
|||||||
bytesin = (int)recvfrom(gspy_socket, inbuffer, MAX_GAMESPY_BUFFER, 0, (SOCKADDR *)&fromaddr, &fromsize);
|
bytesin = (int)recvfrom(gspy_socket, inbuffer, MAX_GAMESPY_BUFFER, 0, (SOCKADDR *)&fromaddr, &fromsize);
|
||||||
if (bytesin > 0) {
|
if (bytesin > 0) {
|
||||||
*(inbuffer + bytesin) = '\0';
|
*(inbuffer + bytesin) = '\0';
|
||||||
mprintf(0, "GSPYIN: %s\n", inbuffer);
|
LOG_DEBUG.printf("GSPYIN: %s", inbuffer);
|
||||||
gspy_ParseReq(inbuffer, &fromaddr);
|
gspy_ParseReq(inbuffer, &fromaddr);
|
||||||
} else if (bytesin == SOCKET_ERROR) {
|
} else if (bytesin == SOCKET_ERROR) {
|
||||||
int lerror = WSAGetLastError();
|
int lerror = WSAGetLastError();
|
||||||
if (lerror != WSAEWOULDBLOCK) {
|
if (lerror != WSAEWOULDBLOCK) {
|
||||||
mprintf(0, "Warning: recvfrom failed for gamespy! (%d)\n", lerror);
|
LOG_WARNING.printf("recvfrom failed for gamespy! (%d)", lerror);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (bytesin > 0);
|
} while (bytesin > 0);
|
||||||
@ -288,7 +287,7 @@ int gspy_SendPacket(SOCKADDR_IN *addr) {
|
|||||||
sprintf(keyvalue, "\\queryid\\%d.%d", gspy_queryid, gspy_packetnumber);
|
sprintf(keyvalue, "\\queryid\\%d.%d", gspy_queryid, gspy_packetnumber);
|
||||||
strcat(gspy_outgoingbuffer, keyvalue);
|
strcat(gspy_outgoingbuffer, keyvalue);
|
||||||
|
|
||||||
mprintf(0, "GSPYOUT: %s\n", gspy_outgoingbuffer);
|
LOG_DEBUG.printf("GSPYOUT: %s", gspy_outgoingbuffer);
|
||||||
sendto(gspy_socket, gspy_outgoingbuffer, strlen(gspy_outgoingbuffer) + 1, 0, (SOCKADDR *)addr, sizeof(SOCKADDR_IN));
|
sendto(gspy_socket, gspy_outgoingbuffer, strlen(gspy_outgoingbuffer) + 1, 0, (SOCKADDR *)addr, sizeof(SOCKADDR_IN));
|
||||||
*gspy_outgoingbuffer = '\0';
|
*gspy_outgoingbuffer = '\0';
|
||||||
return 0;
|
return 0;
|
||||||
@ -391,7 +390,7 @@ int gspy_DoEcho(SOCKADDR_IN *addr, char *msg) {
|
|||||||
strcpy(buf, msg);
|
strcpy(buf, msg);
|
||||||
char *p = strstr(buf, "\\echo\\");
|
char *p = strstr(buf, "\\echo\\");
|
||||||
if (!p) {
|
if (!p) {
|
||||||
mprintf(0, "Couldn't find echo keyword in gamespy query, this is a wacky bug that should never happen!\n");
|
LOG_FATAL << "Couldn't find 'echo' keyword in gamespy query, this is a wacky bug that should never happen!";
|
||||||
Int3();
|
Int3();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -405,17 +404,17 @@ int gspy_DoBasic(SOCKADDR_IN *addr) {
|
|||||||
char buf[MAX_GAMESPY_BUFFER];
|
char buf[MAX_GAMESPY_BUFFER];
|
||||||
|
|
||||||
sprintf(buf, "\\gamename\\%s", THISGAMENAME);
|
sprintf(buf, "\\gamename\\%s", THISGAMENAME);
|
||||||
mprintf(0, "Sending to gamespy: %s\n", buf);
|
LOG_DEBUG.printf("Sending to gamespy: %s", buf);
|
||||||
gspy_AddToBuffer(addr, buf);
|
gspy_AddToBuffer(addr, buf);
|
||||||
|
|
||||||
// sprintf(buf,"\\gamever\\%d.%d",Program_version.major,Program_version.minor);
|
// sprintf(buf,"\\gamever\\%d.%d",Program_version.major,Program_version.minor);
|
||||||
sprintf(buf, "\\gamever\\%s %.1d.%.1d.%.1d", THISGAMEVER, Program_version.major, Program_version.minor,
|
sprintf(buf, "\\gamever\\%s %.1d.%.1d.%.1d", THISGAMEVER, Program_version.major, Program_version.minor,
|
||||||
Program_version.build);
|
Program_version.build);
|
||||||
mprintf(0, "Sending to gamespy: %s\n", buf);
|
LOG_DEBUG.printf("Sending to gamespy: %s", buf);
|
||||||
gspy_AddToBuffer(addr, buf);
|
gspy_AddToBuffer(addr, buf);
|
||||||
|
|
||||||
sprintf(buf, "\\location\\%d", gspy_region);
|
sprintf(buf, "\\location\\%d", gspy_region);
|
||||||
mprintf(0, "Sending to gamespy: %s\n", buf);
|
LOG_DEBUG.printf("Sending to gamespy: %s", buf);
|
||||||
gspy_AddToBuffer(addr, buf);
|
gspy_AddToBuffer(addr, buf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -509,7 +508,7 @@ int gspy_DoGameInfo(SOCKADDR_IN *addr) {
|
|||||||
int gspy_DoHeartbeat(SOCKADDR_IN *addr) {
|
int gspy_DoHeartbeat(SOCKADDR_IN *addr) {
|
||||||
char buf[MAX_GAMESPY_BUFFER];
|
char buf[MAX_GAMESPY_BUFFER];
|
||||||
sprintf(buf, "\\heartbeat\\%d\\gamename\\%s", gspy_listenport, THISGAMENAME);
|
sprintf(buf, "\\heartbeat\\%d\\gamename\\%s", gspy_listenport, THISGAMENAME);
|
||||||
mprintf(0, "GSPYOUT: %s\n", buf);
|
LOG_DEBUG.printf("GSPYOUT: %s", buf);
|
||||||
sendto(gspy_socket, buf, strlen(buf) + 1, 0, (SOCKADDR *)addr, sizeof(SOCKADDR_IN));
|
sendto(gspy_socket, buf, strlen(buf) + 1, 0, (SOCKADDR *)addr, sizeof(SOCKADDR_IN));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user