by Farzher » May 28th, 2011, 3:34 am
by Benjaminsen » May 28th, 2011, 10:05 am
by Farzher » May 28th, 2011, 7:03 pm
by Henrik » May 28th, 2011, 7:59 pm
by Farzher » May 29th, 2011, 9:53 am
by Oliver » May 31st, 2011, 9:49 am
by Farzher » June 1st, 2011, 8:07 pm
[RoomType("matchmaking")]
public class GameCode : Game<Player>
{
public override void GameStarted() { }
public override void GameClosed() { }
public override void UserJoined(Player player)
{
Player opponent = null;
if (PlayerCount >= 2)
{
foreach (Player p in Players)
{
if (p != player)
{
opponent = p;
break;
}
}
}
if (opponent != null)
{
string id = randomString(20);
opponent.Send("gameFound", id);
player.Send("gameFound", id);
opponent.Disconnect();
player.Disconnect();
}
}
public override void UserLeft(Player player) { }
private static string randomString(int length)
{
string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
char[] chars = new char[length];
Random random = new Random();
for (int i = 0; i < length; i++)
{
chars[i] = allowedChars[random.Next(0, allowedChars.Length)];
}
return new string(chars);
}
}
by WindieGames » June 2nd, 2011, 4:34 am
by wanara » December 4th, 2012, 11:13 am
by dreamora » December 4th, 2012, 5:28 pm
by jgames » February 8th, 2013, 8:08 pm
public override void UserJoined(Player player) {
Player opponent = null;
if (PlayerCount >= 2) {
foreach (Player p in Players) {
if (p != player) {
opponent = p;
break;
}
}
}
if (opponent != null) {
Console.WriteLine("Made Match: " + player.ConnectUserId+ " vs. " + opponent.ConnectUserId);
string id = randomString(20);
opponent.Send("gameFound", id);
player.Send("gameFound", id);
opponent.Disconnect();
player.Disconnect();
}
}
by henshouse » February 9th, 2013, 8:43 pm
by Benjaminsen » February 15th, 2013, 1:28 pm
by henshouse » February 16th, 2013, 5:00 am
by jgames » February 16th, 2013, 10:16 am
by JimLion » June 22nd, 2014, 1:56 pm
by AquamentosGames » July 10th, 2014, 1:28 pm
JimLion wrote:Nice, thanks guys. I will definitely be looking into using some of this code for my own multiplayer game lobby
One quation for you guys using Mac / Mono. When you make a new C# project what kind of project is it?
by JimLion » September 26th, 2014, 4:02 am
by fpanettieri » October 8th, 2014, 7:41 pm
by JimLion » December 11th, 2014, 9:47 pm
by JimLion » January 7th, 2015, 3:11 am
by milalhjovich » June 30th, 2016, 11:26 am
by sally » July 27th, 2016, 1:58 am
by MoDDiB » October 24th, 2016, 9:43 am
by Henrik » October 24th, 2016, 10:11 pm
by MoDDiB » October 24th, 2016, 10:33 pm
But matchmaking rooms allow for more functionality, you can apply criteria to the users so you get similar users together, and you can expand your criteria until you find enough players to start a game, etc. It's a trade-off, and each game can pick the model that suits it best.
by Henrik » October 24th, 2016, 11:21 pm
by MoDDiB » October 25th, 2016, 9:11 am
by MoDDiB » November 10th, 2018, 9:28 am
Henry1122 wrote:At the point when a client joins this room and there is as of now a client associated with it, send them both an irregular room id to join and detach them from the match making room...
by Zwick » March 17th, 2019, 8:22 pm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PlayerIO.GameLibrary;
namespace TheButton
{
[RoomType("Matchmaking")]
class Matchmaking : GameBase
{
public int aiDelay;
public override void GameStarted()
{
aiDelay = int.Parse(RoomData["aiDelay"]);
aiDelay = aiDelay > 0 ? aiDelay : 5000;
AddTimer(matchmakingAttempt, 1000);
}
private void matchmakingAttempt()
{
var enumerator = Players.GetEnumerator();
while (enumerator.MoveNext())
{
Player player1 = enumerator.Current;
player1.MatchmakingAttempts++;
if (player1.MatchmakingAttempts * 1000 > aiDelay)
{
matchmakeAIPlayer(player1);
continue;
}
if (!player1.Matchmaked)
{
Player player2 = findOpponentTo(player1);
if (player2 != null)
{
matchmake(player1, player2);
}
}
}
}
private void matchmake(Player player1, Player player2)
{
Console.WriteLine("Made Match: " + player1.Username + " vs. " + player2.Username);
string id = "room" + M.RandomString(20);
player1.Send("gameFound", id, "Classic");
player2.Send("gameFound", id, "Classic");
player1.Disconnect();
player2.Disconnect();
player1.Matchmaked = true;
player2.Matchmaked = true;
}
private void matchmakeAIPlayer(Player player)
{
// matchmake with AI after AI_DELAY
player.Matchmaked = true;
string id = "room" + M.RandomString(20);
player.Send("gameFound", id, "ClassicAI");
}
private Player findOpponentTo(Player player)
{
var enumerator = Players.GetEnumerator();
while (enumerator.MoveNext())
{
Player opponent = enumerator.Current;
if (player.Username != opponent.Username && !opponent.Matchmaked)
{
return opponent;
}
}
return null;
}
[DebugAction("Matchmake AI NOW", DebugAction.Icon.Time)]
public void matchmakeAIPlayerNow()
{
matchmakeAIPlayer(GetOpponentTo(null));
}
}
}