- Home /
Login System Using XML Server/Client
tl;dr : I can't think of logic to send my already working login/register system between client/server.
Alright, so its 6:40AM here. Forgive me if I don't make sense or if I ask a stupid question. I figure there's a chance I'll wake up tomorrow and the someone will have a brilliant answer out of the kindness in their hearts. Ok, so here's the problem:
I'm running short on the logic here. I have a login system. It allows you to create a username and password with the click of the register button and stores it in an XML on my computer. It allows logging in, doesn't allow overwriting(from normal users), doesn't allow wrong passwords, etc. :D sweet. The only thing I can't wrap my head around is how would I send the password and username that someone types in on a client to my server through RPC.
For clarification, I have two scripts. One is the connect/username and password text fields. They are on two different game objects for the sake of finding them rather easily. I could easily attach them to the same object. Ok back to the problem.
I thought that it would be pretty easy to simply set the username and password = _username and _password for simplicity's sake. But now that I think about it, I think I will probably need arrays that +1 every time a new player connects. But then again, if the fields reset after a player sends the information, what does it matter?
I guess I'm asking for a run through on logic, here. I'm thinking of running an if(server) then set username and password to _username and _password, and if(client) then send username and password to server. I'm not exactly sure how to do that per say. Any suggestions/code examples would be great. Another thing I'm considering is programming a client separate from the server. I'm not sure how well that will work, but my logic right now(lack of sleep logic) tells me it would be awesome! (I haven't gone about doing it yet, though). Any help/suggestions/"here you go stupid" I eagerly await! I shall continue "mucking" with this code until my face hits the keyboard. :)
EDIT: (changed name to be more specific)
Ok, so after some sleep and a day of thought I am still having a bit of trouble. I have a client/server in one at this point in time and I plan on hosting it on a dedicated desktop that is relatively powerful. I plan on separating the script to two distinct projects, but thats currently irrelevant. I think I could have some sort of "listener" that trips whenever a client connects.
I could trip the onPlayerConnect() function and run code on the client side so that is sends the variable name and password across the connection and have the server store it in a variable thats created only during the function call. Well I'm going to read up a bit more on Unity's listeners. I'm not too familiar with them. I'll try using the above logic if I don't find any listeners that will do what I want.
Answer by SirGive · Dec 09, 2010 at 05:09 AM
I had a registration and log in system working strictly with Unity. You click a button, and it took the text for your password, and the text for your user name and stored it in an XML. I could not think of how to send from a client to a server. The solution was actually pretty easy:
For the register/login buttons I used the following if conditions:
if (Network.isClient)
{
login = true;//or register for the other button
networkView.RPC("Send", RPCMode.Server, name, pass, login, register);
login = false;//or register for the other button
}
I ran this inside OnGUI under the button code:
if (Network.isServer&&login==true){ //or register
login=false;//or register for the other button
//regular code that was executed when button was pressed
}
and the following RPC:
@RPC
function Send(name:String,pass:String,login:Boolean,register:Boolean,info:NetworkMessageInfo)
{
if ( Authenticate(name,password,login,register) )
{
networkView.RPC( "OnRegisterSuccess", info.sender );
}
else
{
networkView.RPC( "OnRegisterFailure", info.sender );
}
}
So there you have it. :D It took me about 2 days to figure this out completely.
EDIT: Special thanks to Statement
Just a comment about your coding style. I don't know about you, but it is pretty hard trying to figure out what flag1 and flag2 means by looking at the code. You should try rename those to something meaningful.
I was thinking that if someone ran into the same problem as me, they'd be able to discern what flags needed to be put where. However, I'll update it.