From f2bcbc9ffdf642d7e361c56c13aef5a20970187b Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Tue, 3 Jun 2025 16:29:34 +0300 Subject: [PATCH 1/2] Enable logging for netcon modules Implementing chained appender initialization scenario for plog. --- Descent3/multi_dll_mgr.cpp | 27 +++- logger/log.h | 4 +- netcon/descent3onlineclient/CMakeLists.txt | 1 + netcon/descent3onlineclient/chat_api.cpp | 28 ++-- netcon/descent3onlineclient/dip_gametrack.cpp | 9 +- netcon/descent3onlineclient/odtclient.cpp | 69 ++++----- netcon/includes/con_dll.h | 12 +- netcon/lanclient/CMakeLists.txt | 1 + netcon/lanclient/lanclient.cpp | 28 ++-- netcon/mtclient/CMakeLists.txt | 1 + netcon/mtclient/chat_api.cpp | 28 ++-- netcon/mtclient/mt_net.cpp | 26 ++-- netcon/mtclient/mtclient.cpp | 138 ++++++++---------- netcon/mtclient/mtgametrack.cpp | 22 +-- netcon/mtclient/mtpilottracker.cpp | 6 - 15 files changed, 175 insertions(+), 225 deletions(-) diff --git a/Descent3/multi_dll_mgr.cpp b/Descent3/multi_dll_mgr.cpp index 1ec0e14a4..a1f797d0b 100644 --- a/Descent3/multi_dll_mgr.cpp +++ b/Descent3/multi_dll_mgr.cpp @@ -333,16 +333,20 @@ typedef void DLLFUNCCALL (*DLLMultiCall_fp)(int eventnum); typedef void DLLFUNCCALL (*DLLMultiScoreCall_fp)(int eventnum, void *data); typedef void DLLFUNCCALL (*DLLMultiInit_fp)(int *api_fp); typedef void DLLFUNCCALL (*DLLMultiClose_fp)(); +typedef void DLLFUNCCALL (*DLLMultiInitLogger_fp)(plog::Severity severity, plog::IAppender* appender); #else typedef void(DLLFUNCCALL *DLLMultiCall_fp)(int eventnum); typedef void(DLLFUNCCALL *DLLMultiScoreCall_fp)(int eventnum, void *data); typedef void(DLLFUNCCALL *DLLMultiInit_fp)(int *api_fp); typedef void(DLLFUNCCALL *DLLMultiClose_fp)(); +typedef void(DLLFUNCCALL *DLLMultiInitLogger_fp)(plog::Severity severity, plog::IAppender* appender); #endif -DLLMultiScoreCall_fp DLLMultiScoreCall = NULL; -DLLMultiCall_fp DLLMultiCall = NULL; -DLLMultiInit_fp DLLMultiInit = NULL; -DLLMultiClose_fp DLLMultiClose = NULL; +DLLMultiScoreCall_fp DLLMultiScoreCall = nullptr; +DLLMultiCall_fp DLLMultiCall = nullptr; +DLLMultiInit_fp DLLMultiInit = nullptr; +DLLMultiClose_fp DLLMultiClose = nullptr; +DLLMultiInitLogger_fp DLLMultiInitLogger = nullptr; + // dllmultiiInfo DLLMultiInfo; // The DLL needs these too. #define MAXTEXTITEMS 100 @@ -584,9 +588,10 @@ void FreeMultiDLL() { if (!std::filesystem::remove(Multi_conn_dll_name)) { LOG_WARNING << "Couldn't delete the tmp dll"; } - DLLMultiCall = NULL; - DLLMultiInit = NULL; - DLLMultiClose = NULL; + DLLMultiCall = nullptr; + DLLMultiInit = nullptr; + DLLMultiClose = nullptr; + DLLMultiInitLogger = nullptr; } // Loads the Multi dll. Returns 1 on success, else 0 on failure @@ -667,6 +672,14 @@ int LoadMultiDLL(const char *name) { FreeMultiDLL(); return 0; } + // Initialize logger. For backward compatibility, lack of DLLMultiInitLogger symbols is non-fatal error. + DLLMultiInitLogger = (DLLMultiInitLogger_fp)mod_GetSymbol(&MultiDLLHandle, "DLLMultiInitLogger", 12); + if (!DLLMultiInitLogger) { + mod_GetLastError(); + LOG_WARNING << "Couldn't get a handle to the dll function DLLMultiInitLogger!"; + } else { + DLLMultiInitLogger(plog::get()->getMaxSeverity(), plog::get()); + } if (first) { // Jeff: Linux dies if you try to free a DLL/so during atexit diff --git a/logger/log.h b/logger/log.h index 0d5b6cfc4..739e3a0e7 100644 --- a/logger/log.h +++ b/logger/log.h @@ -18,8 +18,8 @@ #pragma once -// This is interface header for chosen logger library. Currently, this is plog. -#include +#include // This is interface header for chosen logger library. Currently, this is plog. +#include // Required for modules. /* In case of swapping to another solution here should be redefined following macros: diff --git a/netcon/descent3onlineclient/CMakeLists.txt b/netcon/descent3onlineclient/CMakeLists.txt index 25aabb07f..14ecb4f5d 100644 --- a/netcon/descent3onlineclient/CMakeLists.txt +++ b/netcon/descent3onlineclient/CMakeLists.txt @@ -18,6 +18,7 @@ target_link_libraries(Descent3_Online_TCP_IP PRIVATE ddio inetfile httplib + logger misc module ui diff --git a/netcon/descent3onlineclient/chat_api.cpp b/netcon/descent3onlineclient/chat_api.cpp index 9fadb4f76..05c4a3680 100644 --- a/netcon/descent3onlineclient/chat_api.cpp +++ b/netcon/descent3onlineclient/chat_api.cpp @@ -31,6 +31,7 @@ #include "chat_api.h" #include "crossplat.h" #include "grdefs.h" +#include "log.h" #include "odtstrings.h" #include "networking.h" @@ -48,12 +49,6 @@ extern nw_Asyncgethostbyname_fp DLLnw_Asyncgethostbyname; typedef int (*PollUI_fp)(); extern PollUI_fp DLLPollUI; -#ifndef RELEASE -#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__) -#else -#define DLLmprintf(...) -#endif - typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...); extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf; #define MAXCHATBUFFER 500 @@ -189,8 +184,7 @@ int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nicknam } while (rcode == 0); if (rcode != 1) { - DLLmprintf(0, "Unable to gethostbyname(\"%s\").\n", serveraddr); - DLLmprintf(0, "WSAGetLastError() returned %d.\n", WSAGetLastError()); + LOG_ERROR.printf("Unable to gethostbyname(\"%s\"): error %d", serveraddr, WSAGetLastError()); DLLnw_Asyncgethostbyname(nullptr, NW_AGHBN_CANCEL, nullptr); return 0; } @@ -207,16 +201,16 @@ int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nicknam if (EINPROGRESS == ret || 0 == ret) #endif { - DLLmprintf(0, "Beginning socket connect\n"); + LOG_INFO << "Beginning socket connect"; Socket_connecting = 1; return 0; } } else { // This should never happen, connect should always return WSAEWOULDBLOCK - DLLmprintf(0, "connect returned too soon!\n"); + LOG_WARNING << "connect returned too soon!"; Socket_connecting = 1; Socket_connected = 1; - DLLmprintf(0, "Socket connected, sending user and nickname request\n"); + LOG_INFO << "Socket connected, sending user and nickname request"; snprintf(signon_str, sizeof(signon_str), "/USER %s %s %s :%s", "user", "user", "user", Chat_tracker_id); SendChatString(signon_str, 1); snprintf(signon_str, sizeof(signon_str), "/NICK %s", Nick_name); @@ -246,7 +240,7 @@ int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nicknam // Writable -- that means it's connected if (select(Chatsock + 1, nullptr, &write_fds, nullptr, &timeout)) { Socket_connected = 1; - DLLmprintf(0, "Socket connected, sending user and nickname request\n"); + LOG_INFO << "Socket connected, sending user and nickname request"; snprintf(signon_str, sizeof(signon_str), "/USER %s %s %s :%s", "user", "user", "user", Chat_tracker_id); SendChatString(signon_str, 1); snprintf(signon_str, sizeof(signon_str), "/NICK %s", Nick_name); @@ -258,7 +252,7 @@ int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nicknam FD_SET(Chatsock, &error_fds); // error -- that means it's not going to connect if (select(Chatsock + 1, nullptr, nullptr, &error_fds, &timeout)) { - DLLmprintf(0, "Select returned an error!\n"); + LOG_ERROR << "select() returned an error!"; return -1; } return 0; @@ -462,13 +456,12 @@ const char *ChatGetString() { if (WSAEWOULDBLOCK != lerror && 0 != lerror) #endif { - DLLmprintf(0, "recv caused an error: %d\n", lerror); + LOG_ERROR.printf("recv() caused an error: %d", lerror); } return nullptr; } if (bytesread) { ch[1] = '\0'; - // DLLmprintf(0,ch); if ((ch[0] == 0x0a) || (ch[0] == 0x0d)) { if (Input_chat_buffer[0] == '\0') { // Blank line, ignore it @@ -476,7 +469,6 @@ const char *ChatGetString() { } strcpy(return_string, Input_chat_buffer); Input_chat_buffer[0] = '\0'; - // DLLmprintf(0,"->|%s\n",return_string); p = ParseIRCMessage(return_string, MSG_REMOTE); return p; @@ -484,7 +476,7 @@ const char *ChatGetString() { strcat(Input_chat_buffer, ch); } else { // Select said we had read data, but 0 bytes read means disconnected - DLLmprintf(0, "Disconnected! Doh!"); + LOG_ERROR << "Disconnected! Doh!"; AddChatCommandToQueue(CC_DISCONNECTED, nullptr, 0); return nullptr; } @@ -931,7 +923,7 @@ char *ParseIRCMessage(char *Line, int iMode) { if (stricmp(szCmd, "376") == 0) // end of motd, trigger autojoin... { if (!Chat_server_connected) { - DLLmprintf(0, "Connected to chat server!\n"); + LOG_INFO << "Connected to chat server!"; Chat_server_connected = 1; // We want to make sure we know our nick. This is somewhat of a hack strcpy(Nick_name, GetWordNum(0, szRemLine + 1)); diff --git a/netcon/descent3onlineclient/dip_gametrack.cpp b/netcon/descent3onlineclient/dip_gametrack.cpp index 6e6b7c7b0..b7be12152 100644 --- a/netcon/descent3onlineclient/dip_gametrack.cpp +++ b/netcon/descent3onlineclient/dip_gametrack.cpp @@ -26,12 +26,7 @@ #include "dip_gametrack.h" #include "httpclient.h" - -#if (defined(LOGGER) && (!defined(RELEASE))) -#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__) -#else -#define DLLmprintf(...) -#endif +#include "log.h" typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...); extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf; @@ -88,7 +83,7 @@ void DecodeApiAnswer(std::stringstream &data) { } void FetchApi() { - DLLmprintf(0, "fetch api.\n"); + LOG_INFO << "fetch api."; D3::HttpClient http_client(TSETSEFLYAPI_HOST); std::stringstream input; auto result = http_client.Get(TSETSEFLYAPI_URI); diff --git a/netcon/descent3onlineclient/odtclient.cpp b/netcon/descent3onlineclient/odtclient.cpp index 3f2de5be2..f4030c003 100644 --- a/netcon/descent3onlineclient/odtclient.cpp +++ b/netcon/descent3onlineclient/odtclient.cpp @@ -21,6 +21,7 @@ #include "grdefs.h" #include "player.h" #include "game.h" +#include "log.h" #include "pilot.h" #include "ddio_common.h" #include "module.h" @@ -187,7 +188,7 @@ void UpdateGamelist(void *lb) { NextGameItemNo++; Gamelist[j].handle = DLLNetwork_games[k].handle; Gamelist[j].used = true; - DLLmprintf(0, "Adding %s\n", DLLNetwork_games[k].name); + LOG_INFO.printf("Adding %s", DLLNetwork_games[k].name); FormatServerLine(fmtline, k); @@ -223,6 +224,7 @@ extern "C" { DLLEXPORT void DLLFUNCCALL DLLMultiInit(int *api_func); DLLEXPORT void DLLFUNCCALL DLLMultiCall(int eventnum); DLLEXPORT void DLLFUNCCALL DLLMultiClose(); +DLLEXPORT void DLLFUNCCALL DLLMultiInitLogger(plog::Severity severity, plog::IAppender* appender); } bool All_ok = true; @@ -233,13 +235,12 @@ void DLLFUNCCALL DLLMultiInit(int *api_func) { Use_netgame_flags = true; CommonDLLInit(api_func); - DLLmprintf(0, "Inside DLLMultiInit...\n"); + LOG_DEBUG << "Inside DLLMultiInit..."; *DLLUse_DirectPlay = false; Auto_start = false; - DLLmprintf(0, "About to create string table...\n"); DLLCreateStringTable("d3online.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); + LOG_DEBUG.printf("%d strings loaded from string table", StringTableSize); if (!StringTableSize) { All_ok = false; return; @@ -250,14 +251,14 @@ void DLLFUNCCALL DLLMultiInit(int *api_func) { // Called when the DLL is shutdown void DLLFUNCCALL DLLMultiClose() { - DLLmprintf(0, "Closing down Online Direct TCP-IP DLL\n"); + LOG_DEBUG << "Closing down Online Direct TCP-IP DLL"; DLLDestroyStringTable(StringTable, StringTableSize); } // The main entry point where the game calls the dll void DLLFUNCCALL DLLMultiCall(int eventnum) { // We don't need eventnum right now. - DLLmprintf(0, "DLLMultiCall:%d!\n", eventnum); + LOG_DEBUG.printf("DLLMultiCall: %d!", eventnum); switch (eventnum) { case MT_EVT_GET_HELP: @@ -327,6 +328,11 @@ void DLLFUNCCALL DLLMultiCall(int eventnum) { } } +void DLLFUNCCALL DLLMultiInitLogger(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +}; + #define CONNECT_IRC_TIMEOUT 30.0 #define MAX_CHAT_SEND_LEN 200 #define MAX_CHAT_CHANNELS 50 @@ -346,10 +352,7 @@ struct { int MainMultiplayerMenu() { knownDirectIpHosts.clear(); - DLLmprintf(0, "MainMultiplayerMenu.\n"); - DLLmprintf(0, "%d", DESCENT3_BLOCK_SIZE); - - DLLmprintf(0, "Inside MainMultiplayerMenu()\n"); + LOG_DEBUG << "Inside MainMultiplayerMenu()"; if (Bypass_chat && !ChatStarted) { int rcode1 = SearchMasterTrackerGameMenu(); if (rcode1 == -1) @@ -472,7 +475,7 @@ int MainMultiplayerMenu() { snprintf(chat_whois_info, sizeof(chat_whois_info), "%s %s", sztrackerid, pilot_name); chat_conn_time = DLLtimer_GetTime(); - DLLmprintf(0, "About to connect...\n"); + LOG_DEBUG << "About to connect..."; do { chat_connected = ConnectToChatServer(CHATTRACKERNAME, CHATPORT, pilot_name, chat_whois_info); p = GetChatText(); @@ -508,7 +511,7 @@ int MainMultiplayerMenu() { DLLNewUIWindowClose(main_wnd); goto shutdownodip; } - DLLmprintf(0, "Connected to chat server!\n"); + LOG_INFO << "Connected to chat server!"; if (!JoinNewLobby("#descent")) { ret = 0; exit_menu = 1; @@ -554,7 +557,7 @@ int MainMultiplayerMenu() { exit_menu = 1; break; default: - DLLmprintf(0, "Warning: Received an unknown chat command!\n"); + LOG_WARNING.printf("Received an unknown chat command (%d)!", cmd); break; } } @@ -633,7 +636,7 @@ int MainMultiplayerMenu() { if (tokp) { // Remove all previous items - DLLmprintf(0, "Refreshing channel list\n"); + LOG_INFO << "Refreshing channel list"; int selitem = DLLOldListGetSelectedIndex(chan_list); char *oldsel = nullptr; @@ -752,9 +755,8 @@ int MainMultiplayerMenu() { case 3: // Join Mastertracker game { - DLLmprintf(0, "Sending Mastertracker game list request.\n"); + LOG_INFO << "Sending Mastertracker game list request."; RequestDIPGameList(); - DLLmprintf(0, "Calling SearchMasterTrackerGameMenu().\n"); DLLNewUIWindowClose(main_wnd); *DLLGame_is_master_tracker_game = 0; int gamestart = SearchMasterTrackerGameMenu(); @@ -790,7 +792,7 @@ int MainMultiplayerMenu() { case 6: // Send a private message // Create new dialog box, prompt for user and message, then send message - DLLmprintf(0, "Sending private Message\n"); + LOG_INFO << "Sending private Message"; // Get the currently selected pilot name strcpy(selpilot, DLLOldListGetItem(user_list, DLLOldListGetSelectedIndex(user_list))); SendWhisper(selpilot); @@ -808,11 +810,10 @@ int MainMultiplayerMenu() { break; case 9: // Find a pilot - DLLmprintf(0, "Finding a pilot\n"); + LOG_INFO << "Finding a pilot"; FindPilot(); break; case 11: { - DLLmprintf(0, "Calling SearchMasterTrackerGameMenu().\n"); DLLNewUIWindowClose(main_wnd); *DLLGame_is_master_tracker_game = 0; int gamestart = SearchMasterTrackerGameMenu(); @@ -829,10 +830,9 @@ int MainMultiplayerMenu() { } break; case 14: // Channel list box - DLLmprintf(0, "Joining new public channel\n"); { int selitem = 0; - DLLmprintf(0, "Joining new public channel\n"); + LOG_INFO << "Joining new public channel"; selitem = DLLOldListGetSelectedIndex(chan_list); if (!JoinNewLobby(chan_info[selitem].origname)) { ret = 0; @@ -884,10 +884,9 @@ int MainMultiplayerMenu() { user_ti[i] = nullptr; } *DLLNewUIWindow_alpha = oldalpha; - DLLmprintf(0, "Disconnecting from Online Direct TCP-IP IRC.\n"); + LOG_INFO << "Disconnecting from Online Direct TCP-IP IRC."; DisconnectFromChatServer(); ChatStarted = 0; - DLLmprintf(0, "Disconnected.\n"); DLLToggleUICallback(1); // Delete all those items we created @@ -1032,7 +1031,7 @@ void ResortGameList(void *lb, int type, bool invert) { #define GET_INFO_ID 50 int SearchMasterTrackerGameMenu() { - DLLmprintf(0, "SearchMasterTrackerGameMenu().\n"); + LOG_DEBUG << "SearchMasterTrackerGameMenu()"; int exit_menu = 0; int cury = 40; int ret = 0; @@ -1158,7 +1157,7 @@ int SearchMasterTrackerGameMenu() { // request master RequestDIPGameList(); *DLLNum_network_games_known = 0; - DLLmprintf(0, "Waiting for Mastertracker response.\n"); + LOG_INFO << "Waiting for Mastertracker response."; auto ui_directip_counter = DLLCreateNewUITextItem("0 Server", GR_LIGHTGRAY); auto directip_counter = DLLTextCreate(main_wnd, ui_directip_counter, 290, curyButtomMenu, 130); @@ -1224,7 +1223,7 @@ int SearchMasterTrackerGameMenu() { // request master if ((DLLtimer_GetTime() - last_master_req_time) > REQ_GAME_MASTER_INTERVAL) { last_master_req_time = DLLtimer_GetTime(); - DLLmprintf(0, "request master\n"); + LOG_INFO << "Request master"; // re request master RequestDIPGameList(); @@ -1235,7 +1234,7 @@ int SearchMasterTrackerGameMenu() { // update existing servers for (apiServerEntry &directIpHost : knownDirectIpHosts) { - DLLmprintf(0, "send directip query to: %d %d\n", directIpHost.ipv4adr, directIpHost.port); + LOG_DEBUG.printf("Send directip query to: %d %d\n", directIpHost.ipv4adr, directIpHost.port); DLLSearchForLocalGamesTCP(directIpHost.ipv4adr, directIpHost.port); } @@ -1276,7 +1275,7 @@ int SearchMasterTrackerGameMenu() { break; gameno = gameid; - DLLmprintf(0, "Selected item is %s\n", DLLNetwork_games[gameno].name); + LOG_DEBUG.printf("Selected item is %s\n", DLLNetwork_games[gameno].name); network_address s_address; s_address.connection_type = NP_TCP; @@ -1292,7 +1291,7 @@ int SearchMasterTrackerGameMenu() { // Check to see if this mission exists! if (DLLmsn_CheckGetMission(&s_address, DLLNetwork_games[gameno].mission)) { if ((DLLTryToJoinServer(&s_address))) { - DLLmprintf(0, "Menu: Game joined!\n"); + LOG_INFO << "Menu: Game joined!"; DLLNewUIWindowClose(main_wnd); exit_menu = 1; ret = 1; @@ -1365,38 +1364,32 @@ int SearchMasterTrackerGameMenu() { gameno = gameid; if (gameid == -1) break; - DLLmprintf(0, "Selected item is %s\n", DLLNetwork_games[gameno].name); + LOG_DEBUG.printf("Selected item is %s", DLLNetwork_games[gameno].name); DLLShowNetgameInfo(&DLLNetwork_games[gameno]); } } break; case SORT_GAMENAME: { - DLLmprintf(0, "Sorting by game name.\n"); invert_sort_gamename = !invert_sort_gamename; ResortGameList(game_list, res, invert_sort_gamename); } break; case SORT_GAMETYPE: { - DLLmprintf(0, "Sorting by game type.\n"); invert_sort_gametype = !invert_sort_gametype; ResortGameList(game_list, res, invert_sort_gametype); } break; case SORT_MISSION: { - DLLmprintf(0, "Sorting by mission.\n"); invert_sort_mission = !invert_sort_mission; ResortGameList(game_list, res, invert_sort_mission); } break; case SORT_LEVEL: { - DLLmprintf(0, "Sorting by level.\n"); invert_sort_levels = !invert_sort_levels; ResortGameList(game_list, res, invert_sort_levels); } break; case SORT_PLAYERS: { - DLLmprintf(0, "Sorting by players.\n"); invert_sort_players = !invert_sort_players; ResortGameList(game_list, res, invert_sort_players); } break; case SORT_PING: { - DLLmprintf(0, "Sorting by ping.\n"); invert_sort_ping = !invert_sort_ping; ResortGameList(game_list, res, invert_sort_ping); } break; @@ -1476,7 +1469,7 @@ int SearchMasterTrackerGameMenu() { int JoinNewLobby(const char *lobby) { int rcode; const char *p; - DLLmprintf(0, "Entering new lobby"); + LOG_INFO << "Entering new lobby"; auto title_text = DLLCreateNewUITextItem(TXT_ODT_ENTERINGLOBBY, UICOL_WINDOW_TITLE); auto cancel_on_text = DLLCreateNewUITextItem(TXT_ODT_CANCEL, UICOL_HOTSPOT_HI); @@ -1503,7 +1496,7 @@ int JoinNewLobby(const char *lobby) { if (rcode == 1) { return 1; } else { - DLLmprintf(0, "Unable to join lobby: %d\n", rcode); + LOG_WARNING.printf("Unable to join lobby: %d", rcode); char txtmessage[200]; char cleanlobby[50]; memset(cleanlobby, 0, 29); diff --git a/netcon/includes/con_dll.h b/netcon/includes/con_dll.h index edf67e576..9dd57050a 100644 --- a/netcon/includes/con_dll.h +++ b/netcon/includes/con_dll.h @@ -755,14 +755,6 @@ struct vmt_descent3_struct { #pragma pack() #endif -///////////////////////////// -// Defines -#ifndef RELEASE -#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__) -#else -#define DLLmprintf(...) -#endif - uint32_t MTClientVer = 100; multi_api API; @@ -1211,7 +1203,7 @@ int StartMultiplayerGameMenu() { std::filesystem::path mission_name = path.filename(); if (DLLIsMissionMultiPlayable((const char*)mission_name.u8string().c_str()) && (stricmp("d3_2.mn3", (const char*)mission_name.u8string().c_str()) != 0)) { - DLLmprintf(0, "Found a mission: %s\n", (const char*)mission_name.u8string().c_str()); + LOG_INFO << "Found a mission: " << mission_name; mi = (msn_list *)DLLmem_malloc(sizeof(msn_list)); strcpy(mi->msn_name, DLLGetMissionName((const char*)mission_name.u8string().c_str())); strcpy(mi->msn_file, (const char*)mission_name.u8string().c_str()); @@ -1354,7 +1346,7 @@ int StartMultiplayerGameMenu() { { // Do warp dialog here if needed if (-1 != DLLMultiLevelSelection()) { - DLLmprintf(0, "Mission loaded successfully!\n"); + LOG_INFO << "Mission loaded successfully!"; DLLMultiStartServer(1, DLLNetgame->scriptname, teams); exit_menu = 1; ret = 1; diff --git a/netcon/lanclient/CMakeLists.txt b/netcon/lanclient/CMakeLists.txt index 799d60214..6db5f716b 100644 --- a/netcon/lanclient/CMakeLists.txt +++ b/netcon/lanclient/CMakeLists.txt @@ -10,6 +10,7 @@ set_target_properties(Direct_TCP_IP PROPERTIES OUTPUT_NAME "Direct TCP~IP") target_link_libraries(Direct_TCP_IP PRIVATE ddio inetfile + logger misc module ui diff --git a/netcon/lanclient/lanclient.cpp b/netcon/lanclient/lanclient.cpp index baf475684..5a0ebc293 100644 --- a/netcon/lanclient/lanclient.cpp +++ b/netcon/lanclient/lanclient.cpp @@ -268,6 +268,7 @@ #include "grdefs.h" #include "player.h" #include "game.h" +#include "log.h" #include "pilot.h" #include "module.h" #include "ddio_common.h" @@ -319,12 +320,13 @@ extern int MTAVersionCheck(uint32_t oldver, char *URL); ///////////////////////////// // Defines -// These next two function prototypes MUST appear in the extern "C" block if called +// These next function prototypes MUST appear in the extern "C" block if called // from a CPP file. extern "C" { DLLEXPORT void DLLFUNCCALL DLLMultiInit(int *api_func); DLLEXPORT void DLLFUNCCALL DLLMultiCall(int eventnum); DLLEXPORT void DLLFUNCCALL DLLMultiClose(); +DLLEXPORT void DLLFUNCCALL DLLMultiInitLogger(plog::Severity severity, plog::IAppender* appender); } static bool All_ok = true; @@ -333,7 +335,6 @@ void DLLFUNCCALL DLLMultiInit(int *api_func) { Use_netgame_flags = true; CommonDLLInit(api_func); DLLCreateStringTable("lanclient.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { All_ok = false; return; @@ -392,6 +393,11 @@ void DLLFUNCCALL DLLMultiCall(int eventnum) { } } +void DLLFUNCCALL DLLMultiInitLogger(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +}; + namespace lanclient { #define GET_INFO_ID 50 // The first multiplayer menu that the user will see...all multiplayer stuff is @@ -479,7 +485,7 @@ int MainMultiplayerMenu() { // char * psel = DLLListGetItem(main_list,DLLListGetSelectedIndex(main_list)) ; // selno = DLLListGetSelectedIndex(main_list); // strcpy(selgame,DLLNetwork_games[selno].name); - DLLmprintf(0, "Selected item = %s\n", selgame); + LOG_DEBUG.printf("Selected item = %s", selgame); selti = NULL; DLLListRemoveAll(main_list); for (int k = 0; k < *DLLNum_network_games_known; k++) { @@ -498,7 +504,7 @@ int MainMultiplayerMenu() { strcat(server_mode, "-ML"); } - DLLmprintf(0, "Found game: %s\n", DLLNetwork_games[k].name); + LOG_INFO.printf("Found game: %s", DLLNetwork_games[k].name); snprintf(fmtline, sizeof(fmtline), "%.20s\t\x02\x02b%s %.10s\x02\x45%.15s\x02\x63%d\x02\x6d%d/%d\x02\x7e%.3f", DLLNetwork_games[k].name, server_mode, DLLNetwork_games[k].scriptname, DLLNetwork_games[k].mission_name, DLLNetwork_games[k].level_num, @@ -514,7 +520,7 @@ int MainMultiplayerMenu() { selgame[20] = '\0'; if (strncmp(selgame, DLLNetwork_games[k].name, 19) == 0) { selti = net_game_txt_items[k]; - DLLmprintf(0, "Found previously selected game in list, reselecting...\n"); + LOG_INFO << "Found previously selected game in list, reselecting..."; } DLLListAddItem(main_list, net_game_txt_items[k]); } @@ -553,7 +559,7 @@ int MainMultiplayerMenu() { // Get the appropriate game address int gameno; gameno = DLLListGetSelectedIndex(main_list); - DLLmprintf(0, "Selected item is %d\n", gameno); + LOG_INFO.printf("Selected item is %d", gameno); network_address s_address; memcpy(&s_address, &DLLNetwork_games[gameno].addr, sizeof(network_address)); s_address.connection_type = NP_TCP; @@ -563,7 +569,7 @@ int MainMultiplayerMenu() { if (DLLDoPlayerMouselookCheck(DLLNetwork_games[gameno].flags)) { if (DLLmsn_CheckGetMission(&s_address, DLLNetwork_games[gameno].mission)) { if ((DLLTryToJoinServer(&s_address))) { - DLLmprintf(0, "Menu: Game joined!\n"); + LOG_INFO << "Menu: Game joined!"; DLLNewUIWindowClose(main_wnd); exit_menu = 1; ret = 1; @@ -627,11 +633,11 @@ int MainMultiplayerMenu() { } iaddr = inet_addr(szdip); - DLLmprintf(0, "Local inet_addr %x\n", iaddr); + LOG_INFO.printf("Local inet_addr %x", iaddr); if (iaddr && (INADDR_NONE != iaddr)) DLLSearchForLocalGamesTCP(iaddr, htons(iport)); else - DLLmprintf(0, "Invalid IP for local search\n"); + LOG_WARNING << "Invalid IP for local search"; DLLListRemoveAll(main_list); for (a = 0; a < MAX_NET_GAMES; a++) if (net_game_txt_items[a]) @@ -692,7 +698,7 @@ void AutoLoginAndJoinGame(void) { *DLLMultiGameStarting = 0; if (!*DLLAuto_login_addr) { - DLLmprintf(0, "Can't autostart because no IP address was specified!!\n"); + LOG_WARNING << "Can't autostart because no IP address was specified!!"; return; } if (*DLLAuto_login_port) { @@ -712,7 +718,7 @@ void AutoLoginAndJoinGame(void) { DLLMultiStartClient(NULL); if ((DLLTryToJoinServer(&s_address))) { - DLLmprintf(0, "Menu: Game joined!\n"); + LOG_INFO << "Menu: Game joined!"; *DLLMultiGameStarting = 1; } } diff --git a/netcon/mtclient/CMakeLists.txt b/netcon/mtclient/CMakeLists.txt index 72c04a41b..4dbaf1ee7 100644 --- a/netcon/mtclient/CMakeLists.txt +++ b/netcon/mtclient/CMakeLists.txt @@ -20,6 +20,7 @@ set_target_properties(Parallax_Online PROPERTIES OUTPUT_NAME "Parallax Online") target_link_libraries(Parallax_Online PRIVATE ddio inetfile + logger misc module ui diff --git a/netcon/mtclient/chat_api.cpp b/netcon/mtclient/chat_api.cpp index 658f107a3..72cc1e2c7 100644 --- a/netcon/mtclient/chat_api.cpp +++ b/netcon/mtclient/chat_api.cpp @@ -31,6 +31,7 @@ #include "chat_api.h" #include "crossplat.h" #include "grdefs.h" +#include "log.h" #include "mtstrings.h" #include "networking.h" @@ -48,12 +49,6 @@ extern nw_Asyncgethostbyname_fp DLLnw_Asyncgethostbyname; typedef int (*PollUI_fp)(); extern PollUI_fp DLLPollUI; -#ifndef RELEASE -#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__) -#else -#define DLLmprintf(...) -#endif - typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...); extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf; #define MAXCHATBUFFER 500 @@ -192,8 +187,7 @@ int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nicknam } while (rcode == 0); if (rcode != 1) { - DLLmprintf(0, "Unable to gethostbyname(\"%s\").\n", serveraddr); - DLLmprintf(0, "WSAGetLastError() returned %d.\n", WSAGetLastError()); + LOG_ERROR.printf("Unable to gethostbyname(\"%s\"): %d.\n", serveraddr, WSAGetLastError()); DLLnw_Asyncgethostbyname(nullptr, NW_AGHBN_CANCEL, nullptr); return 0; } @@ -209,16 +203,16 @@ int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nicknam if (EINPROGRESS == ret || 0 == ret) #endif { - DLLmprintf(0, "Beginning socket connect\n"); + LOG_INFO << "Beginning socket connect"; Socket_connecting = 1; return 0; } } else { // This should never happen, connect should always return WSAEWOULDBLOCK - DLLmprintf(0, "connect returned too soon!\n"); + LOG_WARNING << "Connect returned too soon!"; Socket_connecting = 1; Socket_connected = 1; - DLLmprintf(0, "Socket connected, sending user and nickname request\n"); + LOG_INFO << "Socket connected, sending user and nickname request"; snprintf(signon_str, sizeof(signon_str), "/USER %s %s %s :%s", "user", "user", "user", Chat_tracker_id); SendChatString(signon_str, 1); snprintf(signon_str, sizeof(signon_str), "/NICK %s", Nick_name); @@ -248,7 +242,7 @@ int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nicknam // Writable -- that means it's connected if (select(Chatsock + 1, nullptr, &write_fds, nullptr, &timeout)) { Socket_connected = 1; - DLLmprintf(0, "Socket connected, sending user and nickname request\n"); + LOG_INFO << "Socket connected, sending user and nickname request"; snprintf(signon_str, sizeof(signon_str), "/USER %s %s %s :%s", "user", "user", "user", Chat_tracker_id); SendChatString(signon_str, 1); snprintf(signon_str, sizeof(signon_str), "/NICK %s", Nick_name); @@ -260,7 +254,7 @@ int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nicknam FD_SET(Chatsock, &error_fds); // error -- that means it's not going to connect if (select(Chatsock + 1, nullptr, nullptr, &error_fds, &timeout)) { - DLLmprintf(0, "Select returned an error!\n"); + LOG_ERROR << "select() returned an error!"; return -1; } return 0; @@ -463,13 +457,12 @@ const char *ChatGetString() { if (WSAEWOULDBLOCK != lerror && 0 != lerror) #endif { - DLLmprintf(0, "recv caused an error: %d\n", lerror); + LOG_ERROR.printf("recv() caused an error: %d", lerror); } return nullptr; } if (bytesread) { ch[1] = '\0'; - // DLLmprintf(0,ch); if ((ch[0] == 0x0a) || (ch[0] == 0x0d)) { if (Input_chat_buffer[0] == '\0') { // Blank line, ignore it @@ -477,7 +470,6 @@ const char *ChatGetString() { } strcpy(return_string, Input_chat_buffer); Input_chat_buffer[0] = '\0'; - // DLLmprintf(0,"->|%s\n",return_string); p = ParseIRCMessage(return_string, MSG_REMOTE); return p; @@ -485,7 +477,7 @@ const char *ChatGetString() { strcat(Input_chat_buffer, ch); } else { // Select said we had read data, but 0 bytes read means disconnected - DLLmprintf(0, "Disconnected! Doh!"); + LOG_ERROR << "Disconnected! Doh!"; AddChatCommandToQueue(CC_DISCONNECTED, nullptr, 0); return nullptr; } @@ -931,7 +923,7 @@ char *ParseIRCMessage(char *Line, int iMode) { if (stricmp(szCmd, "376") == 0) // end of motd, trigger autojoin... { if (!Chat_server_connected) { - DLLmprintf(0, "Connected to chat server!\n"); + LOG_INFO << "Connected to chat server!"; Chat_server_connected = 1; // We want to make sure we know our nick. This is somewhat of a hack strcpy(Nick_name, GetWordNum(0, szRemLine + 1)); diff --git a/netcon/mtclient/mt_net.cpp b/netcon/mtclient/mt_net.cpp index d8c669e21..a94fef1d1 100644 --- a/netcon/mtclient/mt_net.cpp +++ b/netcon/mtclient/mt_net.cpp @@ -74,7 +74,8 @@ #endif #include -#include "pstypes.h" + +#include "log.h" #include "networking.h" #include "mtgametrack.h" #include "mt_net.h" @@ -130,17 +131,10 @@ SOCKADDR_IN ptrackaddr; SOCKADDR_IN ctrackaddr; SOCKADDR_IN sockaddr; -#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__) - #define NW_AGHBN_CANCEL 1 #define NW_AGHBN_LOOKUP 2 #define NW_AGHBN_READ 3 -// extern void DLLDebug_ConsolePrintf (int n, const char *format, ... ); -typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...); - -extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf; - typedef int (*nw_Asyncgethostbyname_fp)(uint32_t *ip, int command, const char *hostname); extern nw_Asyncgethostbyname_fp DLLnw_Asyncgethostbyname; @@ -173,12 +167,12 @@ void InitMTSockets() { #ifdef WIN32 int error = WSAStartup(ver, &ws_data); if (error != 0) { - DLLmprintf(0, "There was an error initializing networking! Error=%d\n", error); + LOG_ERROR.printf("There was an error initializing networking! Error=%d", error); return; } else #endif { - DLLmprintf(0, "Network initted successfully!\n"); + LOG_INFO << "Network initted successfully!"; } { @@ -189,7 +183,7 @@ void InitMTSockets() { gtrackaddr.sin_family = AF_INET; // This would be a good place to resolve the IP based on a domain name - DLLmprintf(0, "Looking up hostname: %s.\n", GAMETRACKERNAME); + LOG_INFO.printf("Looking up hostname: %s.", GAMETRACKERNAME); DLLnw_Asyncgethostbyname(&ip, NW_AGHBN_LOOKUP, GAMETRACKERNAME); @@ -204,8 +198,7 @@ void InitMTSockets() { } while (rcode == 0); if (rcode != 1) { - DLLmprintf(0, "Unable to gethostbyname(\"%s\").\n", GAMETRACKERNAME); - DLLmprintf(0, "WSAGetLastError() returned %d.\n", WSAGetLastError()); + LOG_ERROR.printf("Unable to gethostbyname(\"%s\"): error %d.\n", GAMETRACKERNAME, WSAGetLastError()); DLLnw_Asyncgethostbyname(nullptr, NW_AGHBN_CANCEL, nullptr); return; } @@ -220,7 +213,7 @@ void InitMTSockets() { sockaddr.sin_family = AF_INET; sockaddr.sin_addr.s_addr = INADDR_ANY; sockaddr.sin_port = 0; // htons(REGPORT); - DLLmprintf(0, "Looking up hostname: %s.\n", PILOTTRACKERNAME); + LOG_INFO.printf("Looking up hostname: %s.", PILOTTRACKERNAME); DLLnw_Asyncgethostbyname(&ip, NW_AGHBN_LOOKUP, PILOTTRACKERNAME); do { rcode = DLLnw_Asyncgethostbyname(&ip, NW_AGHBN_READ, PILOTTRACKERNAME); @@ -232,8 +225,7 @@ void InitMTSockets() { } while (rcode == 0); if (rcode != 1) { - DLLmprintf(0, "Unable to gethostbyname(\"%s\").\n", PILOTTRACKERNAME); - DLLmprintf(0, "WSAGetLastError() returned %d.\n", WSAGetLastError()); + LOG_ERROR.printf("Unable to gethostbyname(\"%s\"): error %d", PILOTTRACKERNAME, WSAGetLastError()); DLLnw_Asyncgethostbyname(nullptr, NW_AGHBN_CANCEL, nullptr); return; } @@ -248,7 +240,7 @@ void InitMTSockets() { void CloseMTSockets() { #ifdef WIN32 if (WSACleanup()) { - DLLmprintf(0, "Error closing wsock!\n"); + LOG_ERROR << "Error closing wsock!"; } #endif } diff --git a/netcon/mtclient/mtclient.cpp b/netcon/mtclient/mtclient.cpp index 84035c5d3..6ba1d19f2 100644 --- a/netcon/mtclient/mtclient.cpp +++ b/netcon/mtclient/mtclient.cpp @@ -417,6 +417,7 @@ #include "player.h" #include "game.h" #include "pilot.h" +#include "log.h" #include "ddio_common.h" #include "mt_net.h" #include "mtgametrack.h" @@ -602,9 +603,8 @@ void UpdateGamelist(void *lb) { NextGameItemNo++; PXOGamelist[j].handle = DLLNetwork_games[k].handle; PXOGamelist[j].used = true; - DLLmprintf(0, "Adding %s\n", DLLNetwork_games[k].name); + LOG_INFO.printf("Adding %s", DLLNetwork_games[k].name); - // DLLmprintf(0,"Found game: %s\n",DLLNetwork_games[k].name); FormatServerLine(fmtline, k, j); if (DLLNetwork_games[k].dedicated_server) { @@ -626,7 +626,6 @@ void UpdateGamelist(void *lb) { if (gameid != -1) { int k = gameid; - // DLLmprintf(0,"Updating %s\n",DLLNetwork_games[gameid].name); char fmtline[200]; FormatServerLine(fmtline, k, j); DLLSetUITextItemText(PXOGamelist[j].ti, fmtline, @@ -646,6 +645,7 @@ extern "C" { DLLEXPORT void DLLFUNCCALL DLLMultiInit(int *api_func); DLLEXPORT void DLLFUNCCALL DLLMultiCall(int eventnum); DLLEXPORT void DLLFUNCCALL DLLMultiClose(); +DLLEXPORT void DLLFUNCCALL DLLMultiInitLogger(plog::Severity severity, plog::IAppender* appender); } bool All_ok = true; @@ -659,12 +659,9 @@ void DLLFUNCCALL DLLMultiInit(int *api_func) { #endif CommonDLLInit(api_func); DLLPXOPort = (uint16_t)((size_t)API.vp[32] & 0xffff); - DLLmprintf(0, "Inside DLLMultiInit...\n"); *DLLUse_DirectPlay = false; Auto_start = false; - DLLmprintf(0, "About to create string table...\n"); DLLCreateStringTable("mtclient.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { All_ok = false; return; @@ -675,7 +672,7 @@ void DLLFUNCCALL DLLMultiInit(int *api_func) { // Called when the DLL is shutdown void DLLFUNCCALL DLLMultiClose() { - DLLmprintf(0, "Closing down PXO DLL\n"); + LOG_DEBUG << "Closing down PXO DLL"; DLLDestroyStringTable(StringTable, StringTableSize); DLLnw_UnRegisterCallback(PXO_NETID_USER_TRACKER); DLLnw_UnRegisterCallback(PXO_NETID_GAME_TRACKER); @@ -746,7 +743,7 @@ void DLLFUNCCALL DLLMultiCall(int eventnum) { *DLLMultiGameStarting = 0; } } else { - DLLmprintf(0, "Login failed!\n"); + LOG_ERROR << "Login failed!"; *DLLMultiGameStarting = 0; return; } @@ -815,6 +812,11 @@ void DLLFUNCCALL DLLMultiCall(int eventnum) { } } +void DLLFUNCCALL DLLMultiInitLogger(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +}; + #ifdef MACINTOSH #pragma export off #endif @@ -883,7 +885,7 @@ int LoginMasterTracker() { switch (res) { case 3: - DLLmprintf(0, "Got event 3!\n"); + LOG_DEBUG << "Got event 3!"; break; case 4: #ifdef WIN32 @@ -924,7 +926,7 @@ int LoginMasterTracker() { DLLCloseSplashScreen(); if (valret == 1) { // User was validated - DLLmprintf(0, "Mastertracker user validated!\n"); + LOG_INFO << "Mastertracker user validated!"; // Run this to make sure we properly ACK the server. for (int j = 0; j < 10; j++) PollPTrackNet(); @@ -936,7 +938,7 @@ int LoginMasterTracker() { break; } else if (valret == -1) { // User invalid! - DLLmprintf(0, "Mastertracker user not validated!\n"); + LOG_WARNING << "Mastertracker user not validated!"; DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_BADLOGIN, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); // Run this to make sure we properly ACK the server. for (int j = 0; j < 10; j++) @@ -944,7 +946,7 @@ int LoginMasterTracker() { break; } else { // timeout waiting for tracker! - DLLmprintf(0, "Mastertracker timeout!\n"); + LOG_ERROR << "Mastertracker timeout!"; DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_TIMEOUTMT, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); // Run this to make sure we properly ACK the server. for (int j = 0; j < 10; j++) @@ -1009,12 +1011,11 @@ struct { int MainMultiplayerMenu() { - DLLmprintf(0, "%d", DESCENT3_BLOCK_SIZE); if (!ShowMessageOfTheDay()) { return 0; } - DLLmprintf(0, "Inside MainMultiplayerMenu()\n"); + LOG_DEBUG << "Inside MainMultiplayerMenu()"; if (Bypass_chat && !ChatStarted) { int rcode1 = SearchMasterTrackerGameMenu(); if (rcode1 == -1) @@ -1141,7 +1142,7 @@ int MainMultiplayerMenu() { snprintf(chat_whois_info, sizeof(chat_whois_info), "%s %s", sztrackerid, pilot_name); chat_conn_time = DLLtimer_GetTime(); // DLLNewUIWindowSetFocusOnEditGadget(send_edit,main_wnd); - DLLmprintf(0, "About to connect...\n"); + LOG_DEBUG << "About to connect..."; do { chat_connected = ConnectToChatServer(CHATTRACKERNAME, CHATPORT, pilot_name, chat_whois_info); // chat_connected = ConnectToChatServer("plasma.outrage.com:7000",pilot_name,chat_whois_info); @@ -1180,7 +1181,7 @@ int MainMultiplayerMenu() { DLLNewUIWindowClose(main_wnd); goto shutdownpxo; } - DLLmprintf(0, "Connected to chat server!\n"); + LOG_INFO << "Connected to chat server!"; if (!JoinNewLobby("#autoselect")) { ret = 0; exit_menu = 1; @@ -1227,7 +1228,7 @@ int MainMultiplayerMenu() { exit_menu = 1; break; default: - DLLmprintf(0, "Warning: Received an unknown chat command!\n"); + LOG_WARNING.printf("Warning: Received an unknown chat command: %d!", cmd); break; } } @@ -1306,7 +1307,7 @@ int MainMultiplayerMenu() { if (tokp) { // Remove all previous items - DLLmprintf(0, "Refreshing channel list\n"); + LOG_DEBUG << "Refreshing channel list"; // get the text of the currently selected channel. // char * oldsel = DLLOldListGetItem(chan_list,DLLOldListGetSelectedIndex(chan_list)); // @@ -1432,9 +1433,8 @@ int MainMultiplayerMenu() { case 3: // Join Mastertracker game { - DLLmprintf(0, "Sending Mastertracker game list request.\n"); + LOG_DEBUG << "Sending Mastertracker game list request."; RequestGameList(); - DLLmprintf(0, "Calling SearchMasterTrackerGameMenu().\n"); DLLNewUIWindowClose(main_wnd); *DLLGame_is_master_tracker_game = 1; int gamestart = SearchMasterTrackerGameMenu(); @@ -1471,7 +1471,7 @@ int MainMultiplayerMenu() { case 6: // Send a private message // Create new dialog box, prompt for user and message, then send message - DLLmprintf(0, "Sending private Message\n"); + LOG_DEBUG << "Sending private Message"; // Get the currently selected pilot name strcpy(selpilot, DLLOldListGetItem(user_list, DLLOldListGetSelectedIndex(user_list))); SendWhisper(selpilot); @@ -1489,19 +1489,18 @@ int MainMultiplayerMenu() { break; case 9: // Find a pilot - DLLmprintf(0, "Finding a pilot\n"); + LOG_DEBUG << "Finding a pilot"; FindPilot(); break; case 10: // Get pilot stats - DLLmprintf(0, "Getting pilot statistics\n"); + LOG_DEBUG << "Getting pilot statistics"; strcpy(selpilot, DLLOldListGetItem(user_list, DLLOldListGetSelectedIndex(user_list))); GetPilotStats(selpilot); break; case 11: { - DLLmprintf(0, "Sending Mastertracker game list request.\n"); + LOG_DEBUG << "Sending Mastertracker game list request."; RequestGameList(); - DLLmprintf(0, "Calling SearchMasterTrackerGameMenu().\n"); DLLNewUIWindowClose(main_wnd); *DLLGame_is_master_tracker_game = 1; int gamestart = SearchMasterTrackerGameMenu(); @@ -1518,10 +1517,9 @@ int MainMultiplayerMenu() { } break; case 14: // Channel list box - DLLmprintf(0, "Joining new public channel\n"); + LOG_DEBUG << "Joining new public channel"; { int selitem = 0; - DLLmprintf(0, "Joining new public channel\n"); selitem = DLLOldListGetSelectedIndex(chan_list); if (!JoinNewLobby(chan_info[selitem].origname)) { ret = 0; @@ -1573,10 +1571,9 @@ int MainMultiplayerMenu() { user_ti[i] = nullptr; } *DLLNewUIWindow_alpha = oldalpha; - DLLmprintf(0, "Disconnecting from PXO.\n"); + LOG_INFO << "Disconnecting from PXO."; DisconnectFromChatServer(); ChatStarted = 0; - DLLmprintf(0, "Disconnected.\n"); DLLToggleUICallback(1); // Delete all those items we created @@ -1842,7 +1839,7 @@ int SearchMasterTrackerGameMenu() { last_req_time = DLLtimer_GetTime(); RequestGameList(); *DLLNum_network_games_known = 0; - DLLmprintf(0, "Waiting for Mastertracker response.\n"); + LOG_INFO << "Waiting for Mastertracker response."; // Menu loop while (!exit_menu) { @@ -1854,14 +1851,13 @@ int SearchMasterTrackerGameMenu() { games = GetGameList(); res = DLLPollUI(); if (games) { - // DLLmprintf(0,"GetGameList() returned a gamedata.\n"); for (i = 0; i < (MAX_GAME_LISTS_PER_PACKET * 4); i++) { // char *gn = games->game_name[i]; if (games->game_type == GT_D3TNG) { DLLSearchForGamesPXO(games->game_server[i], games->game_port[i]); } else { if (games->game_server[i] && games->game_port[i]) { - DLLmprintf(0, "Bad bad bad!!!!\n"); + LOG_WARNING << "Bad bad bad!!!!"; DLLSearchForGamesPXO(games->game_server[i], games->game_port[i]); } } @@ -1910,7 +1906,7 @@ int SearchMasterTrackerGameMenu() { break; gameno = gameid; - DLLmprintf(0, "Selected item is %s\n", DLLNetwork_games[gameno].name); + LOG_DEBUG.printf("Selected item is %s", DLLNetwork_games[gameno].name); network_address s_address; s_address.connection_type = NP_TCP; @@ -1926,7 +1922,7 @@ int SearchMasterTrackerGameMenu() { // Check to see if this mission exists! if (DLLmsn_CheckGetMission(&s_address, DLLNetwork_games[gameno].mission)) { if ((DLLTryToJoinServer(&s_address))) { - DLLmprintf(0, "Menu: Game joined!\n"); + LOG_INFO << "Menu: Game joined!"; DLLNewUIWindowClose(main_wnd); exit_menu = 1; ret = 1; @@ -2000,38 +1996,32 @@ int SearchMasterTrackerGameMenu() { gameno = gameid; if (gameid == -1) break; - DLLmprintf(0, "Selected item is %s\n", DLLNetwork_games[gameno].name); + LOG_INFO.printf("Selected item is %s", DLLNetwork_games[gameno].name); DLLShowNetgameInfo(&DLLNetwork_games[gameno]); } } break; case SORT_GAMENAME: { - DLLmprintf(0, "Sorting by game name.\n"); invert_sort_gamename = !invert_sort_gamename; ResortGameList(game_list, res, invert_sort_gamename); } break; case SORT_GAMETYPE: { - DLLmprintf(0, "Sorting by game type.\n"); invert_sort_gametype = !invert_sort_gametype; ResortGameList(game_list, res, invert_sort_gametype); } break; case SORT_MISSION: { - DLLmprintf(0, "Sorting by mission.\n"); invert_sort_mission = !invert_sort_mission; ResortGameList(game_list, res, invert_sort_mission); } break; case SORT_LEVEL: { - DLLmprintf(0, "Sorting by level.\n"); invert_sort_levels = !invert_sort_levels; ResortGameList(game_list, res, invert_sort_levels); } break; case SORT_PLAYERS: { - DLLmprintf(0, "Sorting by players.\n"); invert_sort_players = !invert_sort_players; ResortGameList(game_list, res, invert_sort_players); } break; case SORT_PING: { - DLLmprintf(0, "Sorting by ping.\n"); invert_sort_ping = !invert_sort_ping; ResortGameList(game_list, res, invert_sort_ping); } break; @@ -2158,13 +2148,13 @@ void DoMTFrame() { if (rcode == 1) { // Copy data from the DLLMTPilotinfo[MTReadingPilot] struct here DLLMNetPlayers[MTWritingPilot].flags &= ~NPF_MT_WRITING_PILOT; - DLLmprintf(0, "Pilot data wrote to the Mastertracker for Player[%d] %s (tid=%s).\n", MTWritingPilot, + LOG_DEBUG.printf("Pilot data wrote to the Mastertracker for Player[%d] %s (tid=%s).", MTWritingPilot, DLLMTPilotinfo[MTWritingPilot].pilot_name, DLLMTPilotinfo[MTWritingPilot].tracker_id); MTWritingPilot = -1; } else { DLLMNetPlayers[MTWritingPilot].flags &= ~NPF_MT_WRITING_PILOT; - DLLmprintf(0, "Pilot write to the mastertracker failed. Error code %d.\n", rcode); + LOG_WARNING.printf("Pilot write to the mastertracker failed. Error code %d.", rcode); MTWritingPilot = -1; } } @@ -2181,7 +2171,7 @@ void DoMTFrame() { DLLMTPilotinfo[i].deaths = DLLMPlayers[i].deaths; DLLMTPilotinfo[i].suicides = DLLMPlayers[i].suicides; DLLMTPilotinfo[i].rank = (DLLMPlayers[i].rank * 65536.0); - DLLmprintf(0, "Sending pilot %d rank of %f\n", i, DLLMTPilotinfo[i].rank / 65536.0); + LOG_INFO.printf("Sending pilot %d rank of %f", i, DLLMTPilotinfo[i].rank / 65536.0); DLLMTPilotinfo[i].lateral_thrust = DLLMPlayers[i].lateral_thrust; DLLMTPilotinfo[i].rotational_thrust = DLLMPlayers[i].rotational_thrust; @@ -2189,7 +2179,7 @@ void DoMTFrame() { DLLMTPilotinfo[i].sliding_pct = 0; // FIXME DLLMPlayers[i].time_in_game = DLLtimer_GetTime(); // when we write this data multiple times we need this - DLLmprintf(0, "Sending User info to the Mastertracker for Player[%d] %s (tid=%s).\n", i, + LOG_INFO.printf("Sending User info to the Mastertracker for Player[%d] %s (tid=%s).", i, DLLMTPilotinfo[i].pilot_name, DLLMTPilotinfo[i].tracker_id); SendD3PilotData(&DLLMTPilotinfo[i]); @@ -2200,7 +2190,7 @@ void DoMTFrame() { // If we never read this pilot's stats, we really don't care what they were. DLLMNetPlayers[i].flags &= ~NPF_MT_READING_PILOT; DLLMNetPlayers[i].flags &= ~NPF_MT_WRITING_PILOT; - DLLmprintf(0, "Didn't write Mastertracker stats for %s because we never received any from the tracker!\n", + LOG_WARNING.printf("Didn't write Mastertracker stats for %s because we never received any from the tracker!", DLLMPlayers[i].callsign); } } @@ -2219,7 +2209,7 @@ void DoMTFrame() { DLLMPlayers[MTReadingPilot].deaths = DLLMTPilotinfo[MTReadingPilot].deaths; DLLMPlayers[MTReadingPilot].suicides = DLLMTPilotinfo[MTReadingPilot].suicides; DLLMPlayers[MTReadingPilot].rank = DLLMTPilotinfo[MTReadingPilot].rank / 65536.0; - DLLmprintf(0, "Read pilot %s rank of %f\n", DLLMPlayers[MTReadingPilot].callsign, + LOG_DEBUG.printf("Read pilot %s rank of %f", DLLMPlayers[MTReadingPilot].callsign, DLLMPlayers[MTReadingPilot].rank); DLLMPlayers[MTReadingPilot].lateral_thrust = DLLMTPilotinfo[MTReadingPilot].lateral_thrust; DLLMPlayers[MTReadingPilot].rotational_thrust = DLLMTPilotinfo[MTReadingPilot].rotational_thrust; @@ -2227,12 +2217,12 @@ void DoMTFrame() { // Something = DLLMTPilotinfo[i].sliding_pct;//FIXME DLLMNetPlayers[MTReadingPilot].flags |= NPF_MT_HAS_PILOT_DATA; - DLLmprintf(0, "Pilot data received from the Mastertracker for Player[%d] %s (tid=%s).\n", MTReadingPilot, + LOG_DEBUG.printf("Pilot data received from the Mastertracker for Player[%d] %s (tid=%s).", MTReadingPilot, DLLMTPilotinfo[MTReadingPilot].pilot_name, DLLMTPilotinfo[MTReadingPilot].tracker_id); MTReadingPilot = -1; } else { // DLLMNetPlayers[MTReadingPilot].flags &= ~NPF_MT_READING_PILOT; - DLLmprintf(0, "Pilot read from mastertracker failed. Error code %d.\n", rcode); + LOG_WARNING.printf("Pilot read from mastertracker failed. Error code %d.", rcode); MTReadingPilot = -1; } } @@ -2241,7 +2231,7 @@ void DoMTFrame() { for (i = 0; i < MAX_NET_PLAYERS; i++) { if (DLLMNetPlayers[i].flags & NPF_MT_READING_PILOT) { MTReadingPilot = i; - DLLmprintf(0, "Requesting User info from the Mastertracker for Player[%d] %s (tid=%s).\n", i, + LOG_DEBUG.printf("Requesting User info from the Mastertracker for Player[%d] %s (tid=%s).", i, DLLMTPilotinfo[i].pilot_name, DLLMTPilotinfo[i].tracker_id); GetD3PilotData(&DLLMTPilotinfo[i], DLLMPlayers[i].callsign, DLLMPlayers[i].tracker_id); CheckPXOForAnomalies(); @@ -2277,9 +2267,9 @@ void DoMTGameOver(void) { DLLMTPilotinfo[i].rotational_thrust = DLLMPlayers[i].rotational_thrust; DLLMTPilotinfo[i].online_time += DLLtimer_GetTime() - DLLMPlayers[i].time_in_game; DLLMTPilotinfo[i].sliding_pct = 0; // FIXME - DLLmprintf(0, "Sending User info to the Mastertracker for Player[%d] %s (tid=%s).\n", i, + LOG_DEBUG.printf("Sending User info to the Mastertracker for Player[%d] %s (tid=%s).", i, DLLMTPilotinfo[i].pilot_name, DLLMTPilotinfo[i].tracker_id); - DLLmprintf(0, "Sending pilot %d rank of %f\n", i, DLLMTPilotinfo[i].rank / 65536.0); + LOG_DEBUG.printf("Sending pilot %d rank of %f", i, DLLMTPilotinfo[i].rank / 65536.0); SendD3PilotData(&DLLMTPilotinfo[i]); while (SendD3PilotData(nullptr) == 0) { DLLDescentDefer(); @@ -2296,7 +2286,7 @@ void DoMTGameOver(void) { int JoinNewLobby(const char *lobby) { int rcode; const char *p; - DLLmprintf(0, "Entering new lobby"); + LOG_INFO << "Entering new lobby"; auto title_text = DLLCreateNewUITextItem(TXT_PXO_ENTERINGLOBBY, UICOL_WINDOW_TITLE); auto cancel_on_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_HI); @@ -2323,7 +2313,7 @@ int JoinNewLobby(const char *lobby) { strcpy(DLLPXO_hosted_lobby_name, lobby); return 1; } else { - DLLmprintf(0, "Unable to join lobby: %d\n", rcode); + LOG_WARNING.printf("Unable to join lobby: %d", rcode); char txtmessage[200]; char cleanlobby[50]; memset(cleanlobby, 0, 29); @@ -2725,7 +2715,7 @@ int GetPilotStats(const char *pilot) { } } if (p == (char *)-1) { - DLLmprintf(0, "Timeout looking for user\n"); + LOG_WARNING << "Timeout looking for user"; DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_TIMEOUTMT, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); DLLCloseSplashScreen(); return 0; @@ -2736,7 +2726,7 @@ int GetPilotStats(const char *pilot) { tokp++; strcpy(tid, p); strcpy(real_pilot, tokp); - DLLmprintf(0, "Requesting pilot info for %s %s\n", tid, real_pilot); + LOG_DEBUG.printf("Requesting pilot info for %s %s", tid, real_pilot); memset(&d3_pilot_info, 0, sizeof(vmt_descent3_struct)); GetD3PilotData(&d3_pilot_info, real_pilot, tid); int iresult = 0; @@ -2757,7 +2747,7 @@ int GetPilotStats(const char *pilot) { } } if (iresult == 1) { - DLLmprintf(0, "Got pilot info for %s %s\n", tid, real_pilot); + LOG_DEBUG.printf("Got pilot info for %s %s", tid, real_pilot); // Do rank thingy here. snprintf(tmp_text, sizeof(tmp_text), "Rank: %s (%d) Next Advance at %d", @@ -2871,7 +2861,7 @@ void AutoLoginAndJoinGame() { DLLDatabaseRead("TrackerLogin", szloginid, &loginlen); DLLDatabaseRead("TrackerPassword", szpassword, &passlen); if (!*DLLAuto_login_addr) { - DLLmprintf(0, "Can't autostart because no IP address was specified!!\n"); + LOG_ERROR << "Can't autostart because no IP address was specified!!"; *DLLMultiGameStarting = 0; goto failed_login; } @@ -2901,18 +2891,18 @@ void AutoLoginAndJoinGame() { } if (valret == 1) { // User was validated - DLLmprintf(0, "Mastertracker user validated!\n"); + LOG_INFO << "Mastertracker user validated!"; strcpy(DLLTracker_id, sztrackerid); strcpy(DLLMPlayers[DLLPlayer_num].tracker_id, sztrackerid); } else if (valret == -1) { // User invalid! - DLLmprintf(0, "Mastertracker user not validated!\n"); + LOG_WARNING << "Mastertracker user not validated!"; DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_BADLOGIN, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); goto failed_login; } else { // timeout waiting for tracker! - DLLmprintf(0, "Mastertracker timeout!\n"); + LOG_WARNING << "Mastertracker timeout!"; DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_TIMEOUTMT, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL); goto failed_login; } @@ -2928,7 +2918,7 @@ void AutoLoginAndJoinGame() { DLLMultiStartClient(nullptr); if ((DLLTryToJoinServer(&s_address))) { - DLLmprintf(0, "Menu: Game joined!\n"); + LOG_DEBUG << "Menu: Game joined!"; *DLLMultiGameStarting = 1; } @@ -2970,20 +2960,20 @@ void AutoLoginAndStartGame() { } if (valret == 1) { // User was validated - DLLmprintf(0, "Mastertracker user validated!\n"); - DLLPrintDedicatedMessage("Mastertracker user validated.\n"); + LOG_INFO << "Mastertracker user validated!"; + DLLPrintDedicatedMessage("Mastertracker user validated."); strcpy(DLLTracker_id, sztrackerid); strcpy(DLLMPlayers[DLLPlayer_num].tracker_id, sztrackerid); } else if (valret == -1) { // User invalid! - DLLmprintf(0, "Mastertracker user not validated!\n"); - DLLPrintDedicatedMessage("Mastertracker user not validated!\n"); + LOG_WARNING << "Mastertracker user not validated!"; + DLLPrintDedicatedMessage("Mastertracker user not validated!"); goto failed_login; } else { // timeout waiting for tracker! - DLLmprintf(0, "Mastertracker timeout!\n"); - DLLPrintDedicatedMessage("Mastertracker timeout!\n"); + LOG_WARNING << "Mastertracker timeout!"; + DLLPrintDedicatedMessage("Mastertracker timeout!"); goto failed_login; } @@ -3018,7 +3008,7 @@ int ShowMessageOfTheDay(void) { if (Motd_version == last_motd_version) { // MOTD is old.... - DLLmprintf(0, "MOTD is old, skipping\n"); + LOG_DEBUG << "MOTD is old, skipping"; return 1; } @@ -3038,7 +3028,7 @@ int ShowMessageOfTheDay(void) { DLLDatabaseRead("LastMOTD", szlastmotd, &motdlen); - DLLmprintf(0, "Getting message of the day...\n"); + LOG_INFO << "Getting message of the day..."; DLLCreateSplashScreen(TXT_PXO_CONNECTING, 1); int mcode = GetD3MOTD(sznewmotd, MAX_MOTD_LEN); do { @@ -3055,7 +3045,7 @@ int ShowMessageOfTheDay(void) { DLLCloseSplashScreen(); if (mcode == 1) { - DLLmprintf(0, "Message of the day: %s\n", sznewmotd); + LOG_INFO.printf("Message of the day: %s", sznewmotd); if (strcmp(szlastmotd, sznewmotd) != 0) { DLLNewUIGameWindowOpen(main_wnd); DLLUIConsoleGadgetputs(console_item, sznewmotd); @@ -3068,17 +3058,17 @@ int ShowMessageOfTheDay(void) { rval = 1; goto close_motd; } else { - DLLmprintf(0, "Message of the day is old, ignoring!\n"); + LOG_DEBUG << "Message of the day is old, ignoring!"; rval = 1; goto close_motd; } } else { - DLLmprintf(0, "Get message of the day failed (%d)!\n", mcode); + LOG_WARNING.printf("Get message of the day failed (%d)!", mcode); goto close_motd; } close_motd: - DLLmprintf(0, "Ending motd\n"); + LOG_DEBUG << "Ending motd"; DLLNewUIGameWindowDestroy(main_wnd); DLLRemoveUITextItem(motd_text); DLLRemoveUITextItem(close_on_text); diff --git a/netcon/mtclient/mtgametrack.cpp b/netcon/mtclient/mtgametrack.cpp index dd73f889a..c1328cfdc 100644 --- a/netcon/mtclient/mtgametrack.cpp +++ b/netcon/mtclient/mtgametrack.cpp @@ -124,6 +124,7 @@ #include "networking.h" #include "mtgametrack.h" #include "byteswap.h" +#include "log.h" #include "mt_net.h" // extern float DLLtimer_GetTime(void); @@ -142,16 +143,6 @@ extern nw_DoReceiveCallbacks_fp DLLnw_DoReceiveCallbacks; typedef int (*nw_SendWithID_fp)(uint8_t id, uint8_t *data, int len, network_address *who_to); extern nw_SendWithID_fp DLLnw_SendWithID; -#if (defined(LOGGER) && (!defined(RELEASE))) -#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__) -#else -#define DLLmprintf(...) -#endif - -typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...); - -extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf; - // Variables game_list GameBuffer[MAX_GAME_BUFFERS]; @@ -225,7 +216,6 @@ int InitGameTrackerClient(int gametype) { void IdleGameTracker() { DLLnw_DoReceiveCallbacks(); // uint32_t bytesin; - // mprintf(0,"IdleGameTracker() entered.\n"); if ((TrackerGameIsRunning) && ((DLLtimer_GetTime() - LastTrackerUpdate) > TRACKER_UPDATE_INTERVAL)) { struct tm *newtime; @@ -233,7 +223,7 @@ void IdleGameTracker() { time(&aclock); /* Get time in seconds */ newtime = localtime(&aclock); // Time to update the tracker again - DLLmprintf(0, "[%.24s] Updating the PXO game tracker!\n", asctime(newtime)); + LOG_INFO.printf("[%.24s] Updating the PXO game tracker!", asctime(newtime)); SendGameTrackerPacker(&TrackerGameData); // sendto(gamesock,(const char *)&TrackerGameData,TrackerGameData.len,0,(SOCKADDR //*)>rackaddr,sizeof(SOCKADDR_IN)); @@ -249,7 +239,7 @@ void IdleGameTracker() { time(&aclock); /* Get time in seconds */ newtime = localtime(&aclock); // Time to update the tracker again - DLLmprintf(0, "[%.24s] (Resending) Updating the PXO game tracker!\n", asctime(newtime)); + LOG_INFO.printf("[%.24s] (Resending) Updating the PXO game tracker!", asctime(newtime)); SendGameTrackerPacker(&TrackerGameData); TrackerAckdUs = 0; @@ -302,10 +292,9 @@ void HandleGamePacket(uint8_t *data, int len, network_address *from) { break; case GNT_GAMELIST_LITE_DATA: if (len < (GAME_HEADER_ONLY_SIZE + sizeof(game_list))) { - DLLmprintf(0, "(%d) packet is too small!\n", len); + LOG_WARNING.printf("(%d) packet is too small!", len); } // Woohoo! Game data! put it in the buffer (if one's free) - // DLLmprintf(0,"GNT_GAMELIST_LITE_DATA received.\n"); for (int i = 0; i < MAX_GAME_BUFFERS; i++) { if (GameBuffer[i].game_type == GT_UNUSED) { memset(&GameBuffer[i], 0, sizeof(game_list)); @@ -329,7 +318,6 @@ void HandleGamePacket(uint8_t *data, int len, network_address *from) { } break; } - // mprintf(0,"Sending ACK.\n"); AckPacket(inpacket.sig); } } @@ -408,7 +396,7 @@ void StartTrackerGame(void *buffer) { time(&aclock); /* Get time in seconds */ newtime = localtime(&aclock); // Time to update the tracker again - DLLmprintf(0, "[%.24s] Updating the PXO game tracker with a new game!\n", asctime(newtime)); + LOG_INFO.printf("[%.24s] Updating the PXO game tracker with a new game!", asctime(newtime)); if (GameType == GT_FREESPACE) { // memcpy(FreeSpaceTrackerGameData,buffer,sizeof(freespace_net_game_data)); diff --git a/netcon/mtclient/mtpilottracker.cpp b/netcon/mtclient/mtpilottracker.cpp index 25e7cf805..9db44acca 100644 --- a/netcon/mtclient/mtpilottracker.cpp +++ b/netcon/mtclient/mtpilottracker.cpp @@ -154,12 +154,6 @@ struct vmt_descent3_struct { #include "mtpilottrack.h" -#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__) - -typedef void (*Debug_ConsolePrintf_fp)(int n, const char *format, ...); - -extern Debug_ConsolePrintf_fp DLLDebug_ConsolePrintf; - typedef float (*timer_GetTime_fp)(); extern timer_GetTime_fp DLLtimer_GetTime; From 87affb656169a43f9da84e6f9a8e623e6ec22acf Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Tue, 3 Jun 2025 18:53:53 +0300 Subject: [PATCH 2/2] Enable logging for netgames modules Implementing chained appender initialization scenario for plog. # Conflicts: # netgames/dmfc/dmfcbase.cpp --- Descent3/Game2DLL.cpp | 29 ++- netgames/anarchy/Anarchy.h | 2 + netgames/anarchy/anarchy.cpp | 12 +- netgames/coop/coop.cpp | 12 +- netgames/coop/coop.h | 2 + netgames/ctf/ctf.cpp | 50 ++--- netgames/ctf/ctf.h | 2 + netgames/dmfc/CMakeLists.txt | 1 + netgames/dmfc/dmfcbase.cpp | 259 ++++++++++++++----------- netgames/dmfc/dmfccfg.cpp | 20 +- netgames/dmfc/dmfcclient.cpp | 37 ++-- netgames/dmfc/dmfchudmessages.cpp | 5 +- netgames/dmfc/dmfcinputcommand.cpp | 10 +- netgames/dmfc/dmfcinternal.h | 5 - netgames/dmfc/dmfcmenu.cpp | 38 ++-- netgames/dmfc/dmfcprecord.cpp | 8 +- netgames/dmfc/dmfcremote.cpp | 18 +- netgames/dmfc/dmfcserver.cpp | 4 +- netgames/dmfc/dmfcui.cpp | 12 +- netgames/dmfc/dmfcvirtual.cpp | 3 +- netgames/entropy/Entropy.h | 2 + netgames/entropy/EntropyBase.cpp | 18 +- netgames/entropy/EntropyRoom.cpp | 2 +- netgames/hoard/Hoard.h | 2 + netgames/hoard/hoard.cpp | 20 +- netgames/hyperanarchy/HyperAnarchy.h | 2 + netgames/hyperanarchy/hyperanarchy.cpp | 25 +-- netgames/includes/DMFC.h | 11 +- netgames/monsterball/monsterball.cpp | 22 ++- netgames/monsterball/monsterball.h | 2 + netgames/roboanarchy/roboAnarchy.h | 2 + netgames/roboanarchy/roboanarchy.cpp | 12 +- netgames/tanarchy/tanDMFC.h | 2 + netgames/tanarchy/tanarchy.cpp | 18 +- 34 files changed, 380 insertions(+), 289 deletions(-) diff --git a/Descent3/Game2DLL.cpp b/Descent3/Game2DLL.cpp index 959c1a121..0e32825b3 100644 --- a/Descent3/Game2DLL.cpp +++ b/Descent3/Game2DLL.cpp @@ -97,6 +97,7 @@ typedef void DLLFUNCCALL (*DLLGameClose_fp)(); typedef void DLLFUNCCALL (*DLLGameGetName_fp)(char *buffer, int maxsize); typedef void DLLFUNCCALL (*DLLGameGetDesc_fp)(char **buffer, int maxsize, int lines); typedef void DLLFUNCCALL (*DLLGetGameInfo_fp)(tDLLOptions *options); +typedef void DLLFUNCCALL (*DLLLoggerInit_fp)(plog::Severity severity, plog::IAppender* appender); #else typedef void(DLLFUNCCALL *DLLGameCall_fp)(int eventnum, dllinfo *data); typedef void(DLLFUNCCALL *DLLGameInit_fp)(int *api_func, uint8_t *all_ok, int num_teams_to_use); @@ -104,11 +105,13 @@ typedef void(DLLFUNCCALL *DLLGameClose_fp)(); typedef void(DLLFUNCCALL *DLLGameGetName_fp)(char *buffer, int maxsize); typedef void(DLLFUNCCALL *DLLGameGetDesc_fp)(char **buffer, int maxsize, int lines); typedef void(DLLFUNCCALL *DLLGetGameInfo_fp)(tDLLOptions *options); +typedef void(DLLFUNCCALL *DLLLoggerInit_fp)(plog::Severity severity, plog::IAppender* appender); #endif -DLLGameCall_fp DLLGameCall = NULL; -DLLGameInit_fp DLLGameInit = NULL; -DLLGameClose_fp DLLGameClose = NULL; -DLLGetGameInfo_fp DLLGetGameInfo = NULL; +DLLGameCall_fp DLLGameCall = nullptr; +DLLGameInit_fp DLLGameInit = nullptr; +DLLGameClose_fp DLLGameClose = nullptr; +DLLGetGameInfo_fp DLLGetGameInfo = nullptr; +DLLLoggerInit_fp DLLLoggerInit = nullptr; dllinfo DLLInfo; tOSIRISModuleInit Multi_d3m_osiris_funcs; std::filesystem::path Multi_game_dll_name; @@ -606,10 +609,11 @@ void FreeGameDLL() { DLLGameClose(); Osiris_UnloadMissionModule(); CloseGameModule(&GameDLLHandle); - DLLGameCall = NULL; - DLLGameInit = NULL; - DLLGameClose = NULL; - DLLGetGameInfo = NULL; + DLLGameCall = nullptr; + DLLGameInit = nullptr; + DLLGameClose = nullptr; + DLLGetGameInfo = nullptr; + DLLLoggerInit = nullptr; } // Loads the game dll. Returns 1 on success, else 0 on failure int LoadGameDLL(const char *name, int num_teams_to_use) { @@ -676,6 +680,15 @@ int LoadGameDLL(const char *name, int num_teams_to_use) { FreeGameDLL(); return 0; } + // Clear out error queue + mod_GetLastError(); + DLLLoggerInit = (DLLLoggerInit_fp)mod_GetSymbol(&GameDLLHandle, "DLLLoggerInit", 12); + if (!DLLLoggerInit) { + LOG_WARNING << "Couldn't get a handle to the dll function DLLLoggerInit!"; + } else { + DLLLoggerInit(plog::get()->getMaxSeverity(), plog::get()); + } + if (first) { // Jeff: Linux for some reason dies if you try to // free a DLL/so on atexit, they should be freed diff --git a/netgames/anarchy/Anarchy.h b/netgames/anarchy/Anarchy.h index f5be6e47a..6a9f9b0cb 100644 --- a/netgames/anarchy/Anarchy.h +++ b/netgames/anarchy/Anarchy.h @@ -43,6 +43,7 @@ #include "osiris_share.h" #include "d3events.h" +#include "log.h" // Setup and processing functions void AnarchyGameInit(int teams); @@ -80,6 +81,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/anarchy/anarchy.cpp b/netgames/anarchy/anarchy.cpp index 54f9a00a8..b3b86bbf0 100644 --- a/netgames/anarchy/anarchy.cpp +++ b/netgames/anarchy/anarchy.cpp @@ -78,7 +78,7 @@ static bool display_my_welcome = false; static void DisplayHUDScores(struct tHUDItem *hitem); static void DisplayScores(void); static void DisplayWelcomeMessage(int player_num); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const char *filename); static void SwitchHUDColor(int i); static void SwitchAnarchyScores(int i); static const char *GetString(int d); @@ -160,7 +160,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us DMFCBase->Set_OnPrintScores(OnPrintScores); DLLCreateStringTable("Anarchy.str", &StringTable, &StringTableSize); - mprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { *all_ok = 0; return; @@ -229,6 +228,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size) { player_record *pr = DMFCBase->GetPlayerRecord(precord_num); if (!pr || pr->state == STATE_EMPTY) { @@ -546,11 +550,11 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const char *filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { - mprintf(0, "Unable to open output file\n"); + LOG_ERROR << "Unable to open output file"; return; } diff --git a/netgames/coop/coop.cpp b/netgames/coop/coop.cpp index f055e2edd..a81407b69 100644 --- a/netgames/coop/coop.cpp +++ b/netgames/coop/coop.cpp @@ -216,7 +216,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us dPlayers = DMFCBase->GetPlayers(); DLLCreateStringTable("Coop.str", &StringTable, &StringTableSize); - mprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { *all_ok = 0; return; @@ -314,6 +313,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + void OnHUDInterval(void) { dstat->DoFrame(); DMFCBase->DisplayOutrageLogo(); @@ -525,7 +529,7 @@ void OnClientObjectKilled(object *obj, object *killer) { DLLGetUltimateParentForObject(&parent, killer); if ((parent->type != OBJ_PLAYER) && (parent->type != OBJ_OBSERVER)) { - mprintf(0, "Robot killed wasn't by a OBJ_PLAYER or OBJ_OBSERVER (%d)\n", parent->type); + LOG_WARNING.printf("Robot killed wasn't by a OBJ_PLAYER or OBJ_OBSERVER (%d)", parent->type); return; } @@ -533,7 +537,7 @@ void OnClientObjectKilled(object *obj, object *killer) { player_record *pr = DMFCBase->GetPlayerRecordByPnum(killer_pnum); if (!pr) { - mprintf(0, "Invalid player record!\n"); + LOG_FATAL << "Invalid player record!"; Int3(); return; } @@ -543,7 +547,7 @@ void OnClientObjectKilled(object *obj, object *killer) { stat->Score[DSTAT_LEVEL]++; stat->Score[DSTAT_OVERALL]++; - mprintf(0, "%s's score is now %d\n", dPlayers[killer_pnum].callsign, stat->Score[DSTAT_LEVEL]); + LOG_INFO.printf("%s's score is now %d", dPlayers[killer_pnum].callsign, stat->Score[DSTAT_LEVEL]); DMFCBase->OnClientObjectKilled(obj, killer); } diff --git a/netgames/coop/coop.h b/netgames/coop/coop.h index 4c2c36480..2e5ba6036 100644 --- a/netgames/coop/coop.h +++ b/netgames/coop/coop.h @@ -62,6 +62,7 @@ #include "osiris_share.h" #include "d3events.h" +#include "log.h" void OnHUDInterval(void); void OnInterval(void); @@ -89,6 +90,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/ctf/ctf.cpp b/netgames/ctf/ctf.cpp index c3b1779ce..4b60f7ae3 100644 --- a/netgames/ctf/ctf.cpp +++ b/netgames/ctf/ctf.cpp @@ -238,7 +238,7 @@ const char *GetString(int d) { else return StringTable[d]; } -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const char *filename); static void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size); static void ShowStatBitmap(int precord_num, int column_num, int x, int y, int w, int h, uint8_t alpha_to_use); @@ -352,7 +352,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us DMFCBase->GameInit(CTFNumOfTeams); DLLCreateStringTable("CTF.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { *all_ok = 0; return; @@ -568,6 +567,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + ///////////////////////////////////////////////////////////// // DMFC Overrides @@ -782,7 +786,7 @@ void OnClientLevelStart(void) { if ((flagid != -1) && (goalroom >= 0) && (goalroom <= DMFCBase->GetHighestRoomIndex()) && (!ROOMNUM_OUTSIDE(goalroom)) && (dRooms[goalroom].used)) { // Safe to create the flag - DLLmprintf(0, "Creating %s Flag\n", DMFCBase->GetTeamString(i)); + LOG_INFO.printf("Creating %s Flag", DMFCBase->GetTeamString(i)); DLLComputeRoomCenter(&vpos, &dRooms[goalroom]); objnum = DLLObjCreate(OBJ_POWERUP, flagid, goalroom, &vpos, NULL, OBJECT_HANDLE_NONE); DLLMultiSendObject(&dObjects[objnum], 0, true); @@ -1027,7 +1031,7 @@ void OnClientCollide(uint8_t *data) { if (DMFCBase->GetScoreLimit(&killgoal)) { if (TeamScores[pteam] >= killgoal) { // That's all she wrote for this level - DLLmprintf(0, "OnClientCollide:Kill Goal Reached!\n"); + LOG_INFO << "OnClientCollide:Kill Goal Reached!"; DMFCBase->EndLevel(); } } @@ -1380,11 +1384,11 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const char *filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { - DLLmprintf(0, "Unable to open output file\n"); + LOG_WARNING << "Unable to open output file"; return; } @@ -2158,7 +2162,7 @@ bool AddFlagToPlayer(int pnum, int team, int flagobjnum) { if (!ret) { // couldn't attach the flag - mprintf(0, "CTF: COULDN'T ATTACH FLAG TO PLAYER, DELETING\n"); + LOG_WARNING << "CTF: COULDN'T ATTACH FLAG TO PLAYER, DELETING"; // tell the clients to remove this flag DLLSetObjectDeadFlag(&dObjects[flagobjnum], true, false); } @@ -2166,7 +2170,7 @@ bool AddFlagToPlayer(int pnum, int team, int flagobjnum) { if (flagobjnum == -1) { // there was an error creating the flag...not good - mprintf(0, "CTF: Couldn't create/unhash flag for attachment\n"); + LOG_WARNING << "CTF: Couldn't create/unhash flag for attachment"; DMFCBase->DisconnectMe(); return false; } @@ -2426,7 +2430,7 @@ void ReceiveGameState(uint8_t *data) { if (our_objnum == -1) { // fatal error - mprintf(0, "CTF: Local Objnums don't match server objnums\n"); + LOG_ERROR << "CTF: Local Objnums don't match server objnums"; ChildFlags[i] = OBJECT_HANDLE_NONE; DMFCBase->DisconnectMe(); } else { @@ -2435,7 +2439,7 @@ void ReceiveGameState(uint8_t *data) { AddFlagToPlayer(HasFlag[i], i, our_objnum); else { // hmm, HasFlag doesn't match ChildFlags - mprintf(0, "CTF: HasFlag doesn't match ChildFlags!!!!\n"); + LOG_WARNING << "CTF: HasFlag doesn't match ChildFlags!!!!"; ChildFlags[i] = OBJECT_HANDLE_NONE; } } @@ -2455,7 +2459,7 @@ int GetFlagCountForPlayer(int pnum) { // 1st check the pnum, make sure it is OK, is it isn't, return 0 if (pnum < 0 || pnum >= DLLMAX_PLAYERS) { // invalid player number, return 0 flags - mprintf(0, "CTF: Invalid PNUM passed to GetFlagCountForPlayer()\n"); + LOG_WARNING << "CTF: Invalid PNUM passed to GetFlagCountForPlayer()"; return 0; } @@ -2477,7 +2481,7 @@ uint8_t GetFlagMaskForPlayer(int pnum) { // 1st check the pnum, make sure it is OK, if it isn't, return 0, meaning no flags if (pnum < 0 || pnum >= DLLMAX_PLAYERS) { // invalid player number, return 0 flags - mprintf(0, "CTF: Invalid PNUM passed to GetFlagMaskForPlayer()\n"); + LOG_WARNING << "CTF: Invalid PNUM passed to GetFlagMaskForPlayer()"; return 0; } @@ -2505,19 +2509,19 @@ bool GivePlayerFlag(int pnum, uint8_t team) { // 1st check the player num, make sure it is valid if (!DMFCBase->CheckPlayerNum(pnum)) { // not a valid player - mprintf(0, "CTF: Invalid pnum passed to GivePlayerFlag()\n"); + LOG_WARNING << "CTF: Invalid pnum passed to GivePlayerFlag()"; return false; } // 2nd check to make sure the team given is valid, and not our own team if (team >= CTFNumOfTeams) { // not a valid team - mprintf(0, "CTF: Invalid team passed to GivePlayerFlag() (team>=CTFNumOfTeams)\n"); + LOG_WARNING << "CTF: Invalid team passed to GivePlayerFlag() (team>=CTFNumOfTeams)"; return false; } if (team == DMFCBase->GetPlayerTeam(pnum)) { // we can't add a flag of the same team to a player - mprintf(0, "CTF: In GivePlayerFlag(), trying to add a player's home team flag\n"); + LOG_INFO << "CTF: In GivePlayerFlag(), trying to add a player's home team flag"; return false; } @@ -2525,14 +2529,14 @@ bool GivePlayerFlag(int pnum, uint8_t team) { // we'll check our HasFlags[] first if (HasFlag[team] != -1) { // hmm, we have someone listed as already having this flag...odd - mprintf(0, "CTF: In GivePlayerFlag(), trying to add a flag, but we see someone else should already have it\n"); + LOG_WARNING << "CTF: In GivePlayerFlag(), trying to add a flag, but we see someone else should already have it"; int player = HasFlag[team]; if (DMFCBase->CheckPlayerNum(player)) { // this player is in the game... // make sure this player doesn't have the flag in his inventory while (DLLInvCheckItem(player, OBJ_POWERUP, FlagIDs[team])) { // we have it listed that he does - mprintf(0, "CTF: In GivePlayerFlag(), we detected the flag in someone elses inventory\n"); + LOG_WARNING << "CTF: In GivePlayerFlag(), we detected the flag in someone elses inventory"; // remove all the flags that this player has of this team...very weird DLLInvRemove(player, OBJ_POWERUP, FlagIDs[team]); SetColoredBalls(player, false); @@ -2546,7 +2550,7 @@ bool GivePlayerFlag(int pnum, uint8_t team) { // reset this value of the array HasFlag[team] = -1; if (DMFCBase->GetLocalRole() != LR_SERVER) { - mprintf(0, "CTF: Game must be out of sync, requesting game state\n"); + LOG_WARNING << "CTF: Game must be out of sync, requesting game state"; DMFCBase->RequestGameState(); } } @@ -2559,7 +2563,7 @@ bool GivePlayerFlag(int pnum, uint8_t team) { // remove all the flags the player has while (DLLInvCheckItem(player, OBJ_POWERUP, FlagIDs[team])) { - mprintf(0, "CTF: In GivePlayerFlag(), detected a flag in a stranger's inventory\n"); + LOG_WARNING << "CTF: In GivePlayerFlag(), detected a flag in a stranger's inventory"; DLLInvRemove(player, OBJ_POWERUP, FlagIDs[team]); SetColoredBalls(player, false); // check to see if the player had a flag attached to him @@ -2579,7 +2583,7 @@ bool GivePlayerFlag(int pnum, uint8_t team) { // so we got here and added a flag to the player, now we need to attach the flag to the player if (!AddFlagToPlayer(pnum, team)) { // there was an error adding the flag,,,,ack! - mprintf(0, "CTF: In GivePlayerFlag(), couldn't attach the flag to the player\n"); + LOG_WARNING << "CTF: In GivePlayerFlag(), couldn't attach the flag to the player"; } } @@ -2590,18 +2594,18 @@ bool GivePlayerFlag(int pnum, uint8_t team) { void LoseFlagForPlayer(int pnum, uint8_t team, bool remove_from_inven) { // 1st check the player number if (pnum < 0 || pnum >= DLLMAX_PLAYERS) { - mprintf(0, "CTF:Invalid pnum passed to LoseFlagForPlayer()\n"); + LOG_WARNING << "CTF:Invalid pnum passed to LoseFlagForPlayer()"; return; } // 2nd check the team number if (team >= CTFNumOfTeams) { - mprintf(0, "CTF:Invalid team passed to LoseFlagForPlayer()\n"); + LOG_WARNING << "CTF:Invalid team passed to LoseFlagForPlayer()"; return; } if (team == DMFCBase->GetPlayerTeam(pnum)) { - mprintf(0, "CTF:Invalid team passed to LoseFlagForPlayer()...same team as player\n"); + LOG_WARNING << "CTF:Invalid team passed to LoseFlagForPlayer()...same team as player"; return; } diff --git a/netgames/ctf/ctf.h b/netgames/ctf/ctf.h index f605a1152..4b180318f 100644 --- a/netgames/ctf/ctf.h +++ b/netgames/ctf/ctf.h @@ -21,6 +21,7 @@ #include "osiris_share.h" #include "d3events.h" +#include "log.h" // If a player dies, becomes an observer or disconnects, it's possible that they // have a flag or more. This function will handle setting certain variables, timer @@ -66,6 +67,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/dmfc/CMakeLists.txt b/netgames/dmfc/CMakeLists.txt index 1ca6f3ecd..5b77fb57b 100644 --- a/netgames/dmfc/CMakeLists.txt +++ b/netgames/dmfc/CMakeLists.txt @@ -30,6 +30,7 @@ add_library(dmfc STATIC ${HEADERS} ${CPPS}) target_link_libraries(dmfc PUBLIC SDL3::SDL3 grtext + logger misc module physics diff --git a/netgames/dmfc/dmfcbase.cpp b/netgames/dmfc/dmfcbase.cpp index 28f3e551a..d5f0e05e2 100644 --- a/netgames/dmfc/dmfcbase.cpp +++ b/netgames/dmfc/dmfcbase.cpp @@ -467,15 +467,16 @@ * $NoKeywords: $ */ +#include +#include +#include +#include + #include "gamedll_header.h" #include "DMFC.h" #include "dmfcinternal.h" #include "dmfcinputcommands.h" - -#include -#include -#include -#include +#include "log.h" char **DMFCStringTable; int DMFCStringTableSize = 0; @@ -1199,7 +1200,6 @@ void DMFCBase::GameInit(int teams) { LoadSettings(); DLLCreateStringTable("dmfc.str", &DMFCStringTable, &DMFCStringTableSize); - mprintf(0, "DMFC Note: %d strings loaded from string table\n", DMFCStringTableSize); // initialize player records PRec_Init(); @@ -1962,7 +1962,7 @@ int DMFCBase::GetMeObjNum(void) { void DMFCBase::OnGameStateRequest(int pnum) { if (pnum == -1) return; - mprintf(0, "%s is requesting Game State information\n", Players[pnum].callsign); + LOG_INFO.printf("%s is requesting Game State information", Players[pnum].callsign); } // DMFCBase::GetTeamForNewPlayer @@ -2470,7 +2470,7 @@ void DMFCBase::SwitchShowHudCallsignLevel(uint8_t level, bool announce) { DLLAddHUDMessage(DTXT_HUDLEVEL_NONE); break; default: - mprintf(0, "DMFC: Invalid HUD Name Level\n"); + LOG_WARNING << "DMFC: Invalid HUD Name Level"; return; break; }; @@ -2495,7 +2495,7 @@ void DMFCBase::SwitchServerHudCallsignLevel(uint8_t level) { DLLAddHUDMessage(DTXT_SHUDLEVEL_NONE); break; default: - mprintf(0, "DMFC: Invalid Server HUD Name Level\n"); + LOG_WARNING << "DMFC: Invalid Server HUD Name Level"; return; break; } @@ -2624,7 +2624,7 @@ void DMFCBase::UpdatePInfo(int victim, int killer, int amount) { id = FindPInfo(killer); if ((id == NULL) || (victim_slot == -1)) { - mprintf(0, "Unable to find PInfos\n"); + LOG_WARNING << "Unable to find PInfos"; return; } @@ -2638,7 +2638,7 @@ void DMFCBase::UpdatePInfo(int victim, int killer, int amount) { int killer_slot = PRec_GetPlayerSlot(killer); if ((vpi == NULL) || (killer_slot == -1)) { - mprintf(0, "Unable to find PInfos\n"); + LOG_WARNING << "Unable to find PInfos"; return; } @@ -2910,14 +2910,14 @@ bool DMFCBase::SetWeaponDeathMessage(const char *weapon_name, const char *messag int weapon_index = DLLFindWeaponName(IGNORE_TABLE(weapon_name)); if (weapon_index == -1) { - mprintf(0, "Unable to set WeaponMessage for %s...can't find it\n", weapon_name); + LOG_WARNING.printf("Unable to set WeaponMessage for %s...can't find it", weapon_name); return false; } int real_weapon = WeaponHash[weapon_index]; if (real_weapon == -1) { - mprintf(0, "You forgot to call AddWeaponHash before adding this Message\n"); + LOG_WARNING.printf("You forgot to call AddWeaponHash before adding this Message"); return false; } @@ -2967,7 +2967,7 @@ void DMFCBase::AddWeaponHash(const char *parent, ...) { int parent_id = DLLFindWeaponName(IGNORE_TABLE(parent)); if (parent_id == -1) { - mprintf(0, "Unable to find parent weapon ID in AddWeaponHash (%s)\n", parent); + LOG_WARNING.printf("Unable to find parent weapon ID in AddWeaponHash (%s)", parent); return; } @@ -3011,7 +3011,7 @@ void DMFCBase::AddWeaponHashArray(const char *parent, int count, char **array) { int parent_id = DLLFindWeaponName(IGNORE_TABLE(parent)); if (parent_id == -1) { - mprintf(0, "Unable to find parent weapon ID in AddWeaponHash (%s)\n", parent); + LOG_WARNING.printf("Unable to find parent weapon ID in AddWeaponHash (%s)", parent); return; } @@ -3087,7 +3087,7 @@ player_record *DMFCBase::GetPlayerRecordByPnum(int pnum) { // Puts a temp ban on a player which will only last the duration of the game void DMFCBase::BanPlayerFromGame(int pnum) { if (pnum >= 0 && pnum < DLLMAX_PLAYERS) { - mprintf(0, "Banning %s\n", Players[pnum].callsign); + LOG_INFO.printf("Banning %s", Players[pnum].callsign); DPrintf(DTXT_DEDS_BAN, Players[pnum].callsign); tBanItem *c; c = m_BanList; @@ -3116,7 +3116,7 @@ void DMFCBase::BanPlayerFromGame(int pnum) { m_iNumBanPlayers++; } else { - mprintf(0, "Unable to ban player...pnum not valid\n"); + LOG_WARNING.printf("Unable to ban player...pnum not valid"); DPrintf(DTXT_DEDS_BAN_ERROR); } } @@ -3195,10 +3195,10 @@ bool DMFCBase::RemoveBan(int index) { // // returns true is the given pnum is banned from the game bool DMFCBase::IsPlayerBanned(int pnum) { - mprintf(0, "Checking a ban on a player..."); + LOG_DEBUG << "Checking a ban on a player..."; if (pnum < 0 || pnum >= DLLMAX_PLAYERS) { - mprintf(0, "Playernum not valid\n"); + LOG_WARNING << "Playernum not valid"; return false; } @@ -3216,16 +3216,14 @@ bool DMFCBase::IsAddressBanned(network_address *addr, const char *tracker_id) { tBanItem *c; c = m_BanList; - mprintf(0, "Checking a ban on an address..."); - while (c) { if (addr && CompareNetworkAddress(&c->addr, addr, false)) { - mprintf(0, "Player addr IS BANNED\n"); + LOG_INFO.printf("Player addr IS BANNED"); return true; } if (*m_bTrackerGame) { if (tracker_id && !strcmp(tracker_id, c->tracker_id)) { - mprintf(0, "Player tid IS BANNED\n"); + LOG_INFO.printf("Player tid %s IS BANNED", tracker_id); return true; } } @@ -3234,7 +3232,7 @@ bool DMFCBase::IsAddressBanned(network_address *addr, const char *tracker_id) { } if (!addr) { - mprintf(0, "Player not banned\n"); + LOG_INFO << "Player not banned"; return false; } @@ -3242,7 +3240,7 @@ bool DMFCBase::IsAddressBanned(network_address *addr, const char *tracker_id) { // the hosts.allow/.deny if (addr->connection_type != NP_TCP) { - mprintf(0, "Player not banned\n"); + LOG_INFO << "Player not banned"; return false; } @@ -3257,7 +3255,7 @@ bool DMFCBase::IsAddressBanned(network_address *addr, const char *tracker_id) { while (curr) { if ((address & curr->mask) == (curr->ip & curr->mask)) { // it is a match - mprintf(0, "Player not banned\n"); + LOG_INFO << "Player not banned"; return false; } curr = curr->next; @@ -3269,13 +3267,13 @@ bool DMFCBase::IsAddressBanned(network_address *addr, const char *tracker_id) { while (curr) { if ((address & curr->mask) == (curr->ip & curr->mask)) { // it is a match - mprintf(0, "Player IS banned\n"); + LOG_INFO << "Player IS banned"; return true; } curr = curr->next; } - mprintf(0, "Player not banned\n"); + LOG_INFO << "Player not banned"; return false; } @@ -3306,7 +3304,7 @@ void DMFCBase::DoDamageToPlayer(int pnum, int type, float amount, bool playsound // Prepares the game so that you can display UI stuff void DMFCBase::StartUIWindow(int id, void *user_data) { if (m_iUIWindowID != -1) { - mprintf(0, "DMFCBase::StartUIWindow(): A Window ID (0x%X) is already defined\n", m_iUIWindowID); + LOG_DEBUG.printf("DMFCBase::StartUIWindow(): A Window ID (0x%X) is already defined", m_iUIWindowID); return; } @@ -3517,116 +3515,153 @@ void DMFCBase::InputCommandFree(void) { // Initializes the variables and data for the input commands. Default DMFC commands are to // be placed in here. void DMFCBase::InputCommandInit(void) { - if (AddInputCommand(DTXT_IC_ALLOWTEAMCHANGE, DTXT_IC_ALLOWTEAMCHANGED, DMFCInputCommand_AllowTeamChange, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_ALLOWTEAMCHANGE, DTXT_IC_ALLOWTEAMCHANGED, DMFCInputCommand_AllowTeamChange, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_AUTOBALANCE, DTXT_IC_AUTOBALANCED, DMFCInputCommand_AutoBalance, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_AUTOBALANCE, DTXT_IC_AUTOBALANCED, DMFCInputCommand_AutoBalance, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_AUTOSAVEDISC, DTXT_IC_AUTOSAVEDISCD, DMFCInputCommand_AutoSaveDisconnect, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_AUTOSAVEDISC, DTXT_IC_AUTOSAVEDISCD, DMFCInputCommand_AutoSaveDisconnect, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_AUTOSAVELEVEL, DTXT_IC_AUTOSAVELEVELD, DMFCInputCommand_AutoSaveLevel, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_AUTOSAVELEVEL, DTXT_IC_AUTOSAVELEVELD, DMFCInputCommand_AutoSaveLevel, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_BALANCE, DTXT_IC_BALANCED, DMFCInputCommand_Balance, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_BALANCE, DTXT_IC_BALANCED, DMFCInputCommand_Balance, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_BAN, DTXT_IC_BAND, DMFCInputCommand_Ban, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_BAN, DTXT_IC_BAND, DMFCInputCommand_Ban, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_BANLIST, DTXT_IC_BANLISTD, DMFCInputCommand_BanList) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_BANLIST, DTXT_IC_BANLISTD, DMFCInputCommand_BanList) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_CHANGETEAM, DTXT_IC_CHANGETEAMD, DMFCInputCommand_ChangeTeam, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_CHANGETEAM, DTXT_IC_CHANGETEAMD, DMFCInputCommand_ChangeTeam, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_ENDLEVEL, DTXT_IC_ENDLEVELD, DMFCInputCommand_EndLevel, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_ENDLEVEL, DTXT_IC_ENDLEVELD, DMFCInputCommand_EndLevel, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_HELP, DTXT_IC_HELPD, DMFCInputCommand_Help) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_HELP, DTXT_IC_HELPD, DMFCInputCommand_Help) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_HUDNAME, DTXT_IC_HUDNAMED, DMFCInputCommand_HudCallsigns) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_HUDNAME, DTXT_IC_HUDNAMED, DMFCInputCommand_HudCallsigns) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_KICK, DTXT_IC_KICKD, DMFCInputCommand_Kick, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_KICK, DTXT_IC_KICKD, DMFCInputCommand_Kick, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_KILLMSGFILTER, DTXT_IC_KILLMSGFILTERD, DMFCInputCommand_KillMsgFilter) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_KILLMSGFILTER, DTXT_IC_KILLMSGFILTERD, DMFCInputCommand_KillMsgFilter) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_NETGAMEINFO, DTXT_IC_NETGAMEINFO, DMFCInputCommand_NetGameInfo) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_NETGAMEINFO, DTXT_IC_NETGAMEINFO, DMFCInputCommand_NetGameInfo) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_OBSERVER, DTXT_IC_OBSERVERD, DMFCInputCommand_Observer) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_OBSERVER, DTXT_IC_OBSERVERD, DMFCInputCommand_Observer) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_PIGGYBACK, DTXT_IC_PIGGYBACKD, DMFCInputCommand_Piggyback) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_PIGGYBACK, DTXT_IC_PIGGYBACKD, DMFCInputCommand_Piggyback) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_PLAYERINFO, DTXT_IC_PLAYERINFOD, DMFCInputCommand_PlayerInfo) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_PLAYERINFO, DTXT_IC_PLAYERINFOD, DMFCInputCommand_PlayerInfo) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_PLAYERS, DTXT_IC_PLAYERSD, DMFCInputCommand_Players) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_PLAYERS, DTXT_IC_PLAYERSD, DMFCInputCommand_Players) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_REHASH, DTXT_IC_REHASHD, DMFCInputCommand_Rehash, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_REHASH, DTXT_IC_REHASHD, DMFCInputCommand_Rehash, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_REMOTE, DTXT_IC_REMOTED, DMFCInputCommand_Remote) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_REMOTE, DTXT_IC_REMOTED, DMFCInputCommand_Remote) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_REMOTEADMIN, DTXT_IC_REMOTEADMIND, DMFCInputCommand_RemoteAdmin, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_REMOTEADMIN, DTXT_IC_REMOTEADMIND, DMFCInputCommand_RemoteAdmin, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_REMOTEADMINLOGOUT, DTXT_IC_REMOTEADMINLOGOUTD, DMFCInputCommand_RemoteAdminLogout) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_REMOTEADMINLOGOUT, DTXT_IC_REMOTEADMINLOGOUTD, DMFCInputCommand_RemoteAdminLogout) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_REMOTEADMINPASS, DTXT_IC_REMOTEADMINPASSD, DMFCInputCommand_RemoteAdminPass, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_REMOTEADMINPASS, DTXT_IC_REMOTEADMINPASSD, DMFCInputCommand_RemoteAdminPass, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_REMOVEBAN, DTXT_IC_REMOVEBAND, DMFCInputCommand_RemoveBan, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_REMOVEBAN, DTXT_IC_REMOVEBAND, DMFCInputCommand_RemoveBan, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SAVESTATS, DTXT_IC_SAVESTATSD, DMFCInputCommand_SaveStats, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SAVESTATS, DTXT_IC_SAVESTATSD, DMFCInputCommand_SaveStats, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SCORES, DTXT_IC_SCORESD, DMFCInputCommand_Scores) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SCORES, DTXT_IC_SCORESD, DMFCInputCommand_Scores) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SERVERHUDNAMES, DTXT_IC_SERVERHUDNAMESD, DMFCInputCommand_ServerHudCallsigns, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SERVERHUDNAMES, DTXT_IC_SERVERHUDNAMESD, DMFCInputCommand_ServerHudCallsigns, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SETGOALLIMIT, DTXT_IC_SETGOALLIMITD, DMFCInputCommand_SetGoalLimit, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SETGOALLIMIT, DTXT_IC_SETGOALLIMITD, DMFCInputCommand_SetGoalLimit, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SETMAXPLAYERS, DTXT_IC_SETMAXPLAYERSD, DMFCInputCommand_SetMaxPlayers, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SETMAXPLAYERS, DTXT_IC_SETMAXPLAYERSD, DMFCInputCommand_SetMaxPlayers, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SETPPS, DTXT_IC_SETPPSD, DMFCInputCommand_SetPPS, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SETPPS, DTXT_IC_SETPPSD, DMFCInputCommand_SetPPS, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SETRESPAWNTIME, DTXT_IC_SETRESPAWNTIMED, DMFCInputCommand_SetRespawnTime, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SETRESPAWNTIME, DTXT_IC_SETRESPAWNTIMED, DMFCInputCommand_SetRespawnTime, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SETTEAMNAME, DTXT_IC_SETTEAMNAMED, DMFCInputCommand_SetTeamName, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SETTEAMNAME, DTXT_IC_SETTEAMNAMED, DMFCInputCommand_SetTeamName, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_SETTIMELIMIT, DTXT_IC_SETTIMELIMITD, DMFCInputCommand_SetTimeLimit, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_SETTIMELIMIT, DTXT_IC_SETTIMELIMITD, DMFCInputCommand_SetTimeLimit, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_STATMSGS, DTXT_IC_STATMSGSD, DMFCInputCommand_StatMsgs) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_STATMSGS, DTXT_IC_STATMSGSD, DMFCInputCommand_StatMsgs) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_TEAM, DTXT_IC_TEAMD, DMFCInputCommand_Team) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_TEAM, DTXT_IC_TEAMD, DMFCInputCommand_Team) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_WAIT, DTXT_IC_WAITD, DMFCInputCommand_Wait, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_WAIT, DTXT_IC_WAITD, DMFCInputCommand_Wait, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } - if (AddInputCommand(DTXT_IC_WARP, DTXT_IC_WARPD, DMFCInputCommand_Warp, true) < 1) - mprintf(0, "DMFC Warning: Error Adding Input Command\n"); + if (AddInputCommand(DTXT_IC_WARP, DTXT_IC_WARPD, DMFCInputCommand_Warp, true) < 1) { + LOG_WARNING << "DMFC: Error Adding Input Command"; + } } // Returns true if the input command can be called remotely @@ -4804,7 +4839,7 @@ void ParseHostsFile(char *filename, tHostsNode **root) { } // we now have a valid mask (s_mask) and a valid ip (s_ip) - mprintf(0, "IP: %s Mask: %s\n", s_ip, s_mask); + LOG_INFO.printf("IP: %s Mask: %s", s_ip, s_mask); ip_address = DLLnw_GetHostAddressFromNumbers(s_ip); mask = DLLnw_GetHostAddressFromNumbers(s_mask); @@ -4825,7 +4860,7 @@ void ParseHostsFile(char *filename, tHostsNode **root) { } error_parse: - mprintf(0, "Error parsing IP Address Mask: %s\n", save_buffer); + LOG_WARNING.printf("Error parsing IP Address Mask: %s", save_buffer); noerror_parse:; } @@ -4852,11 +4887,11 @@ void DMFCBase::ReadInHostsAllowDeny(void) { // parse away if (deny_exist) { - mprintf(0, "Parsing hosts.deny\n"); + LOG_INFO << "Parsing hosts.deny"; ParseHostsFile(deny_fn, &m_DenyList); } if (allow_exist) { - mprintf(0, "Parsing hosts.allow\n"); + LOG_INFO << "Parsing hosts.allow"; ParseHostsFile(allow_fn, &m_AllowList); } } @@ -4921,7 +4956,7 @@ void DMFCBase::ParseStartupScript(void) { if ((autoexec_arg = DLLFindArg("-autoexec", 1)) != 0) { // a specific autoexec.dmfc file was specified, use that strcpy(path, GetGameArg(autoexec_arg + 1)); - mprintf(0, "Override AUTOEXEC.DMFC to %s\n", path); + LOG_INFO << "Override AUTOEXEC.DMFC to " << path; } else { // use the default autoexec.dmfc DLLddio_MakePath(path, LocalD3Dir, "netgames", "autoexec.dmfc", NULL); @@ -4946,7 +4981,7 @@ void DMFCBase::ParseStartupScript(void) { } if (!ok_to_read) { - mprintf(0, "AUTOEXEC.DMFC: Line too long\n"); + LOG_WARNING << "AUTOEXEC.DMFC: Line too long"; } else { if (buffer[1] == '$') { InputCommandHandle(&buffer[1]); @@ -5339,7 +5374,7 @@ int DMFCBase::GetConnectingPlayerTeam(int slot) { // we need to reconnect the player to the player records before we get the team if (!PRec_ReconnectPlayerToSlot(slot, prec_num, Players, NetPlayers)) { - mprintf(0, "Unable to reassign reconnecting player (%s) to Player Record slot #%d\n", + LOG_FATAL.printf("Unable to reassign reconnecting player (%s) to Player Record slot #%d", Players[slot].callsign, prec_num); Int3(); @@ -5364,7 +5399,7 @@ int DMFCBase::GetConnectingPlayerTeam(int slot) { } } - mprintf(0, "CONNECTING PLAYER (%s): Team assigned to %d\n", Players[slot].callsign, team); + LOG_INFO.printf("CONNECTING PLAYER (%s): Team assigned to %d", Players[slot].callsign, team); return team; } @@ -5478,7 +5513,7 @@ void DMFCBase::TranslateTextMacro(const char *src, char *destination, int dest_s // now replace the token... *token_string = '\0'; - mprintf(0, "Looking for token for %s\n", token); + LOG_INFO.printf("Looking for token for %s", token); CallOnGetTokenString(token, token_string, 512); // make sure we don't go too far diff --git a/netgames/dmfc/dmfccfg.cpp b/netgames/dmfc/dmfccfg.cpp index 3a56fcfe8..533d8d14b 100644 --- a/netgames/dmfc/dmfccfg.cpp +++ b/netgames/dmfc/dmfccfg.cpp @@ -337,10 +337,10 @@ bool CRegistry::Import() { DLLOpenCFILE(&file, name, "rt"); if (!file) { - mprintf(0, "Unable to import %s\n", name); + LOG_WARNING.printf("Unable to import %s", name); return false; } - mprintf(0, "Importing %s\n", name); + LOG_INFO.printf("Importing %s", name); Destroy(); bool oktocreate; @@ -363,7 +363,7 @@ bool CRegistry::Import() { if (buffer[0] == '[') { // Create a key! PARSE_KEY(newbuff); - mprintf(0, "Found Key: |%s|\n", newbuff); + LOG_INFO.printf("Found Key: |%s|", newbuff); CreateKey(newbuff); } else if (buffer[0] == '\"') { // Create a record @@ -395,9 +395,9 @@ bool CRegistry::Import() { ptr++; // blow by = PARSE_STRING(data); if (!CreateRecord(newbuff, REGT_STRING, data)) { - mprintf(0, "Unable to create String record: %s\n", newbuff); + LOG_DEBUG.printf("Unable to create String record: %s", newbuff); } else { - mprintf(0, "Created String record %s = %s\n", newbuff, data); + LOG_DEBUG.printf("Created String record %s = %s", newbuff, data); } break; case REGT_DWORD: @@ -407,14 +407,14 @@ bool CRegistry::Import() { idata = axtoi(data); if (!CreateRecord(newbuff, REGT_DWORD, &idata)) { - mprintf(0, "Unable to create dword record: %s\n", newbuff); + LOG_DEBUG.printf("Unable to create dword record: %s", newbuff); } else { - mprintf(0, "Created dword record %s = %X\n", newbuff, idata); + LOG_DEBUG.printf("Created dword record %s = %X", newbuff, idata); } break; } } else { - mprintf(0, "Expected [ or \"\n"); + LOG_DEBUG.printf("Expected [ or \""); } } } @@ -425,7 +425,7 @@ bool CRegistry::Import() { void CRegistry::CreateKey(const char *name) { tKey *curr; if (LookupKey(name)) { - mprintf(0, "Key: %s already exists\n", name); + LOG_DEBUG.printf("Key: %s already exists", name); return; } @@ -530,7 +530,7 @@ bool CRegistry::CreateRecord(const char *name, char type, void *data) { curr = LookupRecord(name, olddata); if (curr) { // ok we have an old value, replace it! - mprintf(0, "Replacing %s\n", name); + LOG_DEBUG.printf("Replacing %s", name); if (curr->data) free(curr->data); free(olddata); diff --git a/netgames/dmfc/dmfcclient.cpp b/netgames/dmfc/dmfcclient.cpp index 08c094cac..7550136b6 100644 --- a/netgames/dmfc/dmfcclient.cpp +++ b/netgames/dmfc/dmfcclient.cpp @@ -433,17 +433,18 @@ void DMFCBase::OnClientPlayerEntersGame(int player_num) { // we have a new player slot = PRec_GetFreeSlot(); if (!PRec_AssignPlayerToSlot(player_num, slot, Players, NetPlayers)) - mprintf(0, "Unable to assign New Player (%s) to Player Record slot #%d\n", Players[player_num].callsign, slot); + LOG_WARNING.printf("Unable to assign New Player (%s) to Player Record slot #%d", + Players[player_num].callsign, slot); else - mprintf(0, "(%s) has been assigned to Player Record slot #%d\n", Players[player_num].callsign, slot); + LOG_INFO.printf("(%s) has been assigned to Player Record slot #%d", Players[player_num].callsign, slot); CallOnPlayerConnect(player_num); } else { // we have a reconnecting player if (!PRec_ReconnectPlayerToSlot(player_num, slot, Players, NetPlayers)) - mprintf(0, "Unable to reassign reconnecting player (%s) to Player Record slot #%d\n", + LOG_WARNING.printf("Unable to reassign reconnecting player (%s) to Player Record slot #%d", Players[player_num].callsign, slot); else - mprintf(0, "Reconnected player (%s) to Player Record slot #%d\n", Players[player_num].callsign, slot); + LOG_INFO.printf("Reconnected player (%s) to Player Record slot #%d", Players[player_num].callsign, slot); CallOnPlayerReconnect(player_num); } } @@ -474,7 +475,7 @@ void DMFCBase::OnClientPlayerEntersGame(int player_num) { PilotPicBmpHandles[w] = BAD_BITMAP_HANDLE; } - mprintf(0, "PPIC ID: %d is %d\n", w, NetPlayers[w].pilot_pic_id); + LOG_INFO.printf("PPIC ID: %d is %d", w, NetPlayers[w].pilot_pic_id); if (NetPlayers[w].pilot_pic_id != 65535) { PilotPicBmpHandles[w] = DLLPPic_GetBitmapHandle(NetPlayers[w].pilot_pic_id); if (PilotPicBmpHandles[w] < BAD_BITMAP_HANDLE) @@ -492,7 +493,7 @@ void DMFCBase::OnClientPlayerEntersGame(int player_num) { PilotPicBmpHandles[player_num] = BAD_BITMAP_HANDLE; } - mprintf(0, "PPIC ID: %d is %d\n", player_num, NetPlayers[player_num].pilot_pic_id); + LOG_INFO.printf("PPIC ID: %d is %d", player_num, NetPlayers[player_num].pilot_pic_id); if (NetPlayers[player_num].pilot_pic_id != 65535) { PilotPicBmpHandles[player_num] = DLLPPic_GetBitmapHandle(NetPlayers[player_num].pilot_pic_id); if (PilotPicBmpHandles[player_num] < BAD_BITMAP_HANDLE) @@ -532,9 +533,9 @@ void DMFCBase::OnClientPlayerDisconnect(int player_num) { PRec_SetPlayerTeam(player_num, Players[player_num].team); if (!PRec_DisconnectPlayer(player_num)) - mprintf(0, "Unable to disconnect player (%s) from Player Records\n", Players[player_num].callsign); + LOG_WARNING.printf("Unable to disconnect player (%s) from Player Records", Players[player_num].callsign); else - mprintf(0, "Disconnected player (%s) from Player Records\n", Players[player_num].callsign); + LOG_INFO.printf("Disconnected player (%s) from Player Records", Players[player_num].callsign); } // DMFCBase::OnMeDisconnectFromServer @@ -604,9 +605,9 @@ void DMFCBase::OnClientLevelEnd(void) { PRec_SetPlayerTeam(i, Players[i].team); if (!PRec_DisconnectPlayer(i)) - mprintf(0, "Unable to disconnect player (%s) from Player Records\n", Players[i].callsign); + LOG_WARNING.printf("Unable to disconnect player (%s) from Player Records", Players[i].callsign); else - mprintf(0, "Disconnected player (%s) from Player Records\n", Players[i].callsign); + LOG_INFO.printf("Disconnected player (%s) from Player Records", Players[i].callsign); } } } @@ -616,7 +617,7 @@ void DMFCBase::OnClientLevelEnd(void) { // Event handler when a player becomes an observer mode // If they are piggybacking another player than piggy is the object pointer, else it's NULL void DMFCBase::OnPlayerEntersObserver(int pnum, object *piggy) { - mprintf(0, "Player %d entering observermode %s\n", pnum, (piggy) ? "Piggyback" : "Roam"); + LOG_INFO.printf("Player %d entering observermode %s", pnum, (piggy) ? "Piggyback" : "Roam"); player_record *pr = PRec_GetPRecordByPnum(pnum); if (pr && pr->state == STATE_INGAME) { PInfo *pi = pr->pinfo; @@ -631,7 +632,7 @@ void DMFCBase::OnPlayerEntersObserver(int pnum, object *piggy) { // // Event handler when a player is leaving observer mode void DMFCBase::OnPlayerExitsObserver(int pnum) { - mprintf(0, "Player %d leaving observer mode\n", pnum); + LOG_INFO.printf("Player %d leaving observer mode", pnum); player_record *pr = PRec_GetPRecordByPnum(pnum); if (pr && pr->state == STATE_INGAME) { PInfo *pi = pr->pinfo; @@ -659,7 +660,7 @@ bool DMFCBase::OnCanChangeTeam(int pnum, int newteam) { // // The user is requesting the game stats to be saved to file, you must handle this completly on // the game's side, nothing is done in DMFC -void DMFCBase::OnSaveStatsToFile(void) { mprintf(0, "User requested stats to be saved!\n"); } +void DMFCBase::OnSaveStatsToFile(void) { LOG_INFO.printf("User requested stats to be saved!"); } // DMFCBase::OnLevelEndSaveStatsToFile // @@ -778,7 +779,7 @@ void DMFCBase::OnInterval(void) { if (GetLocalRole() == LR_SERVER && IAmDedicatedServer() && m_bMakeClientsWait) { if (DedicatedLevelWait > 0 && DedicatedLevelWait <= (*Gametime)) { // time to stop waiting! - mprintf(0, "Telling clients that they can play!\n"); + LOG_INFO << "Telling clients that they can play!"; DPrintf("Allowing Clients To Play\n"); PauseRealGameTime(false); MakeClientsWait(false); @@ -860,7 +861,7 @@ void DMFCBase::OnKeypress(int key) { void DMFCBase::OnInputString(char *input_string) { if (!InputCommandHandle(input_string)) { // The input command wasn't handled! - mprintf(0, "DMFC Warning: Input Command '%s' wasn't handled\n", input_string); + LOG_WARNING.printf("Input Command '%s' wasn't handled", input_string); } } @@ -907,7 +908,7 @@ void DMFCBase::OnPlayerReconnect(int player_num) { SendTeamAssignment(player_num, team, false); Players[player_num].team = team; CallOnPlayerChangeTeam(player_num, team, false, false); - mprintf(0, "Reassigning (%s) to %s team\n", Players[player_num].callsign, GetTeamString(team)); + LOG_INFO.printf("Reassigning (%s) to %s team", Players[player_num].callsign, GetTeamString(team)); } } @@ -932,7 +933,7 @@ void DMFCBase::OnPlayerConnect(int player_num) { SendTeamAssignment(player_num, team, false); //@@Players[player_num].team = team; CallOnPlayerChangeTeam(player_num, team, false, false); - mprintf(0, "Assigning (%s) to %s team\n", Players[player_num].callsign, GetTeamString(team)); + LOG_INFO.printf("Assigning (%s) to %s team", Players[player_num].callsign, GetTeamString(team)); } } } @@ -1085,7 +1086,7 @@ void DMFCBase::OnClientObjectDestroyed(object *obj) {} // // This event occurs when a player plays an audio taunt void DMFCBase::OnPlayAudioTaunt(int pnum) { - mprintf(0, "%s plays an audio taunt\n", Players[pnum].callsign); + LOG_INFO.printf("%s plays an audio taunt", Players[pnum].callsign); SetPlayerTauntIndicator(pnum); } diff --git a/netgames/dmfc/dmfchudmessages.cpp b/netgames/dmfc/dmfchudmessages.cpp index c2f908e95..4378cac79 100644 --- a/netgames/dmfc/dmfchudmessages.cpp +++ b/netgames/dmfc/dmfchudmessages.cpp @@ -272,7 +272,7 @@ void DMFCBase::DoRandomDeathMessage(int killernum, int victimnum, uint32_t hash) if ((hash != 0xFFFFFFFF) && (me->type == OBJ_PLAYER) && ((me->id == GetPlayerNum()) || ((rand() % 3) == 1))) { weapon_index = DLLMultiMatchWeapon(hash); if (weapon_index == -1) { - mprintf(0, "Server Weapon Doesn't Match!\n"); + LOG_WARNING.printf("Server Weapon Doesn't Match!"); } } } @@ -367,8 +367,7 @@ void DMFCBase::DoRandomDeathMessage(int killernum, int victimnum, uint32_t hash) } } else { // either me or it doesn't exist - mprintf(0, "**********************************************************************\n"); - mprintf(0, "Either me or it doesn't exist for death message\n"); + LOG_WARNING.printf("Either me or it doesn't exist for death message"); if (me) { // only the killer doesn't exist diff --git a/netgames/dmfc/dmfcinputcommand.cpp b/netgames/dmfc/dmfcinputcommand.cpp index a5d351f4a..920bcb193 100644 --- a/netgames/dmfc/dmfcinputcommand.cpp +++ b/netgames/dmfc/dmfcinputcommand.cpp @@ -189,7 +189,7 @@ void DMFCInputCommand_Team(const char *input_string) { if ((t == -1) || (t == curr_team) || (curr_team == -1)) return; - mprintf(0, "Attempting to change teams to %s team\n", team); + LOG_INFO.printf("Attempting to change teams to %s team", team); DLLAddHUDMessage(DTXT_TEAMCHANGEATTEMPT, team); basethis->RequestTeamChange(t, basethis->GetPlayerNum(), true); } @@ -228,7 +228,7 @@ void DMFCInputCommand_ChangeTeam(const char *input_string) { if ((!basethis->CheckPlayerNum(p)) || (t == -1) || (t == curr_team) || (curr_team == -1)) return; - mprintf(0, "Attempting to change %s to %s team\n", basethis->Players[p].callsign, team); + LOG_INFO.printf("Attempting to change %s to %s team", basethis->Players[p].callsign, team); DLLAddHUDMessage(DTXT_STEAMCHANGEATTEMPT, basethis->Players[p].callsign, team); basethis->RequestTeamChange(t, p, true); } @@ -907,7 +907,7 @@ void DMFCInputCommand_Observer(const char *input_string) { return; } - mprintf(0, "SwitchObserverMode %s [%d]\n", (turn_on) ? "On" : "Off", pnum); + LOG_INFO.printf("SwitchObserverMode %s [%d]", (turn_on) ? "On" : "Off", pnum); DLLMultiSendRequestToObserve(OBSERVER_MODE_ROAM, (turn_on) ? 1 : 0, 0); } @@ -954,12 +954,12 @@ void DMFCInputCommand_Piggyback(const char *input_string) { DLLMultiSendRequestToObserve(OBSERVER_MODE_ROAM, 0, 0); } if (pnum == basethis->GetPlayerNum()) { - mprintf(0, "Returning to self\n"); + LOG_INFO << "Returning to self"; return; } if (basethis->CallOnAllowObserverChange(true)) { - mprintf(0, "Switching to piggyback for player %d\n", topnum); + LOG_INFO.printf("Switching to piggyback for player %d", topnum); DLLMultiSendRequestToObserve(OBSERVER_MODE_PIGGYBACK, 1, basethis->Players[topnum].objnum); } } diff --git a/netgames/dmfc/dmfcinternal.h b/netgames/dmfc/dmfcinternal.h index 45a68b08c..c0937a6aa 100644 --- a/netgames/dmfc/dmfcinternal.h +++ b/netgames/dmfc/dmfcinternal.h @@ -269,11 +269,6 @@ class DMFCBase; -#ifdef mprintf // undefine mprintf and redirect it to use DLLmprintf -#undef mprintf -#endif -#define mprintf(...) DLLmprintf(__VA_ARGS__) - #define MAX_DBNAME_SIZE 32 #define MAX_DBLABEL_SIZE 128 diff --git a/netgames/dmfc/dmfcmenu.cpp b/netgames/dmfc/dmfcmenu.cpp index 5602ac712..fdfbe8fd3 100644 --- a/netgames/dmfc/dmfcmenu.cpp +++ b/netgames/dmfc/dmfcmenu.cpp @@ -944,16 +944,16 @@ void RemoveBanByIndex(int index) { basethis->RemoveBan(index); } // Server Only. Kicks a player from the game void KickPlayer(int pnum) { if (basethis->GetLocalRole() != LR_SERVER) { - mprintf(0, "KickPlayer Error: You're Not The Server\n"); + LOG_WARNING << "KickPlayer Error: You're Not The Server"; return; } if (pnum == basethis->GetPlayerNum()) { - mprintf(0, "KickPlayer Error: Server can't kick themself\n"); + LOG_WARNING << "KickPlayer Error: Server can't kick themself"; DLLAddHUDMessage(DTXT_SERVERCANTKICK); return; } if (!basethis->CheckPlayerNum(pnum)) { - mprintf(0, "KickPlayer Error: Pnum %d not in game\n", pnum); + LOG_WARNING.printf("KickPlayer Error: Pnum %d not in game", pnum); DLLAddHUDMessage(DTXT_INVALIDPNUM, pnum); return; } @@ -963,16 +963,16 @@ void KickPlayer(int pnum) { // Server Only. Temp bans a player from the game void BanPlayer(int pnum) { if (basethis->GetLocalRole() != LR_SERVER) { - mprintf(0, "BanPlayer Error: You're Not The Server\n"); + LOG_WARNING << "BanPlayer Error: You're Not The Server"; return; } if (pnum == basethis->GetPlayerNum()) { - mprintf(0, "BanPlayer Error: Server can't ban themself\n"); + LOG_WARNING << "BanPlayer Error: Server can't ban themself"; DLLAddHUDMessage(DTXT_SERVERCANTBAN); return; } if (!basethis->CheckPlayerNum(pnum)) { - mprintf(0, "BanPlayer Error: Pnum %d not in game\n", pnum); + LOG_WARNING.printf("BanPlayer Error: Pnum %d not in game", pnum); DLLAddHUDMessage(DTXT_INVALIDPNUM, pnum); return; } @@ -983,7 +983,7 @@ void BanPlayer(int pnum) { // Server Only. Ends the current level void EndMultiLevel(int i) { if (basethis->GetLocalRole() != LR_SERVER) { - mprintf(0, "You're Not The Server\n"); + LOG_WARNING << "You're Not The Server"; return; } DLLMultiEndLevel(); @@ -992,11 +992,11 @@ void EndMultiLevel(int i) { // Server Only. Automatically balances the teams void BalanceTeams(int i) { if (basethis->GetLocalRole() != LR_SERVER) { - mprintf(0, "You're Not The Server\n"); + LOG_WARNING << "You're Not The Server"; return; } - mprintf(0, "Balancing Teams\n"); + LOG_INFO << "Balancing Teams"; DPrintf(DTXT_BALANCINGTEAMS); // First we need to get a count of how many are on each team @@ -1038,7 +1038,7 @@ void BalanceTeams(int i) { ShouldHave[i]++; for (i = 0; i < MAX_TEAMS; i++) { - mprintf(0, "%s team should have %d players and has %d now\n", + LOG_INFO.printf("%s team should have %d players and has %d now", basethis->GetTeamString(i), ShouldHave[i], TeamCount[i]); @@ -1089,7 +1089,7 @@ void BalanceTeams(int i) { // Server Only. Switches AutoTeamSelect On/Off void SwitchAutoTeamSelect(int i) { if (basethis->GetLocalRole() != LR_SERVER) { - mprintf(0, "You're Not The Server\n"); + LOG_WARNING << "You're Not The Server"; return; } bool on = (i == 1) ? true : false; @@ -1099,7 +1099,7 @@ void SwitchAutoTeamSelect(int i) { // Server Only. Switches allowing Team Changing on/off void SwitchTeamChange(int i) { if (basethis->GetLocalRole() != LR_SERVER) { - mprintf(0, "You're not the server\n"); + LOG_WARNING << "You're not the server"; return; } bool on = (i == 1) ? true : false; @@ -1122,7 +1122,7 @@ void SwitchPlayerInfo(int pnum) { } if (!basethis->CheckPlayerNum(pnum)) { - mprintf(0, "%d is invalid for playerinfo\n", pnum); + LOG_WARNING.printf("%d is invalid for playerinfo", pnum); return; } @@ -1151,19 +1151,19 @@ void SwitchServerHudPlayerName(int i) { // Change teams (or more specifically request to change teams) void ChangeTeams(int team) { if ((team < 0) || (team > 3)) { - mprintf(0, "Invalid team requested (%d)\n", team); + LOG_WARNING.printf("Invalid team requested (%d)", team); return; } int curr_team = basethis->Players[basethis->GetPlayerNum()].team; if (curr_team == -1) { - mprintf(0, "Dedicated Server Can't Change Teams\n"); + LOG_WARNING << "Dedicated Server Can't Change Teams"; DPrintf(DTXT_NODEDICATEDTEAM); return; } if (team == curr_team) { - mprintf(0, "You're already on the %s team\n", basethis->GetTeamString(team)); + LOG_WARNING.printf("You're already on the %s team", basethis->GetTeamString(team)); DPrintf(DTXT_SAMETEAMCHANGE, basethis->GetTeamString(team)); return; } @@ -1183,7 +1183,7 @@ void SwitchObserverMode(int i) { pobj = &basethis->Objects[basethis->Players[pnum].objnum]; - mprintf(0, "SwitchObserverMode %s [%d]\n", (i == 1) ? "On" : "Off", pnum); + LOG_INFO.printf("SwitchObserverMode %s [%d]", (i == 1) ? "On" : "Off", pnum); if (pobj->type == OBJ_OBSERVER) { if ((i == 0) && (basethis->CallOnAllowObserverChange(false))) @@ -1208,12 +1208,12 @@ void SwitchPiggyBack(int pnum) { DLLMultiSendRequestToObserve(OBSERVER_MODE_ROAM, 0, 0); } if (pnum == basethis->GetPlayerNum()) { - mprintf(0, "Returning to self\n"); + LOG_INFO << "Returning to self"; return; } if (basethis->CallOnAllowObserverChange(true)) { - mprintf(0, "Switching to piggyback for player %d\n", pnum); + LOG_INFO.printf("Switching to piggyback for player %d", pnum); DLLMultiSendRequestToObserve(OBSERVER_MODE_PIGGYBACK, 1, basethis->Players[pnum].objnum); } } diff --git a/netgames/dmfc/dmfcprecord.cpp b/netgames/dmfc/dmfcprecord.cpp index d12fafc41..3eb7f213d 100644 --- a/netgames/dmfc/dmfcprecord.cpp +++ b/netgames/dmfc/dmfcprecord.cpp @@ -161,7 +161,7 @@ int PRec_SetupUserPRec(int sizeof_user_stats, int (*pack_callback)(void *user_in int size = MAX_GAME_DATA_SIZE - (104 + 5 * MAX_PLAYER_RECORDS); if (sizeof_user_stats > size) { // the user mod specified too big of a size - mprintf(0, "DMFC Warning: In PRec_SetupUserPRec(), the size given is too large for a packet\n"); + LOG_FATAL << "In PRec_SetupUserPRec(), the size given is too large for a packet"; Int3(); goto user_stats_err; } @@ -361,7 +361,7 @@ bool PRec_AssignPlayerToSlot(int pnum, int slot, player *players_array, netplaye if (basethis->IsMasterTrackerGame() && (basethis->Players[pnum].tracker_id)) { // we are in a master tracker game, so save the tracker ID - mprintf(0, "PREC: Got a PXO Player ID of %s\n", basethis->Players[pnum].tracker_id); + LOG_INFO.printf("PREC: Got a PXO Player ID of %s", basethis->Players[pnum].tracker_id); Player_records[slot].tracker_id = strdup(basethis->Players[pnum].tracker_id); } else { // either it's not a tracker game or the tracker_id member of players is void @@ -569,7 +569,7 @@ void PRec_SendPRecToPlayer(int pnum) { } } - mprintf(0, "*Player Record: Send out %d packets of total %d bytes to %s\n", + LOG_INFO.printf("*Player Record: Send out %d packets of total %d bytes to %s", totalcount, totalsize, basethis->Players[pnum].callsign); @@ -606,7 +606,7 @@ void PRec_ReceivePRecFromServer(uint8_t *data) { memcpy(pr->tracker_id, &data[count], len); pr->tracker_id[len] = '\0'; } else { - mprintf(0, "PREC: UH OH!!! OUT OF MEMORY\n"); + LOG_WARNING << "PREC: UH OH!!! OUT OF MEMORY"; } count += len; } else { diff --git a/netgames/dmfc/dmfcremote.cpp b/netgames/dmfc/dmfcremote.cpp index 702500e8c..e15293229 100644 --- a/netgames/dmfc/dmfcremote.cpp +++ b/netgames/dmfc/dmfcremote.cpp @@ -152,7 +152,7 @@ void Remote_ProcessFrame(void) { // make sure they are in the game if (!pr || pr->state != STATE_INGAME) { // the player is no longer in the game - mprintf(0, "REMOTE: Removing authorization for %s\n", (pr->callsign) ? (pr->callsign) : ""); + LOG_INFO.printf("REMOTE: Removing authorization for %s", (pr->callsign) ? (pr->callsign) : ""); Remote_Logout(p); // change the key for the slot @@ -185,7 +185,7 @@ void Remote_Enable(bool enable) { Use_remote_admin = false; } - mprintf(0, "Remote Administration: %s\n", (Use_remote_admin) ? "On" : "Off"); + LOG_INFO.printf("Remote Administration: %s", (Use_remote_admin) ? "On" : "Off"); if (!Use_remote_admin) { // log out all the logged in players @@ -303,7 +303,7 @@ void Remote_SetMyKey(uint8_t key[8]) { pr = PRec_GetPRecordByPnum(basethis->GetPlayerNum()); int prec = translate_precptr_to_index(pr); if (prec == -1) { - mprintf(0, "INVALID PREC!\n"); + LOG_FATAL << "INVALID PREC!"; Int3(); return; } @@ -318,7 +318,7 @@ void Remote_ClientProcess(const char *command) { if (!IAmAnAdmin) { // only let "login" go through if (!strnicmp(command, "login", strlen("login"))) { - mprintf(0, "Sending login attempt for remote administration\n"); + LOG_INFO << "Sending login attempt for remote administration"; } else { return; } @@ -463,7 +463,7 @@ void Remote_SendStringToServer(const char *string) { pr = PRec_GetPRecordByPnum(basethis->GetPlayerNum()); int prec = translate_precptr_to_index(pr); if (prec == -1) { - mprintf(0, "INVALID PREC!\n"); + LOG_FATAL << "INVALID PREC!"; Int3(); return; } @@ -471,7 +471,7 @@ void Remote_SendStringToServer(const char *string) { Remote_encrypt(Authorized_players[prec].curr_key, slen, (uint8_t *)string, &new_strlen, &packet_data); if (new_strlen == 0) { - mprintf(0, "COULDN'T ENCRYPT\n"); + LOG_FATAL << "COULDN'T ENCRYPT"; Int3(); return; } @@ -513,7 +513,7 @@ void Remote_RecieveStringFromServer(uint8_t *data, char *buffer, int size) { pr = PRec_GetPRecordByPnum(basethis->GetPlayerNum()); int prec = translate_precptr_to_index(pr); if (prec == -1) { - mprintf(0, "INVALID PREC!\n"); + LOG_FATAL << "INVALID PREC!"; Int3(); return; } @@ -557,7 +557,7 @@ void Remote_SendStringToClient(int client, const char *string) { pr = PRec_GetPRecordByPnum(client); int prec = translate_precptr_to_index(pr); if (prec == -1) { - mprintf(0, "INVALID PREC!\n"); + LOG_FATAL << "INVALID PREC!"; Int3(); return; } @@ -571,7 +571,7 @@ void Remote_SendStringToClient(int client, const char *string) { Remote_encrypt(Authorized_players[prec].curr_key, slen, (uint8_t *)string, &new_strlen, &packet_data); if (new_strlen == 0) { - mprintf(0, "COULDN'T ENCRYPT\n"); + LOG_FATAL << "COULDN'T ENCRYPT"; Int3(); return; } diff --git a/netgames/dmfc/dmfcserver.cpp b/netgames/dmfc/dmfcserver.cpp index 6bd882f64..b3916ade8 100644 --- a/netgames/dmfc/dmfcserver.cpp +++ b/netgames/dmfc/dmfcserver.cpp @@ -116,7 +116,7 @@ void DMFCBase::OnServerPlayerKilled(object *killer_obj, int victim_pnum) { else { Data->iParam = (int)DLLMultiGetMatchChecksum(OBJ_WEAPON, Data->iParam); if (Data->iParam == -1) { - mprintf(0, "Unable to generate checksum for weapon id\n"); + LOG_WARNING << "Unable to generate checksum for weapon id"; } } @@ -233,7 +233,7 @@ void DMFCBase::OnServerLevelStart(void) { if (GetLocalRole() == LR_SERVER && IAmDedicatedServer()) { if (DedicatedLevelWait > 0) { // time to stop waiting! - mprintf(0, "Telling clients to wait\n"); + LOG_INFO << "Telling clients to wait"; DPrintf("\nMaking Clients Wait %.2f seconds\n", DedicatedLevelWait); PauseRealGameTime(true); MakeClientsWait(true); diff --git a/netgames/dmfc/dmfcui.cpp b/netgames/dmfc/dmfcui.cpp index 2c2e05859..d709e25ba 100644 --- a/netgames/dmfc/dmfcui.cpp +++ b/netgames/dmfc/dmfcui.cpp @@ -193,9 +193,9 @@ void UpdateTeamPlacementDialog(void) { tpdi.trans[team][curr_lb_count[team]] = i; // update the translator curr_lb_count[team]++; } else - mprintf(0, "Couldn't create text item\n"); + LOG_WARNING << "Couldn't create text item"; } else { - mprintf(0, "Listbox not valid!\n"); + LOG_WARNING << "Listbox not valid!"; } } else { TeamDlgInitialTeamSettings[i] = TeamDlgFinalTeamSettings[i] = TS_NOTINGAME; @@ -825,7 +825,7 @@ void DMFCBase::DoDMFCUIWaitForPlayers(bool clients_wait) { UpdateWaitForPlayersDialog(); - mprintf(0, "1:Entering UI Loop\n"); + LOG_DEBUG << "1:Entering UI Loop"; while (!exit_menu) { int res; @@ -836,11 +836,11 @@ void DMFCBase::DoDMFCUIWaitForPlayers(bool clients_wait) { } switch (res) { case NEWUIRES_FORCEQUIT: - mprintf(0, "1:Got a force quit\n"); + LOG_DEBUG << "1:Got a force quit"; exit_menu = true; break; case UID_OK: // exit menu - mprintf(0, "1:Got a regular quit\n"); + LOG_DEBUG << "1:Got a regular quit"; exit_menu = true; break; case 10: // kick player @@ -875,7 +875,7 @@ void DMFCBase::DoDMFCUIWaitForPlayers(bool clients_wait) { }; } - mprintf(0, "1:Out of UI Loop\n"); + LOG_DEBUG << "1:Out of UI Loop"; // the wait is over, let them in if (clients_wait) { diff --git a/netgames/dmfc/dmfcvirtual.cpp b/netgames/dmfc/dmfcvirtual.cpp index 657f69188..60d272db3 100644 --- a/netgames/dmfc/dmfcvirtual.cpp +++ b/netgames/dmfc/dmfcvirtual.cpp @@ -69,6 +69,7 @@ #include "DMFC.h" #include "dmfcinternal.h" #include "d3events.h" +#include "log.h" // DMFCBase::InitializeVirtualHandles // Prepares the virtual handles @@ -991,7 +992,7 @@ void DMFCBase::TranslateEvent(int eventnum, dllinfo *data) { TranslateTextMacro(src_string, dest_string, dest_size); } break; default: - DLLmprintf(0, "DMFC Warning: Unhandled Event #%X\n", eventnum); + LOG_WARNING.printf("DMFC Warning: Unhandled Event #%X", eventnum); break; } } diff --git a/netgames/entropy/Entropy.h b/netgames/entropy/Entropy.h index 4fd455a92..26fbe3706 100644 --- a/netgames/entropy/Entropy.h +++ b/netgames/entropy/Entropy.h @@ -26,6 +26,7 @@ OSIRIS functions to control them. */ #include "osiris_share.h" #include "d3events.h" +#include "log.h" /* ===================================================================== @@ -70,6 +71,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/entropy/EntropyBase.cpp b/netgames/entropy/EntropyBase.cpp index 996dfeea9..f67e2bce4 100644 --- a/netgames/entropy/EntropyBase.cpp +++ b/netgames/entropy/EntropyBase.cpp @@ -189,7 +189,7 @@ static int snd_virus_pickup = -1; static void DisplayHUDScores(struct tHUDItem *hitem); static void DisplayWelcomeMessage(int player_num); static void SortTeamScores(int *sortedindex, int *scores); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const char *filename); static void OnLabSpewTimer(void); void RemoveVirusFromPlayer(int player_num, bool remove_all); static bool ScanForLaboratory(int team, int *newlab); @@ -298,7 +298,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us DMFCBase->GameInit(NUM_TEAMS); DLLCreateStringTable("entropy.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { *all_ok = 0; return; @@ -431,6 +430,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + // The server has just started, so clear out all the stats and game info void OnServerGameCreated(void) { DMFCBase->OnServerGameCreated(); @@ -804,7 +808,7 @@ void OnServerCollide(object *me_obj, object *it_obj) { } if (virus_team == -1) { // hey! we hit a virus that doesn't belong to any team!! - DLLmprintf(0, "Virus (%d) doesn't belong to any team, removing...\n", virus_objnum); + LOG_INFO.printf("Virus (%d) doesn't belong to any team, removing...", virus_objnum); DMFCBase->OnServerCollide(me_obj, it_obj); DLLSetObjectDeadFlag(it_obj, true, false); return; @@ -944,13 +948,13 @@ void TakeOverRoom(int newteam, int oldteam, int roomnum, int victor) { } if (!success) { - DLLmprintf(0, "Invalid Takeover!!!!!!!\n"); + LOG_WARNING << "Invalid Takeover!!!!!!!"; return; } // print out hud message (and sound?) char buffer[256]; - DLLmprintf(0, "old=%d new=%d\n", oldteam, newteam); + LOG_DEBUG.printf("old=%d new=%d", oldteam, newteam); snprintf(buffer, sizeof(buffer), TXT_TAKEOVER, (victor != -1) ? dPlayers[victor].callsign : TXT_NONAME, DMFCBase->GetTeamString(oldteam), room_buf); DLLAddHUDMessage(buffer); @@ -1394,11 +1398,11 @@ void OnControlMessage(uint8_t msg, int from_pnum) { } } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const char *filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { - DLLmprintf(0, "Unable to open output file\n"); + LOG_WARNING << "Unable to open output file"; return; } diff --git a/netgames/entropy/EntropyRoom.cpp b/netgames/entropy/EntropyRoom.cpp index eae45ee8b..a00f06f6a 100644 --- a/netgames/entropy/EntropyRoom.cpp +++ b/netgames/entropy/EntropyRoom.cpp @@ -168,7 +168,7 @@ void DoServerConfigureDialog(void) { exit_menu = true; DLLEditGetText(virus_pk_edit, tempbuffer, 20); int newpk = atoi(tempbuffer); - DLLmprintf(0, "New Virus/Kill = %d\n", newpk); + LOG_INFO.printf("New Virus/Kill = %d", newpk); break; }; } diff --git a/netgames/hoard/Hoard.h b/netgames/hoard/Hoard.h index acdb656cf..abbcb65e3 100644 --- a/netgames/hoard/Hoard.h +++ b/netgames/hoard/Hoard.h @@ -21,6 +21,7 @@ #include "osiris_share.h" #include "d3events.h" +#include "log.h" void HoardGameInit(int teams); @@ -63,6 +64,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/hoard/hoard.cpp b/netgames/hoard/hoard.cpp index 2149f7152..d0b7f53f2 100644 --- a/netgames/hoard/hoard.cpp +++ b/netgames/hoard/hoard.cpp @@ -130,7 +130,7 @@ static void DisplayWelcomeMessage(int player_num); static void DoBallsEffect(int i, int count); static void ReceiveHoardInv(uint8_t *data); static void SendHoardInv(int playernum); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const char *filename); static void ReceiveGameConfig(uint8_t *data); static void OnClientPlayerEntersGame(int player_num); @@ -308,7 +308,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us dPlayers = DMFCBase->GetPlayers(); DLLCreateStringTable("Hoard.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { *all_ok = 0; return; @@ -320,7 +319,7 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us if (DMFCBase->AddInputCommand("mincount", "[Dedicated Server Only]\nSets the minimum number of hoard orbs needed to score.\n", DMFCInputCommand_MinCount, true) < 1) - mprintf(0, "Hoard Warning: Error Adding Input Command\n"); + LOG_WARNING << "Hoard Warning: Error Adding Input Command"; HoardGameInit(1); @@ -345,7 +344,7 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us HoardID = DLLFindObjectIDName("Hoardorb"); if (HoardID == -1) { - DLLmprintf(0, "HOARD: BIG WARNING, COULDN'T FIND HOARD ORB ID...YOUR GAME IS IN JEOPARDY!\n"); + LOG_WARNING << "HOARD: BIG WARNING, COULDN'T FIND HOARD ORB ID...YOUR GAME IS IN JEOPARDY!"; *all_ok = 0; return; } @@ -466,6 +465,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + // DMFCApp::GameInit // // Sets up all the DLL functions and pointers and preps the class for use. This ABSOLUTLY must be @@ -785,7 +789,7 @@ void OnClientPlayerChangeSegment(int player_num, int newseg, int oldseg) { // check the score to see if we hit the limit if (DMFCBase->GetScoreLimit(&score)) { if (score <= ((stat) ? stat->Score[DSTAT_LEVEL] : 0)) { - DLLmprintf(0, "Score limit reached\n"); + LOG_INFO << "Score limit reached"; DMFCBase->EndLevel(); } } @@ -856,7 +860,7 @@ void OnClientCollide(object *me_obj, object *it_obj) { DLLSetObjectDeadFlag(it_obj, true, false); } } else - DLLmprintf(0, "HOARD BIG WARNING: TRYING TO ADD NONPOWERUP TO INVENTORY! (%d)\n", it_obj->type); + LOG_WARNING.printf("HOARD BIG WARNING: TRYING TO ADD NONPOWERUP TO INVENTORY! (%d)", it_obj->type); // add rotating balls if necessary DoBallsEffect(playernum, count + 1); @@ -1024,11 +1028,11 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const char *filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { - DLLmprintf(0, "Unable to open output file\n"); + LOG_WARNING << "Unable to open output file"; return; } diff --git a/netgames/hyperanarchy/HyperAnarchy.h b/netgames/hyperanarchy/HyperAnarchy.h index ba6c7ea6d..c965d9d6f 100644 --- a/netgames/hyperanarchy/HyperAnarchy.h +++ b/netgames/hyperanarchy/HyperAnarchy.h @@ -21,6 +21,7 @@ #include "osiris_share.h" #include "d3events.h" +#include "log.h" //!!!!!!!ADD YOUR EVENT HANDLER OVERRIDES HERE!!!!!!!!!!! void OnInterval(void); @@ -55,6 +56,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/hyperanarchy/hyperanarchy.cpp b/netgames/hyperanarchy/hyperanarchy.cpp index 11dac65e4..834a9d93d 100644 --- a/netgames/hyperanarchy/hyperanarchy.cpp +++ b/netgames/hyperanarchy/hyperanarchy.cpp @@ -152,7 +152,7 @@ static int FindHyperObjectNum(void); // if no one does. static int FindHyperOrbInInventory(void); static void ResetTimer(void); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const char *filename); void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size) { player_record *pr = DMFCBase->GetPlayerRecord(precord_num); @@ -232,7 +232,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us DMFCBase->Set_OnClientPlayerEntersGame(OnClientPlayerEntersGame); DLLCreateStringTable("hyper.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { *all_ok = 0; return; @@ -261,7 +260,7 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us HyperOrbID = DLLFindObjectIDName("Hyperorb"); if (HyperOrbID == -1) { - DLLmprintf(0, "Hyper Anarchy: BIG WARNING, COULDN'T FIND HyperOrb ID...YOUR GAME IS IN JEOPARDY!\n"); + LOG_WARNING << "Hyper Anarchy: BIG WARNING, COULDN'T FIND HyperOrb ID...YOUR GAME IS IN JEOPARDY!"; *all_ok = 0; return; } @@ -381,6 +380,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + ////////////////////////////////////////////////////////////// /////// Overrides /////////////////////////////////////////// @@ -470,9 +474,8 @@ void OnServerGameCreated(void) { void OnServerLevelStart(void) { // Now create a hyper orb in a random room -eek if (HyperOrbID != -1) { - DLLmprintf(0, "Attempting to create HyperOrb in a random room\n"); int room = GetRandomValidRoom(); - DLLmprintf(0, "Room %d selected\n", room); + LOG_INFO.printf("Creating HyperOrb in a random room %d", room); // We got a good room // Safe to create the flag CreateHyperOrbInRoom(room); @@ -754,7 +757,6 @@ void OnServerCollide(object *me_obj, object *it_obj) { if ((me_obj->type == OBJ_PLAYER) && (DLLInvCheckItem(it_obj->id, OBJ_POWERUP, HyperOrbID))) { /* //Two Players collided...one had orb - DLLmprintf(0,"Player2Player\n"); DMFCBase->CallClientEvent(EVT_CLIENT_GAMECOLLIDE,DMFCBase->GetMeObjNum(),DMFCBase->GetItObjNum(),-1); DMFCBase->CallOnClientCollide(me_obj,it_obj); */ @@ -875,7 +877,7 @@ void OnClientPlayerKilled(object *killer_obj, int victim_pnum) { // check the score to see if we hit the limit if ((DMFCBase->GetScoreLimit(&score))) { if (score <= stat->Score[DSTAT_LEVEL]) { - DLLmprintf(0, "Score limit reached\n"); + LOG_INFO << "Score limit reached"; DMFCBase->EndLevel(); } } @@ -903,11 +905,11 @@ void OnClientPlayerDisconnect(int player_num) { DMFCBase->OnClientPlayerDisconnect(player_num); } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const char *filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { - DLLmprintf(0, "Unable to open output file\n"); + LOG_WARNING << "Unable to open output file"; return; } @@ -1103,7 +1105,7 @@ void ReceiveHyperGameState(uint8_t *data) { KillCount = MultiGetInt(data, &count); if (WhoHasOrb != -1) { - DLLmprintf(0, "%s has the score orb!\n", dPlayers[WhoHasOrb].callsign); + LOG_INFO.printf("%s has the score orb!", dPlayers[WhoHasOrb].callsign); DLLInvAddTypeID(WhoHasOrb, OBJ_POWERUP, HyperOrbID, -1, -1, 0, NULL); } UpdateEffect(); @@ -1373,12 +1375,11 @@ void SortPlayerScores(int *sortedindex, int size) { // Generates a valid random room int GetRandomValidRoom(void) { - while (1) { + while (true) { int room; room = rand() % (DMFCBase->GetHighestRoomIndex() + 1); if ((!ROOMNUM_OUTSIDE(room)) && ((DMFCBase->GetRooms())[room].used)) { if (!((DMFCBase->GetRooms())[room].flags & RF_EXTERNAL)) { - DLLmprintf(0, "Room %d selected\n", room); return room; } } diff --git a/netgames/includes/DMFC.h b/netgames/includes/DMFC.h index 38a5f81f4..c1863ddd2 100644 --- a/netgames/includes/DMFC.h +++ b/netgames/includes/DMFC.h @@ -295,6 +295,7 @@ #include "gamedll_header.h" #include "DMFCKeyCodes.h" +#include "log.h" #ifndef RELEASE @@ -316,7 +317,7 @@ #endif #define Int3() \ do { \ - mprintf(0, "Fatal error at %s:%d.\n", __FILE__, __LINE__); \ + LOG_FATAL.printf("Fatal error at %s:%d.", __FILE__, __LINE__); \ DEBUG_BREAK(); \ } while (0) @@ -330,8 +331,6 @@ #define DLLASSERT(x) ASSERT(x) -#define DLLmprintf(...) DLLDebug_ConsolePrintf(__VA_ARGS__) - #else // Release build #ifdef DEBUG_BREAK @@ -340,7 +339,6 @@ #define DEBUG_BREAK() #define DLLASSERT(x) -#define DLLmprintf(...) #ifdef Int3 #undef Int3 @@ -354,11 +352,6 @@ #endif // #ifndef RELEASE -#ifdef mprintf // undefine mprintf and redirect it to use DLLmprintf -#undef mprintf -#endif -#define mprintf DLLmprintf - #define DLLMAX_PLAYERS MAX_PLAYERS #define DLLMAX_TEAMS 4 #define RED_TEAM 0 diff --git a/netgames/monsterball/monsterball.cpp b/netgames/monsterball/monsterball.cpp index e5e6c571d..4fe4c6c66 100644 --- a/netgames/monsterball/monsterball.cpp +++ b/netgames/monsterball/monsterball.cpp @@ -295,7 +295,7 @@ static void OnTimerScoreKill(void); static void OnTimerKill(void); static void OnTimerRegen(void); static void OnTimerRegenKill(void); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const char *filename); static void SortPlayerSlots(int *sorted_list, int count); static void SendLastHitInfo(void); static void GetLastHitInfo(uint8_t *data); @@ -418,7 +418,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us DMFCBase->GameInit(NumOfTeams); DLLCreateStringTable("monster.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); // add the death and suicide messages DMFCBase->AddDeathMessage(TXT_KILLEDA, true); @@ -540,6 +539,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + bool OnCanChangeTeam(int pnum, int newteam) { if (!DMFCBase->OnCanChangeTeam(pnum, newteam)) return false; @@ -793,7 +797,7 @@ void HandlePickupPowerball(object *owner) { bool ret = DLLAttachObject(owner, 0, bobj, 0, true); if (!ret) { // blah! - mprintf(0, "COULDN'T ATTACH MONSTERBALL TO PLAYER!!!!!!\n"); + LOG_WARNING << "COULDN'T ATTACH MONSTERBALL TO PLAYER!!!!!!"; } } @@ -1065,7 +1069,7 @@ void OnClientLevelStart(void) { DLLMultiPaintGoalRooms(NULL); - DLLmprintf(0, "Getting Monsterball info\n"); + LOG_INFO << "Getting Monsterball info"; if (!GetMonsterballInfo(DLLFindObjectIDName(IGNORE_TABLE(MONSTERBALL_ID_NAME)))) { FatalError("Error finding Monsterball room\n"); } @@ -1429,11 +1433,11 @@ void OnPrintScores(int level) { } } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const char *filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { - DLLmprintf(0, "Unable to open output file\n"); + LOG_WARNING << "Unable to open output file"; return; } @@ -1774,7 +1778,7 @@ void GetGameStartPacket(uint8_t *data) { NumOfTeams = temp; // we need to find the objnum of the Monsterball...it is there somewhere - DLLmprintf(0, "Looking for Monsterball in level\n"); + LOG_INFO << "Looking for Monsterball in level"; int objnum = -1; for (i = 0; i < MAX_OBJECTS; i++) { @@ -1784,7 +1788,7 @@ void GetGameStartPacket(uint8_t *data) { break; } } - DLLmprintf(0, "Monsterball %s\n", (objnum == -1) ? "Not Found" : "Found"); + LOG_INFO.printf("Monsterball %s", (objnum == -1) ? "Not Found" : "Found"); if (objnum == -1) { FatalError("Couldn't Find Monsterball when it should be there"); } @@ -1819,7 +1823,7 @@ void SendGameStartPacket(int pnum) { MultiAddByte(temp, data, &count); // we're done - DLLmprintf(0, "Sending Game State to %s\n", dPlayers[pnum].callsign); + LOG_INFO.printf("Sending Game State to %s", dPlayers[pnum].callsign); DMFCBase->SendPacket(data, count, pnum); } diff --git a/netgames/monsterball/monsterball.h b/netgames/monsterball/monsterball.h index 8620c339b..2bdb14a99 100644 --- a/netgames/monsterball/monsterball.h +++ b/netgames/monsterball/monsterball.h @@ -53,6 +53,7 @@ #include "osiris_share.h" #include "d3events.h" +#include "log.h" //!!!!!!!ADD YOUR EVENT HANDLER OVERRIDES HERE!!!!!!!!!!! bool OnCanChangeTeam(int pnum, int newteam); @@ -89,6 +90,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/roboanarchy/roboAnarchy.h b/netgames/roboanarchy/roboAnarchy.h index 8ec50df0a..a119b0671 100644 --- a/netgames/roboanarchy/roboAnarchy.h +++ b/netgames/roboanarchy/roboAnarchy.h @@ -43,6 +43,7 @@ #include "osiris_share.h" #include "d3events.h" +#include "log.h" // Setup and processing functions void AnarchyGameInit(int teams); @@ -80,6 +81,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/roboanarchy/roboanarchy.cpp b/netgames/roboanarchy/roboanarchy.cpp index e49f1b074..200fdf3fa 100644 --- a/netgames/roboanarchy/roboanarchy.cpp +++ b/netgames/roboanarchy/roboanarchy.cpp @@ -75,7 +75,7 @@ static bool display_my_welcome = false; static void DisplayHUDScores(struct tHUDItem *hitem); static void DisplayScores(void); static void DisplayWelcomeMessage(int player_num); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const char *filename); static void SwitchHUDColor(int i); static void SwitchAnarchyScores(int i); @@ -155,7 +155,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us DMFCBase->Set_OnPrintScores(OnPrintScores); DLLCreateStringTable("Anarchy.str", &StringTable, &StringTableSize); - mprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { *all_ok = 0; return; @@ -224,6 +223,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size) { player_record *pr = DMFCBase->GetPlayerRecord(precord_num); if (!pr || pr->state == STATE_EMPTY) { @@ -541,11 +545,11 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const char *filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { - mprintf(0, "Unable to open output file\n"); + LOG_WARNING << "Unable to open output file"; return; } diff --git a/netgames/tanarchy/tanDMFC.h b/netgames/tanarchy/tanDMFC.h index dcb56cb2e..54f3c1b79 100644 --- a/netgames/tanarchy/tanDMFC.h +++ b/netgames/tanarchy/tanDMFC.h @@ -21,6 +21,7 @@ #include "osiris_share.h" #include "d3events.h" +#include "log.h" //!!!!!!!ADD YOUR EVENT HANDLER OVERRIDES HERE!!!!!!!!!!! void OnGameStateRequest(int pnum); @@ -44,6 +45,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data); DLLEXPORT void DLLFUNCCALL DLLGameClose(); DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options); +DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender); DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor); DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id); DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr); diff --git a/netgames/tanarchy/tanarchy.cpp b/netgames/tanarchy/tanarchy.cpp index 26080e2ff..7b757b231 100644 --- a/netgames/tanarchy/tanarchy.cpp +++ b/netgames/tanarchy/tanarchy.cpp @@ -76,9 +76,11 @@ * $NoKeywords: $ */ +#include + #include "gamedll_header.h" -#include #include "idmfc.h" +#include "log.h" #include "tanDMFC.h" #include "tanarchystr.h" IDMFC *DMFCBase = NULL; @@ -185,7 +187,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us DMFCBase->GameInit(NUM_TEAMS); DLLCreateStringTable("tanarchy.str", &StringTable, &StringTableSize); - DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize); if (!StringTableSize) { *all_ok = 0; return; @@ -308,6 +309,11 @@ void DLLFUNCCALL DLLGameClose() { } } +void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) { + plog::init(severity, appender); + LOG_DEBUG << "Logger for module initialized"; +} + // The server has just started, so clear out all the stats and game info void OnServerGameCreated(void) { DMFCBase->OnServerGameCreated(); @@ -618,11 +624,11 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const char *filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { - DLLmprintf(0, "Unable to open output file\n"); + LOG_ERROR << "Unable to open output file"; return; } @@ -836,7 +842,7 @@ void OnDisconnectSaveStatsToFile(void) { // Handles when we get a new player packet void GetGameStartPacket(uint8_t *data) { // get the team scores - DLLmprintf(0, "Receiving Team Scores from server\n"); + LOG_INFO << "Receiving Team Scores from server"; int count = 0, i; for (i = 0; i < NUM_TEAMS; i++) { TeamScore[i] = MultiGetInt(data, &count); @@ -857,7 +863,7 @@ void SendGameStartPacket(int pnum) { } // we're done - DLLmprintf(0, "Sending Team Scores to %s\n", dPlayers[pnum].callsign); + LOG_INFO.printf("Sending Team Scores to %s", dPlayers[pnum].callsign); DMFCBase->SendPacket(data, count, pnum); }