- Home /
get return on networkView.RPC
Hey
I have following line of code:
networkView.RPC("Register",RPCMode.Server,username);
So my problem with that line is, that I need to get an answer from the server whether or not the username is already used by another player. But I don't know how I could send the message from the server back to the client. As I only want this one client to get the answer not all clients.
Answer by Kiloblargh · Apr 23, 2014 at 10:37 PM
You just need to check the NetworkMessageInfo.sender
attribute sent automatically with the RPC :
from the docs:
@RPC
function PrintText (text : String, info : NetworkMessageInfo)
{
Debug.Log(text + " from " + info.sender);
}
AFAIK there is no RPCMode that lets you send to a single specific player (why not? dunno...) but you can use RPCMode.Others
and have it just do nothing if the sent network player id does not match the local player's.
But I'm not sure about your idea of using a Unity game server to register / keep track of in-use usernames in the first place, I would use (actually, am using) a WWWForm connecting to a PHP script connecting to an SQL database.
hmm.
I understand your doubts. But I always struggle setting up sql databases, well I mostly fail, so I was trying to get around it. I was going to handle a high amount of users through that network view, so sending messages to all users will be quiet a problem.
I guess I need to either lern that sql and php stuff or find another way to setup a server-client-system
They needn't all be connected to it at once. If I understand what you're trying to do, a player would connect to your 'login server', first, get a response, then disconnect. Once they're in a game, they are directly connected to another player and their username is stored in the login server's PlayerPrefs. If your game is an $$anonymous$$$$anonymous$$O, you should go with a third-party $$anonymous$$$$anonymous$$O server solution because Unity's built in networking won't cut it. (Also if setting up a database is a struggle for you, taking on a $$anonymous$$$$anonymous$$O project is just masochism.)