Skip to content

Commit f0d427c

Browse files
committed
Enable logging for netgames modules
Implementing chained appender initialization scenario for plog.
1 parent 0acd456 commit f0d427c

34 files changed

+379
-288
lines changed

Descent3/Game2DLL.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,21 @@ typedef void DLLFUNCCALL (*DLLGameClose_fp)();
9797
typedef void DLLFUNCCALL (*DLLGameGetName_fp)(char *buffer, int maxsize);
9898
typedef void DLLFUNCCALL (*DLLGameGetDesc_fp)(char **buffer, int maxsize, int lines);
9999
typedef void DLLFUNCCALL (*DLLGetGameInfo_fp)(tDLLOptions *options);
100+
typedef void DLLFUNCCALL (*DLLLoggerInit_fp)(plog::Severity severity, plog::IAppender* appender);
100101
#else
101102
typedef void(DLLFUNCCALL *DLLGameCall_fp)(int eventnum, dllinfo *data);
102103
typedef void(DLLFUNCCALL *DLLGameInit_fp)(int *api_func, uint8_t *all_ok, int num_teams_to_use);
103104
typedef void(DLLFUNCCALL *DLLGameClose_fp)();
104105
typedef void(DLLFUNCCALL *DLLGameGetName_fp)(char *buffer, int maxsize);
105106
typedef void(DLLFUNCCALL *DLLGameGetDesc_fp)(char **buffer, int maxsize, int lines);
106107
typedef void(DLLFUNCCALL *DLLGetGameInfo_fp)(tDLLOptions *options);
108+
typedef void(DLLFUNCCALL *DLLLoggerInit_fp)(plog::Severity severity, plog::IAppender* appender);
107109
#endif
108-
DLLGameCall_fp DLLGameCall = NULL;
109-
DLLGameInit_fp DLLGameInit = NULL;
110-
DLLGameClose_fp DLLGameClose = NULL;
111-
DLLGetGameInfo_fp DLLGetGameInfo = NULL;
110+
DLLGameCall_fp DLLGameCall = nullptr;
111+
DLLGameInit_fp DLLGameInit = nullptr;
112+
DLLGameClose_fp DLLGameClose = nullptr;
113+
DLLGetGameInfo_fp DLLGetGameInfo = nullptr;
114+
DLLLoggerInit_fp DLLLoggerInit = nullptr;
112115
dllinfo DLLInfo;
113116
tOSIRISModuleInit Multi_d3m_osiris_funcs;
114117
std::filesystem::path Multi_game_dll_name;
@@ -606,10 +609,11 @@ void FreeGameDLL() {
606609
DLLGameClose();
607610
Osiris_UnloadMissionModule();
608611
CloseGameModule(&GameDLLHandle);
609-
DLLGameCall = NULL;
610-
DLLGameInit = NULL;
611-
DLLGameClose = NULL;
612-
DLLGetGameInfo = NULL;
612+
DLLGameCall = nullptr;
613+
DLLGameInit = nullptr;
614+
DLLGameClose = nullptr;
615+
DLLGetGameInfo = nullptr;
616+
DLLLoggerInit = nullptr;
613617
}
614618
// Loads the game dll. Returns 1 on success, else 0 on failure
615619
int LoadGameDLL(const char *name, int num_teams_to_use) {
@@ -676,6 +680,15 @@ int LoadGameDLL(const char *name, int num_teams_to_use) {
676680
FreeGameDLL();
677681
return 0;
678682
}
683+
// Clear out error queue
684+
mod_GetLastError();
685+
DLLLoggerInit = (DLLLoggerInit_fp)mod_GetSymbol(&GameDLLHandle, "DLLLoggerInit", 12);
686+
if (!DLLLoggerInit) {
687+
LOG_WARNING << "Couldn't get a handle to the dll function DLLLoggerInit!";
688+
} else {
689+
DLLLoggerInit(plog::get()->getMaxSeverity(), plog::get());
690+
}
691+
679692
if (first) {
680693
// Jeff: Linux for some reason dies if you try to
681694
// free a DLL/so on atexit, they should be freed

netgames/anarchy/Anarchy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include "osiris_share.h"
4545
#include "d3events.h"
46+
#include "log.h"
4647

4748
// Setup and processing functions
4849
void AnarchyGameInit(int teams);
@@ -80,6 +81,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t
8081
DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data);
8182
DLLEXPORT void DLLFUNCCALL DLLGameClose();
8283
DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options);
84+
DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender);
8385
DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor);
8486
DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id);
8587
DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr);

