Actions with multiple users


#1

I have 2 chat rooms, in every room I have 5 users and input field , where every user can enter some number and submit it to validate on server, if number equal (for example) to 5 than users in this room win, and users in other room lose, so I have 5 users that win and 5 that lose.

So, what I want: when one of team win, than redirect users that wins to some WIN page, and at the same time redirect users that lose to LOSE page. And !THIS IMPORTANT! if some users for example was offline but his team won or lose , than when the next time user log in show LOSE or WIN page which depends on whether his team won or not.

So I see 3 problems for which I do not find a solution:

  1. Redirect group of users
  2. Track when one of team win (track for all users that play game)
    (Blaze if unsuitable)
  3. If some team wins and user was offline , hen the next time user log
    in show LOSE or WIN page

I know that a lot of questions and they are very extensive, but could not find the solution, help somebody !

EDIT : Important ! When someone wins I delete all chat rooms and messages, (Rooms.remove() etc.) And new game starts every 3 days


#2

There’s a bunch of ways to do all of these things. Going to go with the regular stackOverflow response: what have you tried and/or what solutions do you propose?

Since I know nothing about your architecture (e.g. whether you store game history or not; what packages you use etc.), I can only give you generalized tips:

  1. Publish the current game information to the user. On the client, track the game status; if it changes to either “lose” or “win”, have the router redirect them to the appropriate page.
  2. Same as above
  3. So many ways to do this. Simplest (but maybe not the best) way: on client startup, check whether their last logout was before the last game ended - if it was, then redirect them to the lose or win page.

#3

Ok, thx but now let’s talk about the 3 point. For example on main page I will do this

{{#if dontseeresults}}

and on heleper

dontseeresults: function(){
  Meteor.call(showresult, Meteor.userId(), function(err,res){
    return res;
  })
}

and on server logic like ( if user last login time < game end time) return true and redirect him
but when the next time he will go to mian page

{{#if dontseeresults}}

this will work again, because he not log out, so maybe I must manipulate with user collection ?


#4

This is how I would do it.

I would have a collection which stores instances of these ‘games’.
Each document would contain the IDs of the players in both ‘teams’.
That document would also store which team won or lost, it could also have a flag for each player to say whether or not they saw their win/loss page.
That way they can login at anytime and be informed if they won or lost.