Esempio n. 1
0
ChatChannel* Chat::createChannel(Player* player, uint16_t channelId)
{
	if(!player || player->isRemoved() || getChannel(player, channelId))
		return NULL;

	switch(channelId)
	{
		case CHANNEL_GUILD:
		{
			ChatChannel* newChannel = NULL;
			if((newChannel = new ChatChannel(channelId, player->getGuildName(), ChatChannel::staticFlags)))
				m_guildChannels[player->getGuildId()] = newChannel;

			return newChannel;
		}

		case CHANNEL_PARTY:
		{
			ChatChannel* newChannel = NULL;
			if(player->getParty() && (newChannel = new ChatChannel(channelId, partyName, ChatChannel::staticFlags)))
				m_partyChannels[player->getParty()] = newChannel;

			return newChannel;
		}

		case CHANNEL_PRIVATE:
		{
			//only 1 private channel for each premium player
			if(!player->isPremium() || getPrivateChannel(player))
				return NULL;

			//find a free private channel slot
			for(uint16_t i = 100; i < 10000; ++i)
			{
				if(m_privateChannels.find(i) != m_privateChannels.end())
					continue;

				uint16_t flags = 0;
				if(dummyPrivate)
					flags = dummyPrivate->getFlags();

				PrivateChatChannel* newChannel = NULL;
				if((newChannel = new PrivateChatChannel(i, player->getName() + "'s Channel", flags)))
				{
					newChannel->setOwner(player->getGUID());
					m_privateChannels[i] = newChannel;
				}

				return newChannel;
			}
		}

		default:
			break;
	}

	return NULL;
}
Esempio n. 2
0
ChatChannel* Chat::createChannel(Player* player, const uint16_t& channelId)
{
	if (getChannel(player, channelId))
	{
		return NULL;
	}

	if (channelId == CHANNEL_GUILD)
	{
		ChatChannel* newChannel = new ChatChannel(channelId, player->getGuild()->getName());
		m_guildChannels[player->getGuildId()] = newChannel;
		return newChannel;
	}
	else if (channelId == CHANNEL_PARTY)
	{
		if (!player->getParty())
		{
			return NULL;
		}

		PrivateChatChannel* newChannel = new PrivateChatChannel(channelId, "Party");
		m_partyChannels[player->getParty()] = newChannel;
		return newChannel;
	}
	else if (channelId == CHANNEL_PRIVATE)
	{
		// Private chat channel

		//only 1 private channel for each player
		if (getPrivateChannel(player))
		{
			return NULL;
		}

		//find a free private channel slot
		uint16_t i = getFreePrivateChannelId();

		if (i != 0)
		{
			PrivateChatChannel* newChannel = new PrivateChatChannel(i, player->getName() + "'s Channel");

			if (!newChannel)
			{
				return NULL;
			}

			newChannel->setOwner(player->getGUID());
			m_privateChannels[i] = newChannel;
			return newChannel;
		}
	}

	return NULL;
}
Esempio n. 3
0
ChatChannel* Chat::createChannel(const Player& player, uint16_t channelId)
{
	if (getChannel(player, channelId)) {
		return NULL;
	}

	switch (channelId) {
		case CHANNEL_GUILD: {
			Guild* guild = player.getGuild();
			if (guild) {
				ChatChannel* newChannel = new ChatChannel(channelId, guild->getName());
				guildChannels[guild->getId()] = newChannel;
				return newChannel;
			}
			break;
		}

		case CHANNEL_PARTY: {
			Party* party = player.getParty();
			if (party) {
				ChatChannel* newChannel = new ChatChannel(channelId, "Party");
				partyChannels[party] = newChannel;
				return newChannel;
			}
			break;
		}

		case CHANNEL_PRIVATE: {
			//only 1 private channel for each premium player
			if (!player.isPremium() || getPrivateChannel(player)) {
				return NULL;
			}

			//find a free private channel slot
			for (uint16_t i = 100; i < 10000; ++i) {
				if (privateChannels.find(i) == privateChannels.end()) {
					PrivateChatChannel* newChannel = new PrivateChatChannel(i, player.getName() + "'s Channel");
					newChannel->setOwner(player.getGUID());
					privateChannels[i] = newChannel;
					return newChannel;
				}
			}
			break;
		}

		default:
			break;
	}
	return NULL;
}
Esempio n. 4
0
ChatChannel* Chat::createChannel(const Player& player, uint16_t channelId)
{
	if (getChannel(player, channelId)) {
		return nullptr;
	}

	switch (channelId) {
		case CHANNEL_GUILD: {
			Guild* guild = player.getGuild();
			if (guild) {
				auto ret = guildChannels.emplace(std::make_pair(guild->getId(), ChatChannel(channelId, guild->getName())));
				return &ret.first->second;
			}
			break;
		}

		case CHANNEL_PARTY: {
			Party* party = player.getParty();
			if (party) {
				auto ret = partyChannels.emplace(std::make_pair(party, ChatChannel(channelId, "Party")));
				return &ret.first->second;
			}
			break;
		}

		case CHANNEL_PRIVATE: {
			//only 1 private channel for each premium player
			if (!player.isPremium() || getPrivateChannel(player)) {
				return nullptr;
			}

			//find a free private channel slot
			for (uint16_t i = 100; i < 10000; ++i) {
				auto ret = privateChannels.emplace(std::make_pair(i, PrivateChatChannel(i, player.getName() + "'s Channel")));
				if (ret.second) { //second is a bool that indicates that a new channel has been placed in the map
					auto& newChannel = (*ret.first).second;
					newChannel.setOwner(player.getGUID());
					return &newChannel;
				}
			}
			break;
		}

		default:
			break;
	}
	return nullptr;
}
Esempio n. 5
0
ChatChannel* Chat::createChannel(Player* player, uint16_t channelId)
{
	if(getChannel(player, channelId))
		return NULL;
		
	if(channelId == 0x00){	
		ChatChannel *newChannel = new ChatChannel(channelId, player->getGuildName());
		if(!newChannel)
			return NULL;
		
		m_guildChannels[player->getGuildId()] = newChannel;
		return newChannel;
	}
	else if(channelId == 0xFFFF){
		//only 1 private channel for each player
		if(getPrivateChannel(player)){
			return NULL;
		}
		
		//find a free private channel slot
		for(uint16_t i = 100; i < 10000; ++i){
			if(m_privateChannels.find(i) == m_privateChannels.end()){
				PrivateChatChannel* newChannel = new PrivateChatChannel(i, player->getName() + "'s Channel");
				if(!newChannel)
					return NULL;
				
				newChannel->setOwner(player->getGUID());

				m_privateChannels[i] = newChannel;
				return newChannel;
			}
		}
	}
		
	return NULL;
}