My game is a card game. I want my clients to send their input/actions to the server. And have the server validate these actions, then send acknowledgments back to the client. But I can’t seem to find a way to send messages from client to server.
Is there a way for PUN to send messages to Photon Server? So far I got these:
After a few digging, I’ve found that you can send operations to the server through PhotonPeer.OpCustom() method. In PUN, PhotonPeer (NetworkingPeer) is a private member variable of PhotonNetwork. PhotonNetwork is basically just a wrapper of PhotonPeer. However, PhotonNetwork doesn’t expose PhotonPeer nor does it provide an interface to call OpCustom().
So the problem still persists, how do I send Custom Operations using PUN?
good to hear you found a way to do what you want to achieve. Maybe I can give you some additional input. You told us that you use Photon Server. This can be extended with Plugins which offers you 9 predefined hooks where you can inject server-side custom logic. One of these hooks is: OnRaiseEvent(IRaiseEventCallInfo info)
As you already noticed by the name, this allows you to respond to client-side RaiseEvent(…) calls and allows the server to check the content of the message by the transmitted event code and to forward the message to other clients or to cancel and return an error message to the sending client.
Just an update, I ended up not using PUN. I am using their Unity SDK instead, which PUN is based off of. The reason is because I felt like PUN is designed for Photon Cloud (without server code). I needed more control so instead of working around PUN, I just used the simpler Photon Unity SDK instead.
Thanks for taking the time to actually work with PUN and our more bare-bones Unity Client SDK.
Your impression is about right: While you could work your way “up” with the Unity SDK, PUN adds several comfy layers on top of the low-level Photon API and you need to dig somewhat to get back most of the control you got otherwise. It depends on preference, which package is best for you.
You were on the right track to use the NetworkingPeer directly. It’s a needed “evil” to hide it somewhat in PUN, so it’s not accidentally used directly, unless you know what you do.
Hope you’re making good progress.