The basic unity networking doesn’t seem to have any obvious option to prevent a client from using RPCMode.Others or RPCMode.all
I’d like to implement something that forces the client to always use RPCMode.Server, and throws an exception if any other mode is used. If a hacked client calls with one of these modes, the server should intercept it and block it (and allows me to write some detection/logging on the server side).
Client security is important in my code, and I can’t allow any client to send an unsupervised message to another client.
So far, I haven’t found anything in UnityEngine.Network that makes this possible.
For reference, I’m using the NetworkView component, and calling with this syntax:
// this bit attached to a GUI button
networkView.RPC("HackTest", RPCMode.Others, "Hax! Fix immediately!");
// This bit listening for the RPC (Client and server, but specifically OTHER clients are receiving this, which is bad
[RPC]
void HackTest(string message, NetworkMessageInfo callerInfo)
{
if (Network.isClient)
{
GameObject theCamera = GameObject.Find("Main Camera");
ConnectionGUI theGui = (ConnectionGUI)theCamera.GetComponent("ConnectionGUI");
theGui.currentMessage = "Hack Received:" + message;
}
// It's kindof expected that the server will get this, but we don't want clients sending messages to eachother.
}
It’s there for a reason.
Other than that, no constructive ideas… Sorry!
Although…
The way RPC works would mean that this method would involve creating a function with every possible name. You should perhaps make a server in a different way, such as using .net sockets (if you have pro, for example)
UPDATE:
I’m writing a new, all-custom network layer, using tcpClient directly.
Fabianzz:
As I understand it, GetComponent<>() could work on IOS devices, but due to other limitations with generics, that particular option hasn’t been added, or isn’t currently supported. I’ve ultimately used your suggestion, but if you port to IOS, it’s not “always” the right way to do it. (I guess).