Apr 16, 2017 01:45 PM
(This post was last modified: Apr 16, 2017 01:52 PM by iNCEPTiON_V.)
EDIT Sorry wrong Forum!
Hello,
im currently trying to wrap my head around this interesting Problem.
So what im trying to implement here, is a basic matchmaking system for my Quiz mobile App ( Server Side ).
Background
For this task im using a ASP.NET Core App with Web Sockets for the Connections.
1. First i would Register the User in a Collection.
2. Find an Opponent Player.
3. Add those Players in a Match Collection ?
Implementation / Logic
1. Register User
2. Find Oponent
3. Store / Create Session with found Players
Now this is where im struggling so far....
How should i store them so i can continue to work with them in the Game.
What im thinking of is , store them in a Dictionary like this ?
Would this go in the right direction? Or is there a better way ? wich im sure there must be :)
Hello,
im currently trying to wrap my head around this interesting Problem.
So what im trying to implement here, is a basic matchmaking system for my Quiz mobile App ( Server Side ).
Background
For this task im using a ASP.NET Core App with Web Sockets for the Connections.
1. First i would Register the User in a Collection.
2. Find an Opponent Player.
3. Add those Players in a Match Collection ?
Implementation / Logic
1. Register User
Code
// Usercollection just stores the Socket and the Username
// very basic.
public static bool RegisterUser(GameSessionModel player) {
if(!UsersOnlineCollection.Contains(player)) {
UsersOnlineCollection.Add(player);
return true;
}
return false;
}2. Find Oponent
Code
public static GameSessionModel FindOponent(GameSessionModel player) {
return UsersOnlineCollection.OrderBy(x => Guid.NewGuid())
.FirstOrDefault(x => x.Username != player.Username && x.IsAvailable);
}3. Store / Create Session with found Players
Now this is where im struggling so far....
How should i store them so i can continue to work with them in the Game.
What im thinking of is , store them in a Dictionary like this ?
Code
// string is the Guid
// concurrentdictionary is a thread safe dictionary
public static ConcurrentDictionary<string, MatchModel> MatchSessions { get; set; }
public static void CreateSession(GameSessionModel playerOne, GameSessionModel playerTwo) {
if (!MatchSessions.ContainsKey(playerOne.MatchGuid)
&& !MatchSessions.ContainsKey(playerTwo.MatchGuid)) {
if (playerOne.MatchGuid == playerTwo.MatchGuid) {
MatchSessions.TryAdd(playerOne.MatchGuid, new MatchModel {
PlayerOne = playerOne, PlayerTwo = playerTwo
});
}
else {
????
}
}
}Would this go in the right direction? Or is there a better way ? wich im sure there must be :)


