0

I apologize in advance for not including any code in this one as the question is so unusual I was unable to find any decent information about it and I have a hard time wrapping my head around it as well. I also apologize if the question displays such a ludicrous lack of understanding on my part, that you sprained something laughing...

Imagine, if you will, a "multiplayer" web page. There's a login page, user can log in, his or her name gets displayed somewhere, cookie is set. So far, no rocket science.

Now let's take it a little further: once the user is logged in, a SECOND user should be able to log in and his or her username should be displayed as well, on the other half of the page, let's say.

Let's assume for a moment that they each get a half page to work with, that way you have a visual idea of what that would be like. It's like opening two text editors next to each other, let's say.

So... how do I approach this? Do I write a proverbial

ApplicationSignInManager.MultiSignIn(ApplicationUser user)

then another

AuthenticationManager.SignIn

and just rewrite the whole shebang beneath it until I get a cookie with two users in it? Is it really that straightforward? (I'm using ASP.NET MVC 5 by the way)

Or is my understanding so lacking that I shouldn't even consider this?

The thing is: the use case is there. I need to build it, any which way. I just can't figure out how to approach it... can you?

EDIT:

  • There will always be a finite number of people interacting with this web page. Let's assume, for the moment, a maximum of 2.
  • YES, these two people will be on the SAME computer, each interacting with only their OWN half of the screen.
Wim Ombelets
  • 5,097
  • 3
  • 39
  • 55
  • So are you saying that 2 people will log in on the same client computer? – NightOwl888 Mar 22 '15 at 20:36
  • @NightOwl888 Exactly! The page is split in half. I get left, you get right. We both log in. – Wim Ombelets Mar 22 '15 at 20:39
  • Take a look at this page: http://ruchirac.blogspot.com.ar/2013/02/basics-of-creating-multiplayer-web.html What you need is SignalR which is built for this kind of realtime stuff. – Nico Mar 22 '15 at 21:08
  • @NicolásCarlo I have no need for SignalR as the page will not need to reflect remote changes in realtime. It's one page on one physical computer with two people. – Wim Ombelets Mar 22 '15 at 21:15

2 Answers2

1

You seem to be confused about a few core concepts when it comes to web programming.

I will assume that the second user is not on the same computer as the first user.

Multiple users can of course be logged in with the default FormsAuthentication that comes with ASP.NET. A cookie would not solve anything since the cookie is "per user".

This is a somewhat complicated matter, because what you are describing would require a pretty intimate client/server relationship.

I assume that you want to be notified of when a user has logged on; when another use has logged on and not on the next page reload. This would require some sort of web service or at least a few ajax-requests.

The first step (however) would be to "flag" the user that has logged on as online, and when the user logs of, flag the user as not-online this way you can fetch the online users at all times via a web request. The way you decide to store your users does not matter; just make sure you can flag them as online/not-online.

The easiest way to get the online users would be via ajax.
Using jQuery:

$.get('users/OnlineList', function (data) { 
    // Let's just assume that "data" is just a comma-separated string of users.
    $('div#online-users').text(data);
});

Then do that every x seconds, via setInterval or similar. This is hacky and ugly, but it works; and it is how many people do it.


But back to the problem at hand.

The way i see it; the best way to do this (if it's always two people). Is to have some sort of "lobby"-system, when User-A logs in, User-A is put in Lobby-1. When User-B logs in, this user is also put in Lobby-1, and Lobby-1 is now closed, no more people can join. User-C and User-D is put in Lobby-2 and so on.

So in conclusion:

  • You have a cool idea, but you are approaching it the wrong way.
  • You need to store the users in some sort of database, with an offline/online flag
  • You need to poll the database now and then to see what users are online
  • You will need to develop some sort of lobby system for the users if you want more than two users be able to use your service simultaneously.
  • You need to touch up on the basics on web programming

I hope my answer has been of some help!

mausworks
  • 1,607
  • 10
  • 23
  • thanks for your insights. I'm sure they'll help me piece together a viable solution. I've updated my question to reflect what I apparently forgot to mention. Be sure to read up on that. The users are NOT on different computers! – Wim Ombelets Mar 22 '15 at 21:10
0

The webpage should check on the webserver/database if a second user is logged in and do something (displaying the username). If you need further infos, let me know.

Let's say you have a login page and after a successful login it updates a record in the table "user" in column "loggedin" to "true". Let's say you have on the main page a ticker, that shows all logged in users. If you navigate to the main page, the page select all users with column "loggedin" = "true and count it. The result is saved in a variable and displayed on the site.

If you want to know something, from different users you have to save it on a database or a "static" variable.

Charlie
  • 1,169
  • 2
  • 16
  • 31