generated from AfonsoCMSousa/CPP-Template
105 lines
3.1 KiB
C++
105 lines
3.1 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <stdint.h>
|
|
|
|
#include <sqlite3.h>
|
|
|
|
#include <logger/logger.h>
|
|
#include <file_io/files.h>
|
|
|
|
#define LOG_DEFAULT (LOG_TIME_STAMP | LOG_COLOR_OUT | LOG_LEVEL_INFO)
|
|
|
|
int main(int argc, char *argv[]) {
|
|
flogf(LOG_TIME_STAMP | LOG_COLOR_OUT | LOG_LEVEL_INFO,
|
|
"Starting Ranking system.\n");
|
|
|
|
char log_file_name[512] = {0};
|
|
char white_list_file_name[512] = {0};
|
|
char fast_time[16] = {0};
|
|
char med_time[16] = {0};
|
|
char slow_time[16] = {0};
|
|
u_int16_t level_up_rating = 0;
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
if (argv[i][0] == '-') {
|
|
switch (argv[i][1]) {
|
|
case 'l':
|
|
if (i + 1 < argc)
|
|
strncpy(log_file_name, argv[++i], sizeof(log_file_name) - 1);
|
|
break;
|
|
case 't':
|
|
if (i + 1 < argc)
|
|
level_up_rating = (u_int16_t)atoi(argv[++i]);
|
|
break;
|
|
case 'w':
|
|
if (i + 1 < argc)
|
|
strncpy(white_list_file_name, argv[++i], sizeof(white_list_file_name) - 1);
|
|
break;
|
|
case 'f':
|
|
if (strncmp(argv[i], "-fast", 5) == 0 && i + 1 < argc)
|
|
strncpy(fast_time, argv[++i], sizeof(fast_time) - 1);
|
|
break;
|
|
case 'm':
|
|
if (strncmp(argv[i], "-med", 4) == 0 && i + 1 < argc)
|
|
strncpy(med_time, argv[++i], sizeof(med_time) - 1);
|
|
break;
|
|
case 's':
|
|
if (strncmp(argv[i], "-slow", 5) == 0 && i + 1 < argc)
|
|
strncpy(slow_time, argv[++i], sizeof(slow_time) - 1);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} else {
|
|
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
if (log_file_name[0] && white_list_file_name[0] && level_up_rating && fast_time[0] && med_time[0] && slow_time[0]) {
|
|
if (file_exists(white_list_file_name) == 0) {
|
|
flogf(LOG_DEFAULT, "Using whitelist file: \"%s\"\n", white_list_file_name);
|
|
} else {
|
|
flogf(LOG_TIME_STAMP | LOG_COLOR_OUT | LOG_LEVEL_ERROR,
|
|
"No file with path \"%s\" was found\n", white_list_file_name);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
if ((strcmp(logFilePath, "MX5") == 0) || (strcmp(logFilePath, "GT86") == 0) ||
|
|
(strcmp(logFilePath, "GT4") == 0) || (strcmp(logFilePath, "GT3") == 0) ||
|
|
(strcmp(logFilePath, "LMH") == 0)) {
|
|
if (file_exists(logFilePath) == 0) {
|
|
char donnor[5];
|
|
char finalPath[256];
|
|
char *date = get_today_yyyymmdd();
|
|
|
|
strcpy(donnor, logFilePath);
|
|
sprintf(finalPath,
|
|
"/mnt/combined/servers/acserver_%s/utils/logs/log-%s.txt", donnor,
|
|
date);
|
|
strncpy(logFilePath, finalPath, sizeof(logFilePath) - 1);
|
|
|
|
if (file_exists(logFilePath) == 0) {
|
|
return 1;
|
|
}
|
|
}
|
|
} else {
|
|
flogf(LOG_TIME_STAMP | LOG_COLOR_OUT | LOG_LEVEL_ERROR,
|
|
"No valid log file name was provided. Please use one of the "
|
|
"following: MX5, GT86, GT4, GT3, LMH\n");
|
|
}
|
|
|
|
if (file_exists(logFilePath) == 0) {
|
|
flogf(LOG_DEFAULT, "Using log file: \"%s\"\n", logFilePath);
|
|
} else {
|
|
flogf(LOG_TIME_STAMP | LOG_COLOR_OUT | LOG_LEVEL_ERROR,
|
|
"No file with path \"%s\" was found\n", logFilePath);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|