Implementation of multiplayer in the game. A comparison of the features of Game Center, Steamworks and GameSparks

Game multiplayer much more interesting the same games without it. But implementation of multiplayer implies a presence of the server code that implements the network communication, and more self-explanatory.

Fortunately, there are many ready-made solutions. During the development of my game I have tried the following options:

    the
  1. Game Center (game for iOS)
  2. the
  3. Steamworks (game for Steam)
  4. the
  5. GameSparks (cross platform solution)

Under the cut I will discuss each of these options, the main opportunities, difficulties, pros and cons. From pieces of code I will refrain. All there in the documentation.

the

Briefly about everything


These option are ranked in order of increasing capability and flexibility. The implementation complexity also increases.

1. GameCenter
The easiest and, at the same time, the narrowest option. The player presses a button, then appears the window search for the enemy. After accumulated a certain number of players, the match starts. At this point, players have the opportunity to exchange messages. After all players have left the match, the game ends.

2. Steamworks
The functionality is divided into two independent parts, the matchmaking and messaging. The first half consists of the chance to create rooms where players can discuss the upcoming match.

The other half is functionality for direct messaging. Both parts are completely independent. At any time send a message to any player, regardless of which rooms he's in.

3. GameSparks
In fact, GameSparks is a complete server with all its attendant advantages. You can store the data of the player to verify his actions. Has built-in mechanisms of self-explanatory, leaderbords, achievements and more.

The first two options are suitable for simple games with little security requirements. And for big serious games of course you needed your own server.

For me, the last option was the most pleasant development, as it failed to get rid of many of the crutches.

the

a Little about our game


GalaxyAdmirals is a turn — based space strategy. The gameplay consists of short battles on a hexagonal playing field. The players take turns, the element of randomness is missing. In fact, it is chess in space.


The game has a campaign of 30 missions. Multiplayer mode is a one on one battle with a random opponent.



The game is made in Unity3D.

the

Game Center


General description


Game Center is the app for iOS. It displays your achievements in other games: achievements, leaderboards. You can add friends to challenge, compare your achievements. The functionality is not great, but the usability of it all, in my opinion, is quite questionable. But the most important thing is that through Game Center you can implement a simple multiplayer.

Integration


Perhaps there are some ready made plugins, but I wrote your Code in Objective C. not a lot, and it's pretty simple.

Implementation of


There are three options for the implementation of multiplayer through Game Center

    the
  1. Turn-based.

    This is for turn-based games, like checkers, chess. Players go in turn. After each turn, the player flies a message in Game Center, now it's his turn. The game does not have to be running. The state of the game stored in Game Center. The players do not communicate with each other, they only communicate with the server to update game state.

  2. the
  3. Self-hosted.

    Game Center provides matchmaking only. You must implement their own multiplayer via your server.
  4. the
  5. Real-time.

    As the previous example, but exchange messages via a relay server Game Center. That's what I used. More about it below.

It looks as follows. The player clicks the button it runs the search of the enemy.


When you start the matchmaking, the player passes the following parameters:

the
    the
  • Maximum, minimum number of players
  • the
  • Group
  • the
  • Attribute

A group is a number in which the encoded additional information on the match. Game Center will find you opponents that have indicated the same group as you.

An attribute is a 32-bit number that indicates the role you want to play. In fact, it is a bitmask. Game Center selects the players so that their bit masks, United by "or", were fully filled with ones.

For example, you want to play chess only for whites. Then you pass a mask of 0xFFFF0000. A player wishing to play for black, must pass 0x0000FFFF. If the player do not care whom to play, then he transmits the completed units of the mask to 0xFFFFFFFF. Then the player who wants to play for the whites, will pick up the enemy who wants to play for black, or the enemy who doesn't care whom to play.

Once opponents are found, starts the match. The player gets a list of enemies that he can send messages. All players come into the game on equal footing. They need to agree which of them is player 1 and who is player # 2. For example, you can sort players by ajtishnikam. Then they both get the same list.

Some special condition "match completed" does not exist. The players first need to agree among themselves that the game is over and then each of them will disconnected.

There is a possibility to send invitation to your friend. This invitation he displayed in Game Center, even if the game is not running. By clicking on the message the game starts. In order for prompts to work correctly, it is necessary to separately handle the two options when the application is running and when not.

Unfortunately, if the player didn't accept the invitation, the player who sent him, would never know. He will wait for him until, until he tires of it.

Problem


1. The problem with the end of the match
The functionality works in such a way that you can't send the message "game over, I'm gone!" and then immediately disconnectes. In this case, the opponent will not receive your message, and will only see what you disconnecters. Thinking that you fell off, he'll claim the victory itself.

Therefore it is necessary to send further confirmation, like "I got your message that the game is over, you can leave."

