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); } }
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); }