我有一个问题,即时通讯想要从FeederBot函数内访问data.names,所以我可以访问从客户端命名的名称。但我不知道如何。我想让这个变量在feeder bot里面访问,这个.nickname = data.names。任何帮助?需要访问变量之外的功能和另一个
io.on('connection', function(socket) {
socket.on('login', function(data) {
console.log("User connected with id:" + data.uuid + " Bot names: " + data.names);
socket.room = data.uuid;
socket.join(data.uuid);
if (data.type == "server") {
io.sockets.in(socket.room).emit("force-login", "server-booted-up");
}
}.bind(this));
socket.on('pos', function(data) {
//console.log(socket.room + " : " + data);
io.sockets.in(socket.room).emit('pos', data);
});
socket.on('cmd', function(data) {
console.log(data);
io.sockets.in(socket.room).emit('cmd', data);
});
socket.on("spawn-count", function(data) {
io.sockets.in(socket.room).emit("spawn-count", data);
});
socket.emit("force-login", "startup");
});
function FeederBot(bot_id, agent, bot_number, server) {
this.bot_id = bot_id; //ID of bot for logging
this.interval_id = 0; //here we will store setInterval's ID
this.ball_id = null;
this.server = ''; //server address will be stored here
this.client = new AgarioClient('Bot_' + this.bot_id); //creates new client
this.client.debug = 0;
this.client.agent = agent;
this.client.headers['user-agent'] = config.userAgent;
if (facebookManager.hasAvailableToken()) {
this.client.auth_token = facebookManager.getToken();
}
this.isOnFeedMission = false; this.nickname = "Exper"
this.lastsent = {minx: 0, miny: 0, maxx: 0, maxy: 0};
this.onboard_client(server, bot_number);
}
有很多的数据在你的代码中,在每个套接字事件处理程序中。你想要哪一个? – RomanPerekhrest
从登录处理程序 – exper