コード例 #1
0
ファイル: chat.cpp プロジェクト: edubart/otserv
void Chat::removeUserFromAllChannels(Player* player)
{
	ChannelList list = getChannelList(player);

	while (!list.empty())
	{
		ChatChannel* channel = list.front();
		list.pop_front();
		channel->removeUser(player);

		if (channel->getOwner() == player->getGUID())
		{
			deleteChannel(player, channel->getId());
		}
	}

	for (NormalChannelMap::iterator it = m_normalChannels.begin(); it != m_normalChannels.end(); ++it)
	{
		it->second->removeUser(player);
	}

	for (GuildChannelMap::iterator it = m_guildChannels.begin(); it != m_guildChannels.end(); ++it)
	{
		it->second->removeUser(player);
	}
}
コード例 #2
0
ファイル: chat.cpp プロジェクト: gianflogao/divinity-ots
void Chat::removeUserFromAllChannels(Player* player)
{
	ChannelList list = getChannelList(player);
	while(list.size()){
		ChatChannel *channel = list.front();
		list.pop_front();
			
		channel->removeUser(player);
		
		if(channel->getOwner() == player->getGUID())
			deleteChannel(player, channel->getId());
	}
}
コード例 #3
0
ファイル: chathandler.cpp プロジェクト: Ablu/invertika
void ChatHandler::handleQuitChannelMessage(ChatClient &client, MessageIn &msg)
{
    MessageOut reply(CPMSG_QUIT_CHANNEL_RESPONSE);

    short channelId = msg.readShort();
    ChatChannel *channel = chatChannelManager->getChannel(channelId);

    if (channelId == 0 || !channel)
    {
        reply.writeByte(ERRMSG_INVALID_ARGUMENT);
    }
    else if (!channel->removeUser(&client))
    {
        reply.writeByte(ERRMSG_FAILURE);
    }
    else
    {
        reply.writeByte(ERRMSG_OK);
        reply.writeShort(channelId);

        // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user left
        // the channel.
        warnUsersAboutPlayerEventInChat(channel,
                client.characterName,
                CHAT_EVENT_LEAVING_PLAYER);

        // log transaction
        Transaction trans;
        trans.mCharacterId = client.characterId;
        trans.mAction = TRANS_CHANNEL_QUIT;
        trans.mMessage = "User left " + channel->getName();
        storage->addTransaction(trans);

        if (channel->getUserList().empty())
        {
            chatChannelManager->removeChannel(channel->getId());
        }
    }

    client.send(reply);
}
コード例 #4
0
ファイル: guildhandler.cpp プロジェクト: Ablu/manaserv
void ChatHandler::handleGuildAcceptInvite(ChatClient &client,
                                          MessageIn &msg)
{
    MessageOut reply(CPMSG_GUILD_ACCEPT_RESPONSE);
    const int guildId = msg.readInt16();
    const bool accepted = msg.readInt8();

    // check guild exists and that member was invited
    // then add them as guild member
    // and remove from invite list
    Guild *guild = guildManager->findById(guildId);
    if (!(guild && guild->checkInvited(client.characterId)))
    {

        reply.writeInt8(ERRMSG_FAILURE);
    }
    else if (accepted)
    {
        // add user to guild
        guildManager->addGuildMember(guild, client.characterId);
        client.guilds.push_back(guild);
        reply.writeInt8(ERRMSG_OK);
        reply.writeString(guild->getName());
        reply.writeInt16(guild->getId());
        reply.writeInt16(guild->getUserPermissions(client.characterId));

        // have character join guild channel
        ChatChannel *channel = joinGuildChannel(guild->getName(), client);
        reply.writeInt16(channel->getId());
        sendGuildListUpdate(guild, client.characterName,
                            GUILD_EVENT_NEW_PLAYER);
    }
    else
    {
        guild->removeInvited(client.characterId);
        reply.writeInt8(ERRMSG_OK);
    }

    client.send(reply);
}
コード例 #5
0
ファイル: guildhandler.cpp プロジェクト: Ablu/manaserv
void ChatHandler::sendGuildRejoin(ChatClient &client)
{
    // Get list of guilds and check what rights they have.
    std::vector<Guild *> guilds =
            guildManager->getGuildsForPlayer(client.characterId);

    client.guilds = guilds;

    for (std::vector<Guild *>::iterator it = guilds.begin(),
         it_end = guilds.end(); it != it_end; ++it)
    {
        Guild *guild = *it;

        const int permissions = guild->getUserPermissions(client.characterId);
        const std::string guildName = guild->getName();

        // Tell the client what guilds the character belongs to
        // and their permissions
        MessageOut msg(CPMSG_GUILD_REJOIN);
        msg.writeString(guildName);
        msg.writeInt16(guild->getId());
        msg.writeInt16(permissions);

        // get channel id of guild channel
        ChatChannel *channel = joinGuildChannel(guildName, client);

        // send the channel id for the autojoined channel
        msg.writeInt16(channel->getId());
        msg.writeString(channel->getAnnouncement());

        client.send(msg);

        sendGuildListUpdate(guild, client.characterName,
                            GUILD_EVENT_ONLINE_PLAYER);
    }
}
コード例 #6
0
ファイル: guildhandler.cpp プロジェクト: Ablu/manaserv
void ChatHandler::handleGuildCreate(ChatClient &client, MessageIn &msg)
{
    MessageOut reply(CPMSG_GUILD_CREATE_RESPONSE);

    // Check if guild already exists and if so, return error
    std::string guildName = msg.readString();
    if (!guildManager->doesExist(guildName))
    {
        if ((int)client.guilds.size() >=
                Configuration::getValue("account_maxGuildsPerCharacter", 1))
        {
            reply.writeInt8(ERRMSG_LIMIT_REACHED);
        }
        else
        {
            // Guild doesnt already exist so create it
            Guild *guild = guildManager->createGuild(guildName, client.characterId);
            reply.writeInt8(ERRMSG_OK);
            reply.writeString(guildName);
            reply.writeInt16(guild->getId());
            reply.writeInt16(guild->getUserPermissions(client.characterId));

            client.guilds.push_back(guild);

            // Send autocreated channel id
            ChatChannel* channel = joinGuildChannel(guildName, client);
            reply.writeInt16(channel->getId());
        }
    }
    else
    {
        reply.writeInt8(ERRMSG_ALREADY_TAKEN);
    }

    client.send(reply);
}
コード例 #7
0
ファイル: chathandler.cpp プロジェクト: Ablu/invertika
void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg)
{
    MessageOut reply(CPMSG_ENTER_CHANNEL_RESPONSE);

    std::string channelName = msg.readString();
    std::string givenPassword = msg.readString();
    ChatChannel *channel = NULL;
    if (chatChannelManager->channelExists(channelName) ||
        chatChannelManager->tryNewPublicChannel(channelName))
    {
        channel = chatChannelManager->getChannel(channelName);
    }

    if (!channel)
    {
        reply.writeByte(ERRMSG_INVALID_ARGUMENT);
    }
    else if (!channel->getPassword().empty() &&
            channel->getPassword() != givenPassword)
    {
        // Incorrect password (should probably have its own return value)
        reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
    }
    else if (!channel->canJoin())
    {
        reply.writeByte(ERRMSG_INVALID_ARGUMENT);
    }
    else
    {
        if (channel->addUser(&client))
        {
            reply.writeByte(ERRMSG_OK);
            // The user entered the channel, now give him the channel
            // id, the announcement string and the user list.
            reply.writeShort(channel->getId());
            reply.writeString(channelName);
            reply.writeString(channel->getAnnouncement());
            const ChatChannel::ChannelUsers &users = channel->getUserList();

            for (ChatChannel::ChannelUsers::const_iterator i = users.begin(),
                    i_end = users.end();
                    i != i_end; ++i)
            {
                reply.writeString((*i)->characterName);
                reply.writeString(channel->getUserMode((*i)));
            }
            // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user went
            // in the channel.
            warnUsersAboutPlayerEventInChat(channel,
                    client.characterName,
                    CHAT_EVENT_NEW_PLAYER);

            // log transaction
            Transaction trans;
            trans.mCharacterId = client.characterId;
            trans.mAction = TRANS_CHANNEL_JOIN;
            trans.mMessage = "User joined " + channelName;
            storage->addTransaction(trans);
        }
        else
        {
            reply.writeByte(ERRMSG_FAILURE);
        }
    }

    client.send(reply);
}