Author Topic: TNet 3 - Send RFC messages  (Read 8611 times)

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
TNet 3 - Send RFC messages
« on: April 30, 2016, 07:41:41 PM »
Hello,

I upgraded to TNet3 and now working on a new prototype.
Looks better and more stable in comparison to version 2.

I could manage to: host a main server (TNServerInstance), make a lobby myself and many other things.
Here is how it works:
- Dedicated server is created. Working good (different EXE file). I have a user, who is ADMIN, who runs inside dedicated server.
- Clients can connect to it. After connecting, I made a custom login process and saving player data. All good.
- The server them returns good or bad player login
- If it is good, join lobby ID 1 (my lobby), bad, just disconnect
- Create a new room (channel), ok

Here is where the problem starts.
- I do this with a new client (new player) or any other new players
- Player connects to the room
- Everyone receives the ChannelData update good (if there are more players)
- But when I try to send a simple chat message, noone receives (using Target.All or Target.Others)
- Even myself (the one who sent the message), do not receive the message (a simple string message)
- If I send a global message from server to all (I mean the server user, the Admin), it works (Target.Broadcast)
- Also, my channels ID usually has big numbers (2435643)... is this normal?

Facts: the players are in the same channelId. Even my own player does not receive the message using Target.All
I had this exact same problem in TNet 2, discovered (at least I suppose) that when I am creating a new channel with "TNManager.CreateChannel", I cannot pass first parameter (levelName) to null, or messages stops going from each other.... I need to pass always a new level scene (this in TNet2). I am suspecting that this same problem is happening, but this time I cannot change the level to solve it cause of my game design.
Is there anything specific I need to know to check what am I doing wrong? Or I really cannot pass as null the levelname?
Thank you.

EDIT:
- Tried with the TNet bat server that comes with the pack, no success
- Tried disabling firewall, anti-virus, everything, no success
I cannot just find out why a simple RFC message does not work if I use Target.All or Target.Others (using Saved or not)
I have no clue what is going on, the Example menu works (even the chat scene), but if I even copy and paste the code of example menu and chat into my own scene (empty one), it just does not work... help?
« Last Edit: May 01, 2016, 07:49:07 PM by xandeck »

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #1 on: May 01, 2016, 07:00:26 PM »
Can I have a TNObject in the same gameObject that I have the script running the server?
Because, I made a lot of changes and this is the only difference between my scene and "0. Menu" demo scene that comes with the package. I made even a prefab of the Chat example, dragging to my scene and it just do not work!

  1. // ################################################################################################
  2.         /// <summary>
  3.         /// Try to send the message
  4.         /// </summary>
  5.         public void _Send_RoomChatMessage(string msg)
  6.         {
  7.                 Debug.Log("Testing: " + msg);
  8.                 tno.Send("_Receive_ChatMessage", Target.All, TNManager.playerID, msg);
  9.         }
  10.         // ################################################################################################
  11.         /// <summary>
  12.         /// Receives message
  13.         /// </summary>
  14.         [RFC] void _Receive_ChatMessage(int pId, string msg)
  15.         {
  16.                 Debug.Log("NETWORK: Received chat message: " + msg);
  17.         }
  18.  

This does not work. Target.Others does not work too.
ONLY works if I broadcast it or send direct to a player (i.e. TNManager.player)
I reimported everything and tried, no luck... I give up until I have some help.

EDIT: Maybe I found the problem (again): just saw that my TNObject stays in channel zero, even if I Join a channel (with all feedbacks working).
The TNObject is already in my scene and I tried with ID from 2 to 9000. Channel never changes.
And I saw that the Example menu and Chat demo, the TNObject does change the channel id of the tno... maybe this is the problem, but still no clue how to solve it.
« Last Edit: May 03, 2016, 09:20:18 AM by xandeck »

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #2 on: May 03, 2016, 12:34:46 PM »
Ok, I was able to solve it and I think this is a bug (maybe not, still waiting support).

- I cannot Connect to TNManager using the same gameObject with a TNObject static ID
- If I do this, my TNObject never gets out of the channel 0 (even using tno.TransferToChannel or whatever). It does not matter, it does not work
- My TNObject ONLY works changing channel, if this gameObject is in another scene during JoinChannel call (and then I call to change the level instead of passing "null")
- To solve it, I need to duplicate my scene, call TNManager.Connect from a whatever gameObject and then change it to a new scene, where my "network manager" with the TNObject is.

I lost almost 2 days on this =/ The tracking of the problem is above, in case you want to know.
Aren... where are you? XD
« Last Edit: May 03, 2016, 01:34:56 PM by xandeck »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #3 on: May 03, 2016, 01:28:28 PM »
Did you check the Chat example that comes with TNet?

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #4 on: May 03, 2016, 01:30:52 PM »
Hello Aren,

Yes, of course =)
As I said in the last post of this topic, it happens the same with your Chat demo if you do the steps I told you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #5 on: May 03, 2016, 01:32:11 PM »
To explain what you're doing wrong...

In TNet 3 objects must belong to a channel. This means, they need to either be dynamically created via TNManager.Instantiate, or they must be in a scene that gets loaded via a passed level name to TNManager.JoinChannel.

If you don't want to pass a level name and want to use a chat object, then have the first person to join the channel instantiate it from a prefab instead as a persistent object.

In your case you have a static object that exists before you even join a channel. That's no longer allowed in TNet 3. TNet 2 allowed it, and it was the reason why RFCs would often get saved for objects that no longer exist, resulting in warnings when joining channels. TNet 3 now checks -- does the object exist? No? Then don't forward/save the RFCs.

xandeck

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 3
  • Posts: 54
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #6 on: May 03, 2016, 01:34:10 PM »
Yes, that's what I was afraid of.
I did not know that 'tnos' has already to be inside a channel, dynamically or not.
But as I said to you, everything worked, besides Target.All and Target.Others and this confused me.
I already changed my logic for this.

All makes sense now, thanks, I wish I could see this info before =P
« Last Edit: May 03, 2016, 01:55:24 PM by xandeck »

Ludopathic

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #7 on: January 06, 2017, 10:30:59 AM »
If you don't want to pass a level name and want to use a chat object, then have the first person to join the channel instantiate it from a prefab instead as a persistent object.

Hi Aren, I've been trying to do exactly that because I have the same issue, however I cannot find an example of where or how to instantiate TNobjects using Tnmanager.instantiate, do you have a code example? for what you mentioned above?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #8 on: January 08, 2017, 02:58:16 PM »

Ludopathic

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #9 on: January 09, 2017, 04:47:07 AM »
I tried this, I could not get it to work. In the meantime, I've moved to Bolt. Maybe I'm use Tnet for a different project in the future once I have some more experience but for now I find it too fiddly. Thanks for all the help.

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #10 on: January 11, 2017, 07:01:40 AM »
I do it this way

TNManager.Instantiate(1, "name", false);

Where name is the Prefab you want to instantiate and you have a copy of the Prefab in the resources folder.

danfoo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 93
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #11 on: September 14, 2017, 11:07:18 AM »
We currently have the gameplay scene load asynchronously via normal Unity calls. Is there a call to load levels async via Tnet.JoinChannel?
Or do we have to load the level (async, normally) first and the instantiate our manager objects? The latter would be more hassle then just calling join channel with an async option...

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: TNet 3 - Send RFC messages
« Reply #12 on: September 14, 2017, 07:03:24 PM »
TNManager.JoinChannel does load the scene asynchronously. No special call necessary. I think all scene loads in TNet are async.

You can access TNManager.loadLevelOperation for the async operation (check for null).