10.02.2015, 17:34
Hello, basically, the logging system I've tried doing just wont work.......
I can't figure out why...
If someone could help or even spot what's wrong with it, that'd be great.
I can't figure out why...
If someone could help or even spot what's wrong with it, that'd be great.
Код:
new File:disconnectlog; new File:connectlog; new File:killls; new File:chatlogs; new File:cmdlog; new File:paylog; new File:adminlog; new logstr[1024]; loggingOnGameModeInit() { new File:tfd; if(!fexist("/logs/Disconnections.txt")) { tfd = fopen("/logs/Disconnections.txt", io_write); if(!tfd) { printf("Failed to create disconnect file!\n"); } else { fclose(tfd); } } disconnectlog = fopen("/logs/Disconnections.txt",io_append); if(!disconnectlog) { printf("Failed to open disconnect file!\n"); } if(!fexist("/logs/Connections.txt")) { tfd = fopen("/logs/Connections.txt", io_write); if(!tfd) { printf("Failed to create connect file!\n"); } else { fclose(tfd); } } connectlog = fopen("/logs/Connections.txt",io_append); if(!connectlog) { printf("Failed to open connect file!\n"); } if(!fexist("/logs/cmdlog.txt")) { tfd = fopen("/logs/cmdlog.txt", io_write); if(!tfd) { printf("Failed to create command log!\n"); } else { fclose(tfd); } } cmdlog = fopen("/logs/cmdlog.txt",io_append); if(!cmdlog) { printf("Failed to open command log\n"); } if(!fexist("/logs/Kills.txt")) { tfd = fopen("/logs/Kills.txt", io_write); if(!tfd) { printf("Failed to create kills file!\n"); } else { fclose(tfd); } } killls = fopen("/logs/kills.txt",io_append); if(!killls) { printf("Failed to open Kill Log file!\n"); } if(!fexist("/logs/pay.txt")) { tfd = fopen("/logs/pay.txt", io_write); if(!tfd) { printf("Failed to create pay log!\n"); } else { fclose(tfd); } } paylog = fopen("/logs/pay.txt",io_append); if(!paylog) { printf("Failed to open pay log\n"); } if(!fexist("/logs/admin.txt")) { tfd = fopen("/logs/admin.txt", io_write); if(!tfd) { printf("Failed to create admin log!\n"); } else { fclose(tfd); } } adminlog = fopen("/logs/admin.txt",io_append); if(!adminlog) { printf("Failed to open admin log\n"); } if(!fexist("/logs/chatlogs.txt")) { tfd = fopen("/logs/chatlogs.txt", io_write); if(!tfd) { printf("Failed to create chat logs file!\n"); } else { fclose(tfd); } } chatlogs = fopen("/logs/chatlogs.txt",io_append); if(!disconnectlog) { printf("Failed to open chat logs file!\n"); } } loggingOnGameModeExit() { if(disconnectlog) { fclose(disconnectlog); } if(connectlog) { fclose(connectlog); } if(cmdlog) { fclose(cmdlog); } if(killls) { fclose(killls); } if(paylog) { fclose(paylog); } if(adminlog) { fclose(adminlog); } if(chatlogs) { fclose(chatlogs); } } loggingOnCharLogin(playerid) { new connected[1024]; new ip[16]; new gpciID[64]; if(connectlog) { new hour; new minute; new second; new day; new month; new year; gettime(hour,minute,second); getdate(year, month, day); gpci(playerid, gpciID, sizeof(gpciID)); GetPlayerIpEx(playerid, ip, sizeof(ip)); format(connected,sizeof(connected),"[%02d/%02d/%02d %02d:%02d:%02d] Player: %s || ID: %d || IP: %s || GPCI: %s connected. \r\n",day, month, year, hour, minute, second, GetPlayerNameEx(playerid, ENameType_CharName), playerid, ip, gpciID); fwrite(connectlog,connected); format(logstr, sizeof(logstr), "INSERT INTO `connections` SET `charid` = %d,`ip` = INET_ATON(\"%s\"),`gpci` = \"%s\",`connecttime` = CURRENT_TIMESTAMP()",GetPVarInt(playerid, "CharID"), ip, gpciID); mysql_function_query(g_mysql_handle, logstr, true, "InsertConnectLog", "d",playerid); return 1; } return 0; } forward InsertConnectLog(playerid); public InsertConnectLog(playerid) { new id = mysql_insert_id(); SetPVarInt(playerid, "ConnectLogID", id); } loggingOnPlayerDisconnect(playerid, reason) { new disconnected[1024]; format(logstr, sizeof(logstr), "UPDATE `connections` SET `disconnecttime` = CURRENT_TIMESTAMP,`quitreason` = %d WHERE `id` = %d",reason,GetPVarInt(playerid, "ConnectLogID")); mysql_function_query(g_mysql_handle, logstr, true, "EmptyCallback", ""); if(disconnectlog) { new hour; new minute; new second; new day; new month; new year; gettime(hour,minute,second); getdate(year, month, day); format(disconnected,sizeof(disconnected),"[%02d/%02d/%02d %02d:%02d:%02d] Name: %s || ID: %d disconnected(%d). \r\n",day, month, year, hour, minute, second,GetPlayerNameEx(playerid, ENameType_CharName),playerid,reason); fwrite(disconnectlog,disconnected); return 1; } return 0; } loggingOnPlayerDeath(playerid, killerid, reason) { new deaths[1024]; if(killls) { new hour; new minute; new second; new day; new month; new year; gettime(hour,minute,second); getdate(year, month, day); if(killerid != INVALID_PLAYER_ID) { format(deaths,sizeof(deaths),"[%02d/%02d %02d:%02d] %s was killed by %s - %d\r\n",day, month, hour, minute, GetPlayerNameEx(playerid, ENameType_CharName), GetPlayerNameEx(killerid, ENameType_CharName), reason); } else { format(deaths,sizeof(deaths),"[%02d/%02d/%02d %02d:%02d:%02d] %s killed - %d\r\n",day, month, year, hour, minute, second,GetPlayerNameEx(playerid, ENameType_CharName), reason); } fwrite(killls,deaths); return 1; } printf("Cannot write file is not open"); return 0; } loggingOnPlayerCommand(playerid, cmdtext[]) { new cmd[1024]; if(cmdlog) { new hour; new minute; new second; new day; new month; new year; gettime(hour,minute,second); getdate(year, month, day); format(cmd,sizeof(cmd),"[%02d/%02d/%02d %02d:%02d:%02d] %s: %s\r\n",day, month, year, hour, minute, second,GetPlayerNameEx(playerid, ENameType_CharName), cmdtext); fwrite(cmdlog,cmd); return 1; } return 0; } AdminLog(playerid, str[]) { if(adminlog) { new hour; new minute; new second; new day; new month; new year; gettime(hour,minute,second); getdate(year, month, day); format(logstr,sizeof(logstr),"[%02d/%02d/%02d %02d:%02d:%02d] %s: %s\r\n",day, month, year, hour, minute, second,GetPlayerNameEx(playerid, ENameType_CharName), str); fwrite(adminlog,logstr); return 1; } return 0; } ChatLogs(playerid, str[]) { if(chatlogs) { new hour; new minute; new second; new day; new month; new year; gettime(hour,minute,second); getdate(year, month, day); format(logstr,sizeof(logstr),"[%02d/%02d/%02d %02d:%02d:%02d] %s: %s\r\n",day, month, year, hour, minute, second,GetPlayerNameEx(playerid, ENameType_CharName), str); fwrite(chatlogs,logstr); return 1; } return 0; } payLog(str[]) { if(paylog) { new hour; new minute; new second; new day; new month; new year; gettime(hour,minute,second); getdate(year, month, day); format(logstr,sizeof(logstr),"[%02d/%02d/%02d %02d:%02d:%02d] %s\r\n",day, month, year, hour, minute, second, str); fwrite(paylog,logstr); return 1; } return 0; }