2
votes
  • I made a RTS game with HTML5 (with create.js) and want to add the multiplayer part with node.js.
  • I can convert the html and javascript file as .exe to run the game as a "normal" application with Web2ExeWin-v0.4.2b
  • I reaserched over node.js and started some simple servers.

  • The Concept: The user opens the game and can start a singleplayer(without server) or the user starts a multiplayer game an can invite friends to the lobby. After that he can start the multiplayer game. Like normal for a rts game.

  • the Idea: To start a server ingame i must execute a "node server.js" command. Now the user will join his server and can send the data to other ingame user to join the game.

  • Problem: What is wrong on this idea? I can't run a cmd command from an user to open a node server because its in javascript.

What is a normal way to implement the node.js multiplayer part in javascript so that every user can create there own ingame server?

1

1 Answers

0
votes

One year after my question: i must say the solution is pretty simple:

With Web2Executable you can compile a html to an .exe But you can add some other file, like a NodeJS file.

The NodeJS file get started in the same time you start the exe.


So the IDEA is every Client is running his own Server all the time from the start of the exe.

If you wanna play a singleplayer match, your local NodeJS Server will accept only one client (the localhost) and you play a game.

If you wanna create a multiplayer match with you and your friends, your local NodeJS Server will accept first the localhost and afterwards some other players and you can start the game.

If you wanna connect to a friends Server, your local NodeJS Server will do nothing.


CONTRA: If start the game from the Desktop or so, the Server is running. So there are always some open ports.

PRO: You can run a NodeJS Server for Javascript. AND Since you wanted to add a multiplayer part, you can also rewrite the whole game to a SERVER-CLIENT communication. I mean, you need to do this for the multiplayer part so dont waste your time and create two seperate game architectures.