netgames/anarchy/anarchy.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static bool display_my_welcome = false;
7878
static void DisplayHUDScores(struct tHUDItem *hitem);
7979
static void DisplayScores(void);
8080
static void DisplayWelcomeMessage(int player_num);
81-
static void SaveStatsToFile(char *filename);
81+
static void SaveStatsToFile(const char *filename);
8282
static void SwitchHUDColor(int i);
8383
static void SwitchAnarchyScores(int i);
8484
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
160160
DMFCBase->Set_OnPrintScores(OnPrintScores);
161161

162162
DLLCreateStringTable("Anarchy.str", &StringTable, &StringTableSize);
163-
mprintf(0, "%d strings loaded from string table\n", StringTableSize);
164163
if (!StringTableSize) {
165164
*all_ok = 0;
166165
return;
@@ -229,6 +228,11 @@ void DLLFUNCCALL DLLGameClose() {
229228
}
230229
}
231230

231+
void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) {
232+
plog::init(severity, appender);
233+
LOG_DEBUG << "Logger for module initialized";
234+
}
235+
232236
void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size) {
233237
player_record *pr = DMFCBase->GetPlayerRecord(precord_num);
234238
if (!pr || pr->state == STATE_EMPTY) {
@@ -546,11 +550,11 @@ void OnPLRInterval(void) {
546550
quick_exit:;
547551
}
548552

549-
void SaveStatsToFile(char *filename) {
553+
void SaveStatsToFile(const char *filename) {
550554
CFILE *file;
551555
DLLOpenCFILE(&file, filename, "wt");
552556
if (!file) {
553-
mprintf(0, "Unable to open output file\n");
557+
LOG_ERROR << "Unable to open output file";
554558
return;
555559
}
556560

netgames/coop/coop.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us
216216
dPlayers = DMFCBase->GetPlayers();
217217

218218
DLLCreateStringTable("Coop.str", &StringTable, &StringTableSize);
219-
mprintf(0, "%d strings loaded from string table\n", StringTableSize);
220219
if (!StringTableSize) {
221220
*all_ok = 0;
222221
return;
@@ -314,6 +313,11 @@ void DLLFUNCCALL DLLGameClose() {
314313
}
315314
}
316315

316+
void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) {
317+
plog::init(severity, appender);
318+
LOG_DEBUG << "Logger for module initialized";
319+
}
320+
317321
void OnHUDInterval(void) {
318322
dstat->DoFrame();
319323
DMFCBase->DisplayOutrageLogo();
@@ -525,15 +529,15 @@ void OnClientObjectKilled(object *obj, object *killer) {
525529
DLLGetUltimateParentForObject(&parent, killer);
526530

527531
if ((parent->type != OBJ_PLAYER) && (parent->type != OBJ_OBSERVER)) {
528-
mprintf(0, "Robot killed wasn't by a OBJ_PLAYER or OBJ_OBSERVER (%d)\n", parent->type);
532+
LOG_WARNING.printf("Robot killed wasn't by a OBJ_PLAYER or OBJ_OBSERVER (%d)", parent->type);
529533
return;
530534
}
531535

532536
int killer_pnum = parent->id;
533537

534538
player_record *pr = DMFCBase->GetPlayerRecordByPnum(killer_pnum);
535539
if (!pr) {
536-
mprintf(0, "Invalid player record!\n");
540+
LOG_FATAL << "Invalid player record!";
537541
Int3();
538542
return;
539543
}
@@ -543,7 +547,7 @@ void OnClientObjectKilled(object *obj, object *killer) {
543547
stat->Score[DSTAT_LEVEL]++;
544548
stat->Score[DSTAT_OVERALL]++;
545549

546-
mprintf(0, "%s's score is now %d\n", dPlayers[killer_pnum].callsign, stat->Score[DSTAT_LEVEL]);
550+
LOG_INFO.printf("%s's score is now %d", dPlayers[killer_pnum].callsign, stat->Score[DSTAT_LEVEL]);
547551

548552
DMFCBase->OnClientObjectKilled(obj, killer);
549553
}

netgames/coop/coop.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
#include "osiris_share.h"
6464
#include "d3events.h"
65+
#include "log.h"
6566

6667
void OnHUDInterval(void);
6768
void OnInterval(void);
@@ -89,6 +90,7 @@ DLLEXPORT void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_t
8990
DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data);
9091
DLLEXPORT void DLLFUNCCALL DLLGameClose();
9192
DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options);
93+
DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender);
9294
DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor);
9395
DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id);
9496
DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr);

