Author Topic: SendQuickly to Target.All  (Read 2741 times)

PerfectPanda

  • Guest
SendQuickly to Target.All
« on: March 31, 2013, 09:32:15 AM »
When I'm using SendQuickly with Target.All to send a UDP RFC to all channel members it appears to only actually run on the caller. This is supported by looking into SendRFC in TNObject where in this case target is changed to Others and executeLocally is set to true (which makes sense), but then the actual network message is only sent if executeLocally is false.

Is the logic of this wrong, or am I totally misunderstanding the intended usage? (For now I can certainly work around this by using Target.Others and then doing the local call myself)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SendQuickly to Target.All
« Reply #1 on: March 31, 2013, 03:00:36 PM »
I believe you're right and you found a valid issue. I've changed the function to:
  1.         static void SendRFC (uint objID, byte rfcID, string rfcName, Target target, bool reliable, params object[] objs)
  2.         {
  3. #if UNITY_EDITOR
  4.                 if (!Application.isPlaying) return;
  5. #endif
  6.                 bool canSendToChannel = TNManager.isInChannel && (target == Target.Host || TNManager.isHosting);
  7.                 bool executeLocally = false;
  8.  
  9.                 if (canSendToChannel)
  10.                 {
  11.                         // We want to echo UDP-based packets locally instead of having them bounce through the server
  12.                         if (!reliable)
  13.                         {
  14.                                 if (target == Target.All)
  15.                                 {
  16.                                         target = Target.Others;
  17.                                         executeLocally = true;
  18.                                 }
  19.                                 else if (target == Target.AllSaved)
  20.                                 {
  21.                                         target = Target.OthersSaved;
  22.                                         executeLocally = true;
  23.                                 }
  24.                         }
  25.  
  26.                         byte packetID = (byte)((int)Packet.ForwardToAll + (int)target);
  27.                         BinaryWriter writer = TNManager.BeginSend(packetID);
  28.                         writer.Write(GetUID(objID, rfcID));
  29.                         if (rfcID == 0) writer.Write(rfcName);
  30.                         UnityTools.Write(writer, objs);
  31.                         TNManager.EndSend(reliable);
  32.                 }
  33.                 else if (target == Target.All || target == Target.AllSaved || (target == Target.Host && TNManager.isHosting))
  34.                 {
  35.                         executeLocally = true;
  36.                 }
  37.                
  38.                 if (executeLocally)
  39.                 {
  40.                         if (rfcID != 0)
  41.                         {
  42.                                 TNObject.FindAndExecute(objID, rfcID, objs);
  43.                         }
  44.                         else
  45.                         {
  46.                                 TNObject.FindAndExecute(objID, rfcName, objs);
  47.                         }
  48.                 }
  49.         }
Edit: Fix for sending an offline message to host.
« Last Edit: April 01, 2013, 05:53:48 AM by ArenMook »

PerfectPanda

  • Guest
Re: SendQuickly to Target.All
« Reply #2 on: March 31, 2013, 07:17:53 PM »
Thanks, I'll modify my local copy and try it!  :)

joboldo

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: SendQuickly to Target.All
« Reply #3 on: May 09, 2013, 07:08:41 AM »
I dont see this code updated in the new 1.69 Version ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SendQuickly to Target.All
« Reply #4 on: May 09, 2013, 07:38:30 AM »
The function has changed since then. Are you having some issue?