当前位置: 首页>>代码示例>>C++>>正文


C++ ChatClient类代码示例

本文整理汇总了C++中ChatClient的典型用法代码示例。如果您正苦于以下问题:C++ ChatClient类的具体用法?C++ ChatClient怎么用?C++ ChatClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ChatClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processMessage

void ChatServer::processMessage(PasswordChangeRequest *msg)
{
    PasswordChangeResult *answer = new PasswordChangeResult;
    ChatClient client = m_clientList.getClient(msg->username);
    QString log;
    if(client.password() == msg->oldPassword)
    {
        client.setPassword(msg->newPassword);
        m_clientList.updateClient(client);
        answer->result = "Password changed!\nDon't forget to use new password in the next authorization.";
        log = "User " + msg->username + " changed his password";
        emit updateTable("clients");
    }
    else
    {
        answer->result = "Given old password is incorrect!";
        log = "User " + msg->username + " tried to change his password. Unfortunately, unsuccessfull.";
    }
    emit serverLog(esNotify, log);
    sendMessageToClient(msg->username, answer);
}
开发者ID:dirktao,项目名称:chat-server,代码行数:21,代码来源:ChatServer.cpp

示例2: handleGuildQuit

void ChatHandler::handleGuildQuit(ChatClient &client, MessageIn &msg)
{
    MessageOut reply(CPMSG_GUILD_QUIT_RESPONSE);
    short guildId = msg.readInt16();

    Guild *guild = guildManager->findById(guildId);
    if (!guild || !guild->checkInGuild(client.characterId))
    {
        reply.writeInt8(ERRMSG_FAILURE);
        client.send(reply);
        return;
    }
    guildManager->removeGuildMember(guild, client.characterId,
                                    client.characterName, &client);

    reply.writeInt8(ERRMSG_OK);
    reply.writeInt16(guildId);
    client.send(reply);


}
开发者ID:hanwujunlc,项目名称:manaserv,代码行数:21,代码来源:guildhandler.cpp

示例3: out

void ChatHandler::handlePartyRejectInvite(ChatClient &client, MessageIn &msg)
{
    MessageOut out(CPMSG_PARTY_REJECTED);

    std::string inviter = msg.readString();


    std::vector<PartyInvite>::iterator itr, itr_end;

    itr = mPartyInvitedUsers.begin();
    itr_end = mPartyInvitedUsers.end();
    bool found = false;

    while (itr != itr_end)
    {
        // Check that the player was invited
        if ((*itr).mInvited == client.characterName &&
            (*itr).mInviter == inviter)
        {
            // remove them from invited users list
            mPartyInvitedUsers.erase(itr);
            found = true;
            break;
        }

        ++itr;
    }

    if (!found)
    {
        out.writeInt8(ERRMSG_FAILURE);
    }

    // send rejection to inviter
    ChatClient *inviterClient = getClient(inviter);

    inviterClient->send(out);
}
开发者ID:mobilehub,项目名称:manaserv,代码行数:38,代码来源:partyhandler.cpp

示例4: getClient

void ChatHandler::handlePartyInvite(MessageIn &msg)
{
    std::string inviterName = msg.readString();
    std::string inviteeName = msg.readString();
    ChatClient *inviter = getClient(inviterName);
    ChatClient *invitee = getClient(inviteeName);

    if (!inviter || !invitee)
        return;

    removeExpiredPartyInvites();
    const int maxInvitesPerTimeframe = 10;
    int &num = mNumInvites[inviterName];
    if (num >= maxInvitesPerTimeframe)
    {
        MessageOut out(CPMSG_PARTY_REJECTED);
        out.writeString(inviterName);
        out.writeInt8(ERRMSG_LIMIT_REACHED);
        inviter->send(out);
        return;
    }
    ++num;

    if (invitee->party)
    {
        MessageOut out(CPMSG_PARTY_REJECTED);
        out.writeString(inviterName);
        out.writeInt8(ERRMSG_FAILURE);
        inviter->send(out);
        return;
    }

    mInvitations.push_back(PartyInvite(inviterName, inviteeName));

    MessageOut out(CPMSG_PARTY_INVITED);
    out.writeString(inviterName);
    invitee->send(out);
}
开发者ID:Philipp-S,项目名称:manaserv,代码行数:38,代码来源:partyhandler.cpp

