- Home /
 
 
               Question by 
               cubrman · Jul 29, 2016 at 07:00 PM · 
                networkingservermessages  
              
 
              Get isServer from NetworkMessage
How to identify if the message was sent by server or clinet from NetworkMessage?
I am creating a custom Spawning behaviour for the players and I want to identify a situation where I am spawning a player on a machine that is both server and client at the same time. Here is my code:
     public override void OnStartServer()
     {
         base.OnStartServer();
         NetworkServer.RegisterHandler(MsgType.AddPlayer, SpawnPlayer);
     }
     void SpawnPlayer(NetworkMessage netMsg)
     {
         AddPlayerMessage msg = netMsg.ReadMessage<AddPlayerMessage>();
         if (netMsg.conn.hostId < 0)
         {
             // Is this the right way to check if the message was sent by the server to himself?
         }
     }
 
               As you can see from the code, right now I check if netMsg.conn.hostId < 0. Is this the right way to do this?
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
UNet "Automatic" server 1 Answer
Starting a small-scope client/server game with Unity 2 Answers
UNET server -batchmode -nographics 1 Answer
Best cross platform Http Library? 1 Answer