Dannu

client.cs

Jul 15th, 2015
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // < +--------------------------------------+ >
  2. // | Project: BLIDChatLogger : client.cs
  3. // | Description: Logs BL_IDs, names, and chat.
  4. // | Author: Aoki
  5. // < +--------------------------------------+ >
  6.  
  7. package BLIDChatLoggingPackage
  8. {
  9. function NMH_Type::Send(%this)
  10. {
  11. %text = %this.getValue();
  12. %text = strReplace(%text, "https://", "http://");
  13.  
  14. if(getSubStr(%text, 0, 1) !$= "^")
  15. {
  16. parent::send(%this);
  17. return;
  18. }
  19.  
  20. if(firstWord(%text) $= "^recallID")
  21. {
  22. %bl_id = getWord(%text, 1);
  23.  
  24. if(%bl_id > 999999 || %bl_id < 100)
  25. %dontDoIt = 1;
  26.  
  27. %fileName = "config/client/BCL/data/" @ %bl_id @ ".txt";
  28.  
  29. if(!isFile(%fileName))
  30. %dontDoIt = 1;
  31.  
  32. if(!%dontDoIt)
  33. {
  34. %file = new fileObject();
  35. %file.openForRead(%fileName);
  36. while(!%file.isEOF()) {
  37. %names = %names @ %file.readLine() @ " "; }
  38. %file.close();
  39. %file.delete();
  40. %msg = "\c3" @ %bl_id @ "\c6:" SPC %names;
  41. newChatSO.addLine(%msg);
  42. %didStuff = 1;
  43. }
  44. }
  45. else if(firstWord(%text) $= "^recallName")
  46. {
  47. %bl_id = $BCL::BL_ID[restWords(%text)];
  48.  
  49. if(%bl_id > 999999 || %bl_id < 100)
  50. %dontDoIt = 1;
  51.  
  52. %fileName = "config/client/BCL/data/" @ %bl_id @ ".txt";
  53.  
  54. if(!isFile(%fileName))
  55. %dontDoIt = 2;
  56.  
  57. if(!%dontDoIt)
  58. {
  59. %file = new fileObject();
  60. %file.openForRead(%fileName);
  61. while(!%file.isEOF()) {
  62. %names = %names @ %file.readLine() @ " "; }
  63. %file.close();
  64. %file.delete();
  65. %msg = "\c3" @ %bl_id @ "\c6:" SPC %names;
  66. newChatSO.addLine(%msg);
  67. %didStuff = 1;
  68. }
  69. }
  70.  
  71. if(%dontDoIt == 1)
  72. newChatSO.addLine("\c3" @ %bl_id @ "\c6:" SPC "No names found.");
  73. else if(%dontDoIt == 2)
  74. newChatSO.addLine("\c6No BL_ID with that name is on your server.");
  75.  
  76. if(!%didStuff && !%dontDoIt)
  77. %this.setValue(%text);
  78. else
  79. %this.setValue("");
  80.  
  81. parent::send(%this);
  82. }
  83.  
  84. function clientcmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
  85. {
  86. if(BCL_isStr(%name) && BCL_isStr(%msg))
  87. echo(%name @ ":" SPC stripMlControlChars(%msg));
  88.  
  89. Parent::clientcmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg);
  90.  
  91. if(!BCL_isStr(%name) || !BCL_isStr(%msg))
  92. return;
  93.  
  94. BCL_loopExportChat(%name, stripMLControlChars(%msg));
  95. }
  96.  
  97. function newPlayerListGui::update(%this, %cl, %name, %BL_ID, %trust, %admin, %score)
  98. {
  99. Parent::update(%this, %cl, %name, %BL_ID, %trust, %admin, %score);
  100. BCL_exportBLID(%BL_ID, %name, %admin);
  101. $BCL::BL_ID[%name] = %BL_ID;
  102. }
  103.  
  104. function disconnect(%a)
  105. {
  106. parent::disconnect(%a);
  107. deleteVariables("$BCL::*");
  108. }
  109. };
  110.  
  111. function BCL_isStr(%str)
  112. {
  113. if(%str !$= "")
  114. return 1;
  115. return 0;
  116. }
  117.  
  118. function BCL_strCheck(%str, %chk)
  119. {
  120. if(strReplace(%str, %chk, "") !$= %str)
  121. return 1;
  122. return 0;
  123. }
  124.  
  125. function BCL_exportBLID(%BL_ID, %name, %admin)
  126. {
  127. if(%BL_ID > 999999 || %BL_ID < 100)
  128. return;
  129.  
  130. %fileName = "config/client/BCL/data/" @ %BL_ID @ ".txt";
  131. %fileWrite = %name;
  132. %file = new FileObject();
  133. %file.openForRead(%fileName);
  134. while(!%file.isEOF()) {
  135. %line = %file.readLine(); }
  136. if(%line !$= %fileWrite)
  137. {
  138. %file.openForAppend(%fileName);
  139. %file.writeLine(%fileWrite);
  140. }
  141. %file.close();
  142. %file.delete();
  143. }
  144.  
  145. function BCL_loopExportChat(%name, %chat)
  146. {
  147. if(!BCL_strCheck($ServerInfo::Name, "\'"))
  148. {
  149. $BCL::hasExported = 0;
  150. if(BCL_isStr(%name) && BCL_isStr(%chat))
  151. {
  152. if(!BCL_isStr($BCL::lzMsg[1]))
  153. $BCL::lzMsgCount = 0;
  154.  
  155. $BCL::lzMsg[$BCL::lzMsgCount++] = %chat;
  156. $BCL::lzName[$BCL::lzMsgCount] = %name;
  157.  
  158. schedule(1000, 0, BCL_loopExportChat);
  159. }
  160. }
  161. else
  162. {
  163. if(!$BCL::hasExported)
  164. {
  165. for(%a = 1; %a <= $BCL::lzMsgCount; %a++)
  166. {
  167. BCL_exportChat($BCL::lzName[%a], $BCL::lzMsg[%a]);
  168. }
  169. $BCL::hasExported = 1;
  170. }
  171. BCL_exportChat(%name, %chat);
  172. }
  173. }
  174.  
  175. function BCL_exportChat(%name, %chat)
  176. {
  177. %date = strReplace(getWord(getDateTime(), 0), "/", "-");
  178. %stupidClock = getSubStr(getDateTime(), 9, 2);
  179.  
  180. if(%stupidClock > 12)
  181. {
  182. %stupidClock -= 12;
  183. %hasTurned = 1;
  184. }
  185.  
  186. %time = %stupidClock @ ":" @ getSubStr(getDateTime(), 12, 2);
  187.  
  188. if(%hasTurned)
  189. %time = %time SPC "PM";
  190. else
  191. %time = %time SPC "AM";
  192.  
  193. %servName = $ServerInfo::Name;
  194. //the next line was taken from Curse's chat logging mod.
  195. %servName = (getSubstr(%servName,strStr(%servName,"\'")+1,1) $= "s") ? %servname = getSubstr(%servname,strStr(%servname,"-")+2,strStr(%servname,"'s")-strStr(%servname,"-")) : %servname = getSubstr(%servname,strStr(%servname,"-")+2,strStr(%servname,"'")-strStr(%servname,"-"));
  196. //this line is fixing a problem the line before made.
  197. %servName = getSubStr($ServerInfo::Name, 0, 1) @ %servName;
  198. %file = new fileObject();
  199. %file.openForAppend("config/client/BCL/chatLogs/" @ %servName @ " Server" @ "/" @ %date @ ".txt");
  200. %file.writeLine("[" @ %time @ "]" @ "[" @ $BCL::BL_ID[%name] @ "]" SPC %name @ ":" SPC %chat);
  201. %file.close();
  202. %file.delete();
  203. }
  204.  
  205. activatePackage(BLIDChatLoggingPackage);
RAW Paste Data