Skip to content

Commit f728b63

Browse files
authored
fix: logs folders and core config reading (#331)
fix: core config reading refactoring
1 parent a619520 commit f728b63

File tree

1 file changed

+48
-42
lines changed

1 file changed

+48
-42
lines changed

cstrike/addons/amxmodx/scripting/ChatAdditions/ChatAdditions_Core.sma

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ enum logType_s {
1717

1818
new logType_s: ca_log_type,
1919
logLevel_s: ca_log_level = logLevel_Debug,
20-
g_logsPath[PLATFORM_MAX_PATH],
2120
bool: ca_update_notify,
2221
ca_log_autodelete_time
2322

@@ -53,11 +52,8 @@ public plugin_precache() {
5352

5453
create_cvar("ChatAdditions_version", PluginVersion, FCVAR_SERVER)
5554

56-
GetLogsFilePath(g_logsPath, .dir = LOG_FOLDER)
57-
5855
Create_CVars()
59-
60-
AutoExecConfig(true, "ChatAdditions_core", "ChatAdditions")
56+
CheckUpdate()
6157
}
6258

6359
public plugin_init() {
@@ -77,8 +73,6 @@ public plugin_init() {
7773
CheckAutoDelete()
7874

7975
CA_Log(logLevel_Debug, "Chat Additions: Core initialized!")
80-
81-
set_task_ex(6.274, "_OnConfigsExecuted")
8276
}
8377

8478
public plugin_end() {
@@ -87,39 +81,40 @@ public plugin_end() {
8781
DestroyForward(g_fwdClientChangeName)
8882
}
8983

90-
public _OnConfigsExecuted() {
91-
CheckUpdate()
92-
}
93-
9484
CheckAutoDelete() {
95-
if (ca_log_autodelete_time > 0) {
96-
if (dir_exists(g_logsPath)) {
97-
new logFile[PLATFORM_MAX_PATH]
98-
new dirHandle
99-
new subDirectory[PLATFORM_MAX_PATH]
100-
new deleteTime
85+
if (ca_log_autodelete_time <= 0)
86+
return
10187

102-
deleteTime = get_systime() - (ca_log_autodelete_time * 60 * 60 * 24)
88+
new logsPath[PLATFORM_MAX_PATH]
89+
GetLogsFilePath(logsPath, .dir = LOG_FOLDER)
10390

104-
dirHandle = open_dir(g_logsPath, logFile, charsmax(logFile))
91+
if (!dir_exists(logsPath))
92+
return
10593

106-
if (dirHandle) {
107-
while (next_file(dirHandle, logFile, charsmax(logFile))) {
108-
if (logFile[0] == '.')
109-
continue
94+
new logFile[PLATFORM_MAX_PATH]
95+
new dirHandle
96+
dirHandle = open_dir(logsPath, logFile, charsmax(logFile))
97+
if (!dirHandle)
98+
return
11099

111-
if (containi(logFile, ".log") == -1) {
112-
formatex(subDirectory, charsmax(subDirectory), "%s/%s", g_logsPath, logFile)
100+
new subDirectory[PLATFORM_MAX_PATH]
101+
new deleteTime = get_systime() - (ca_log_autodelete_time * (60 * 60 * 24))
113102

114-
ReadFolder(deleteTime, subDirectory)
103+
while (next_file(dirHandle, logFile, charsmax(logFile))) {
104+
if (logFile[0] == '.')
105+
continue
115106

116-
continue
117-
}
118-
}
119-
close_dir(dirHandle)
120-
}
107+
if (containi(logFile, ".log") == -1) {
108+
formatex(subDirectory, charsmax(subDirectory), "%s/%s", logsPath, logFile)
109+
110+
// TODO: refactor this
111+
ReadFolder(deleteTime, subDirectory)
112+
113+
continue
121114
}
122115
}
116+
117+
close_dir(dirHandle)
123118
}
124119

125120
ReadFolder(deleteTime, logPath[]) {
@@ -185,6 +180,14 @@ Create_CVars() {
185180
),
186181
ca_log_autodelete_time
187182
)
183+
184+
AutoExecConfig(true, "ChatAdditions_core", LOG_FOLDER)
185+
186+
new configsDir[PLATFORM_MAX_PATH]
187+
get_configsdir(configsDir, charsmax(configsDir))
188+
189+
server_cmd("exec %s/plugins/%s/ChatAdditions_core.cfg", configsDir, LOG_FOLDER)
190+
server_exec()
188191
}
189192

190193
public plugin_natives() {
@@ -283,38 +286,41 @@ public bool: native_CA_Log(const plugin_id, const argc) {
283286

284287
new logLevel_s: level = logLevel_s: get_param(arg_level)
285288

286-
if (ca_log_level < level) {
289+
if (ca_log_level < level)
287290
return false
288-
}
289291

290292
new msg[2048]
291293
vdformat(msg, charsmax(msg), arg_msg, arg_format)
292294

293295
new logsFile[PLATFORM_MAX_PATH]
294296

295-
if (ca_log_type > _Default)
296-
{
297-
new pluginName[32]
297+
if (ca_log_type > _Default) {
298+
new logsPath[PLATFORM_MAX_PATH]
299+
get_localinfo("amxx_logs", logsPath, charsmax(logsPath))
300+
301+
new pluginName[PLATFORM_MAX_PATH]
298302
get_plugin(plugin_id, pluginName, charsmax(pluginName))
299303

300304
replace(pluginName, charsmax(pluginName), ".amxx", "")
301305

302-
new logsPath[PLATFORM_MAX_PATH]
303-
formatex(logsPath, charsmax(logsPath), "%s/%s", g_logsPath, pluginName)
306+
formatex(logsPath, charsmax(logsPath), "%s/%s", logsPath, pluginName)
304307

305-
if (!dir_exists(logsPath)) {
308+
if (!dir_exists(logsPath))
306309
mkdir(logsPath)
307-
}
308310

309311
new year, month, day
310312
date(year, month, day)
311313

312-
formatex(logsFile, charsmax(logsFile), "%s/%s__%i-%02i-%02i.log", logsPath, pluginName, year, month, day)
314+
formatex(logsFile, charsmax(logsFile), "%s/%s__%i-%02i-%02i.log",
315+
logsPath,
316+
pluginName[sizeof(LOG_FOLDER)],
317+
year, month, day
318+
)
313319
}
314320

315321
switch (ca_log_type) {
316-
case _LogToDir: log_to_file(logsFile, msg)
317322
case _Default: log_amx(msg)
323+
case _LogToDir: log_to_file(logsFile, msg)
318324
case _LogToDirSilent: log_to_file_ex(logsFile, msg)
319325
}
320326

0 commit comments

Comments
 (0)