How to abort room when there is no opponent player available in Google Play Games? - unity3d

I am creating a Multiplayer Game in Unity.
To create a room, I am using:
PlayGamesPlatform.Instance.RealTime.CreateQuickGame(MinOpponents, MaxOpponents, GameVariant, listener);
To get progress of room creation, I am using:
public void OnRoomSetupProgress(float progress) {
}
The above function, however, is just called once at progress = 20 and then, never again if there are no other players available.
Since initially, I won't have a lot of players using this app, I want to wait for 10 seconds to connect to any other player and if there are no players, I want to start the game with built in AI. For this, I need to abort the current room setup progress in a clean way. I don't know how can I move further.
Please let me know if you know solution for this scenario.

With regards to Multiplayer Game in Unity, this GitHub post only discussed about leaving the room when the game finishes using PlayGamesPlatform.Instance.RealTime.LeaveRoom(); to trigger a call to your listener's OnLeftRoom.
You may want to try Adding Real-time Multiplayer Support to Your Android Game specifically Adding a waiting room UI which states that
If you use the waiting room UI, you do not need to implement additional logic to decide when the game should be started or canceled, as seen earlier in shouldStartGame() and shouldCancelGame(). When you obtain an Activity.RESULT_OK result, you can start right away since the required number of participants have been connected. Likewise, when you get an error result from the waiting room UI, you can simply leave the room.
To leave the room, call leave():
// leave room
Games.RealTimeMultiplayer.leave(mGoogleApiClient, null, mRoomId);
// remove the flag that keeps the screen on
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Related

How can I sync local movement to Photon Network in Unity?

im making a multiplayer FPS game, and I have pretty much all the networking done and working. The issue is, that photon is syncing to players local movement, but if u have a bad connection, you could not tell it is happening cause player send late updates to the server and you can see other players lagging but you can move free and smoothly.
Im aware a lot of games work this way but i also know there are games like medal of honor that your player get stock in the last place every one else saw you. I need to know how to implement this on my game, because gameplay depends on it.
What you describe is "local prediction" of actions / movement.
If I understand this right, you want clients to not act or move if there wasn't a confirmation? If so, you'd need an authoritative host or server. You'd always wait for a confirmation from the host to move the player in any way.
But .. this is not going to work well. Players will feel the lag very much and this is annoying.
You probably want to predict the movement, then correct the local situation if the server disagrees.
I would recommend using Fusion instead of PUN for shooters. It can be run with host and has a nice API to reconcile the actual state from prediction to what the host simulated.

Sending game state only for entities that are "visible"?

Let's say I have an open world game that supports multiple players.
The game stores their positioning by X and Y in this world.
Also, whoever is playing the game can see a canvas of 11x11, where his player-self is represented on this screen, always centered.
The game world has 1000x1000 squares to walk using keys.
What I know is that:
I could emit events whenever a player walks,
check this event data at the server-side (to see if it is possible and the speed is correct/anti-cheating measures),
update the game state which contains all players and positioning,
re-emit this state from the server so every client would be able to render properly this new player.
The problem is, should I really update someone who isn't even being seen?
When everyone is walking around, moving items, earning levels, etc - those events are being emitted from the client, and that's okay, but thinking about the server-side, it will re-emit that for each update state, and, maybe that will be overloaded?
Also, sending the whole game state, even if it isn't being rendered, opens so many breaches to cheating that this made me think that there is another option.
I'm a beginner at Networking and Game Development, and that is being hard to get into my mind - so I decided to try and put it into a question. This way, maybe with someone reading what I'm thinking about, I might get some clarification. Perhaps I'm just thinking about it the wrong way.
Q: should I really update someone who isn't even being seen?
There is no need.
The normal way MMORPG games do in the server side is to cyclely process network packages and some other calculations like the connection of players like skill cast or something else.
The central of a server may look like below
void run()
{
while (true)
{
processNetwork();
processSkills();
processMoves();
...
}
}
The loop will run several times a second, like 20 frames a second is enough cause players can not feel the little frame, they think they move/play smoothly but the trueth is not.
For your question, player only need to see some little area, when he moves, the server will braodcast his postion to others in the area and the players in his area in the next frame.
And that is just the simpliest model, actual model will be more complicated and we will detach different functions of the game to different server, sucn as chat server, battle server, auction server and others.

What's the approach to use when developing API with a callback?

