DRogue Posted October 31, 2016 Report Share Posted October 31, 2016 (edited) How do I use the on 'save' and on 'read' functions? When I'm doing it like this: const user = new SteamUser(); user.logOn(); user.storage.on('save', function(filename, contents, callback) { // filename is the name of the file, as a string // contents is a Buffer containing the file's contents // callback is a function which you MUST call on completion or error, with a single error argument // For example: console.log(filename, contents, callback); }); user.storage.on('read', function(filename, callback) { // filename is the name of the file, as a string // callback is a function which you MUST call on completion or error, with an error argument and a Buffer argument // For example: console.log(filename, callback); });I just get the output on start of my electron app: cellid-86[...].txt 91 (err) { if(callback) { callback(err || null); } } servers.json [91, 10, 9…] (err) { if(callback) { callback(err || null); } } So first this 'cellid-...txt' file and then the 'server.json'. But when I start an actual game via steam and close it the 'save' or 'read' event functions aren't called. Edited November 1, 2016 by DRogue Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted October 31, 2016 Report Share Posted October 31, 2016 I'm confused as to what you're talking about regarding an "actual game via steam". Can you explain exactly what you're doing and what you expect to happen? Quote Link to comment Share on other sites More sharing options...
DRogue Posted November 1, 2016 Author Report Share Posted November 1, 2016 I thought that when I start a game locally the on 'read' event gets called and I can determine from where the save game should be loaded. And when I close the game that the on 'save' event gets called and I can save the file to a cloud server or something. With "actual game" I just mean a game I bought and pressing "Play" in the Steam client. Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted November 1, 2016 Report Share Posted November 1, 2016 Sorry, you're a bit confused as to what the function of the storage engine is. It isn't for Steam Cloud data (that hasn't been implemented in steam-user at all). Rather, it's for saving data generated by the module itself (for example, sentry files and server lists). By default that data is saved to a platform-specific application data path, but the storage engine allows you to redirect storage elsewhere. Quote Link to comment Share on other sites More sharing options...
DRogue Posted November 1, 2016 Author Report Share Posted November 1, 2016 (edited) Ah okay alright, thank you. (that hasn't been implemented in steam-user at all) Do you mean that this is something that can be implemented or would you say there's no way accessing this part of the steam client? Edited November 1, 2016 by DRogue Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted November 1, 2016 Report Share Posted November 1, 2016 It could be implemented, but I wouldn't bank on it happening anytime soon. Quote Link to comment Share on other sites More sharing options...
jazz Posted November 9, 2016 Report Share Posted November 9, 2016 My example for mysql: user.storage.on('save', function(filename, contents, callback) { connection.query('REPLACE INTO `jsteam_custom_storage` (`filename`, `content`) VALUES (?, ?);', [filename, contents], function(err, results) { callback(err); }); }); user.storage.on('read', function(filename, callback) { connection.query('SELECT `content` FROM `jsteam_custom_storage` WHERE `filename` = ?', [filename], function (err, results, fields) { if(err) { callback(err); return; } callback(null, results[0].content); }); }); Please, tell me, what I need call back, when file does not exist (e. g. first start)? Quote Link to comment Share on other sites More sharing options...
jazz Posted November 9, 2016 Report Share Posted November 9, 2016 (edited) Found. Now works fine.var mysql = require('mysql'); var connection = mysql.createConnection({ host : reldb_host, user : reldb_user, password : reldb_password, database : reldb // ssl : { ca : fs.readFileSync(__dirname + '/mysql-ca.crt') } }); connection.connect(function(err) { if (err) { console.error('error connecting: ' + err.stack); return; } console.log('connected as id ' + connection.threadId); }); user.storage.on('save', function(filename, contents, callback) { connection.query('REPLACE INTO `jsteam_custom_storage` (`filename`, `content`) VALUES (?, ?);', [filename, contents], function(err, results) { callback(err); }); }); user.storage.on('read', function(filename, callback) { connection.query('SELECT `content` FROM `jsteam_custom_storage` WHERE `filename` = ?', [filename], function (err, results, fields) { if(err) { callback(err); return; } if(results.length) {console.log(results); callback(null, results[0].content); } else { callback(new Error("File not found")); }; }); }); I wanted to add init.sql, but cloudflare banned me with that.upd: changed. Edited November 9, 2016 by jazz Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted November 9, 2016 Report Share Posted November 9, 2016 If that works it's a fluke. You should pass an Error to the callback, like this: callback(new Error("File not found")); jazz 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.