-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathNWNXBase.cpp
133 lines (106 loc) · 3.32 KB
/
NWNXBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/***************************************************************************
NWNX Base class - Library for custom expansions
Copyright (C) 2003 Ingmar Stieger (Papillon, [email protected]) and
Jeroen Broekhuizen ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
#include "NWNXBase.h"
#include <stdarg.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CNWNXBase::CNWNXBase()
{
// m_hFile = INVALID_HANDLE_VALUE;
m_fFile = NULL;
debuglevel = 0;
}
CNWNXBase::~CNWNXBase()
{
// The OnRelease function is always called before
// an instance is deleted
OnRelease();
}
bool CNWNXBase::OnCreate(gline *config, const char* LogFile)
{
// save pointer to config data
nwnxConfig = config;
// generic config options
BaseConf();
// try to open the log file
m_fFile = fopen(LogFile, "w");
return (m_fFile != NULL);
}
bool CNWNXBase::OnRelease()
{
// close the log file
int ret;
if (m_fFile)
ret = fclose(m_fFile);
return (ret == 0);
}
unsigned long CNWNXBase::OnRequestObject(char *gameObject, char* Request)
{
return 0x7F000000;
}
void CNWNXBase::Log(int priority, const char *pcMsg, ...)
{
va_list argList;
char acBuffer[2048];
if (m_fFile && priority <= debuglevel) {
// build up the string
va_start(argList, pcMsg);
vsnprintf(acBuffer, 2047, pcMsg, argList);
acBuffer[2047] = 0;
va_end(argList);
// log string in file
fputs(acBuffer, m_fFile);
fflush(m_fFile);
}
}
int CNWNXBase::ParamLog(int priority, const char *msg, char *Parameters)
{
// record it for posterity
Log(priority, msg);
// if it fits, shove it in.
if (strlen(Parameters) >= strlen(msg)) {
strcpy(Parameters, msg);
// success
return 1;
}
// not enough room
return 0;
}
int CNWNXBase::SetDebugLevel(int level)
{
int temp = debuglevel;
//printf("[%s] SetDebugLevel(%d) called. Current value=%d\n",
// confKey,level,temp);
if (level != debuglevel) {
debuglevel = level;
Log(0, "* debuglevel changed to %d from %d\n", debuglevel, temp);
}
return temp;
}
int CNWNXBase::GetDebugLevel()
{
return debuglevel;
}
void CNWNXBase::BaseConf()
{
if (confKey == NULL || !nwnxConfig->exists(confKey))
return;
if (nwnxConfig->exists(confKey, "debuglevel")) {
SetDebugLevel(atoi((char*)((*nwnxConfig)[confKey]["debuglevel"].c_str())));
}
}