public ChallengeComponent(IApplication application, INetworkedSession curSession, INetworkedSession otherSession, ChallengeDirection direction) { _application = application; CurSession = curSession; OtherSession = otherSession; Direction = direction; }
public void Leave(INetworkedSession session) { if (!_sessions.Remove(session)) throw new OperationException("You were not in the lobby to begin with?"); var userId = session.Registry.Get<AuthComponent, uint>(auth => auth.Id); foreach (var existingSession in _sessions) existingSession.Publish(new SessionLeftLobbyEvent(userId)); }
public void SendMessage(INetworkedSession session, string message) { if (!_sessions.Contains(session)) throw new InvalidOperationException("Can not send a lobby message if you are not in the lobby"); var userId = session.Registry.Get<AuthComponent, uint>(auth => auth.Id); foreach (var existingSession in _sessions.Where(t => t != session)) { existingSession.Publish(new LobbyMessageSentEvent(userId, message)); } }
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; }
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); }
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); }
public bool Contains(INetworkedSession session) { return _sessions.Contains(session); }
public void Leave(INetworkedSession session) { if (!_sessions.Remove(session)) throw new OperationException("You were not in the lobby to begin with"); //inform the rest in the lobby an entry had left var userId = session.Registry.Get<AuthComponent, uint>(auth => auth.Id); foreach (var existingSession in _sessions) { existingSession.Publish(new SessionLeftLobbyEvent(userId)); } session.Registry.TryGet<ChallengeComponent>(challenge => { challenge.Abort(); }); }