예제 #1
0
        public bool CreateChallenge(INetworkedSession challenger, INetworkedSession challenged)
        {
            if (_sessionInGame.Contains(challenger) || _sessionInGame.Contains(challenged) ||
                challenged.Registry.Has<ChallengeComponent>() || challenger.Registry.Has<ChallengeComponent>())
                return false;

            var challengerUserId = challenger.Registry.Get<AuthComponent, uint>(t => t.Id);
            challenger.Registry.Set(new ChallengeComponent(_application, challenger, challenged, ChallengeDirection.Challenged));
            challenged.Registry.Set(new ChallengeComponent(_application, challenged, challenger, ChallengeDirection.Challenger));

            challenged.Publish(new ChallengeCreatedEvent(challengerUserId));

            return true;
        }
예제 #2
0
        public void Join(INetworkedSession session)
        {
            // if already joined, throw exception
            if (_sessions.Contains(session))
                throw new OperationException("You may only join the lobby once.");

            // publishes a join lobby event to user who just joined
            // passes in a list of lobby sessions converted from current sessions
            session.Publish(new JoinLobbyEvent(_sessions.Select(
                t => t.Registry.Get<AuthComponent, LobbySession>(auth => new LobbySession(auth.Id, auth.Username)))));

            var lobbySession = session.Registry.Get<AuthComponent, LobbySession>(auth => new LobbySession(auth.Id, auth.Username));

            // need to inform all other sessions
            foreach (var existingSession in _sessions)
                existingSession.Publish(new SessionJoinedLobbyEvent(lobbySession));

            _sessions.Add(session);
        }
예제 #3
0
        public void Join(INetworkedSession session)
        {
            if (_sessions.Contains(session))
                throw new OperationException("You may only join the lobby once");

            //inform other existing sessions that a new session has joined
            session.Publish(new JoinLobbyEvent(_sessions.Select(
                t => t.Registry.Get<AuthComponent, LobbySession>(
                    auth => new LobbySession(auth.Id, auth.Username)
                    )
                    )
                    )
                );

            //inform the rest in the lobby a new entry
            var lobbySession = session.Registry.Get<AuthComponent, LobbySession>(
                auth => new LobbySession(auth.Id, auth.Username)
                );
            foreach (var existingSession in _sessions)
                existingSession.Publish(new SessionJoinedLobbyEvent(lobbySession));

            _sessions.Add(session);
        }