Skip to main content

Channel

You can implement channel joins and exits. You can also use callback when a new user joins or exits the channel.

tip

When a channel group has been set in the console based on the user's country, language, countrycode, or guild, the user automatically enters the channel according to their properties when they connect to the chat server. To set the automatic channel group, check the console guide documentation.

caution

You cannot use language, country, countrycode, guild, and whisper as channel group names. These are reserved words used in the Auto Create Channel function.

Description

The following details callback methods, call methods, and information classes related to the channel.

Callback methods

// This callback method is relayed when a user joins a channel. It transfers the channel's information.
public void OnJoinChannel(ChannelInfo channelInfo) { }

// This callback method is relayed when a user exits a channel. It transfers the channel's information.
public void OnLeaveChannel(ChannelInfo channelInfo) { }

// This callback method is relayed when a new user connects to a channel. It transfers the user's information.
public void OnJoinChannelPlayer(string channelGroup, string channelName, UInt64 channelNumber, string gamerName, string avatar) { }

// This callback method is relayed when a user exits a channel. It transfers the user's information.
public void OnLeaveChannelPlayer(string channelGroup, string channelName, UInt64 channelNumber, string gamerName, string avatar) { }

Call methods

// Only private channels can be created in an SDK.
// You will need to use the console for other channel types.

// This is the method that creates private channels. It inserts and delivers the channel group, channel number, channel name, maximum users, and password.
// If you do not enter a password, the channel will be created as a public channel.
// If the channel number is sent as 0, the server automatically grants the channel number.
ChatClient.SendCreatePrivateChannel(string channelGroup, UInt64 channelNumber = 0, string channelName = "default", uint maxCount = 50, string password = "")

// This is the channel join method of the open channel type. It passes the channel group and the channel's name as arguments.
ChatClient.SendJoinOpenChannel(string channelGroup, string channelName)

// This is the channel join method of the private channel type. It passes the channel group and the channel's number as arguments.
ChatClient.SendJoinPrivateChannel(string channelGroup, ulong channelNumber, string password = "")

// This is the channel exit method. It passes the channel group, channel name, and channel number as arguments.
ChatClient.SendLeaveChannel(string channelGroup, string channelName, UInt64 channelNumber = 0)
// These methods are related to the guild channel and are usable only if you are using BACKND Base's guild function.

// This is the guild channel join method.
ChatClient.SendJoinGuildChannel();

// This is the guild channel exit method.
ChatClient.SendLeaveGuildChannel();
If you are using BACKND Base's guild function, you must implement a separate logic for the guild chat entry and exit of a new guild.

For example, you must call the following code after the guild creation (CreateGuildV3).

ChatClient.SendJoinGuildChannel();

You must call the following code after withdrawing from the guild (WithdrawGuildV3).

ChatClient.SendLeaveGuildChannel();

Additionally, if you set the guild registration acceptance to real-time notification, you must call the guild chat entry method when the OnApprovedGuildJoin callback occurs. Calling the method will automatically allow users to enter the guild chat channel of the guild they joined.

Guild chat will become unavailable until the user reconnects if the logic is not handled separately.

To create a guild channel using only Chat SDK, you must implement it using the following method:

Enter the following code when creating a guild. You need to use a channel group name other than guild as it is a reserved word used in the auto channel creation function. You are automatically connected to the channel when the guild is created.

ChatClient.SendCreatePrivateChannel("guilds", 1, "guildname", 100, "");

After reconnecting, you must call the method below to connect to the guild channel.

ChatClient.SendJoinPrivateChannel("guilds", 1);

For guild members, call the method above upon immediate guild join or acceptance, even if the callback has been implemented.

If withdrawal and kick callback is implemented on a guild member, the following method must be called for that member to exit the guild channel:

ChatClient.SendLeaveChannel("guilds", "guildname", 1);

Information class

public class PlayerInfo
{
// Player name
public string GamerName = string.Empty;

// Player avatar name
public string Avatar = string.Empty;
}
public class ChannelInfo
{
// Channel group name
public string ChannelGroup = string.Empty;

// Channel name
public string ChannelName = string.Empty;

// Channel number
public UInt64 ChannelNumber = 0;

// Channel's max number of users
public uint MaxCount = 0;

// Information of currently logged-in players
public Dictionary<string, PlayerInfo> Players = new Dictionary<string, PlayerInfo>();

// List of chat messages
public List<MessageInfo> Messages = new List<MessageInfo>();
}