seishun / node-steam

Interface directly with Steam servers from Node.js
MIT License
1k stars 181 forks source link

How can I implement custom handlers for custom events #387

Closed PanicIsReal closed 7 years ago

PanicIsReal commented 7 years ago

I have included steam-resources and this is my little bit of code so far:

import { SteamUser } from 'steam';
import Steam from 'steam-resources';
import ByteBuffer from 'bytebuffer';

let EMsg = Steam.EMsg;
let schema = Steam.Internal;

class _SteamUser extends SteamUser {
  constructor(steamClient) {
    super(steamClient);

    this._client.on('message', function (header, body, callback) {
      console.log(header);
      if (header.msg in handlers)
        handlers[header.msg].call(this, ByteBuffer.wrap(body, ByteBuffer.LITTLE_ENDIAN), callback);
    }.bind(this));

  }

  getClientAppList() {
    console.log("HERRREEE")
    this._client.send({
      msg: EMsg.ClientGetClientAppList
    }, new schema.CMsgClientGetClientAppList({
      games: true
    }).toBuffer());
  }
}

var handlers = {};

// Enums to trigger handler
console.log(EMsg.ClientGetClientAppListResponse, "APP RESPONSE");
console.log(EMsg.ClientGetClientAppList, "REQUEST");

// Event not firing as I am not receiving 5519 response but am sending a 5518 enum
handlers[EMsg.ClientGetClientAppListResponse] = function (data) {
  console.log("HERE")
  console.log(data);
}

export default _SteamUser;

Everything works fine, but I don't seem to get the handler to fire, I don't see the event handler firing, this is my console output after running this code:

5519 'APP RESPONSE'
5518 'REQUEST'
1303
1305
5501
5501
5501
HERRREEE
751
768
5456
767
5553
5587
780
798
5528
779
850
5430
783
880
5480
880
782
1
831
1
5463
1
5510
1

I don't know if I'm sending the proto wrong or something but any information would be great.

seishun commented 7 years ago

Does the problem remain if you use 'message'/send directly? If so, it's a Steam protocol issue. Maybe you didn't specify sufficient data in the ClientGetClientAppList request, or maybe Steam just doesn't support it anymore. Have you tried using NetHook to see what the official Steam client sends and receives?

PanicIsReal commented 7 years ago

Not sure what NetHook is, and I haven't tried using message / send directly I just basically copy pasta'd some code from your handlers, I will try to do that tonight when I get home from work in about 12 hours.

PanicIsReal commented 7 years ago

Exactly which class has the send method if you don't access it through this._client

seishun commented 7 years ago

https://github.com/seishun/node-steam#messagesend

https://github.com/SteamRE/SteamKit/tree/master/Resources/NetHook2

How did you find out about ClientGetClientAppList if not NetHook?

PanicIsReal commented 7 years ago

Ctrl+F on the protobufs and typing keywords in like Game or App till I found the proto that did what I thought it was doing to do :)

scholtzm commented 7 years ago

Use the NetHook, otherwise it's like trying to drive with your eyes closed.

PanicIsReal commented 7 years ago

Ok I will try that out when I'm back home, will report back.

But in terms of message/send, I see the bit of documentation there, but is that steamUser.send or steamClient.send or am I just having some reading comprehension issues

seishun commented 7 years ago

It's steamClient.send, otherwise it would be documented in the README for SteamUser.

PanicIsReal commented 7 years ago

Ah ok fair enough, sorry, 5am here.

So I should just need to this.steamCli = steamClient; in my constructor and then this.steamCli.send... Will let you know what happens after I get to play around with it. Thanks.

PanicIsReal commented 7 years ago

But I do feel like that block of the readme could be easily clarified by not grouping message/send in the same title

Something like

Send Is a method of steamClient used to send messages to the steam servers, the callback is handled through the messages event handler

Or something along those lines. Thanks though!

Also if it helps clarifying my intentions I'm trying to basically build my own steam client with electron and this package to add more functionality and hopefully a plugin system so people can add their own plugins to the steam client. It's open source and under my repos.

Ne3tCode commented 7 years ago

Looks like ClientGetClientAppList is a request from server to client, and ClientGetClientAppListResponse is a response from client to server.

Upd: I was right, just hethooked it ^_^ This is a part of remote control system.

PanicIsReal commented 7 years ago

Oh ok thanks for that. I'll need to find the one that gets the users owned apps/games so I can populate their app/game list in my own steam client. Thanks.

scholtzm commented 7 years ago

I'm trying to basically build my own steam client with electron and this package to add more functionality and hopefully a plugin system so people can add their own plugins to the steam client.

< offtopic > Might wanna contribute to Punk. 😄 I've been using it for over a year now but I don't have as much time to improve it as I'd like. It already has a plugin system + a bunch of other stuff.

If you have more questions, you might want to visit /r/SteamBot since it's better suited for Q/A type of thing. < /offtopic >

seishun commented 7 years ago

the callback is handled through the messages event handler

The callback is for the response to the message (if any), 'message' is for incoming messages that are NOT responses.

PanicIsReal commented 7 years ago

@scholtzm that does look nice, I will continue to work on mine but I sure don't mind contributing to yours

@seishun Thanks I wasn't 100% sure how to word it, was just more of an example. I will close this issue as I feel this is no longer really related to this package. Thanks for the input guys