简体   繁体   English

我如何只允许将某些邮件设置为用户[NODE.JS]

[英]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. 触发事件,可以在服务器端处理该事件,并且任何回调数据都将发送回客户端。

http://socket.io/docs/ http://socket.io/docs/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 只允许某些用户编辑ASPxGridView - Only Allow Certain Users to Edit ASPxGridView 仅允许iPad应用程序用户访问某些文件 - Only allow ipad application users to reach certain files 如何只允许用户编辑其数据 - How to allow users to only edit their Data 如何只允许用户与我的程序进行交互? - How to allow users only interactive with my program? 如何将C#中的泛型方法约束为仅允许T具有TryParse的T? - How would I constrain a generic method in C# to only allow T where T has TryParse? 当Visual Studio仅允许将其作为“应用程序”设置时,如何允许用户更改SQL连接字符串? - How can I allow users to alter the SQL connection string, when Visual Studio only allows it to be an “Application” setting? 如何允许仅属于角色的用户访问文件夹中的文件? - How Can i allow users belongs to role only to access files in folder? 只允许某些类编辑某些属性 - Only allow certain classes to edit certain properties 如何只允许管理员在 identityserver4 中注册新用户 - How to allow only admins to register new users in identityserver4 如何在 C# 中只允许将一定范围的数字输入到字符串中 - How to allow only a certain range of numbers to be inputted into a string in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM