Improved channel support.

This commit is contained in:
Nicolás Ortega Froysa
2017-11-17 17:18:33 +01:00
parent c6eb1d6b09
commit 909a5ff740
2 changed files with 32 additions and 5 deletions

View File

@ -34,6 +34,11 @@ int NeoComm_join_channel(const char *channel_name) {
add_error("NeoComm must be initialized.");
return 0;
}
else if(channel_name[0] != '#')
{
add_error("Channel name must start with `#'.");
return 0;
}
const std::string s_chan_name(channel_name);
if(s_chan_name.empty())
@ -66,17 +71,35 @@ int NeoComm_join_channel(const char *channel_name) {
return 1;
}
void NeoComm_leave_channel(const char *channel_name) {
int NeoComm_leave_channel(const char *channel_name) {
if(not node.isRunning())
return;
{
add_error("NeoComm must be initialized.");
return 0;
}
else if(channel_name[0] != '#')
{
add_error("Channel name must start with `#'.");
return 0;
}
const std::string s_chan_name(channel_name);
if(channels.find(s_chan_name) == channels.end())
return;
{
add_error("Channel does not exist.");
return 0;
}
else if(s_chan_name.empty())
{
add_error("Chan name is empty.");
return 0;
}
struct channel_info *channel = &channels[s_chan_name];
channel->token.wait();
node.cancelListen(channel->hash, channel->token.get());
channels.erase(s_chan_name);
return 1;
}
struct message *NeoComm_get_next_message(const char *channel_name) {