-
Notifications
You must be signed in to change notification settings - Fork 1
/
SteamLogger.js
125 lines (95 loc) · 3.61 KB
/
SteamLogger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const SteamUser = require("steam-user");
const SteamTotp = require("steam-totp");
const SteamCommunity = require('steamcommunity');
const path = require('path');
const request = require('request');
var mysql = require('mysql');
let user = new SteamUser();
let community = new SteamCommunity();
console.log("Starting SteamLogger...");
const steam_user = ``;
const steam_pass = ``;
const steam_shared_secret = "";
const steam_api = ``;
const db_host = `localhost`;
const db_user = `root`;
const db_pass = ``;
const db_database = `steamlogger`;
const db_port = 3306;
const db_multipleStatements = false;
var connection = mysql.createConnection({
host: `${db_host}`,
user: `${db_user}`,
password: `${db_pass}`,
database: `${db_database}`,
port: `${db_port}`,
multipleStatements: db_multipleStatements
})
connection.connect(function(err) {
if (err) throw err
});
function handleDisconnect(connection) {
connection.on('error', function(err) {
if (!err.fatal) {
return;
}
if (err.code !== 'PROTOCOL_CONNECTION_LOST') {
throw err;
}
console.log('Re-connecting lost connection: ' + err.stack);
connection = mysql.createConnection(connection);
handleDisconnect(connection);
connection.connect();
});
}
handleDisconnect(connection);
const colors = {
red: "\x1b[31m%s\x1b[0m",
purple: "\x1b[35m%s\x1b[0m",
green: "\x1b[32m%s\x1b[0m",
cyan: "\x1b[36m%s\x1b[0m",
yellow: "\x1b[33m%s\x1b[0m"
}
function login(){
user.logOn({
"accountName": `${steam_user}`,
"password": `${steam_pass}`,
"twoFactorCode": SteamTotp.getAuthCode(`${steam_shared_secret}`)
})
user.on("loggedOn", function() {
console.log(colors.green, "Successfully logged into Steam!");
user.on('Profile', function(communityitemid) {
console.log(communityitemid);
})
user.on("webSession", function(sessionID, cookies) {
community.setCookies(cookies);
user.setPersona(SteamUser.EPersonaState.Online);
user.on('friendMessage', function(steamID, message) {
var steamID3 = steamID.getSteam3RenderedID();
var steamID64 = steamID.getSteamID64();
let Sprofile = `http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${steam_api}&steamids=${steamID64}`;
let options = {json: true};
console.log("Friend message from " + steamID.getSteam3RenderedID() + ": " + message);
function InsertDATA(Sid3, Sid64, Spersonaname, Savatar, Smsg) {
// connection.query(`INSERT INTO friends (steamID3, steamID64, personaname) VALUES (?,?,?, (WHERE NOT EXISTS (SELECT * FROM friends WHERE steamID64 = (?)))) `, [Sid3, Sid64, Spersonaname, Sid64], function(err, result) {
// if (err) throw err
// });
connection.query(`INSERT INTO received (steamID3, steamID64, personaname, avatar, message) VALUES (?,?,?,?,?)`, [Sid3, Sid64, Spersonaname, Savatar, Smsg], function(err, result) {
if (err) throw err
});
}
request(Sprofile, options, (error, res, body) => {
var personaname = body["response"]["players"][0]["personaname"];
var avatar = body["response"]["players"][0]["avatarfull"];
if (error) {
return console.log(error)
};
if (!error && res.statusCode == 200) {
InsertDATA(steamID3, steamID64, personaname, avatar, message);
};
});
});
});
});
}
login();