rendered paste bodyclass ChatChannel
{
public:
ChatChannel(unsigned short channelId, std::string channelName){
m_id = channelId;
m_name = channelName;
};
private:
typedef std::map<long, Player*> UsersMap;
UsersMap m_users;
m_name;
m_id;
};
class Chat
{
public:
Chat(){
// Create the default channels
ChatChannel *newChannel;
newChannel = new ChatChannel(0x04, "Game-Chat");
if(newChannel)
m_normalChannels[0x04] = newChannel;
newChannel = new ChatChannel(0x05, "Trade");
if(newChannel)
m_normalChannels[0x05] = newChannel;
newChannel = new ChatChannel(0x06, "RL-Chat");
if(newChannel)
m_normalChannels[0x06] = newChannel;
};
bool createChannel(unsigned short channelId, std::string &channelName){
if(getChannel(channelId, channelName))
return false;
if(channelId == 0x00)
{
ChatChannel *newChannel = new ChatChannel(channelId, channelName);
if(!newChannel)
return false;
m_guildChannels[channelName] = newChannel;
return true;
}
return false;
};
bool deleteChannel(unsigned short channelId, std::string &channelName){
if(channelId == 0x00)
{
GuildChannelMap::iterator it = m_guildChannels.find(channelName);
if(it == m_guildChannels.end())
return false;
delete it->second;
m_guildChannels.remove(it);
return true;
}
return false;
};
bool addUserToChannel(Player *player, unsigned short channeld){
ChatChannel *channel = getChannel(channelId, channelName);
if(!channel)
return false;
if(channel->addUser(player))
return true;
else
return false;
};
bool removeUserFromChannel(Player *player, unsigned short channelId, std::string &channelName){
ChatChannel *channel = getChannel(channelId, channelName);
if(!channel)
return false;
if(channel->removeUser(player))
return true;
else
return false;
};
bool talkToChannel(Player *player, std::string &text, unsigned short channelId, std::string &channelName){
ChatChannel *channel = getChannel(channelId, channelName);
if(!channel)
return false;
if(channel->talk(player, text, channelId))
return true;
else
return false;
};
private:
ChatChannel *getChannel(unsigned short channelId, std::string &channelName){
if(channelId == 0x00)
{
GuildChannelMap::iterator it = m_guildChannels.find(channelName);
if(it == m_guildChannels.end())
return NULL;
}
else
{
NormalChannelMap::iterator it = m_normalChannels.find(channelId);
if(it == m_normalChannels.end())
return NULL;
}
return it->second;
};
typedef std::map<unsigned short, ChatChannel*> NormalChannelMap;
typedef std::map<std::string, ChatChannel*> GuildChannelMap;
NormalChannelMap m_normalChannels;
GuildChannelMap m_guildChannels;
};