Getting player/actor id when deserializing on server

Options
Marek
Marek
edited March 2014 in Photon Server
Hi,

After i register custom types on server, Deserialize method is called every time data arives on server.
My question is, can i somehow get something like PhotonView/Player/Actor ID of user client who sended that data in deserialize method or somewhere else in code??

Comments

  • Tobias
    Options
    PUN does register a few custom types which we don't register on the server. You can do that, I think.
    Find the de/serialization methods for those types in CustomTypes.cs and adjust them for the server side. Register looks a bit different (client versus server), if I'm not mistaken.

    The biggest problem will be: Most messages that PUN sends are not well documented. The hashtables we use in the clients contain values like IDs in keys that are numbered rather than named. We can't provide full documentation for that at the moment. PUN was not expected to have server logic and we don't really plan to disclose plain and cleanly how we implement Unity Networking features...

    However: Let us know how you do and maybe I can throw in some hints when you're stuck.
  • Marek
    Options
    Thanks for reply. Yeah i already used custom types to send identifier with data i was just curious if i can somehow distinguish between players on the server side (like from who are data that are being deserialized) without sending such data myself.

    Anyway thanks for informations :)
  • Marek
    Options
    I dont want to make new thread so i ask here, is it possible to boradcast event from server?
    I want to make an event (right before operation response) and send it to all players. I found SendEvent method but it seems like its sending event only to the peer who is calling that event.
    How can i send it to all?
    Thanks
  • You can use the "BroadCastEvent" method of the ApplicationBase class.
  • Marek
    Options
    Yes i've fount that but what to use as Peer list ?
  • You need to keep track of the peers to which you want to send the event.

    What do you mean by "all players"? All players that are connected to a specific application? In that case, you could add a peer list to the Application class (that inherits from ApplicationBase), add a peer whenever CreatePeer() is called and remove the peer from the list when OnDisconnect() is called. You can then pass this list to the SendEvent method.

    Is this what you are looking for?
  • Marek
    Options
    Thanks that's probably exactly what i looking for :D

    And yes all players within one room.
    I'm intending to send some data on server, check it (again on server) and when they are all right i want to broadcast an event from server to all players in room (like did i hit him? -> yes -> send to all players) i want to do this this way to minimize roundtrip. i know i could go player->OperationToServer->OperationResponseToPlayer->Player->RPC/OpCustomEvent but it will be slower (i hope i explained it somehow well :D )
  • Oh, I see. If you want to send events in a room: there is an "Actor" collection for each room, and each "Actor" holds a reference to the peer. That's what you are looking for, I guess. :)