Author Topic: Help regarding Target.Broadcast  (Read 3053 times)

Etarnalazure

  • Guest
Help regarding Target.Broadcast
« on: October 04, 2013, 01:54:09 PM »
Hey Aren!

I've finally downloaded the newest Tnet so I could use the WorldChat
feature.

However, it does not seem to work.

When writing new messages and using target.broadcast instead of target.all.

No new messages show up.

I even tried with more than one client online at the same time to check if it was just because it only worked if it detected more than one client.

I also tried moving one of the clients to a different scene (Still connected to the same server) and then trying it out. Same deal. (I'm using the inbuilt server solution, not the external one)

Any chance you could tell me how to use it?

I'll post the code so you can see if the error is on my part:

  1. [RequireComponent(typeof(TNObject))]
  2. public class UIGameChat : UIChat
  3. {
  4.         TNObject tno;
  5.  
  6.         /// <summary>
  7.         /// Sound to play when a new message arrives.
  8.         /// </summary>
  9.  
  10.         public AudioClip notificationSound;
  11.  
  12.         /// <summary>
  13.         /// If you want the chat window to only be shown in multiplayer games, set this to 'true'.
  14.         /// </summary>
  15.  
  16.         public bool destroyIfOffline = false;
  17.  
  18.         /// <summary>
  19.         /// We want to listen to input field's events.
  20.         /// </summary>
  21.  
  22.         void Start ()
  23.         {
  24.                 if (destroyIfOffline && !TNManager.isInChannel)
  25.                 {
  26.                         Destroy(gameObject);
  27.                 }
  28.                 else tno = GetComponent<TNObject>();
  29.                 tno.rebuildMethodList = true;
  30.         }
  31.  
  32.         /// <summary>
  33.         /// Send the chat message to everyone else.
  34.         /// </summary>
  35.  
  36.         protected override void OnSubmit (string text)
  37.         {
  38.                 tno.Send("OnChat", Target.Broadcast, TNManager.playerID, text);
  39.         }
  40.  
  41.         [RFC]
  42.         void OnChat(int playerID, string text)
  43.         {
  44.                 Color color = Color.white;
  45.                 Player sender = TNManager.GetPlayer(playerID);
  46.  
  47.                 if (sender != null)
  48.                 {
  49.                         // If the message was not sent by the player, color it differently and play a sound
  50.                         if (playerID != TNManager.playerID)
  51.                                 color = new Color(0.6f, 1.0f, 0f);
  52.  
  53.                         // Embed the player's name into the message
  54.                         text = string.Format("[{0}]: {1}", sender.name, text);
  55.                 }
  56.                 Add(text, color);
  57.  
  58.                 if (notificationSound != null)
  59.                         NGUITools.PlaySound(notificationSound);
  60.         }
  61.  
  62.         void OnNetworkPlayerJoin  (Player p) { Add(p.name + " has joined the game."); }
  63.         void OnNetworkPlayerLeave (Player p) { Add(p.name + " has left the game."); }
  64. }
  65.  
  66.  

(I think that chat code is from the StarLink game, I'll try with some of the other chat examples as well just to be sure though.)
« Last Edit: October 04, 2013, 08:56:20 PM by Etarnalazure »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help regarding Target.Broadcast
« Reply #1 on: October 04, 2013, 09:59:12 PM »
I just double-checked... my bad. I forgot to check in a modification to the TNGameClient file. You can fix it quickly on your end by opening up that file and going to line 681 (case Packet.ForwardToHost). Add the following case right below it:
  1. case Packet.Broadcast:

Etarnalazure

  • Guest
Re: Help regarding Target.Broadcast
« Reply #2 on: October 06, 2013, 03:26:46 PM »
Like so?

  1. case Packet.ForwardToHost:
  2.                         {
  3.                                 if (onForwardedPacket != null) onForwardedPacket(reader);
  4.                                 break;
  5.                         }
  6.                         case Packet.Broadcast:
  7.                         {
  8.                                 break;
  9.                         }
  10.  

I'm pretty sure I'm misunderstanding something :o
« Last Edit: October 06, 2013, 03:32:27 PM by Etarnalazure »

Etarnalazure

  • Guest
Re: Help regarding Target.Broadcast
« Reply #3 on: October 06, 2013, 03:35:06 PM »
Right, I've tried two things:

  1. case Packet.ForwardToHost:
  2.                         {
  3.                                 if (onForwardedPacket != null) onForwardedPacket(reader);
  4.                                 break;
  5.                         }
  6.                         case Packet.Broadcast:
  7.                         {
  8.                                 break;
  9.                         }
  10.  
  11.  

And:

  1. case Packet.ForwardToHost:
  2.                         {
  3.                                 if (onForwardedPacket != null) onForwardedPacket(reader);
  4.                                 break;
  5.                         }
  6.                         case Packet.Broadcast:
  7.  

The second one results in this error:
  1.  
  2. EndOfStreamException: Failed to read past end of stream.
  3. System.IO.BinaryReader.ReadChar () (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/BinaryReader.cs:340)
  4. TNet.UnityTools.ReadObject (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:624)
  5. TNet.UnityTools.Read (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:530)
  6. TNManager.OnForwardedPacket (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNManager.cs:826)
  7. TNet.GameClient.ProcessPacket (TNet.Buffer buffer, System.Net.IPEndPoint ip) (at Assets/Tools/TNet/Client/TNGameClient.cs:691)
  8. TNet.GameClient.ProcessPackets () (at Assets/Tools/TNet/Client/TNGameClient.cs:627)
  9. TNManager.Update () (at Assets/Tools/TNet/Client/TNManager.cs:834)
  10.  
  11.  

And with the first one nothing happens when I try and send a message with Broadcast. No error, no chat message. Nothing.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help regarding Target.Broadcast
« Reply #4 on: October 06, 2013, 09:42:12 PM »
No, literally right after that line:
  1. case Packet.ForwardToHost:
  2. case Packet.Broadcast:
  3. {
  4.     ....
  5.  

Etarnalazure

  • Guest
Re: Help regarding Target.Broadcast
« Reply #5 on: October 06, 2013, 09:56:38 PM »
I think I'm missing something;

This is how my code looks now:
(Which gives me 3 different errors)
  1. switch (response)
  2.                 {
  3.                         case Packet.Empty: break;
  4.                         case Packet.ForwardToAll:
  5.                         case Packet.ForwardToOthers:
  6.                         case Packet.ForwardToAllSaved:
  7.                         case Packet.ForwardToOthersSaved:
  8.                         case Packet.ForwardToHost:
  9.                         case Packet.Broadcast:
  10.                         case Packet.ForwardToPlayer:
  11.                         {
  12.                                 // Skip the player ID
  13.                                 reader.ReadInt32();
  14.                                 if (onForwardedPacket != null) onForwardedPacket(reader);
  15.                                 break;
  16.                         }
  17.                         case Packet.ResponsePing:
  18.                         {
  19.                                 mPing = (int)(mTime - mPingTime);
  20.                                 mCanPing = true;
  21.                                 break;
  22.                         }
  23.                         case Packet.ResponseSetUDP:
  24.                         {
  25.  

Could you post the entire switch case? Because I am clearly missing something
here.

Heres the errors:

  1. EndOfStreamException: Failed to read past end of stream.
  2. System.IO.BinaryReader.ReadChar () (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/BinaryReader.cs:340)
  3. TNet.UnityTools.ReadObject (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:624)
  4. TNet.UnityTools.Read (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:530)
  5. TNManager.OnForwardedPacket (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNManager.cs:826)
  6. TNet.GameClient.ProcessPacket (TNet.Buffer buffer, System.Net.IPEndPoint ip) (at Assets/Tools/TNet/Client/TNGameClient.cs:687)
  7. TNet.GameClient.ProcessPackets () (at Assets/Tools/TNet/Client/TNGameClient.cs:627)
  8. TNManager.Update () (at Assets/Tools/TNet/Client/TNManager.cs:834)
  9.  

  1. EndOfStreamException: Failed to read past end of stream.
  2. System.IO.BinaryReader.FillBuffer (Int32 numBytes) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/BinaryReader.cs:119)
  3. System.IO.BinaryReader.ReadSingle () (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/BinaryReader.cs:506)
  4. TNet.UnityTools.ReadColor (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:614)
  5. TNet.UnityTools.ReadObject (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:640)
  6. TNet.UnityTools.Read (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:530)
  7. TNManager.OnForwardedPacket (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNManager.cs:826)
  8. TNet.GameClient.ProcessPacket (TNet.Buffer buffer, System.Net.IPEndPoint ip) (at Assets/Tools/TNet/Client/TNGameClient.cs:687)
  9. TNet.GameClient.ProcessPackets () (at Assets/Tools/TNet/Client/TNGameClient.cs:627)
  10. TNManager.Update () (at Assets/Tools/TNet/Client/TNManager.cs:834)
  11.  

  1. EndOfStreamException: Failed to read past end of stream.
  2. System.IO.BinaryReader.FillBuffer (Int32 numBytes) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/BinaryReader.cs:119)
  3. System.IO.BinaryReader.ReadUInt16 () (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.IO/BinaryReader.cs:513)
  4. TNet.UnityTools.ReadObject (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:667)
  5. TNet.UnityTools.Read (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNUnityTools.cs:530)
  6. TNManager.OnForwardedPacket (System.IO.BinaryReader reader) (at Assets/Tools/TNet/Client/TNManager.cs:826)
  7. TNet.GameClient.ProcessPacket (TNet.Buffer buffer, System.Net.IPEndPoint ip) (at Assets/Tools/TNet/Client/TNGameClient.cs:687)
  8. TNet.GameClient.ProcessPackets () (at Assets/Tools/TNet/Client/TNGameClient.cs:627)
  9. TNManager.Update () (at Assets/Tools/TNet/Client/TNManager.cs:834)
  10.  


Is there supposed to be code within the "case Packet.Broadcast"?

Am i supposed to move the code from "ForwardToHost" into the "Broadcast" case?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help regarding Target.Broadcast
« Reply #6 on: October 06, 2013, 10:43:41 PM »
Just grab 1.8.2b, it has this fix in it.

Etarnalazure

  • Guest
Re: Help regarding Target.Broadcast
« Reply #7 on: October 06, 2013, 10:50:48 PM »
Sounds good.

Been looking forward to the Broadcast feature :)