示例5: memset

//By Luiz45 - Add a "Friend" to a blackList
void ChatClient::SendBlackListAdd(sUT_FRIEND_BLACK_ADD_REQ* pData)
{
	sTU_FRIEND_BLACK_ADD_RES pBlackAdd;
	memset(&pBlackAdd, 0, sizeof(pBlackAdd));
	pBlackAdd.wOpCode = TU_FRIEND_ADD_RES;
	memcpy(pBlackAdd.wchName, pData->awchName, NTL_MAX_SIZE_CHAR_NAME_UNICODE);
	ChatClient* pChatToWhisper = pServer->GetChatManager()->GetChatClient(pData->awchName);
	if (NULL == pChatToWhisper){
		pBlackAdd.wResultCode = COMMUNITY_FRIEND_CHAR_NOT_FOUND;
	}
	else{
		if (SearchFriendDB(pChatToWhisper->GetCharSerialID()))
		{
			pBlackAdd.wResultCode = COMMUNITY_FRIEND_CHAR_ARLEADY_ADDED;
		}
		else
		{
			pServer->ServerDB->ExecuteQuery("INSERT INTO `blacklist`(`owner_id`,`target_id`) VALUES ('%u','%u');", this->GetCharSerialID(), pChatToWhisper->GetCharSerialID());
			pBlackAdd.targetID = pChatToWhisper->GetCharSerialID();
			pBlackAdd.wResultCode = GAME_SUCCESS;
		}
	}
	Send(&pBlackAdd, sizeof(pBlackAdd));
}
开发者ID:ChowZenki,项目名称:dboserver,代码行数:25,代码来源:ChatProtocol.cpp

示例6: reply

void ChatHandler::handleWhoMessage(ChatClient &client)
{
    MessageOut reply(CPMSG_WHO_RESPONSE);

    std::map<std::string, ChatClient*>::iterator itr, itr_end;
    itr = mPlayerMap.begin();
    itr_end = mPlayerMap.end();

    while (itr != itr_end)
    {
        reply.writeString(itr->first);
        ++itr;
    }

    client.send(reply);
}
开发者ID:Ablu,项目名称:invertika,代码行数:16,代码来源:chathandler.cpp

示例7: reply

void ChatHandler::handleGuildKickMember(ChatClient &client, MessageIn &msg)
{
    MessageOut reply(CPMSG_GUILD_KICK_MEMBER_RESPONSE);
    short guildId = msg.readInt16();
    std::string otherCharName = msg.readString();

    Guild *guild = guildManager->findById(guildId);

    if (!guild)
    {
        reply.writeInt8(ERRMSG_INVALID_ARGUMENT);
        client.send(reply);
        return;
    }
    ChatClient *otherClient = getClient(otherCharName);
    unsigned otherCharId;
    if (otherClient)
        otherCharId = otherClient->characterId;
    else
        otherCharId = storage->getCharacterId(otherCharName);

    if (otherCharId == 0)
    {
        reply.writeInt8(ERRMSG_INVALID_ARGUMENT);
        client.send(reply);
        return;
    }

    if (!((guild->getUserPermissions(client.characterId) & GAL_KICK) &&
            guild->checkInGuild(otherCharId) &&
            otherCharId != client.characterId))
    {
        reply.writeInt8(ERRMSG_INSUFFICIENT_RIGHTS);
        client.send(reply);
        return;
    }
    if (otherClient)
    {
        // Client is online. Inform him about that he got kicked
        MessageOut kickMsg(CPMSG_GUILD_KICK_NOTIFICATION);
        kickMsg.writeInt16(guild->getId());
        kickMsg.writeString(client.characterName);
        otherClient->send(kickMsg);
    }

    guildManager->removeGuildMember(guild, otherCharId, otherCharName,
                                    otherClient);
    reply.writeInt8(ERRMSG_OK);
    client.send(reply);
}
开发者ID:Ablu,项目名称:manaserv,代码行数:50,代码来源:guildhandler.cpp

示例8: handleQuitChannelMessage

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);
}
开发者ID:Ablu,项目名称:invertika,代码行数:41,代码来源:chathandler.cpp

