Start Multiplayer Game Functionality

0 votes
Hi All

I am developing real time multiplayer game. WhenI test my game, if 2 users click "Play Game" button at the same time, both of them joins and subsribe room at the same time so that onUserJoinedRoom event is not executed for booth of them:) Therefore, I cannot send update peers.Therefore, I cannot send start game pack. If I use getLiveRoomInfo function and check if number of users is 2, start game. But this time since 2 users enter same time, booth users sees there are 2 users in the room and I cannot set the roomOwner:) In my logic first user who enters room is roomowner. So in that case there are two room owner. I do not know how to handle this? If there is a little time between I click play game buttons between users, no problem.

EDIT:This problem occus when 2 users enter an existing room.(You know dynamic rooms are not destroyed immediately. So another users can join room)

Thanks
related to an answer for: When to start game
asked Jun 2 in Unity by gokhan (20 points)
edited Jun 2 by gokhan

1 Answer

0 votes
Hi Gokhan,

Apologies for late reply.

Could you please let me know which API you are calling to join a room? It will help me in suggesting the solution to handle this situation.

Thanks.
answered Jun 5 by rajeev.etc (1,438 points)
Hello Rajeev
Here is my step by step api calls to start a multiplayer game.
1-WarpClient.GetInstance().JoinRoomWithProperties(tableProperties);
2-if success: WarpClient.GetInstance().SubscribeRoom(roomId);
if resource not found:WarpClient.GetInstance ().CreateRoom(roomType,userName,2,tableProperties);
3-If subscribe success:WarpClient.GetInstance ().GetLiveRoomInfo(roomId);
4-getJoinedUsers().Length==2 WarpClient.GetInstance ().SendUpdatePeers (pack);

Now:Since two users enters SendUpdatePeers code at the same time, this cause problems in my game... As I said before this problem occus if two players click the "Play Game" buttonat the same time. If there is slightly lag between clicks no problem. However, if we think there are thousands of player playing game at the same time, this problem will most likely to occur. I need your urgent help.
Thanks
Hi Gokhan,
As you have mentioned in your question that this problem generally comes when both users are joining already existing room. In that case, whenever you are creating room, you can add one more property say "GameStarted" with value as "false". When game is started then you can update the property value as "true".

When you are calling joinRoomWithProperties API, use this property to filter unused rooms after Game is finished. You can only join the room if it has "GameStarted" value as "false".

I think this will help in your case.

Thanks.
Hi Rajeev
This way, problem still will be exit in a different way. Although there are players want to play, they cannot match each other and create seperate rooms, isnt it?
are there any other way you think?
I can add a new api to the SDK using which you only have to call one API to join and subscribe a room. So, this way you will not miss the onUserJoined callback in any case. But adding this API will take some development time. I will update you on the timeline after discussing this from development team.
It would be really usefull for me and for others friend. I am waiting your feedback. Thanks
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
Migrate from Parse to ShepHertz App42
...