Hey guys,
I'm running into the same problem as you guys, I think it's a design issue as I have come from using the built-in networking as well...
This is a simplified version of what i'm working on :
- Each player controls a ship (the player avatar)
- The player can choose 2 weapons to attach to their ship
- Each weapon fires a specific type of ammo
The point that i'm stuck on is when a player fires a weapon,
Using the built in networking I did it this way :
- The player sends their control input on the ship to the server (host)
- The server applies the input to the ship, and sends out the new position to the clients
- If the one of the fire buttons was pressed, the ship (server side) 'checks' with the corresponding weapon that it can be fired.
- If true, the server sends an RPC to all clients (on some kind of GameManager script), to spawn the correct ammo and passes a new NetworkViewID and ownerID with it.
- The ammo is instantiated on all clients and uses the NetworkViewID to receive updates from the server.
But this design pattern doesn't work using TNet
If the server creates the ammo using TNManager.Create(ammoPrefab) then the server is always the 'owner' of the ammo, and as far as I can tell the 'ownerID' is the only indentifier for objects created in this way (because we can't pass extra parameters on Instantiation). So there's no way I can determine who the real owner was.
Another approach is to have the client spawn the ammo (TNManager.Create). But if that's the case, I would want the server/host to verify that this was allowed to happen (otherwise the client could easily cheat, spawning any ammo they want or adjusting refire rates etc).
So the server would somehow need to determine which player fired this Ammo (that's easy enough, with the TNManager.objectOwnerID called OnAwake()), get that player's ship and which weapon it came from (all I have to go on here is the ammo prefab?) and check with the weapon if the shot was allowed (x time has passed since the last shot). If it's not allowed then the server destroy's the Ammo.
But even if that was possible, this way probably wouldn't work because of fluctuations in latency (if i'm comaparing the time that the weapon was last fired)
I'm stumped here and it's really frustrating because I know it's just that i'm thinking in the wrong way....
Am I being too paranoid wanting the server to check everything? (From what I've read, you should never trust the clients)
Thanks!