Author Topic: [SOLVED] Strange tno.Send behaviour  (Read 1786 times)

raptorx81

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 12
    • View Profile
[SOLVED] Strange tno.Send behaviour
« on: May 08, 2016, 08:23:42 PM »
I'm running into a bit of an issue with a new project using TNet 3. Here's my code, and I'll explain what I'm trying to do ..

  1. using UnityEngine;
  2. using System.Collections;
  3. using TNet;
  4.  
  5. public class TNetInGameManager : TNBehaviour {
  6.  
  7.         public static TNetInGameManager Instance;
  8.  
  9.         int masterIndex = 0;
  10.  
  11.         void Start()
  12.         {
  13.                 Instance = this;
  14.         }
  15.  
  16.         public void AskForIndex()
  17.         {
  18.                 Debug.Log("Asking for index from host : " + TNManager.GetHost(TNManager.lastChannelID).id);
  19.                 Debug.Log("My Player ID: " + TNManager.playerID);
  20.                 tno.Send("AskForPlayerIndex", TNManager.GetHost(TNManager.lastChannelID).id, TNManager.playerID);
  21.  
  22.                 // This causes even weirder behaviour.
  23.                 //tno.Send("AskForPlayerIndex", Target.Host, TNManager.playerID);
  24.         }
  25.  
  26.         [RFC]
  27.         void AskForPlayerIndex(int id)
  28.         {
  29.                 Debug.Log("My Player ID: " + TNManager.playerID);
  30.                 Debug.Log("Received index request from client " + id);
  31.  
  32.                 tno.Send("SendPlayerIndex", id, masterIndex);
  33.  
  34.                 masterIndex++;
  35.         }
  36.  
  37.         [RFC]
  38.         void SendPlayerIndex(int ind)
  39.         {
  40.                 Debug.Log("Received Index from Master!");
  41.                 GameManager.instance.i = ind;
  42.         }
  43.        
  44. }
  45.  

So when a client enters the channel, the player needs a 'slot' for the game (from 0 to 3). So when I join the channel, I call AskForIndex. This then should then send a simple request to the host of the channel to the method "AskForPlayerIndex". From there the host should then send a simple integer back to the requesting client via "SendPlayerIndex".

So it should send a request from Client -> Host -> Client. But what's actually happening is Client -> Client -> Client.

My Debug line logs out the correct Host ID ( TNManager.GetHost(TNManager.lastChannelID).id ), but for whatever reason on line 20, it's sending it to the local player instead. Any thoughts?

EDIT : Ugh time for me to take a break. Turns out all my weird TNet issues were being caused by an outdated dedicated TNet server. As soon as I used the TNServer.exe file in the TNet package, everything works as intended.
« Last Edit: May 08, 2016, 09:03:33 PM by raptorx81 »

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
Re: [SOLVED] Strange tno.Send behaviour
« Reply #1 on: May 09, 2016, 03:42:39 PM »
I was having a similar problem.
Check if your gameObject with "tno" is dynamically instantiated. If not, it will be better if you do (Aren can correct me).
I was trying to send a simple message and nothing was happening. Since now TNet 3 supports multiple channels, I had some confusion too.

EDIT: Ugh, just saw that is already solved =P