- Home /
Get RPC senders ID, or IP?
When a client sends an RPC, is it possible for the pickup, eg. Server, to by function get that senders network ID or IP, or do I need to attach it from the sender, as a variable, eg. Sender : String and send with the RPC? Seems a little stupid.
Answer by voodoo · Dec 30, 2012 at 06:15 AM
Add a NetworkMessageInfo parameter onto your RPC method but don't worry about including it when you call the RPC, it will be automatically filled in:
// Somewhere...
networkView.RPC("AnRPCMethod", RPCMode.Others, "String sent", new Vector3(1f,4f,2f) );
// The RPC
[RPC] public void AnRPCMethod(string aString, Vector3 aVector, NetworkMessageInfo info) {
// Do some things
NetworkPlayer netPlayer = info.sender;
string playerIP = netPlayer.ipAddress;
}
See: NetworkMessageInfo
Note that you can't pick the real sender this way on another client. On clients, the sender is always either the client himself or the server, never another client.
If you want another client to know who sent the RPC you'll have to explicitly add that as a parameter for the RPC.
Your answer
Follow this Question
Related Questions
RPC is called but it doesn't destroy some GameObject instances 1 Answer
Spawning Clients 1 Answer
RPC Call Mix Up Issues 0 Answers
Networking RPC calls never sent to other clients 1 Answer
network.RPC behavior 1 Answer