What's the approach that should I use to develop an API that receives two moves and return a result (win/lose/draw)?
Scattegories game
Example:
Animal that starts with letter L
Player 1 - move: Lion
Player 2 - move: Lyon
thegame.com/api/v1/game/1/player/1/move/1
thegame.com/api/v1/game/1/player/2/move/1
How return the result to the players?
Should object player wait for the response or ask result?
What's the best way to develop an API with a callback?
Any other way to resolve this kind of problem?
Thanks.
Plurals are a bit more common, ie:
thegame.com/api/v1/games/1/players/1/moves/1
I think it's probably more logical for moves to be directly under the game, independent of players:
thegame.com/api/v1/games/1/moves/1
where each move has an associated player who made the move. This would make it easy to re-run all moves and understand the game history.
For players, their canonical URL would be independent of games
thegame.com/api/v1/players/1
You can still have a way to access all games for a player and all players for a game, if you like
thegame.com/api/v1/players/1/games
thegame.com/api/v1/games/1/players
Assuming this is a 2 (or more) player game with humans waiting on each other, you could probably make each client poll the game every few seconds. e.g. if a client has made the latest move, it starts polling the URL thegame.com/api/v1/games/1?moves_since=123456. This returns a list of all moves since the timestamp 123456. The timestamp could be the time the last move was made by this user. Once it returns a valid move, the client shows that to the user and waits for them to make their own move. If there are several players, the "game" resource could include a field like "nextMover" to indicate which player is next to make a move.
A more modern way would be to use something like Websockets so the client gets an immediate push from the server when changes occur. It's mostly a similar design but server immediately notifies all clients of updates instead of clients polling.

Check if a player is still online or gone offline by power-off or Gameroom exit

I have a player that is playing my game in Facebook Gameroom. In my database there is a flag telling me the player is logged in with Facebook so I can tell he is online. In Unity I have a script implementing MonoBehaviour.OnApplicationQuit() to flag the player as offline and MonoBehaviour.OnApplicationFocus(bool) to flag the player as NoFocus or AFK.
Case 1: Let's say that electricity problem shuts down player's PC. How can I flag the player as offline? Is there anyway to detect that the player is shut down?
Case 2: Player closes Gameroom window. Is there anyway to detect this action? OnApplicationQuit() didn't work on this.
The standard way to handle this is to set up a timeout for your lastseen datetime stamp. Your game should refresh the time stamp regularly (such as on a timed interval, or on an event such as sending a chat message or accomplishing something)...
Then you set up a job on your database (such as an Agent Job in MSSQL Server) to pull all records logged in that the timestamp has expired. The job then changed the LoggedIn flag so that the user is logged out. Also, the job's agent could easily be a program that runs in the background on one of your servers that handles this... but, this is the basic method to handle the situations that you asked about.
Good luck and hope that this helps!!
I can offer both as a single solution:
I suggest you to ping the Internet service using a delayed loop (like wait 2sec and loop again...) and check the room window you are talking about.
The sure solution for internet connections is to ping the Internet (google.com / yourhost.com)while doing this loop, in the same loop you can also check the room window

Game Center Simultaneous Turns

I'm new to iOS (although I do have a lot of C++ experience) and I am working on a turn-based card game using gamecenter. Here's the catch - The player who's turn it is is the judge and waits for all OTHER players to play a card before the turn is over. Is there a way to do this in Game Center, so all players chose what to do simultaneously and once all have done so, the judge is notified, makes a decision, and then passes priority to the next player? For example, say we start turn 1. I ask the question, #"What is your favorite color?" to all players passing them a gamestate which has that as the question and them not having answered it. Then you respond, #"Green", and our friend Steve responds #"Blue". I then decide which is better, give one of you a point, and then whoever I gave the point becomes the new judge. My question is, how do I allow all players to respond simultaneously, rather than sequentially. I know that, worst case, I could sequentially loop around through players until it comes back to me, then judge it, but this would slow down my game and make it less fun. Is there a way to do this simultaneously?
I agree with NSSplendid about the API for turnbased games requiring sequential turns. The only truly simultaneous method would be using the real-time matches from GKMatch, and that isn't really an option for games with more than a few players.
However, the sequential version could be improved slightly by using a programmatic approach to game center instead of the default view controller.
Ending a turn fires off a push notification through Game Center, and by using GKTurnBasedEventHandler's method handleTurnEventForMatch:didBecomeActive:, you can receive that in your app. When the judge asks the question, have the users display that as part of the game, and have their responses stored locally until their turn. Once it becomes a given player's turn, they receive the notification, even with the app in the background.
In the method, it can check the locally stored answer and end the turn immediately, if they've answered. If they haven't, send the turn once the answer is complete. It's not truly simultaneous, but the judge gets the answers as soon as everyone has responded, without the players having to wait for one player to finish before they can enter their own answers.
The players won't get the notification that the judge has ended their turn until they open the app, but they can't see the question anyways without doing that. Another approach to this, though slightly wasteful, is after the judge ends their turn with their question, is to do a runthrough of all the players ending their turn as soon as they get the "Your turn" notification, so everyone knows a question has been asked, then doing the steps from the previous two paragraphs.
The iOS API is built around the model of sequential turns. While the workaround you mentioned will work, there is no way to get GC to do real concurrent turns. Sorry ):