TheBlackParrot

agagableh

Jan 16th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.13 KB | None | 0 0
  1. //LogWriter by Kalphiter
  2. //Modified slightly by TBP.
  3.  
  4. //Function to output an updated date.
  5. function loggerloop(){
  6. cancel($loggersched);
  7. $upddate = getDate();
  8. $loggersched = schedule(60000,0,'loggerloop');
  9. }
  10. loggerloop();
  11.  
  12.  
  13. $LOGWrite::CommonPath = "Add-Ons/Server_TBP/Logs/" @ strreplace($upddate,"/",".") @ "/";
  14.  
  15. $LOGWrite::UnbanPath = $LOGWrite::CommonPath @ "unbans.txt";
  16. $LOGWrite::BanPath = $LOGWrite::CommonPath @ "bans.txt";
  17. $LOGWrite::ChatPath = $LOGWrite::CommonPath @ "chat.txt";
  18. $LOGWrite::helpPath = $LOGWrite::CommonPath @ "help.txt";
  19. $LOGWrite::ConnectionPath = $LOGWrite::CommonPath @"connections.txt";
  20.  
  21. $LOGWrite::statusPath = $LOGWrite::CommonPath @"status.txt";
  22.  
  23. //For /whis logging(IGSO only)
  24. $LOGWrite::whisPath = "config/server/Adminlogs/whis.txt";
  25.  
  26. if(isFile("Add-Ons/Script_IGSO.zip"))
  27. $LOGWrite::HasIgso = true;
  28. else
  29. $LOGWrite::HasIgso = false;
  30.  
  31.  
  32. if(!isFile($LOGWrite::helpPath))
  33. createHelpFile($LOGWrite::helpPath);
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. package LogWriter
  41. {
  42.  
  43. function addTime()
  44. {
  45. %getTime = firstWord(getDateTime()) TAB restWords(getDateTime());
  46. return %getTime;
  47. }
  48.  
  49.  
  50. function writeToFileLine(%filepath, %crap)
  51. {
  52. %file = new FileObject();
  53. %file.openForAppend(%filepath);
  54. %file.writeLine(%crap);
  55. %file.close();
  56. %file.delete();
  57. }
  58.  
  59.  
  60. function createHelpFile(%location)
  61. {
  62. %crap1 = "How to read the logs\r\n\r\n";
  63. %crap2 = "";
  64. %crap3 = "Ban logs\r\nDate, banner's name, banner's ID, banned's name, banned's ID, amount of time, reason\r\n\r\n";
  65. %crap4 = "Unban logs\r\nDate, unbanner, unbanner's ID, unbanned's name(if applicable), unbanned's ID\r\n\r\n";
  66. %crap5 = "Chat logs\r\nDate, name, ID, message\r\n\r\n";
  67. %crap6 = "Status logs(demotion and promotion)\r\nDate, Person who did it, who did it's ID, action, opposing name, opposing ID\r\n";
  68. %crap7 = "Actions: N means normal, S means super admin, A means admin\r\n\r\n";
  69. %crap8 = "Whis logs(only if you have IGSO)\r\nDate, client's ID, target's name, target's ID, message\r\n\r\n";
  70. %crap9 = "Connection logs\r\nDate, connect/disconnect, name, BL ID, IP Address\r\n\r\n";
  71.  
  72. %allCrap = %crap1 @ %crap2 @ %crap3 @ %crap4 @ %crap5 @ %crap6 @ %crap7 @ %crap8 @ %crap9;
  73. writeToFileLine(%location, %allCrap);
  74. }
  75.  
  76.  
  77. function GameConnection::onClientLeaveGame(%this)
  78. {
  79.  
  80. %type = "D";
  81.  
  82. //Date, connect/disconnect, name, BL ID, IP address
  83. writeToFileLine($LOGWrite::ConnectionPath, addTime() TAB %type TAB %this.name TAB %this.bl_id TAB %this.getRawIP());
  84.  
  85. parent::onClientLeaveGame(%this,%name,%a,%b,%c,%d,%e);
  86. }
  87.  
  88.  
  89. function GameConnection::autoAdminCheck(%this)
  90. {
  91. %type = "C";
  92.  
  93. //Date, connect/disconnect, name, BL ID, IP address
  94. writeToFileLine($LOGWrite::ConnectionPath, addTime() TAB %type TAB %this.name TAB %this.bl_id TAB %this.getRawIP());
  95.  
  96. parent::autoAdminCheck(%this);
  97. }
  98.  
  99.  
  100. function serverCmdmessageSent(%client, %text)
  101. {
  102. parent::serverCmdmessageSent(%client, %text);
  103. writeToFileLine($LOGWrite::ChatPath, addTime() TAB %client.name TAB %client.bl_id TAB %text);
  104. }
  105.  
  106. function servercmdRTB_DeAdminPlayer(%client,%victim)
  107. {
  108.  
  109. %oldMask = %victim.isAdmin @ %victim.isSuperAdmin;
  110. parent::servercmdRTB_DeAdminPlayer(%client,%victim);
  111. %newMask = %victim.isAdmin @ %victim.isSuperAdmin;
  112.  
  113. if(%newMask $= %oldMask) //if there is no rank change, let's just exit
  114. return;
  115.  
  116. if(%victim.isSuperAdmin)
  117. %origRank = "S";
  118.  
  119. if(%victim.isAdmin)
  120. %origRank = "A";
  121.  
  122. //Admin or super admin to normal player
  123. %rankChange = %origRank @"-N";
  124.  
  125. //Date, Person who did it, who did it's ID, action, opposing name, opposing ID
  126. writeToFileLine($LOGWrite::statusPath, addTime() TAB %client.name TAB %client.bl_id TAB %rankChange TAB %victim.name TAB %victim.bl_id);
  127. }
  128.  
  129.  
  130.  
  131. function servercmdRTB_AdminPlayer(%client,%victim)
  132. {
  133. %oldMask = %victim.isAdmin @ %victim.isSuperAdmin;
  134. Parent::serverCmdRTB_AdminPlayer(%client,%victim);
  135. %newMask = %victim.isAdmin @ %victim.isSuperAdmin;
  136.  
  137. if(%newMask !$= %oldMask)
  138. {
  139.  
  140. if(%victim.isSuperAdmin)
  141. {
  142. %adminLevel = 2;
  143. %status = "S";
  144. }
  145.  
  146. else
  147. {
  148. %adminLevel = 0;
  149. %status = "A";
  150. }
  151.  
  152. writeToFileLine($LOGWrite::statusPath, addTime() TAB %client.name TAB %client.bl_id TAB %status @"-A" TAB %victim.name TAB %victim.bl_id);
  153. }
  154. }
  155.  
  156.  
  157. function servercmdRTB_SuperAdminPlayer(%client, %victim)
  158. {
  159. %oldMask = %victim.isAdmin @ %victim.isSuperAdmin;
  160. Parent::serverCmdRTB_AdminPlayer(%client,%victim);
  161. %newMask = %victim.isAdmin @ %victim.isSuperAdmin;
  162.  
  163. if(%newMask !$= %oldMask)
  164. {
  165.  
  166. if(%victim.isAdmin)
  167. {
  168. %adminLevel = 1;
  169. %status = "A";
  170. }
  171.  
  172. else
  173. {
  174. %adminLevel = 0;
  175. %status = "N";
  176. }
  177.  
  178. writeToFileLine($LOGWrite::statusPath, addTime() TAB %client.name TAB %client.bl_id TAB %status @"-S" TAB %victim.name TAB %victim.bl_id);
  179. }
  180. }
  181.  
  182.  
  183. function serverCmdWhis(%client,%victim,%a1,%a2,%a3,%a4,%a5,%a6,%a7,%a8,%a9,%a10,%a11,%a12,%a13,%a14,%a15,%a16,%a17,%a18,%a19,%a20)
  184. {
  185.  
  186. if(!$LOGWrite::HasIgso)
  187. {
  188. return;
  189. }
  190.  
  191. if(!%victim.name) //don't log if person was not found
  192. {
  193. parent::serverCmdWhis(%client,%victim,%a1,%a2,%a3,%a4,%a5,%a6,%a7,%a8,%a9,%a10,%a11,%a12,%a13,%a14,%a15,%a16,%a17,%a18,%a19,%a20);
  194. return;
  195. }
  196.  
  197. %msg = %a1 SPC %a2 SPC %a3 SPC %a4 SPC %a5 SPC %a6 SPC %a7 SPC %a8 SPC %a9 SPC %a10 SPC %a11 SPC %a12 SPC %a13 SPC %a14 SPC %a15 SPC %a16 SPC %a17 SPC %a18 SPC %a19 SPC %a20;
  198.  
  199. //Date, client's name, client's ID, target's name, target's ID, message
  200. writeToFileLine($LOGWrite::whisPath, addTime() TAB %client.name TAB %client.bl_id TAB %victim.name TAB %victim.bl_id TAB %msg);
  201. parent::serverCmdWhis(%client,%Victim,%a1,%a2,%a3,%a4,%a5,%a6,%a7,%a8,%a9,%a10,%a11,%a12,%a13,%a14,%a15,%a16,%a17,%a18,%a19,%a20);
  202. }
  203.  
  204.  
  205. function servercmdUnban(%unbanner, %positionInList)
  206. {
  207. %banCount = BanManagerSO.numBans;
  208. parent::servercmdunban(%unbanner, %positionInList);
  209. if(%banCount == BanManagerSO.numBans)
  210. return;
  211.  
  212. //%unbanner person who is unbanning this person
  213. //%positionInList position of the person being unbanned in the unban list
  214.  
  215. //Also another benefit, you can see expired bans, in case of abuse
  216.  
  217. //Date, unbanner, unbanner's ID, unbanned's name(if applicable), unbanned's ID
  218.  
  219. if(!banManagerSO.victimName[%positionInList])
  220. %nameIfApplicable = "?";
  221.  
  222. writeToFileLine($LOGWrite::UnbanPath, addTime() TAB %unbanner.name TAB %unbanner.bl_id TAB %nameIfApplicable TAB banManagerSO.victimBL_ID[%positionInList]);
  223.  
  224. }
  225.  
  226.  
  227. function servercmdBan(%banner, %bannedClient, %bannedID, %banTime, %banReason)
  228. {
  229. %banCount = BanManagerSO.numBans;
  230. %reason = BanManagerSO.Reason[getField(1, BanManagerSO.isBanned(%bannedID))];
  231. parent::servercmdban(%banner, %bannedClient, %bannedID, %banTime, %banReason);
  232. //if the ban count didn't change, it probably means they're not allowed to ban
  233. //But, an admin may revise a previous ban in which the ban count will not change, so we check to see if the reason changed
  234. if(%banCount == BanManagerSO.numBans && %banReason $= BanManagerSO.Reason[getField(1, BanManagerSO.isBanned(%bannedID))])
  235. return;
  236.  
  237. if(!%banner.isAdmin)
  238. return;
  239.  
  240. //And newly discovered,
  241.  
  242. //%banner person who is issuing ban
  243. //%bannedClient person being banned(If person has never visited server, will return BL_ID
  244. //%bannedID ID of person being banned
  245. //%banTime Time in minutes(-1 is forever, you've heard that before)
  246. //%banReason Reason, obviously
  247.  
  248. //What's being written to the file:
  249. //Date, banner's name, banner's ID, banned's name, banned's ID, time, reason
  250.  
  251. //It is possible to ban people with the /ban command, but they might not have their name in the server "history"
  252. //The server history logs all IDs and names in the clear bricks list, and once the server is shut it dissapears
  253. %nameIfApplicable = %bannedClient.name;
  254. if(!%bannedClient.name)
  255. %nameIfApplicable = "?";
  256.  
  257. writeToFileLine($LOGWrite::BanPath, addTime() TAB %banner.name TAB %banner.bl_id TAB %nameIfApplicable TAB %bannedID TAB %banTime TAB %banReason);
  258. }
  259.  
  260.  
  261. };
  262.  
  263. activatePackage(LogWriter);
Advertisement
Add Comment
Please, Sign In to add comment