damopewpew / samp.js

46 stars 13 forks source link

Are there any plans making this for node.js? #53

Open krlicmuhamed opened 8 years ago

krlicmuhamed commented 8 years ago

Node.js has a bigger community, more modules and a non-blocking architecture ! This would be awesome! I would like to contribute, any thoughts, hints, suggestions on this?

Thanks.

Yiin commented 8 years ago

I agree, would be awesome.

krlicmuhamed commented 8 years ago

Now that I think of it, node.js would enable us to easily cluster samp servers ! There's no need for any custom mysql connectors you can use any database you want with hundreds of node.js modules! We have to make a fork of this for node.js/io.js !

tallytarik commented 8 years ago

Could you elaborate on what you mean by "make this for node.js"? This is plugin that allows you to use javascript instead of pawn to write gamemodes for SA-MP. It uses the v8 javascript engine like node.js, but the similarities pretty much stop there.

Node.js modules are incompatible with this plugin because they rely on core node modules (file, io, net, etc.) which are not implemented in samp.js. require() also works differently in samp.js.

I'm confused with what you mean about clustering sa-mp servers. That would require you to implement the actual sa-mp server in node, including some shared realtime database or another way to communicate between the workers. You would have to reverse engineer the sa-mp server in order to re-implement it in node. This is also just generally a bad idea - game servers aren't normally clustered because they run on a single CPU/thread. The performance limitations you might reach with a game server can't be resolved by throwing more physical processes at it. But anyway, all of that is completely unrelated to and beyond the scope of this project, which is just a plugin for the default sa-mp server! If I misunderstood and you actually meant something else, I'm keen to hear about it.

krlicmuhamed commented 8 years ago

@ev0lution Yes, It sounds humongus! I thought this was a great place to bring this idea. Instead of making another platform with v8 ( what samp.js currently is ), why not remake this project as a node.js module?

And clustering can be made with tcp/udp sockets, you don't need to recreate a sa-mp server! It's just a matter of one plugin that reads all events from the sa-mp server, communicates with the (node.js) cluster and back!

But the cluster isn't the main idea (although It maybe addressed with sa-mp server developers in the future). The main idea is to make gamemodes with node.js platfrom instead of a custom v8 platform the samp.js currently is, that alone has many awesome implications!

tallytarik commented 8 years ago

@l0oky I'm still really confused about making this a node.js module.

Right now, this plugin uses the v8 engine so you can write javascript for sa-mp. Node also uses the v8 engine so you can write javascript for whatever.

What exactly would you be doing? As in, what do you think this plugin actually is that you would make for node.js? The one feature of this plugin (javascript) is already the entire basis of node. Node has nothing to do with sa-mp by default, so you would be making... nothing? Unless, like I said before, you actually implemented the sa-mp server in node, which is near-impossible.

I'm also still confused about your interpretation of clustering. You can't just run multiple sa-mp servers and use node to make them communicate with each other - and if you tried to do that, why? What do you think the benefits would be? Clustering works for web servers because they deal with single requests that take less than a second. There are a finite amount of these that can be handled by each process but you can use multiple cores of your CPU to increase this when your requests/second increase, and these clustered workers can share a backend database. This is completely different to a game server, which runs on a single thread and has persistent, realtime connections to its players.

krlicmuhamed commented 8 years ago

@ev0lution The plugin is basically the middleware that allows Node.js module to communicate with sa-mp server.

As for the benefits of Node.js, I think this is obvious.. Active (and growing) community is #1 in my point of view. Just the accessibility of the javascript language isn't enough you need a lot of community-based modules. This eliminates the need for the samp.js team to make/require stuff like database connectors, and allows much wider audience to partake in building this project (not to mention use it).

damopewpew commented 8 years ago

I orginally looked into implementing node.js into the sa-mp plugin but node.js is a complicated beast which isn't really designed to be embedded into something else.

How do you propose the module communicate with the sa-mp server? I'm not sure you understand how sa-mp plugins/server work and how node.js plugins work.

Anyway there is an alternative way to do some of what you want currently with samp.js, but will be limited in some respects. All you need to do is create a node.js app which uses sockets to listen on a port for connections, then in sa-mp.js create a script which uses sockets to connect to the node server. Then you do communicate between them, use some evil eval on the samp.js side to execute whatever you want via messages emitted from nodejs, or the other way around.

For example

samp.js

socket.on('command', function(command){
     let val = eval(command);
     socket.emit('reply', val);
});

Obviously you would make it a bit more advanced, maybe add some message ids so you can effectively communicate the replies back to the server.

krlicmuhamed commented 8 years ago

@damospiderman Exactly. That was the idea. My humble attempt at this. Altrough this is not a samp.js project, Its a SA-MP plugin that should read/send events with sockets. Still not finished or even working ofc.

vico93 commented 8 years ago

IMO he says about making a implementation of SAMP Server in node.js. in other words, get rid of standard PAWN SA:MP Server and make a standalone server based on node.js. Dont know if SA:MP EULA allows this.