Exemplo n.º 1
0
        internal static void CreateNewMatch(string playerOneId, string playerOneName)
        {
            try
            {
                MatchState match = new MatchState();

                if (m_Matches.ContainsKey(match.MatchIdentity))
                {
                    Console.WriteLine("Created Match With Duplicate Identity..");
                    CreateNewMatch(playerOneId, playerOneName);
                }

                else
                {
                    AddPlayerToMatch(match, playerOneId, playerOneName);
                    m_Matches.Add(match.MatchIdentity, match);

                    if (ServerCore.DebugMode)
                    {
                        Console.WriteLine("New Match ({0}) Created: {1} : {2}",
                                          match.MatchIdentity.Substring(0, 8), match.PlayerOne.AccountIdentity, match.PlayerOne.Username);
                    }

                    MatchEventDispatcher.InvokeMatchCreatedEvent(new MatchCreatedEventArgs(match));
                }
            }

            catch (Exception e) { Console.WriteLine(e.ToString()); }
        }
Exemplo n.º 2
0
        internal static void AddSpectatorToMatch(string matchId, string clientId, string accountId, string username)
        {
            if (m_Matches.ContainsKey(matchId))
            {
                MatchState match = m_Matches[matchId];
                AccountHandler.GetAccountById(accountId).SetCurrentMatch(match);

                if (match.CanAddSpectator())
                {
                    MatchEventDispatcher.InvokeSpectatorJoinEvent
                        (new SpectatorJoinEventArgs(matchId, true, clientId));

                    PlayerState spectator = new PlayerState(accountId, username);

                    match.AddSpectator(spectator);

                    MatchEventDispatcher.InvokeSpectatorSyncEvent
                        (new SpectatorSyncEventArgs(match, spectator));

                    match.SyncAllNetStatesWithSpec(spectator);
                }

                else
                {
                    MatchEventDispatcher.InvokeSpectatorJoinEvent
                        (new SpectatorJoinEventArgs(matchId, false, clientId));
                }
            }
        }
Exemplo n.º 3
0
        private void EndMatch_One(string[] segments)
        {
            string matchId = segments[2];

            MatchHandler.EndMatch(matchId);

            MatchEventDispatcher.InvokeMatchEndEvent(new MatchEndEventArgs(matchId));
        }
Exemplo n.º 4
0
        internal static void AttemptToJoinMatch(ClientState client, string matchId)
        {
            if (m_Matches.ContainsKey(matchId))
            {
                MatchState match = m_Matches[matchId];

                if (match.MatchIsFull())
                {
                    MatchEventDispatcher.InvokeMatchJoinResultEvent(new MatchJoinEventArgs(client, match.MatchIdentity, false));
                }
                else
                {
                    AddPlayerToMatch(match, client.AccountRelative.AccountId, client.AccountRelative.Username);

                    MatchEventDispatcher.InvokeMatchJoinResultEvent(new MatchJoinEventArgs(client, match.MatchIdentity, true));

                    MatchEventDispatcher.InvokeMatchSyncEvent(new MatchSyncEventArgs(match));
                }
            }
        }
Exemplo n.º 5
0
        internal static void RemoveUserFromMatch(MatchState match, string accountId)
        {
            PlayerState   userRemoved;
            DepartureType departureType = DepartureType.Unknown;

            match.RemoveUserFromMatch(accountId, out departureType, out userRemoved);

            if (match.PlayerOne == null & match.PlayerTwo == null)
            {
                if (m_Matches.ContainsKey(match.MatchIdentity))
                {
                    m_Matches.Remove(match.MatchIdentity);
                    MatchEventDispatcher.InvokeMatchEndEvent
                        (new MatchEndEventArgs(match.MatchIdentity));
                }
            }

            else
            {
                MatchEventDispatcher.InvokeUserDepartedEvent
                    (new UserDepartedEventArgs(match, departureType, userRemoved));
            }
        }