Ejemplo n.º 1
0
        ConnectedPlayerData GetNewConnectedPlayerData(Socket socket, int searchedPlayerAmount)
        {
            ConnectedPlayerData connectedPlayerData = new ConnectedPlayerData(socket,
                                                                              ConnectedSocketState.WaitingForPlayers, searchedPlayerAmount);

            return(connectedPlayerData);
        }
Ejemplo n.º 2
0
        void ProcessConnectionError(ConnectedPlayerData user)
        {
            m_IsActive = false;
            user.socket.Close();

            ConnectionErrorDelegate connectionErrorDelegate;

            if (m_EventsManager.TryGetDelegate(DelegateType.ConnectionError, out connectionErrorDelegate))
            {
                Task.Run(() => connectionErrorDelegate.Invoke());
            }
            else
            {
                Console.Write($"{DelegateType.ConnectionError.ToString()} was not invoked");
            }
        }
Ejemplo n.º 3
0
        void AddNewConnectedUser(int searchedPlayerAmount, Socket socket)
        {
            //#TODO remove after debugging
            if (searchedPlayerAmount == 1)
            {
                ConnectedPlayerData connectedPlayerData = GetNewConnectedPlayerData(socket, searchedPlayerAmount);

                List <ConnectedPlayerData> temp = new List <ConnectedPlayerData>();
                temp.Add(connectedPlayerData);
                FinalizeConnection(temp);

                Task.Run(() => m_OnPlayersConnectedCallback(temp));
                return;
            }
            /////////////////////////////////////////////////////////////////////////

            List <ConnectedPlayerData> pendingPlayersForSearchedAmount;

            if (m_PendingPlayers.TryGetValue(searchedPlayerAmount, out pendingPlayersForSearchedAmount))
            {
                ConnectedPlayerData connectedPlayerData = GetNewConnectedPlayerData(socket, searchedPlayerAmount);

                pendingPlayersForSearchedAmount.Add(connectedPlayerData);
                Console.WriteLine($"{pendingPlayersForSearchedAmount.Count.ToString()} player(s) for {searchedPlayerAmount} players room");

                if (searchedPlayerAmount == pendingPlayersForSearchedAmount.Count)
                {
                    Console.WriteLine($"Readiness check for {searchedPlayerAmount} players room");
                    FinalizeConnection(pendingPlayersForSearchedAmount);

                    Task.Run(() => m_OnPlayersConnectedCallback(pendingPlayersForSearchedAmount));
                    m_PendingPlayers.Remove(searchedPlayerAmount);
                }
            }
            else
            {
                List <ConnectedPlayerData> newPendingPlayerForSearchedAmount = new List <ConnectedPlayerData>();
                ConnectedPlayerData        connectedPlayerData = GetNewConnectedPlayerData(socket, searchedPlayerAmount);

                newPendingPlayerForSearchedAmount.Add(connectedPlayerData);
                Console.WriteLine($"{newPendingPlayerForSearchedAmount.Count.ToString()} player(s) for {searchedPlayerAmount} players room");

                m_PendingPlayers.Add(searchedPlayerAmount, newPendingPlayerForSearchedAmount);
            }
        }