Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- var path = require('path');
- var https = require('https');
- var parseString = require('xml2js').parseString;
- var platform = process.platform;
- var jid = "watchlist.bot@eneticum.de";
- var password = "logbotpw";
- var room = "lobby@conference.eneticum.de";
- var XMPPClient = require("node-xmpp-client");
- var client = new XMPPClient({
- jid: jid,
- password: password
- });
- client.on('online', function() {
- console.log("online");
- client.send(new Client.Stanza("presence", {from: jid, to: room}));
- });
- process.on('SIGINT', function(code) {
- console.log('leaving the room')
- var stanza = new Client.Stanza('presence', {from: jid, to: room, type: 'unavailable'})
- client.send(stanza)
- setTimeout(function() {
- process.exit()
- }, 1000);
- });
- var reading = false;
- var watcher;
- var files = [];
- var curFile = "";
- var characters = [];
- var logpath = process.argv[2];
- startDirWatcher(logpath);
- function startDirWatcher (fp) {
- if(watcher) watcher.close();
- if(!fp || fp == "") return;
- watcher = fs.watch(fp, function (event, filename) {
- if(curFile != filename) console.log(filename);
- if(curFile != filename) files[fp + path.sep + filename] = { row: 0, off: 0 };
- curFile = filename;
- parseFile(fp + path.sep + filename, filename);
- });
- }
- function parseFile (f, fn) {
- var cnk = "";
- var off = 0;
- if(reading) return;
- reading = true;
- fs.createReadStream(f, { start: files[f].off }).on("data", function (chunk) { off += chunk.length; cnk += chunk.toString("utf8"); }).on("end", function () {
- files[f].off += off;
- reading = false;
- var data = cnk.split("\n");
- for(var i = 0; i < data.length; i++) {
- if(data[i].indexOf("OnContactLoggedOn") >= 0 || data[i].indexOf("OnContactLoggedOff") >= 0) {
- var type = data[i].indexOf("OnContactLoggedOn") >= 0 ? "logon" : "logoff";
- var m = data[i].match(/<MarshalStream '(.+?)'>|<MarshalStream "(.+?)">/);
- if(m && m.length > 1) {
- STORAGE = [];
- eval('var n = "' + m[m[1] ? 1 : 2].replace(/"/g, "\\\"") + ' ";');
- dat = n.replace(/\\x/g, "").hexEncode();
- ind = 2 + (4 * 2);
- var tmpo = processSnip();
- var di = tmpo[1][1][0];
- getCharacterSheet(di, function (data) {
- console.log(data.characterName + " " + type);
- sendNotification(data.characterID, data.characterName, type);
- characters[data.characterID] = { state: type, data: data, id: data.characterID, name: data.characterName };
- });
- }
- }
- }
- });
- }
- function sendNotification (id, name, state) {
- client.send(new Client.Stanza("message", { to: room, type: "groupchat"})
- .c("body")
- .t(("@name @state (@url)")
- .replace(new RegExp("@name", "g"), name)
- .replace(new RegExp("@state", "g"), "just logged " + state.substr(3))
- .replace(new RegExp("@url","g"), "https://zkillboard.com/character/" + id + "/" )
- )
- .up()
- .up()
- .c("html", { xmlns: 'http://jabber.org/protocol/xhtml-im' })
- .c("body", { xmlns: 'http://www.w3.org/1999/xhtml' })
- .c("a", { href: "https://zkillboard.com/character/" + id + "/" })
- .t(name)
- .up()
- .up()
- .t(" just logged " + state.substr(3))
- );
- //var stanza = "<message type='groupchat' to='lobby@conference.eneticum.de'><body>@name @state (@url)</body><html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'><a href='@url'>@name</a> @state</body></html></message>";
- //client.methodCall("send_stanza_c2s", [{ user: "admin", server: "eneticum.de", password: "hase2001", admin: true }, { user: "admin", host: "eneticum.de", resource: "LogBot", stanza: stanza.replace(new RegExp("@name", "g"), data.characterName).replace(new RegExp("@state", "g"), "just logged " + type.substr(3)).replace(new RegExp("@url","g"), "https://zkillboard.com/character/" + di + "/" ) }], function (err, val) { console.log(err, val); });
- }
- // stuff
- var PROTOCOL_ID = 0x7e;
- var TYPE = {
- NONE: 0x01, // 1: None
- GLOBAL: 0x02, // 2: usually a type, function or class object, but just the name,
- // so it has to exist for this to decode properly.
- INT64: 0x03, // 3: 8 byte signed int
- INT32: 0x04, // 4: 4 byte signed int
- INT16: 0x05, // 5: 2 byte signed int
- INT8: 0x06, // 6: 1 byte signed int
- MINUSONE: 0x07, // 7: the value of -1
- ZERO: 0x08, // 8: the value of 0
- ONE: 0x09, // 9: the value of 1
- FLOAT: 0x0a, // 10: 8 byte float
- FLOAT0: 0x0b, // 11: the value of 0.0
- //COMPLEX: 0x0c, // 12: (not used, complex number)
- STRINGL: 0x0d, // 13: string, longer than 255 characters using normal count*
- STRING0: 0x0e, // 14: string, empty
- STRING1: 0x0f, // 15: string, 1 character
- STRING: 0x10, // 16: string, next byte is 0x00 - 0xff being the count.
- STRINGR: 0x11, // 17: string, reference to line in strings.txt (stringTable)
- UNICODE: 0x12, // 18: unicode string, next byte is count*
- BUFFER: 0x13, // 19: buffer object... hmmm
- TUPLE: 0x14, // 20: tuple, next byte is count*
- LIST: 0x15, // 21: list, next byte is count*
- DICT: 0x16, // 22: dict, next byte is count*
- INSTANCE: 0x17, // 23: class instance, name of the class follows (as string, probably)
- BLUE: 0x18, // 24: blue object.
- CALLBACK: 0x19, // 25: callback
- //PICKLE: 0x1a, // 26: (not used, old pickle method)
- REF: 0x1b, // 27: shared object reference
- CHECKSUM: 0x1c, // 28: checksum of rest of stream
- COMPRESS: 0x1d, // 29: (not used)
- //UNUSED: 0x1e, // 30: (not used)
- TRUE: 0x1f, // 31: True
- FALSE: 0x20, // 32: False
- PICKLER: 0x21, // 33: standard pickle of undetermined size
- REDUCE: 0x22, // 34: reduce protocol
- NEWOBJ: 0x23, // 35: new style class object
- TUPLE0: 0x24, // 36: tuple, empty
- TUPLE1: 0x25, // 37: tuple, single element
- LIST0: 0x26, // 38: list, empty
- LIST1: 0x27, // 39: list, single element
- UNICODE0: 0x28, // 40: unicode string, empty
- UNICODE1: 0x29, // 41: unicode string, 1 character,
- DBROW: 0x2a, // 42: database row (quite hard, custom data format)
- STREAM: 0x2b, // 43: embedded marshal stream
- TUPLE2: 0x2c, // 44: tuple, 2 elements
- MARK: 0x2d, // 45: marker (for the NEWOBJ/REDUCE iterators that follow them)
- UTF8: 0x2e, // 46: UTF8 unicode string, buffer size count follows*,
- LONG: 0x2f, // 47: big int, byte count follows.,
- };
- var SHARED_FLAG = 0x40;
- String.prototype.hexEncode = function () {
- var hex, i;
- var result = "";
- for (i=0; i<this.length; i++) {
- hex = this.charCodeAt(i).toString(16);
- result += ("0"+hex).slice(-2);
- }
- return result
- }
- function processSnip () {
- var type = parseInt(getBytes(1), 16);
- var shared = (type & SHARED_FLAG) == SHARED_FLAG;
- type &= ~SHARED_FLAG;
- var result;
- switch(type) {
- case TYPE.TUPLE2:
- result = [processSnip(), processSnip()];
- break;
- case TYPE.FLOAT0:
- case TYPE.ZERO:
- result = 0;
- break;
- case TYPE.ONE:
- result = 1;
- break;
- case TYPE.MINUSONE:
- result = -1;
- break;
- case TYPE.LIST:
- case TYPE.TUPLE:
- result = Array.apply(null, Array(parseInt(getBytes(1), 16))).map(function () { return processSnip(); });
- break;
- case TYPE.INT32:
- result = parseInt(lTobEnd(getBytes(4)), 16);
- break;
- case TYPE.STRINGR:
- result = stringTable[parseInt(getBytes(1), 16)];
- break;
- case TYPE.LONG:
- result = new bigInt(lTobEnd(getBytes(parseInt(getBytes(1), 16))), 16).toString();
- break;
- case TYPE.INT16:
- result = parseInt(lTobEnd(getBytes(2)), 16);
- break;
- case TYPE.STRING:
- case TYPE.STRINGL:
- case TYPE.BUFFER:
- result = hexToString(getBytes(parseInt(getBytes(1), 16)));
- break;
- case TYPE.FLOAT:
- var ua = new Uint8Array(8);
- ua.set(getBytes(8).match(/.{1,2}/g).map(function (m) { return "0x" + m; }));
- result = new DataView(ua.buffer).getFloat64(0, true);
- break;
- case TYPE.TRUE:
- result = true;
- break;
- case TYPE.FALSE:
- result = false;
- break;
- case TYPE.NONE:
- result = null;
- break;
- case TYPE.STRING0:
- case TYPE.UNICODE0:
- result = "";
- break;
- case TYPE.DICT:
- var length = parseInt(getBytes(1), 16);
- var data = {};
- for(var i = 0; i < length; i++) {
- var tmp = processSnip();
- var tmpind = processSnip();
- if(typeof tmpind != "string" && typeof tmp == "string")
- data[tmp] = tmpind;
- else
- data[tmpind] = tmp;
- }
- result = data;
- break;
- case TYPE.UTF8:
- result = hexToString(getBytes(parseInt(getBytes(1), 16)));
- break;
- case TYPE.INT8:
- result = parseInt(lTobEnd(getBytes(1)), 16);
- break;
- case TYPE.REF:
- result = STORAGE[parseInt(getBytes(1), 16) - 1];
- break;
- case TYPE.LIST0:
- case TYPE.TUPLE0:
- result = [];
- break;
- case TYPE.INSTANCE:
- result = { "(instanceName)": processSnip(), "(instanceData)": processSnip() };
- break;
- case TYPE.DBROW:
- result = processDBROW();
- break;
- case TYPE.GLOBAL:
- result = { "(global)": hexToString(getBytes(parseInt(getBytes(1), 16))) };
- break;
- case TYPE.CALLBACK:
- result = { "(callback)": processSnip() };
- break;
- case TYPE.REDUCE:
- var results = [];
- var tmpres;
- while((tmpres = processSnip()) && tmpres != "(mark)") {
- results.push(tmpres);
- }
- processSnip(); // remove 2nd mark
- result = { "(reduce)": results };
- break;
- case TYPE.NEWOBJ:
- result = { "(newobj)": processSnip() };
- break;
- case TYPE.MARK:
- result = "(mark)";
- break;
- case TYPE.TUPLE1:
- case TYPE.LIST1:
- result = [processSnip()];
- break;
- case TYPE.INT64:
- result = new bigInt(lTobEnd(getBytes(8)), 16).toString();
- break;
- case TYPE.STRING1:
- result = hexToString(getBytes(1));
- break;
- case TYPE.STREAM:
- var tmpind = ind;
- var length = parseInt(getBytes(1), 16);
- ind += 2 + (2 * 4);
- var res = { "(marshal)": [] };
- while(ind < (tmpind + (length * 2))) res["(marshal)"].push(processSnip());
- result = res;
- break;
- case 0x00:
- break;
- default:
- if(settings.logging) console.log("TYPE " + type + " OFF " + ind);
- }
- if(shared) {
- STORAGE.push(result);
- }
- return result;
- }
- function getBytes(cnt) {
- var res = dat.substr(ind, 2 * cnt);
- ind += 2 * cnt;
- return res;
- }
- function lTobEnd (hex) {
- return !hex.match(/.{1,2}/g) ? hex : hex.match(/.{1,2}/g).reverse().join("");
- }
- function getCharacterSheet (id, cb) {
- var req = https.request(
- {
- host: "api.eveonline.com",
- path: "/EVE/CharacterAffiliation.xml.aspx",
- method: "POST",
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'user-agent': 'EVETOOL by rschuh, charinfo.eve@eneticum.de'
- }
- }, function (res) {
- var resData = "";
- res.on("data", function (chunk) {
- resData += chunk;
- });
- res.on("end", function () {
- parseString(resData, function (err, result) {
- if(err) {
- console.log(err);
- console.log(resData);
- } else {
- if(result.eveapi) {
- if(result.eveapi.error) {
- console.log(result.eveapi.error);
- } else {
- if(cb) cb(result.eveapi.result[0].rowset[0].row[0].$);
- }
- }
- }
- });
- });
- }).on('error', function(e) {
- console.error(e);
- });
- req.write("ids=" + id);
- req.end();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement