Skip to main content
Version: 1.3.0

Channel

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

tip

When language-specific (language) channel group has been set in the console, the user automatically enters the channel according to their language when they enter 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 method

// Called when channel join is completed
void OnJoinChannel(BackndChat::ChannelInfo channelInfo)
{
// channelInfo: Contains channel information, user list, and previous messages
}

// Called when channel leave is completed
void OnLeaveChannel(BackndChat::ChannelInfo channelInfo)
{
// channelInfo: Information about the channel that was left
}

// Called when another user joins the channel
void OnJoinChannelPlayer(
string channelGroup,
string channelName,
uint64_t channelNumber,
BackndChat::PlayerInfo player)
{
// player: Information about the user who joined
}

// Called when another user leaves the channel
void OnLeaveChannelPlayer(
string channelGroup,
string channelName,
uint64_t channelNumber,
BackndChat::PlayerInfo player)
{
// player: Information about the user who left
}

Call method

// 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.
BackndChat::BDChatMain::SendCreatePrivateChannel(string channelGroup, uint64_t channelNumber = 0, string channelName = "default", uint32_t 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.
BackndChat::BDChatMain::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.
BackndChat::BDChatMain::SendJoinPrivateChannel(string channelGroup, uint64_t channelNumber, string password = "");

// This is the channel exit method. It passes the channel group, channel name, and channel number as arguments.
BackndChat::BDChatMain::SendLeaveChannel(string channelGroup, string channelName, uint64_t channelNumber);

Information class

ChannelInfo

Channel information that is provided when entering a channel.

struct ChannelInfo
{
// Channel group name
string ChannelGroup;

// Channel name
string ChannelName;

// Channel number
uint64_t ChannelNumber;

// Channel’s max number of users
uint32_t MaxCount;

// Information of currently logged-in players
map<string, PlayerInfo> Players;

// List of previous chat messages
vector<MessageInfo> Messages;
};

PlayerInfo

Information of users in the channel.

struct PlayerInfo
{
// Player name
string GamerName;

// Player avatar name
string Avatar;

// Player language
string Language;

// Player metadata
map<string, string> Metadata;
};

Check previous messages

void UChatManager::OnJoinChannel(const FChannelInfo& ChannelInfo)
{
// Check previous messages
for (const FMessageInfo& Msg : ChannelInfo.Messages)
{
UE_LOG(LogTemp, Log, TEXT("[Previous messages] %s: %s"),
*Msg.GamerName, *Msg.Message);
UE_LOG(LogTemp, Log, TEXT("Sent time: %s"), *Msg.SendTime);
}

// Check users who are currently logged in
for (const TPair<FString, FPlayerInfo>& Pair : ChannelInfo.Players)
{
UE_LOG(LogTemp, Log, TEXT("Connected: %s"),
*Pair.Value.GamerName);
}
}