MatchMaker

                Never    
C#
       
//using System.Collections;
//using System.Collections.Generic;
//using UnityEngine;
//using Mirror;
//using System;
//using System.Security.Cryptography;
//using System.Text;

//[Serializable]
//public class Match {
//    public string matchID;
    
//    public SyncListGameObject players = new SyncListGameObject();
//    //public SyncList<GameObject> players = new SyncList<GameObject>();

//    public Match(string matchID, GameObject player)
//    {
//        this.matchID = matchID;
//        players.Add(player);
//    }

//    public Match(){}
//}

//[Serializable]
//public class SyncListGameObject: SyncList<GameObject> {

//    public SyncListGameObject(){}
//}

//[Serializable]
//public class SyncListMatch: SyncList<Match> {

//    public SyncListMatch() { }
//}

//[Serializable]

//public class MatchString {

//    public string value;

//    public MatchString() { }
//    public MatchString(string value) { this.value = value; }
//}

//public class MatchMaker : NetworkBehaviour
//{
//    public static MatchMaker instance;

//    public SyncListMatch matches = new SyncListMatch();
//    public SyncList<MatchString> matchIDs = new SyncList<MatchString>();
    
//    [SerializeField] GameObject turnManagerPrefab;

//    public MatchMaker()
//    {

//    }

//    private void Start()
//    {
//        instance = this;
//    }
//    public bool HostGame(string _matchID, GameObject _player, out int playerIndex)
//    {
//        MatchString matchStringID = new MatchString(_matchID);

//        playerIndex = -1;
//        if (!matchIDs.Contains(matchStringID))
//        {
//            matchIDs.Add(matchStringID);
//            matches.Add(new Match(_matchID, _player));
//            Debug.Log("Match generated");
//            playerIndex = 1;
//            return true;
//        }
//        else
//        {
//            Debug.Log($"Match ID already exists!");
//            return false;
//        }
//    }


//    public bool JoinGame(string _matchID, GameObject _player, out int playerIndex)
//    {
//        MatchString matchStringID = new MatchString(_matchID);
//        //Debug.Log($"MatchIDCount: {matchIDs.Count}");
//        playerIndex = -1;
//        bool joinFlag = false;
//        if (matchIDs.Contains(matchStringID))
//        {
//            joinFlag = true;
//            for (int i=0;i<matches.Count;i++)
//            {
//                if (matches[i].matchID == _matchID)
//                {
//                    if (matches[i].players.Count < 2) matches[i].players.Add(_player);
//                    else { joinFlag = false; break; }
//                    playerIndex = matches[i].players.Count;
//                    //Debug.Log($"PlayerIndex: {playerIndex}");
//                    break;
//                }
//            }
//            Debug.Log("Match joined");
//            return joinFlag;
//        }
//        else
//        {
//            Debug.Log($"Match ID does not exist!");
//            return joinFlag;
//        }
//    }

//    public void BeginGame(string _matchID)
//    {
//        GameObject newTurnManager = Instantiate(turnManagerPrefab);
//        NetworkServer.Spawn(newTurnManager);
//        newTurnManager.GetComponent<NetworkMatch>().matchId = _matchID.ToGuid();
//        TurnManager turnManager = newTurnManager.GetComponent<TurnManager>();

//        for (int i=0;i<matches.Count;i++)
//        {
//            if(matches[i].matchID == _matchID)
//            {
//                foreach (var player in matches[i].players)
//                {
//                    LobbyPlayer _player = player.GetComponent<LobbyPlayer>();
//                    turnManager.AddPlayer(_player);
//                    _player.StartGame();
//                }
//                break;
//            }
//        }
//    }

//    public static string GetRandomMatchID()
//    {
//        string _id = string.Empty;

//        for(int i = 0; i < 5; i++)
//        {
//            int random = UnityEngine.Random.Range(0,36);
//            if (random < 26)
//            {
//                _id += (char)(random + 65);
//            }
//            else
//            {
//                _id += (random - 26).ToString();
//            }
//        }
//        //Debug.Log($"Random Match ID: {_id}");
//        return _id;
//    }
//}

//public static class MatchExtensions
//{
//    public static Guid ToGuid(this string id){
//        MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
//        byte[] inputBytes = Encoding.Default.GetBytes(id);
//        byte[] hashBytes = provider.ComputeHash(inputBytes);

//        return new Guid(hashBytes);
//    }

//}

Raw Text