예제 #1
0
 /// <summary>
 /// Removes a user from the list and adds a DisconnectEvent to handle
 /// the notification to other users within this room.
 /// </summary>
 /// <param name="user">User to remove.</param>
 public void RemoveUser(User user)
 {
   if (user != null && users.Contains(user))
   {
     users.Remove(user);
     // create the DisconnectEvent and add it to this room's list.
     DispatchEvent(new Event(user, new Property("disconnect", "true", false)));
   }
 }
예제 #2
0
 /// <summary>
 /// Adds a new user to the room.
 /// </summary>
 /// <param name="user">User to add.</param>
 public void AddUser(User user)
 {
   if (!users.Contains(user))
   {
     users.Add(user);
     user.Room = this;
     // clear optional events of a previous room
     user.Events.Clear();
   }
 }
예제 #3
0
 /// <summary>
 /// Retrieves the User object that represents myself.
 /// </summary>
 /// <param name="context">The current HttpContext.</param>
 /// <returns>My User instance.</returns>
 public User GetMyUser(HttpContext context)
 {
   // first check if a User is known for the current request
   User user = context.Items["Multiplayer.User"] as User;
   if (user != null)
     return user;
     
   // for multiple users per session, check user based on id
   if (MultipleUsersPerSession)
   {
     // check if an id was passed in the request
     string id = GetInput(context)["id"];        
     if (!String.IsNullOrEmpty(id))
     {
       user = context.Session["Multiplayer.User." + id] as User;
       if (user == null)
         throw new Exception("User id " + id + " was not found in your session.");
     }
     if (user == null)
     {
       user = new User();
       context.Session["Multiplayer.User." + user.Id] = user;
     }
   }     
   // if only 1 user per session is allowed 
   else
   {
     user = context.Session["Multiplayer.User"] as User;
     if (user == null)
       context.Session["Multiplayer.User"] = user = new User();
   }
   
   // store the user for this request
   context.Items["Multiplayer.User"] = user;
   return user;
 }
예제 #4
0
 /// <summary>
 /// Returns true if the requested User is currently present in this room.
 /// </summary>
 /// <param name="user">User to check.</param>
 /// <returns>True if the requested User is currently present in this room.</returns>
 public bool ContainsUser(User user)
 {
   return users.Contains(user);
 }
예제 #5
0
 /// <summary>
 /// Creates a new property change Event instance for the give User
 /// and the given Property.
 /// </summary>
 /// <param name="user"></param>
 /// <param name="property"></param>
 public Event(User user, Property property)
 {
   this.user = user;
   this.property = property;
 }