MultiConnectSDK › SDK Apps
16. A complete match, end to end
This puts sections 6, 8, 10 and 11 together for a two-player match on your game server.
When the match starts:
- Both players connect with player sessions on (Scripts 6.4 and 6.5), so the server knows they are who they say.
- The server takes both entry fees in one step (Script 10.1). If either can't pay, nobody is charged and the match doesn't start.
When the match ends:
- The server pays the winner, with a key made from the match id (Script 10.1).
- It submits the win to the leaderboard (Script 8.1).
- It counts the win toward today's tasks (Script 11.2).
- It records an analytics event (Script 4.1).
Script 16.1: Server: the end of a match
using System.Collections.Generic;
using System.Threading.Tasks;
using MultiConnect;
using MultiConnect.App;
public static class MatchEnd
{
public static async Task Finish(string matchId, string winner, string loser, long prize)
{
await McAppServer.GrantAsync(winner, "coins", prize, matchId + ":prize", "Match prize");
await McAppServer.SubmitScoreAsync("weekly_wins", winner, 1, requestId: matchId + ":win");
await McAppServer.AddTaskProgressAsync(winner, "wins", 1, requestId: matchId + ":wins");
await McAppServer.AddTaskProgressAsync(winner, "games_played", 1, requestId: matchId + ":played:" + winner);
await McAppServer.AddTaskProgressAsync(loser, "games_played", 1, requestId: matchId + ":played:" + loser);
McAnalytics.Track("match_end", new Dictionary<string, string> { { "prize", prize.ToString() } });
}
}
Every call uses a key or request id made from the match id. If the server retries after a network error, or a second server instance finishes the same match, nothing is paid or counted twice.

