I'm working with Nodejs, Express, and Socket.io, I started out with this tutorial for a chat with multiple rooms and which is quite popular:
http://psitsmike.com/2011/10/node-js-and-socket-io-multiroom-chat-tutorial/
I added a feature in which one player can challenge another one(within the room, where there might be other players) to a 1v1 rock, paper, scissor match in a turn based manner. Everytime a player chooses any of his 3 options available(rock,paper,scissor), I send to a function in the backend the ID of his opponent and the option chosen.
I wanna know if there is a better way to communicate through sockets other than sending the id each time, and what other alternatives are out there to emulate a match between 2 players only, without having to worry about the connection being lost or having other players interfere.
What if you start a new room for a new game? Both challenger and opponent get added to the new room.
There will be no interference even if either player starts games with other opponents as all games are in separate rooms...
Related
What I'm trying to do:
authoritative server - physics completely under the authority of the server: Nothing moves until the server says it does
handle up to 50 players per game map
Players and other game objects will
interact/collide with each other and physics like projectile shooting are required.
Web browser multipalyer game.
Client: theree.js, A-Frame
Server: lance-gg
Can I use lance-gg for the gameplay and the game objects synchronization?
Would it be impossible or very hard to provide a smooth physics experience to the player?
Since there is some time since last update, bug is something I should be worried about?
I have liked a lot the Sprocket League github project.
When I tried to reserch a bit for the Lance-gg, I have saw it has been a time since the last update.
Is there a notification sent when a player joins a turn based gamecenter match? I can't find any documentation about it. Right now I'm polling the match data and checking when a player joins before I show my game ui...
No, they don’t notify you when someone joins your game. The way turned based Game Center matches work is the first player creates the game and takes their turn. Then, they get notified again once someone else has join and completed their turn.
We have a resources named Games and Players
/games -> Get all Games available
/games/{game-id} -> Get the game details of specific Game with game-id
/players/me -> Get logged in Player details
There will be Games played by the player which can be tagged under Games or Players
Scenario 1
/games/me -> Fetches games played by the current logged in player
This groups the request under Games tag. I'm using Swagger API so this call will be going to GamesAPI controller on the client generated code. I see its fair to be in the Games api rather than player as its related to games.
Problem : It looks too odd to consider "me" as a special id as it looks it is one form of {game-id} which I can't digest.
Scenario 2
/players/me/games -> Fetches games played by the current logged in player
This groups it under Player tag which goes to PlayerAPI after code generation. The path has a meaning which is good but, its more relevant to have it in GamesAPI (by my choice - I could be wrong, please suggest)
Among these two scenarios which is the better way to design this problem?
Scenario 1 seems to be better among two because in general your games url will land to GameController and there you can have action function for fetching all games, one game of given id, or the logged in user's games.
Relationship design is driven in API's how your schema's are designed .So, in your case
1 Player can play 1 or Many games - So 1 to Many relationship
Hence, you should be grouping game data based of players . So, 2 scenarios arise for an API to have better performance
Scenario 1
Is it easier to search in Games for the player id and then group them?
Scenario 2
Is it easier to search Players on the basis of the Game id and then group them?
Logically, speaking and considering scenario 1 makes more sense , hence
/games/{player-id} -> Fetches games played by the current logged in player
This is how I solved it.
As mentioned with Scenario 1, I see "me" conflicts with {game-id} and confuses users.
With Scenario 2, I see fetching user games from player API isn't intuitive.
So I went with an approach where it tries to keep the endpoints minimal.
I added a new query parameter "playedOnly:boolean" for GET /games which returns all the games related to the player.
This simplifies lot of things. I can still go with /games endpoint and no more confusion!
In my web-based multiplayer game which I am using Nodejs and Socket.io,
I want to have some random boxes that player can destroy them. this is what I did:
on server I made a object array that contains random x,y of boxes. when a player connects, server send him the object array and so client render the boxes in client side.
Now when a player destroy one of the boxes It sends x,y of the destroyed box to server, then server removes that x,y from the object array (for new players) and generate a new x,y (for new box to replace the destroyed box). and finally server send a new object including the destroyed box x,y and the new box x,y And So players render the new box and delete the destroyed box.
Now this is working but since I'm new to making such multiplayer games, I'm not sure if the server can handle this (there is maximum 40 players on a server and there is like 500-800 boxes on map and well this is just one small part of the game). I'm worried about performance, So will there be any problems? Is there a better way to this? any advice?
I think the problem with the boxes is quite special. In general you should always try to keep scalability in mind and try to split different domains on different services.
But in this special case, I would say it depends on your implementation and of course your server specs. How many boxes are destroyed per second? There are so many unknown variables in your question.
I am making a little game using node.js for the server and a .js file embedded in a HTML5 canvas for clients. The players each have and object they can move around with the arrow keys.
Now I have made 2 different ways of updating the game, one was sending the new position of the player everytime it changes. It worked but my server had to process around 60 x/y pairs a second(the update rate of the client is 30/sec and there were 2 players moving non-stop).
The second method was to only send new position and speed/direction of the player's object when they change their direction speed, so basically on the other clients the movement of the player was interpolated using the direction/speed from the last update. My server only had to process very few x/y7speed/direction packets, however my clients experienced a little lag when the packets arrived since the interpolated position was often a little bit away from the actual position written in the packet.
Now my questions is: Which method would you recommend? And how should I make my lag compensation for either method?
If you have low latency, interpolate from the position in which the object is drawn up the new position. In low latency it does not represent much of a difference.
If you have high latency, you can implement a kind of EPIC.
http://www.mindcontrol.org/~hplus/epic/
You can also check how it is done in Browser-Quest.
https://github.com/mozilla/BrowserQuest
Good luck!