示例9: handleGuildAcceptInvite

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);
}
开发者ID:Ablu,项目名称:manaserv,代码行数:40,代码来源:guildhandler.cpp

示例10: handleAnnounceMessage

void ChatHandler::handleAnnounceMessage(ChatClient &client, MessageIn &msg)
{
    std::string text = msg.readString();

    if (!stringFilter->filterContent(text))
    {
        warnPlayerAboutBadWords(client);
        return;
    }

    if (client.accountLevel == AL_ADMIN || client.accountLevel == AL_GM)
    {
        // TODO: b_lindeijer: Shouldn't announcements also have a sender?
        LOG_INFO("ANNOUNCE: " << text);
        MessageOut result(CPMSG_ANNOUNCEMENT);
        result.writeString(text);

        // We send the message to all players in the default channel as it is
        // an announcement.
        sendToEveryone(result);

        // log transaction
        Transaction trans;
        trans.mCharacterId = client.characterId;
        trans.mAction = TRANS_MSG_ANNOUNCE;
        trans.mMessage = "User announced " + text;
        storage->addTransaction(trans);
    }
    else
    {
        MessageOut result(CPMSG_ERROR);
        result.writeByte(ERRMSG_INSUFFICIENT_RIGHTS);
        client.send(result);
        LOG_INFO(client.characterName <<
            " couldn't make an announcement due to insufficient rights.");
    }

}
开发者ID:Ablu,项目名称:invertika,代码行数:38,代码来源:chathandler.cpp

示例11: handlePartyAcceptInvite

void ChatHandler::handlePartyAcceptInvite(ChatClient &client, MessageIn &msg)
{
    MessageOut out(CPMSG_PARTY_ACCEPT_INVITE_RESPONSE);

    std::string inviter = msg.readString();

    // Check that the player was invited
    std::vector<PartyInvite>::iterator itr, itr_end;
    itr = mPartyInvitedUsers.begin();
    itr_end = mPartyInvitedUsers.end();

    bool found = false;

    while (itr != itr_end)
    {
        if ((*itr).mInvited == client.characterName &&
            (*itr).mInviter == inviter)
        {
            // make them join the party
            if (handlePartyJoin(client.characterName, inviter))
            {
                out.writeInt8(ERRMSG_OK);
                mPartyInvitedUsers.erase(itr);
                found = true;
                break;
            }
        }

        ++itr;
    }

    if (!found)
    {
        out.writeInt8(ERRMSG_FAILURE);
    }

    client.send(out);
}
开发者ID:mobilehub,项目名称:manaserv,代码行数:38,代码来源:partyhandler.cpp

示例12: handleListChannelsMessage

void ChatHandler::handleListChannelsMessage(ChatClient &client, MessageIn &)
{
    MessageOut reply(CPMSG_LIST_CHANNELS_RESPONSE);

    std::list<const ChatChannel*> channels =
        chatChannelManager->getPublicChannels();

    for (std::list<const ChatChannel*>::iterator i = channels.begin(),
            i_end = channels.end();
            i != i_end; ++i)
    {
        reply.writeString((*i)->getName());
        reply.writeInt16((*i)->getUserList().size());
    }

    client.send(reply);

    // log transaction
    Transaction trans;
    trans.mCharacterId = client.characterId;
    trans.mAction = TRANS_CHANNEL_LIST;
    storage->addTransaction(trans);
}
开发者ID:Philipp-S,项目名称:manaserv,代码行数:23,代码来源:chathandler.cpp

示例13: sendGuildRejoin

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);
    }
}
开发者ID:Ablu,项目名称:manaserv,代码行数:36,代码来源:guildhandler.cpp

示例14: handleGuildCreate

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);
}
开发者ID:Ablu,项目名称:manaserv,代码行数:36,代码来源:guildhandler.cpp

示例15: main

/**
 *  This is the main function which creates a chat client object
 *  and runs the chat.
 */
int main(int argc, char* argv[]) {
	ChatClient cc = ChatClient();
	cc.run(argc, argv);
}
开发者ID:thodde,项目名称:progc,代码行数:8,代码来源:ChatClient.cpp


注:本文中的ChatClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。