netgames/ctf/ctf.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ const char *GetString(int d) {
238238
else
239239
return StringTable[d];
240240
}
241-
static void SaveStatsToFile(char *filename);
241+
static void SaveStatsToFile(const char *filename);
242242
static void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size);
243243
static void ShowStatBitmap(int precord_num, int column_num, int x, int y, int w, int h, uint8_t alpha_to_use);
244244

@@ -352,7 +352,6 @@ void DLLFUNCCALL DLLGameInit(int *api_func, uint8_t *all_ok, int num_teams_to_us
352352

353353
DMFCBase->GameInit(CTFNumOfTeams);
354354
DLLCreateStringTable("CTF.str", &StringTable, &StringTableSize);
355-
DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize);
356355
if (!StringTableSize) {
357356
*all_ok = 0;
358357
return;
@@ -568,6 +567,11 @@ void DLLFUNCCALL DLLGameClose() {
568567
}
569568
}
570569

570+
void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender) {
571+
plog::init(severity, appender);
572+
LOG_DEBUG << "Logger for module initialized";
573+
}
574+
571575
/////////////////////////////////////////////////////////////
572576
// DMFC Overrides
573577

@@ -782,7 +786,7 @@ void OnClientLevelStart(void) {
782786
if ((flagid != -1) && (goalroom >= 0) && (goalroom <= DMFCBase->GetHighestRoomIndex()) &&
783787
(!ROOMNUM_OUTSIDE(goalroom)) && (dRooms[goalroom].used)) {
784788
// Safe to create the flag
785-
DLLmprintf(0, "Creating %s Flag\n", DMFCBase->GetTeamString(i));
789+
LOG_INFO.printf("Creating %s Flag", DMFCBase->GetTeamString(i));
786790
DLLComputeRoomCenter(&vpos, &dRooms[goalroom]);
787791
objnum = DLLObjCreate(OBJ_POWERUP, flagid, goalroom, &vpos, NULL, OBJECT_HANDLE_NONE);
788792
DLLMultiSendObject(&dObjects[objnum], 0, true);
@@ -1027,7 +1031,7 @@ void OnClientCollide(uint8_t *data) {
10271031
if (DMFCBase->GetScoreLimit(&killgoal)) {
10281032
if (TeamScores[pteam] >= killgoal) {
10291033
// That's all she wrote for this level
1030-
DLLmprintf(0, "OnClientCollide:Kill Goal Reached!\n");
1034+
LOG_INFO << "OnClientCollide:Kill Goal Reached!";
10311035
DMFCBase->EndLevel();
10321036
}
10331037
}
@@ -1380,11 +1384,11 @@ void OnPLRInterval(void) {
13801384
quick_exit:;
13811385
}
13821386

1383-
void SaveStatsToFile(char *filename) {
1387+
void SaveStatsToFile(const char *filename) {
13841388
CFILE *file;
13851389
DLLOpenCFILE(&file, filename, "wt");
13861390
if (!file) {
1387-
DLLmprintf(0, "Unable to open output file\n");
1391+
LOG_WARNING << "Unable to open output file";
13881392
return;
13891393
}
13901394

@@ -2158,15 +2162,15 @@ bool AddFlagToPlayer(int pnum, int team, int flagobjnum) {
21582162

21592163
if (!ret) {
21602164
// couldn't attach the flag
2161-
mprintf(0, "CTF: COULDN'T ATTACH FLAG TO PLAYER, DELETING\n");
2165+
LOG_WARNING << "CTF: COULDN'T ATTACH FLAG TO PLAYER, DELETING";
21622166
// tell the clients to remove this flag
21632167
DLLSetObjectDeadFlag(&dObjects[flagobjnum], true, false);
21642168
}
21652169
}
21662170

21672171
if (flagobjnum == -1) {
21682172
// there was an error creating the flag...not good
2169-
mprintf(0, "CTF: Couldn't create/unhash flag for attachment\n");
2173+
LOG_WARNING << "CTF: Couldn't create/unhash flag for attachment";
21702174
DMFCBase->DisconnectMe();
21712175
return false;
21722176
}
@@ -2426,7 +2430,7 @@ void ReceiveGameState(uint8_t *data) {
24262430

24272431
if (our_objnum == -1) {
24282432
// fatal error
2429-
mprintf(0, "CTF: Local Objnums don't match server objnums\n");
2433+
LOG_ERROR << "CTF: Local Objnums don't match server objnums";
24302434
ChildFlags[i] = OBJECT_HANDLE_NONE;
24312435
DMFCBase->DisconnectMe();
24322436
} else {
@@ -2435,7 +2439,7 @@ void ReceiveGameState(uint8_t *data) {
24352439
AddFlagToPlayer(HasFlag[i], i, our_objnum);
24362440
else {
24372441
// hmm, HasFlag doesn't match ChildFlags
2438-
mprintf(0, "CTF: HasFlag doesn't match ChildFlags!!!!\n");
2442+
LOG_WARNING << "CTF: HasFlag doesn't match ChildFlags!!!!";
24392443
ChildFlags[i] = OBJECT_HANDLE_NONE;
24402444
}
24412445
}
@@ -2455,7 +2459,7 @@ int GetFlagCountForPlayer(int pnum) {
24552459
// 1st check the pnum, make sure it is OK, is it isn't, return 0
24562460
if (pnum < 0 || pnum >= DLLMAX_PLAYERS) {
24572461
// invalid player number, return 0 flags
2458-
mprintf(0, "CTF: Invalid PNUM passed to GetFlagCountForPlayer()\n");
2462+
LOG_WARNING << "CTF: Invalid PNUM passed to GetFlagCountForPlayer()";
24592463
return 0;
24602464
}
24612465

@@ -2477,7 +2481,7 @@ uint8_t GetFlagMaskForPlayer(int pnum) {
24772481
// 1st check the pnum, make sure it is OK, if it isn't, return 0, meaning no flags
24782482
if (pnum < 0 || pnum >= DLLMAX_PLAYERS) {
24792483
// invalid player number, return 0 flags
2480-
mprintf(0, "CTF: Invalid PNUM passed to GetFlagMaskForPlayer()\n");
2484+
LOG_WARNING << "CTF: Invalid PNUM passed to GetFlagMaskForPlayer()";
24812485
return 0;
24822486
}
24832487

@@ -2505,34 +2509,34 @@ bool GivePlayerFlag(int pnum, uint8_t team) {
25052509
// 1st check the player num, make sure it is valid
25062510
if (!DMFCBase->CheckPlayerNum(pnum)) {
25072511
// not a valid player
2508-
mprintf(0, "CTF: Invalid pnum passed to GivePlayerFlag()\n");
2512+
LOG_WARNING << "CTF: Invalid pnum passed to GivePlayerFlag()";
25092513
return false;
25102514
}
25112515

25122516
// 2nd check to make sure the team given is valid, and not our own team
25132517
if (team >= CTFNumOfTeams) {
25142518
// not a valid team
2515-
mprintf(0, "CTF: Invalid team passed to GivePlayerFlag() (team>=CTFNumOfTeams)\n");
2519+
LOG_WARNING << "CTF: Invalid team passed to GivePlayerFlag() (team>=CTFNumOfTeams)";
25162520
return false;
25172521
}
25182522
if (team == DMFCBase->GetPlayerTeam(pnum)) {
25192523
// we can't add a flag of the same team to a player
2520-
mprintf(0, "CTF: In GivePlayerFlag(), trying to add a player's home team flag\n");
2524+
LOG_INFO << "CTF: In GivePlayerFlag(), trying to add a player's home team flag";
25212525
return false;
25222526
}
25232527

25242528
// 3rd, make sure no one else currently has this flag
25252529
// we'll check our HasFlags[] first
25262530
if (HasFlag[team] != -1) {
25272531
// hmm, we have someone listed as already having this flag...odd
2528-
mprintf(0, "CTF: In GivePlayerFlag(), trying to add a flag, but we see someone else should already have it\n");
2532+
LOG_WARNING << "CTF: In GivePlayerFlag(), trying to add a flag, but we see someone else should already have it";
25292533
int player = HasFlag[team];
25302534
if (DMFCBase->CheckPlayerNum(player)) {
25312535
// this player is in the game...
25322536
// make sure this player doesn't have the flag in his inventory
25332537
while (DLLInvCheckItem(player, OBJ_POWERUP, FlagIDs[team])) {
25342538
// we have it listed that he does
2535-
mprintf(0, "CTF: In GivePlayerFlag(), we detected the flag in someone elses inventory\n");
2539+
LOG_WARNING << "CTF: In GivePlayerFlag(), we detected the flag in someone elses inventory";
25362540
// remove all the flags that this player has of this team...very weird
25372541
DLLInvRemove(player, OBJ_POWERUP, FlagIDs[team]);
25382542
SetColoredBalls(player, false);
@@ -2546,7 +2550,7 @@ bool GivePlayerFlag(int pnum, uint8_t team) {
25462550
// reset this value of the array
25472551
HasFlag[team] = -1;
25482552
if (DMFCBase->GetLocalRole() != LR_SERVER) {
2549-
mprintf(0, "CTF: Game must be out of sync, requesting game state\n");
2553+
LOG_WARNING << "CTF: Game must be out of sync, requesting game state";
25502554
DMFCBase->RequestGameState();
25512555
}
25522556
}
@@ -2559,7 +2563,7 @@ bool GivePlayerFlag(int pnum, uint8_t team) {
25592563

25602564
// remove all the flags the player has
25612565
while (DLLInvCheckItem(player, OBJ_POWERUP, FlagIDs[team])) {
2562-
mprintf(0, "CTF: In GivePlayerFlag(), detected a flag in a stranger's inventory\n");
2566+
LOG_WARNING << "CTF: In GivePlayerFlag(), detected a flag in a stranger's inventory";
25632567
DLLInvRemove(player, OBJ_POWERUP, FlagIDs[team]);
25642568
SetColoredBalls(player, false);
25652569
// check to see if the player had a flag attached to him
@@ -2579,7 +2583,7 @@ bool GivePlayerFlag(int pnum, uint8_t team) {
25792583
// so we got here and added a flag to the player, now we need to attach the flag to the player
25802584
if (!AddFlagToPlayer(pnum, team)) {
25812585
// there was an error adding the flag,,,,ack!
2582-
mprintf(0, "CTF: In GivePlayerFlag(), couldn't attach the flag to the player\n");
2586+
LOG_WARNING << "CTF: In GivePlayerFlag(), couldn't attach the flag to the player";
25832587
}
25842588
}
25852589

@@ -2590,18 +2594,18 @@ bool GivePlayerFlag(int pnum, uint8_t team) {
25902594
void LoseFlagForPlayer(int pnum, uint8_t team, bool remove_from_inven) {
25912595
// 1st check the player number
25922596
if (pnum < 0 || pnum >= DLLMAX_PLAYERS) {
2593-
mprintf(0, "CTF:Invalid pnum passed to LoseFlagForPlayer()\n");
2597+
LOG_WARNING << "CTF:Invalid pnum passed to LoseFlagForPlayer()";
25942598
return;
25952599
}
25962600

25972601
// 2nd check the team number
25982602
if (team >= CTFNumOfTeams) {
2599-
mprintf(0, "CTF:Invalid team passed to LoseFlagForPlayer()\n");
2603+
LOG_WARNING << "CTF:Invalid team passed to LoseFlagForPlayer()";
26002604
return;
26012605
}
26022606

26032607
if (team == DMFCBase->GetPlayerTeam(pnum)) {
2604-
mprintf(0, "CTF:Invalid team passed to LoseFlagForPlayer()...same team as player\n");
2608+
LOG_WARNING << "CTF:Invalid team passed to LoseFlagForPlayer()...same team as player";
26052609
return;
26062610
}
26072611

netgames/ctf/ctf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "osiris_share.h"
2323
#include "d3events.h"
24+
#include "log.h"
2425

2526
// If a player dies, becomes an observer or disconnects, it's possible that they
2627
// 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
6667
DLLEXPORT void DLLFUNCCALL DLLGameCall(int eventnum, dllinfo *data);
6768
DLLEXPORT void DLLFUNCCALL DLLGameClose();
6869
DLLEXPORT void DLLFUNCCALL DLLGetGameInfo(tDLLOptions *options);
70+
DLLEXPORT void DLLFUNCCALL DLLLoggerInit(plog::Severity severity, plog::IAppender* appender);
6971
DLLEXPORT int DLLFUNCCALL GetGOScriptID(const char *name, uint8_t isdoor);
7072
DLLEXPORT void DLLFUNCCALLPTR CreateInstance(int id);
7173
DLLEXPORT void DLLFUNCCALL DestroyInstance(int id, void *ptr);

0 commit comments

Comments
 (0)