diff --git a/src/Client/Channel.cpp b/src/Client/Channel.cpp new file mode 100644 index 0000000..e8553fa --- /dev/null +++ b/src/Client/Channel.cpp @@ -0,0 +1,147 @@ +#include "common.h" +#include "PseuWoW.h" + +#include "Channel.h" + +void Channel::Join(std::string channel, std::string password) +{ + if (IsOnChannel(channel)) + return; + + // Send join channel request + WorldPacket worldPacket; + worldPacket.SetOpcode(CMSG_JOIN_CHANNEL); + worldPacket << channel << password; + _worldSession->SendWorldPacket(worldPacket); + + // Put in channels-joined list, but don't flag as joined yet + ChannelStruct channelStruct; + channelStruct.channel = "TestChannel"; + channelStruct.password = ""; + channelStruct.joined = false; + + channels.push_back(channelStruct); +} + +void Channel::Leave(std::string channel) +{ + for(std::vector::iterator i = channels.begin(); i != channels.end(); i++) + { + ChannelStruct s = *(i); + if (s.channel == channel) + { + if (s.joined) + { + // Send leave channel request + WorldPacket worldPacket; + worldPacket.SetOpcode(CMSG_LEAVE_CHANNEL); + worldPacket << channel; + _worldSession->SendWorldPacket(worldPacket); + } + } + } +} + +void Channel::Say(std::string channel, std::string text, uint32 lang) +{ + _worldSession->SendChatMessage(CHAT_MSG_CHANNEL, lang, text, channel); +} + +bool Channel::IsOnChannel(std::string channel) +{ + for(std::vector::iterator i = channels.begin(); i != channels.end(); i++) + { + ChannelStruct s = *(i); + if (s.channel == channel) + { + if (s.joined) + { + return true; + } + } + } + + return false; +} + +void Channel::HandleNotifyOpcode(WorldPacket &packet) +{ + uint8 code; + uint64 guid; + + std::string channel, name; + + packet >> code >> channel; + + for(std::vector::iterator i = channels.begin(); i != channels.end(); i++) + { + ChannelStruct s = *(i); + if (s.channel == channel) + { + switch (code) + { + // Player joined channel you are on + case 0x00: + packet >> guid; + if(guid){ + name = _worldSession->plrNameCache.GetName(guid); + if (name.empty()) + { + _worldSession->SendQueryPlayerName(guid); + name = "Unknown Entity"; + } + } + + printf("%s joined channel %s\n", channel.c_str()); + break; + + // Player leaved channel you are on + case 0x01: + packet >> guid; + if(guid){ + name = _worldSession->plrNameCache.GetName(guid); + if (name.empty()) + { + _worldSession->SendQueryPlayerName(guid); + name = "Unknown Entity"; + } + } + + printf("%s leaved channel %s\n", channel.c_str()); + break; + + // You joined channel successfully + case 0x02: + s.joined = true; + printf("You joined channel %s\n", channel.c_str()); + break; + + // You leaved channel successfully + case 0x03: + channels.erase(i); + printf("You leaved channel %s\n", channel.c_str()); + break; + + // Wrong password while trying to join channel + case 0x04: + channels.erase(i); + printf("Could not join channel %s (Wrong password)\n", channel.c_str()); + break; + + // Not on channel while trying to write to channel etc. + case 0x05: + channels.erase(i); + printf("Your are not on channel %s\n", channel.c_str()); + break; + } + return; + } + } + + // TODO: Even more channel notices to handle + /* + printf("Channel notice not handled! Code: %d - Channel name: %s\nData:\n", code, channel.c_str()); + packet.textlike(); + printf("\n"); + */ +} diff --git a/src/Client/Channel.h b/src/Client/Channel.h new file mode 100644 index 0000000..82606b6 --- /dev/null +++ b/src/Client/Channel.h @@ -0,0 +1,37 @@ +#ifndef _CHANNEL_H +#define _CHANNEL_H + +#include "SysDefs.h" +#include "Opcodes.h" +#include "WorldPacket.h" +#include "WorldSession.h" + +struct ChannelStruct +{ + std::string channel; + std::string password; + bool joined; +}; + +class Channel +{ +public: + Channel(WorldSession *worldSession) + { + _worldSession = worldSession; + } + + void Join(std::string channel, std::string password); + void Leave(std::string channel); + void Say(std::string channel, std::string text, uint32 lang); + bool IsOnChannel(std::string channel); + void HandleNotifyOpcode(WorldPacket &packet); + + // TODO: Add Kick/Ban/Mode/Owner/Mute/Invite and all that stuff + +private: + std::vectorchannels; + WorldSession *_worldSession; +}; + +#endif \ No newline at end of file diff --git a/src/Client/World/CMSGConstructor.cpp b/src/Client/World/CMSGConstructor.cpp index 35bb865..00aa0dc 100644 --- a/src/Client/World/CMSGConstructor.cpp +++ b/src/Client/World/CMSGConstructor.cpp @@ -24,9 +24,8 @@ void WorldSession::SendChatMessage(uint32 type, uint32 lang, std::string msg, st packet<IsOnChannel(to)) return; - // TODO: be sure the channel is joined before writing into this channel packet<