Author Topic: Chat Across Multiple Channels  (Read 5323 times)

Vorrtex

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Chat Across Multiple Channels
« on: April 13, 2015, 11:38:37 AM »
I have a game that's split up into multiple floors of a dungeon (each floor is its own scene and channel) but I'd like to have the chat open so that players can talk to one another across all floors/channels.

Is this possible using tnet?

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Chat Across Multiple Channels
« Reply #1 on: April 13, 2015, 06:57:37 PM »
unfortunately, a flaw in the overall design of tnet.

if you are not in the same channel, you must send private messages to the player name.  another problem is keeping track of all players in all channels.  there are threads covering both these issues though...

alternately, you could create a custom server packet and then respond to all players online (or in specific channels).

yes, it is possible.  for me, i try to keep everything that is *non-database* in RFC's and use server packets for data that needs to be stored in mySQL.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Chat Across Multiple Channels
« Reply #2 on: April 16, 2015, 07:53:15 AM »
Sure it's possible.
  1. tno.Send("SomeFunction", Target.Broadcast, "Hello world!");
Assuming you execute it on a TNObject with ID that's present in all channels, it will work as expected.

I use it to do /global chat in Windward, for example.

Elmo loves cookies

  • Jr. Member
  • **
  • Thank You
  • -Given: 60
  • -Receive: 1
  • Posts: 62
    • View Profile
Re: Chat Across Multiple Channels
« Reply #3 on: August 06, 2016, 12:13:28 PM »
Target.Broadcast - this send for everyone on Server, If I have two games on server, How I can separate sending chat message between two games?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Chat Across Multiple Channels
« Reply #4 on: August 06, 2016, 09:42:08 PM »
Broadcasts are a TNet 2 thing. There are no broadcasts in TNet 3. If you want to send a packet to everyone on the server, make everyone join the same channel first (for example the chat channel). Multiple channel support = chat uses one channel, game uses another.

Elmo loves cookies

  • Jr. Member
  • **
  • Thank You
  • -Given: 60
  • -Receive: 1
  • Posts: 62
    • View Profile
Re: Chat Across Multiple Channels
« Reply #5 on: August 07, 2016, 01:26:17 AM »
Multiple channel support = chat uses one channel, game uses another.
But how its work?
Can you make some example? please:)

Elmo loves cookies

  • Jr. Member
  • **
  • Thank You
  • -Given: 60
  • -Receive: 1
  • Posts: 62
    • View Profile
Re: Chat Across Multiple Channels
« Reply #6 on: August 07, 2016, 04:40:55 AM »
I make on the map object "Sender" with TNobject(exposed ChannelID != 0)
and added to this object C# script:

  1. using TNet;
  2.  
  3. public class Sender : TNBehaviour
  4. {
  5.     static public Sender singleton;
  6.  
  7.     void Awake()
  8.     {
  9.         singleton = this;
  10.     }
  11.     void Start()
  12.     {
  13.         for (int i = 0; i < Region.list.size; ++i)
  14.         {
  15.             Region region = Region.list[i];
  16.             if (!TNManager.IsInChannel(region.channelID))
  17.                 TNManager.JoinChannel(region.channelID, true);
  18.         }
  19.     }
  20.  
  21.     [RFC]
  22.     public void ChangeLB(string newName, string newCat, int newVal)
  23.     {
  24.         ScoreManager.instance.ChangeScore(newName, newCat, newVal);
  25.     }
  26. }

it have RFC function for everybody change Score in LeaderBoard, and it connect for every channel on the map by "Region.list".

and then I send like this:

  1. Sender.singleton.tno.Send("ChangeLB", Target.All, TNManager.playerName + "ў" + TNManager.player.id.ToString(), "scores", moneyScore);

that is work perfect, but correctly it is?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Chat Across Multiple Channels
« Reply #7 on: August 08, 2016, 06:22:15 PM »
Joining multiple channels is simple, and there is a tutorial covering it. Check the examples that come with TNet.

All TNObjects must belong to channels in TNet 3. In TNet 2 an object could exist without joining a channel. This is no longer the case with TNet 3.

In order for an object to belong to a channel, it must either be dynamically instantiated after joining a channel, or it must exist in a scene that gets loaded as a result of the TNManager.JoinChannel(id, "scene") call. In your case your "Sender" object has an RFC for communication, yet it performs channel joining inside its Start() function. This implies the object exists before joining a channel. This approach will only work if the "Sender" object itself is only loaded as a result of JoinChannel().

Elmo loves cookies

  • Jr. Member
  • **
  • Thank You
  • -Given: 60
  • -Receive: 1
  • Posts: 62
    • View Profile
Re: Chat Across Multiple Channels
« Reply #8 on: August 09, 2016, 05:41:31 AM »
From tutorial I can understand only how I can join through Channels.
Can you add in this tutorial - how realize chat in multichannel?:)
I dont understand how send and receive chat msg through specific channel

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Chat Across Multiple Channels
« Reply #9 on: August 09, 2016, 06:32:08 AM »
All RFCs are automatically sent through the channel that the TNObject belongs to. You don't need to specify anything yourself. This is why I said all objects must belong to channels in TNet 3.

To ensure that the object is in the channel you want, you need to create it there using TNManager.Instantiate(channelID, ...). For objects that are a part of the scene, they will assume the ID of the channel that loaded the level -- that one gets specified as a part of your TNManager.JoinChannel(channelID, "Scene Name").