[英]How would I only allow only certain messages to be set users [NODE.JS]
I am working on a mutliplayer game and decided to use NodeJS aspart of the system. 我正在做一个多层游戏,因此决定将NodeJS用作系统的一部分。 The nodeJS is linked to mc# game emulator via TCP. nodeJS通过TCP链接到mc#游戏模拟器。
However how would I send messages to certain user ID? 但是,我将如何发送消息给某些用户ID? Each individual user in the database is sided by a unique user ID (EG 1) 数据库中的每个用户都有唯一的用户ID(EG 1)
How can I do this so if a user in game does a certain thing and that sends a message from Node ONLY TO THEM. 如果游戏中的用户做某件事并且仅将消息从Node发送给他们,我该怎么做。
Since I can't run node on the same port as my cms (Port 80). 由于我无法在与cms(端口80)相同的端口上运行节点。 I need a method in which I can use PHP to pull the ID or something. 我需要一种可以使用PHP提取ID或其他内容的方法。
Use as Jquery and 'GET'? 用作Jquery和“ GET”? I'm suck. 我很烂
By message I mean data such as sending a javascript window. 消息指的是诸如发送JavaScript窗口之类的数据。
Options available: JQuery Javascript PHP Node 可用选项:JQuery Javascript PHP节点
I thought of a method were the user id is presented within a div through a parameter in PHP (EG $ID) and then javascript checked against the div and the message to see if the ids matched. 我想到了一种方法,该方法是在PHP中通过参数(EG $ ID)在div中显示用户ID,然后针对div和消息检查javascript以查看ID是否匹配。 Then within the message the users ID would be included, then somehow I could split the message? 然后在邮件中将包含用户ID,然后以某种方式可以拆分邮件? so its "","" (ID,MESSAGE) 因此其为“”,“”(ID,MESSAGE)
Code: 码:
var socket = io.connect(' http://dev.com '); var socket = io.connect(' http://dev.com '); socket.on('field', function (data) { socket.on('field',function(data){
if ($("#userid").text().indexOf(data) > -1)
{
window.alert('lol');
console.log(data);
$("#field").html(data);
}
else
{
window.alert("Something has gone wrong with the node server...");
}
}); });
It didn't work. 没用
THE PAGE: 这一页: THE C#: C#: THE NODE: 节点:
Based on your response in the comments: 根据您在评论中的回复:
Inside the messages are just html that node sends to the page via a Node HTTP server. 消息中只是节点通过节点HTTP服务器发送到页面的html。 The messages aren't big just little things like "window.open("google.com");. Messages are only triggered if a user clicks a certain thing within game and no. 消息不仅仅只是“ window.open(“ google.com”);”之类的小东西,仅当用户单击游戏中的某件事时才触发消息。
It sounds to me like what you really want is some sort of RPC. 在我看来,您真正想要的是某种RPC。 There's a solid NPM module called Socket.IO which wraps all this up nicely for you. 有一个名为Socket.IO的可靠NPM模块 ,可以为您很好地包装所有这些内容。 Fire an event, it can be handled server-side, and any callback data gets sent back to the client. 触发事件,可以在服务器端处理该事件,并且任何回调数据都将发送回客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.