@@ -17,7 +17,6 @@ enum logType_s {
17
17
18
18
new logType_s: ca_log_type,
19
19
logLevel_s: ca_log_level = logLevel_Debug,
20
- g_logsPath[PLATFORM_MAX_PATH],
21
20
bool: ca_update_notify,
22
21
ca_log_autodelete_time
23
22
@@ -53,11 +52,8 @@ public plugin_precache() {
53
52
54
53
create_cvar (" ChatAdditions_version" , PluginVersion, FCVAR_SERVER)
55
54
56
- GetLogsFilePath (g_logsPath, .dir = LOG_FOLDER)
57
-
58
55
Create_CVars ()
59
-
60
- AutoExecConfig (true , " ChatAdditions_core" , " ChatAdditions" )
56
+ CheckUpdate ()
61
57
}
62
58
63
59
public plugin_init () {
@@ -77,8 +73,6 @@ public plugin_init() {
77
73
CheckAutoDelete ()
78
74
79
75
CA_Log (logLevel_Debug, " Chat Additions: Core initialized!" )
80
-
81
- set_task_ex (6 .274 , " _OnConfigsExecuted" )
82
76
}
83
77
84
78
public plugin_end () {
@@ -87,39 +81,40 @@ public plugin_end() {
87
81
DestroyForward (g_fwdClientChangeName)
88
82
}
89
83
90
- public _OnConfigsExecuted () {
91
- CheckUpdate ()
92
- }
93
-
94
84
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
101
87
102
- deleteTime = get_systime () - (ca_log_autodelete_time * 60 * 60 * 24 )
88
+ new logsPath[PLATFORM_MAX_PATH]
89
+ GetLogsFilePath (logsPath, .dir = LOG_FOLDER)
103
90
104
- dirHandle = open_dir (g_logsPath, logFile, charsmax (logFile))
91
+ if (! dir_exists (logsPath))
92
+ return
105
93
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
110
99
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 ) )
113
102
114
- ReadFolder (deleteTime, subDirectory)
103
+ while (next_file (dirHandle, logFile, charsmax (logFile))) {
104
+ if (logFile[0 ] == ' .' )
105
+ continue
115
106
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
121
114
}
122
115
}
116
+
117
+ close_dir (dirHandle)
123
118
}
124
119
125
120
ReadFolder (deleteTime, logPath[]) {
@@ -185,6 +180,14 @@ Create_CVars() {
185
180
),
186
181
ca_log_autodelete_time
187
182
)
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 ()
188
191
}
189
192
190
193
public plugin_natives () {
@@ -283,38 +286,41 @@ public bool: native_CA_Log(const plugin_id, const argc) {
283
286
284
287
new logLevel_s: level = logLevel_s: get_param (arg_level)
285
288
286
- if (ca_log_level < level) {
289
+ if (ca_log_level < level)
287
290
return false
288
- }
289
291
290
292
new msg[2048 ]
291
293
vdformat (msg, charsmax (msg), arg_msg, arg_format)
292
294
293
295
new logsFile[PLATFORM_MAX_PATH]
294
296
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]
298
302
get_plugin (plugin_id, pluginName, charsmax (pluginName))
299
303
300
304
replace (pluginName, charsmax (pluginName), " .amxx" , " " )
301
305
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)
304
307
305
- if (! dir_exists (logsPath)) {
308
+ if (! dir_exists (logsPath))
306
309
mkdir (logsPath)
307
- }
308
310
309
311
new year, month, day
310
312
date (year, month, day)
311
313
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
+ )
313
319
}
314
320
315
321
switch (ca_log_type) {
316
- case _LogToDir: log_to_file (logsFile, msg)
317
322
case _Default: log_amx (msg)
323
+ case _LogToDir: log_to_file (logsFile, msg)
318
324
case _LogToDirSilent: log_to_file_ex (logsFile, msg)
319
325
}
320
326
0 commit comments