- Home /
How to check if the player is already logged in
Hello everyone!
Is there any way to check if the player is already logged in the server? Like, if the username his player and a another player is trying to connect with the same username then tell that this user is already logged in. Can I do this with array list?
Thanks for reading, any help is appriciated :)
-John
The idea is correct, but you can't really assume that if two players have the same name, that they're automatically the same person. (you might want to check their IPs for that). If it's for something simple as a shooter, you'd probably want to just ask the second player to change his nick or or display it on the server as something like "player[2]" (where [2] is added automatically)
How you want to handle this is pretty much up to you. You could send the player info to the server and check it on the server side to see if the player can log on with that info or have the player connect to the server no matter what and just do something else ins$$anonymous$$d once the player is already connected.
What have you tried and how did it work for you?
I didn't tried anything yet. I think that I found a way to solve this with PHP. Also with PHP Im creating the accounts plus logging in. If that doesnt work then I will try your solution. But a question for your first solution[IP]: If the player is connected with the same IP the denie the second connect. But, if the player is logged in on his account and a another guy tries to access this account from a totaly different computer and IP then it will not denied it?
Thanks for the reply :)
Well, if you only would check the IP, then yes - he would be able to log on from more than one location. All that is up to you and how you want to handle it. You could just try checking if the user is logged in (either by userName or ID) and it should work just fine. There are a lot of scenarios how you could handle this. It really depends on what you really want and what type of game you're working. If you simply want to check if the player is already logged in then you would most probably just mark some variable on the server for the player as being logged in and check that value when logging in.
I'm not too familiar with RPC. You most probably can do that, but from what I have read on http://docs.unity3d.com/Documentation/Components/net-RPCDetails.html it's mot of a way to send out information to all connected clients which would be rather pointless in this case.
How exactly do you handle logging in? How do you send the request to the server? Are you using Unities built in server and client or have you written your own and how do you send information to clients?
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
"Foreach" in an Array? 1 Answer
Storing instances of a script in a list. 0 Answers
How to use an Array list of classes inside a class? 1 Answer
How can I check if ALL items in an array/list meet a condition? 2 Answers