Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions Descent3/Game2DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,21 @@ 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);
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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
27 changes: 20 additions & 7 deletions Descent3/multi_dll_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions logger/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#pragma once

// This is interface header for chosen logger library. Currently, this is plog.
#include <plog/Log.h>
#include <plog/Log.h> // This is interface header for chosen logger library. Currently, this is plog.
#include <plog/Init.h> // Required for modules.

/*
In case of swapping to another solution here should be redefined following macros:
Expand Down
1 change: 1 addition & 0 deletions netcon/descent3onlineclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_link_libraries(Descent3_Online_TCP_IP PRIVATE
ddio
inetfile
httplib
logger
misc
module
ui
Expand Down
28 changes: 10 additions & 18 deletions netcon/descent3onlineclient/chat_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "chat_api.h"
#include "crossplat.h"
#include "grdefs.h"
#include "log.h"
#include "odtstrings.h"
#include "networking.h"

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -462,29 +456,27 @@ 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
return nullptr;
}
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;
}
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;
}
Expand Down Expand Up @@ -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));
Expand Down
9 changes: 2 additions & 7 deletions netcon/descent3onlineclient/dip_gametrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading