Tugamars_PT

Untitled

Jun 29th, 2016
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. Tugamars - Today at 12:13 AM
  2. Hello
  3. Anyone here ?
  4. sirsquidness - Today at 12:14 AM
  5. hello!
  6. yes
  7. Tugamars - Today at 12:14 AM
  8. You are one of the project manager on Opensourcelan, right ?
  9. sirsquidness - Today at 12:16 AM
  10. yeah, that's me
  11. Tugamars - Today at 12:16 AM
  12. First of all, nice to meet you 😃
  13. I am here trying to understand your log-parser for srcds logs, and i cant just understand where you call the file to be parsed. Can you give me a light ?
  14. sirsquidness - Today at 12:17 AM
  15. Sure thing, just a moment
  16. The wrapper I used to test it as I was writing is here https://github.com/OpenSourceLAN/better-csgo-log-parser/blob/master/test.ts which opens a file and reads it line by line, feeding each line in to the parser
  17. GitHub
  18. OpenSourceLAN/better-csgo-log-parser
  19. better-csgo-log-parser - A CSGO log parser that works
  20.  
  21. Tugamars - Today at 12:19 AM
  22. okay, but in what line you can the file ? its the 5 line ?
  23. call*
  24. sirsquidness - Today at 12:20 AM
  25. yeah, line 5
  26. Tugamars - Today at 12:21 AM
  27. I cant just understand how i can call a file like log-30-06-2016.log, from what u got here --> fs.readFileSync(process.argv[2]).toString().split("\n");
  28. sirsquidness - Today at 12:21 AM
  29. var fileContents = fs.readFileSync(process.argv[2]).toString().split("\n");
  30.  
  31. fs.readFileSync takes a filename and returns the whole text of the file in a Buffer object. We call .toString() on the buffer so that it's a string. And then split it by line so that we can pass each line in to the parser individually
  32. process.argv[2] is the filename - in the test.js file, I pass it as a command line argument, so it ends up in argv
  33. you can replace process.argv[2] with "log-30-06-2016.log" or another variable with a filename, and it'll open that file
  34. Tugamars - Today at 12:22 AM
  35. oh ok. But var process is related to a library, no ?
  36. sirsquidness - Today at 12:23 AM
  37. Correct. process is a node library. You can see the documentation for it here https://nodejs.org/dist/latest-v6.x/docs/api/process.html
  38. Specifically https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_process_argv for the way command line arguments work 😃
  39. Tugamars - Today at 12:24 AM
  40. Ok, and if i replace process.argv[2] with "log-30-06-2016.log", it will return exactly the same result ? O.o
  41. sirsquidness - Today at 12:28 AM
  42. here is a different and shorter script that will read the file
  43. var fs = require('fs');
  44. var logparser = require('./index');
  45. var filenameToRead = "log-30-06-2016.log";
  46.  
  47. var parser = new logparser();
  48.  
  49. var fileContents = fs.readFileSync(filenameToRead).toString().split("\n");
  50.  
  51. for (var i = 0; i < fileContents.length; i++) {
  52. var parsedLine = parser.parseLine(fileContents[i]);
  53. console.log(parsedLine);
  54. }
  55. so that will read every line in the log file and print it to the console
  56. Tugamars - Today at 12:30 AM
  57. Ok, replacing that on the test.js is the same, thats it ?
  58. sirsquidness - Today at 12:31 AM
  59. yup, you can replace test.js with that or make another file in the same directory
  60. Tugamars - Today at 12:32 AM
  61. Ok, and than it will print the things on a console '
  62. the console*
  63. sirsquidness - Today at 12:34 AM
  64. yes
  65. What's the project you are working on? 😃
  66. Tugamars - Today at 12:34 AM
  67. If you see this, its done with ebot
  68. (Click on the map to see what im talking)
  69. not that
  70. Wrong thing
  71. What im talking is something like that, Scorebot + log. But i just can do it with eBot, and to do with ebot you need sql rights on the database, wich almost no one gives
  72. So i need to do it with a general thing, like LOG
  73. sirsquidness - Today at 12:37 AM
  74. cool 😃
  75. Tugamars - Today at 12:37 AM
  76. But my knowlege of node/js is almost 0 :/
  77. sirsquidness - Today at 12:38 AM
  78. you may also be interested in https://github.com/OpenSourceLAN/csgo-competition-manager/tree/master/log-receiver this folder
  79. GitHub
  80. OpenSourceLAN/csgo-competition-manager
  81. csgo-competition-manager - A simple web tool to manager CSGO competitive servers
  82.  
  83. you can tell a srcds/csgo server to send its log over the network
  84. Tugamars - Today at 12:39 AM
  85. i checked that, but it works on server-side, no?
  86. sirsquidness - Today at 12:39 AM
  87. the files in that folder will listen for the network log messages and let you update statistics live
  88. it can be anywhere with internet access
  89. Tugamars - Today at 12:40 AM
  90. definedSources: [
  91. { address: "10.0.0.100", port: 27015, password: "12345" }
  92. thats where i define where to get the log from ?
  93. (its on the test.ts)
  94. sirsquidness - Today at 12:42 AM
  95. The reason that is there is that there is optional security on the log protocol
  96. If you do not set a password on the protocol using the srcds cvar sv_logsecret (I think), you do not need to put anything in there
  97. But if you do set a log password in your srcds instance, you do need to enter the server in to the definedSources
  98. Tugamars - Today at 12:45 AM
  99. yeah, i figured it will work like that. But if you put log_adress my.ip, and dont use sv_logsecret, you need to define the ip of the server anyway ?
  100. sirsquidness - Today at 12:46 AM
  101. By default it will accept logs from any server
  102. The library only receives the UDP packets from the servers, it does not connect or send anything to the servers, so it doesn't need to know what the servers are
  103. Tugamars - Today at 12:47 AM
  104. hm. And it will automatic parse the log and print it to somewhere or just receive ?
  105. sirsquidness - Today at 12:49 AM
  106. you register a handler with it
  107. l.on("data", (d: Listener.LogMessage) => {
  108. console.log("Got: ", parser.parseLine(d.message));
  109. });
  110. When it receives a packet, it will read it and emit a data event, which will be handled by that
  111. You can read more about how the event emitter works here https://nodejs.org/dist/latest-v6.x/docs/api/events.html#events_class_eventemitter
  112. Tugamars - Today at 12:51 AM
  113. Thank you so much, man. Im understanding how it works. Just need to see how to adapt it to my reality
  114. Again, thank you, you have been very helpful and its quite rare to see people like that. Thanks again
  115. sirsquidness - Today at 12:52 AM
  116. No problem.
  117. Also, since you're new to javascript, watch out - I wrote these in TypeScript, which gets turned in to javascript. So you will need to do
  118. npm install -g [email protected]
  119. tsc
  120.  
  121. if you haven't already to compile the typescript to javascript
  122. Tugamars - Today at 12:53 AM
  123. Yeah, i figured that. Thanks 😃
  124. Im gone leave, thanks again 😃
  125. Escolher Ficheiros
Advertisement
Add Comment
Please, Sign In to add comment