2. The problem of disconnection of one of players
The connection between players is established peer-to-peer. So if one player lost Internet, both get the message that the enemy was off. The idea is that we should lose the award to a player who has fallen off, and victory to the player who remained in game. And most worryingly, there is no way to ask the Game Center, who remained in the game, and who disconnecters.

To find out have to insert crutches. For example, to check the connection to Game Center immediately after the disconnection of the opponent (for example, I asked for the status achivok). If Game Center doesn't respond, you can assume that I fell off, not the enemy.

But even this may not work. For example, the player can minimize the application. When he deploys the app, the connection to the player would be already broken, but the connection to the Internet will continue and the player can choose what the opponent off, and not himself. In short, it is necessary to insert additional crutches.

Cons


the
    the
  • Too simple functionality of matchmaking.
  • the
  • Has to create an unpleasant crutches.

the

Steamworks


General description



Integration


The Steamworks SDK is written in C++. Therefore, the integration in Unity3D wraper necessary. Of several options I selected at random was Steamworks.NET. In principle, wrapper not bad, all integrated well but later I noticed some strange behavior.

Each function returns the result via callback that looks like this.

the
protected void OnResult(LobbyEnter_t pCallback, bool failure)

As you can see, the function expects an additional Boolean parameter which needs to report a failed operation. As it turned out, this option never returns true. Even if you do something deliberately wrong. Don't know whether the jamb is the Steamworks SDK or Steamworks.NET. From the developers of a clear answer I received and had to get out with the help of crutches.

Implementation of


As I wrote above, Steamworks has a more flexible matchmaking. Here is a sample list of what you can do:

the
    the
  • to Create a room (here they are called "lobby")
  • the
  • to give the room some parameter (for example, to specify the name of the room and on what map you play)
  • the
  • to Filter the list of rooms on one or more parameters
  • the
  • Assign a parameter to the player in the room
  • the
  • to Send a message inside the room

We used all this functionality in our stimovsky version.



As can be seen from the screenshot before the match to chat in catice, choose a race, choose a map and other parameters of the match.br>
Not all players are equal. The player who created the room is the owner (owner). If the owner left the room, then this title is shifted randomly to another player in the room. This player can play the role of arbitrator in disputes.

Theoretically, the whole gaming functionality can be implemented directly inside the room, to store the state of the game right there. But all this smacks of perversion.

The incentive does not exist special functions to create a connection between players. You just send a message to any player. If the connection has not been installed before, it installs automatically (the other side has to confirm that he wants to communicate with you). If the connection suddenly broke, the steam would try to reconnect the next time you send a message.

As in Game Center, there is no such condition as "game over". Ie players must agree among themselves when the game is over.

The incentive there is an interesting functionality. Say you're making a game through steam, and through its servers. You can register your server to the incentive. The player can obtain a list of all registered servers. Thus steam acts as a directory of external servers.

Problem


1. The problem of disconnection of one of players.
Unfortunately, as in Game Center, you can't determine lost the connection to the server you or your opponent. You have to write crutches.

Pros


the
    the
  • More flexible functionality of matchmaking.

Cons


the
    the
  • Odd behavior Steamworks.NET error.
  • the problem with the disconnection of players.


the

GameSparks


General description


GameSparks is a service that acts as backend server for games. It allows you to store data, run scripts, has built-in mechanisms for matchmaking, achievements, leaderbords and much more.

Integration


GameSparks is integrated in Unity3D using the official plugin. Everything works perfectly.

Implementation of


All scripts are written in JavaScript. So the first thing I did was set up the environment to write on a normal strongly-typed language. I used TypeScript.

The interaction with the server is very simple. We send to the server a message. On the server the script runs corresponding to this message. The script reads the information from the database, makes changes, and returns us the result. The same script can send a message to any other user. All very simple and logical.
In principle, GameSparks allows you to implement arbitrarily complex matchmaking. You can, for example, make the room as the incentive. But I decided not to bother and use built-in matchmaking.

When you start matchmaking, you need to pass a power player (numeric parameter). Then GameSparks returns of foes that is transmitted to a certain value (in absolute or relative values).

For real-time multiplayer is the ability to create separate rooms. This room can be started with a script that is constantly spinning on the server side. But I haven't used this functionality. To send messages between players I used simple script which just relayed the message to a given player.

Pros


the
    the
  • Have the ability to store player data on the server
  • the
  • Managed to get rid of the crutches that have been used in Game Center and Steam. The server always knows who is online and who is not and always possible to reliably determine who left the game.

Cons


the
    the
  • is a Bit messy documentation.
  • Promised that indie developers can run the game for free. In fact, I had to pay.


the

Council


Create additional tools to visualize the processes happening inside your code. For example, I wrote logimouse server.


On the left shows the log of one player, right — log the other. The arrows drawn from the message, at which point the message was sent, to what it is.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Address FIAS in the PostgreSQL environment. Part 4. EPILOGUE

PostgreSQL: Analytics for DBA

Audit Active Directory tools with Powershell releases. Part 1