From ad33f3d79fd91ec659a481e0891e2d83076b09b3 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Tue, 3 Sep 2024 12:25:27 +0300 Subject: [PATCH] Update gamespy.cpp to use new logger --- Descent3/gamespy.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Descent3/gamespy.cpp b/Descent3/gamespy.cpp index baa773f8..9b90f877 100644 --- a/Descent3/gamespy.cpp +++ b/Descent3/gamespy.cpp @@ -54,7 +54,7 @@ #include "descent.h" #include "gamespy.h" #include "gamespyutils.h" -#include "mono.h" +#include "log.h" #include "multi.h" #include "networking.h" #include "player.h" @@ -130,7 +130,7 @@ int gspy_Init() { if (SOCKET_ERROR == gspy_socket) { 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; } SOCKADDR_IN sock_addr{}; @@ -147,17 +147,17 @@ int gspy_Init() { } else { 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); 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; } // make the socket non-blocking make_nonblocking(gspy_socket); CFILE *cfp = cfopen(cfgpath, "rt"); if (cfp) { - mprintf(0, "Found a gamespy config file!\n"); + LOG_INFO << "Found a gamespy config file!"; char hostn[MAX_HOSTNAMELEN]; for (auto &server : gspy_server) { @@ -188,10 +188,10 @@ int gspy_Init() { if (INADDR_NONE == inet_addr(hostn)) { // This is a name we must resolve HOSTENT *he; - mprintf(0, "Resolving hostname for gamespy: %s\n", hostn); + LOG_DEBUG.printf("Resolving hostname for gamespy: %s", hostn); he = gethostbyname(hostn); 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; INADDR_SET_SUN_SADDR(&server.sin_addr, INADDR_NONE); } else { @@ -206,8 +206,7 @@ int gspy_Init() { uint32_t resolved_addr; INADDR_GET_SUN_SADDR(&server.sin_addr, &resolved_addr); if (resolved_addr != INADDR_NONE) { - mprintf(0, "Sending gamespy heartbeats to %s:%d\n", inet_ntoa(server.sin_addr), - htons(server.sin_port)); + LOG_INFO.printf("Sending gamespy heartbeats to %s:%d", inet_ntoa(server.sin_addr), htons(server.sin_port)); } } } @@ -250,7 +249,7 @@ void gspy_DoFrame() { uint32_t resolved_addr; INADDR_GET_SUN_SADDR(&server.sin_addr, &resolved_addr); 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); } } @@ -261,12 +260,12 @@ void gspy_DoFrame() { bytesin = (int)recvfrom(gspy_socket, inbuffer, MAX_GAMESPY_BUFFER, 0, (SOCKADDR *)&fromaddr, &fromsize); if (bytesin > 0) { *(inbuffer + bytesin) = '\0'; - mprintf(0, "GSPYIN: %s\n", inbuffer); + LOG_DEBUG.printf("GSPYIN: %s", inbuffer); gspy_ParseReq(inbuffer, &fromaddr); } else if (bytesin == SOCKET_ERROR) { int lerror = WSAGetLastError(); 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); @@ -288,7 +287,7 @@ int gspy_SendPacket(SOCKADDR_IN *addr) { sprintf(keyvalue, "\\queryid\\%d.%d", gspy_queryid, gspy_packetnumber); 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)); *gspy_outgoingbuffer = '\0'; return 0; @@ -391,7 +390,7 @@ int gspy_DoEcho(SOCKADDR_IN *addr, char *msg) { strcpy(buf, msg); char *p = strstr(buf, "\\echo\\"); 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(); return 0; } @@ -405,17 +404,17 @@ int gspy_DoBasic(SOCKADDR_IN *addr) { char buf[MAX_GAMESPY_BUFFER]; 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); // 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, Program_version.build); - mprintf(0, "Sending to gamespy: %s\n", buf); + LOG_DEBUG.printf("Sending to gamespy: %s", buf); gspy_AddToBuffer(addr, buf); 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); return 0; @@ -509,7 +508,7 @@ int gspy_DoGameInfo(SOCKADDR_IN *addr) { int gspy_DoHeartbeat(SOCKADDR_IN *addr) { char buf[MAX_GAMESPY_BUFFER]; 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)); return 0;