# Matchmaking
With a matchmaker system users can create a match, search for opponents or they can create a match with their friends
# Request Match Without Playmate
Users can request or create a normal, rank and level match for a specific number of teams, playmates and match modes.
# Normal Game
If a user requests a normal game, the server makes a matching base on an online user without considering the other user's rank or level.
client.Matchmacker.RequestMatch(capacity, numberOfTeam, 'normal', 'TDM', (res) =>{});
TIP
You should set match mode in the dashboard
# Rank Game
If a user requests a rank game, the server makes a matching based on the other user's rank. The range parameter use for finding a match base on how much the rank should be, upper or lower than the user rank. For example, if the user rank is 2 and the range is 1 a server will find a user with a rank between 1-3. If you want the exact rank as user rank put 0.
client.Matchmacker.RequestMatch(capacity, numberOfTeam, 'rank', range, 'TDM', (res) =>{});
# Level Game
If a user requests a level game, the server makes a matching based on the other user's level.The range parameter use for finding a match base on how much the level should be, upper or lower than the user level.
client.Matchmacker.RequestMatch(capacity , numberOfTeam, 'level', range, 'TDM', (res) =>{});
WARNING
The remainder of capacity/team must be equal to 0
TIP
If you need all of your players to be enemy together set the team parameter to 1
# Cancel Request
User can cancel the request for a match. It's valid until the server cant find any match, after that user can't cancel the request
client.Matchmacker.CancelMatch((res) => {});
# Request Playmate Match
Here the user can create a match and invite others to that match. Friends can play together or play as teammate against other opponents
# Create Match
To create a match we can use CreatePlaymateMatch method. The person who makes the match is considered as the leader and that person can control the room like an invitation, remove, start or cancel the match.
client.Matchmacker.CreatePlaymateMatch((res) =>
{
if (res.Type == "success")
{
playmateId = res.Data["playmateId"].Value;
}
});
As a callback we get playmateId we should use this id to send other requests.
# Invite Playmate
We need userId and playmateId to inviting our friends to the room.
client.Matchmacker.InvitePlaymate(friendUserId, playmateId ,(res)=> {});
# Accept Playmate
If somebody sends an invitation we can accept or deny that invitation. to do that we need sender userId and sender playmateId which we can get them from OnPlaymate event
client.Matchmacker.AcceptPlaymate(senderUserId, senderPlaymateId , (res)=>
{
playmateId = res.Data["playmateId"].Value;
});
As a guest, we need playmateId for another requests too.
# Deny Playmate
User can deny invitation by using DenyPlaymate method.
client.Matchmacker.DenyPlaymate(senderUserId, senderPlaymateId, (res) => {});
# Leave Playmate
After the user joined the room, the user can leave that room by using LeavePlaymate method.
client.Matchmacker.LeavePlaymate(senderUserId, senderPlaymateId, (res) =>{});
# Destroy Playmate Match
If the owner of the room decide to destroy that playmate match that user should use DestroyPlaymateMatch method
client.Matchmacker.DestroyPlaymateMatch(playmateId,(res) =>{});
# Request Match
After all, if everything is ready the owner of the room can request for normal, rank, or level match
# Normal Match
To request a normal match we must use RequestMatch method like below
client.Matchmacker.RequestMatch(capacity, numberOfTeam, playmateId, "normal", 'TDM', (res) =>{});
# Rank Or Level Match
To request a rank or level match we must use RequestMatch method like below
client.Matchmacker.RequestMatch(capacity, numberOfTeam, playmateId, "rank", range, 'TDM', (res) =>{});
# Cancel Playmate Match
The owner of the room can cancel the request for a match. It's valid until the server finds a match, after that user can't cancel the request.
client.Matchmacker.CancelMatch(playmateId, (res) => {});
# OnPlaymate Event
All playmate match callbacks handled with OnPlaymate event.
client.Matchmacker.OnPlaymate = (res) =>
{
// somebody sent you a match request
if (res.Code == 0)
{
Debug.Log(res.UserId);
Debug.Log(res.Username);
Debug.Log(res.UserSocketId);
Debug.Log(res.PlaymateId);
Debug.Log(res.Username + res.Username + " send you game request ");
senderUserId = res.UserId;
senderUsername = res.Username;
senderPlaymateId = res.PlaymateId;
}
if (res.Code == 1)
{
Debug.Log(res.Username + " accept your game request ");
}
if (res.Code == 2)
{
Debug.Log(res.Username + " deny your game request ");
}
if (res.Code == 3)
{
Debug.Log(res.Username + " leave your game ");
}
if (res.Code == 4)
{
Debug.Log(res.Message); // You and your playmates is on search queue for a match
}
if (res.Code == 5)
{
Debug.Log(res.Message); // The owner of the room canceled searching for a match
}
if (res.Code == 6)
{
Debug.Log(res.Message); // The owner of the room destroyed the room
}
};
# OnMatchmaking Event
After the user requests a match, the server will find a match and the result will appear on the OnMatchmaking event.
client.Matchmacker.OnMatchmaking = (res) =>
{
foreach (var user in res)
{
Debug.Log(user.MatchId);
Debug.Log(user.PlaymateUserId);
Debug.Log(user.PlaymateUsername);
Debug.Log(user.PlaymateSocketId);
Debug.Log(user.PlaymateLevel);
Debug.Log(user.PlaymateRank);
Debug.Log(user.Team);
matchId = user.MatchId;
}
};
We need matchId to send our in match packages.