I have this code in NODE.JS to connect to socket.io server and dont work.
var io = require('socket.io-client');
var socket = io('https://pt53.tribalwars.com.pt:8081/game', {
query: "sessid=" + tribal.sid + "&village_id=" + tribal.village_id + "&screen=overview",
rememberUpgrade: !0 //true
})
socket.on('connect', function(){
console.log("CONNECTED")
console.log(socket.id);
});
The value of
tribal.sid // Session ID
and
tribal.village_id //Village ID
is from cookies after login in the game. I already have it working.
HTML
Here is the webpage code in some script tag (pt53.tribalwars.com.pt) WORLD 53
Example: Connection.connect(ip,port,sessionid,protocol)
Connection.connect('pt53.tribalwars.com.pt', 8081, '88ab75e0bdf2', true);
JS
file (game.js) METHOD connect:
connect: function(e, i, n, o) {
var t = this;
if ("android" !== window.game_data.device) {
if (!this.isSupportedBrowser()) return void this.showUnsupportedBrowserNotice();
if (!window.iosappdata || $.inArray("socket.io", window.iosappdata.capabilities) === -1) {
if ("undefined" == typeof io) return void Connection.debug("node", "Couldn't connect to backend: socket.io not available");
var a = "undefined" != typeof game_data.village ? game_data.village.id : 0,
r = {
query: "sessid=" + n + "&village_id=" + a + "&screen=" + game_data.screen,
rememberUpgrade: !0
};
Boolean($.cookie("websocket_available")) === !0, this.socket = io.connect((o ? "https://" : "http://") + e + ":" + i + "/game", r);
var s = this.socket;
this.socket.on("connect", function() {
Connection.debug("Connected to backend"), $(Connection).trigger("connected");
for (var e = 0; e < t.emit_queue.length; e++) {
var i = t.emit_queue[e];
s.emit(i[0], i[1])
}
t.emit_queue = []
}), this.socket.io.engine.on("upgrade", function(e) {
$.cookie("websocket_available", !0)
}), this.socket.on("connect_error", function() {
$(Connection).trigger("connect_error")
}), this.socket.on("disconnect", function(e) {
Connection.debug("disconnected"), $(Connection).trigger("disconnected")
}), this.socket.on("error", function(e) {
"Invalid session" === e && $(Connection).trigger("disconnected")
}), $.each(this.pending_handlers, function(e, i) {
Connection.registerHandler(e, i)
})
}
}
},
I can post more code about this file if needed.
Conclusion
I wonder if it's possible, I can not connect, can it be missing cookies or something? The address is correct and the query option is also correct :/
via backnd
No comments:
Post a Comment