diff --git a/bin/scripts/_enterworld.def b/bin/scripts/_enterworld.def index 5e114a3..67af666 100644 --- a/bin/scripts/_enterworld.def +++ b/bin/scripts/_enterworld.def @@ -21,6 +21,12 @@ SAY [${@version_short}] login successful. // 126 = TEXTEMOTE_READY EMOTE 126 +// join some channels... +JOINCHANNEL generalchat +JOINCHANNEL help +JOINCHANNEL tradee +// ... + // add your own stuff here // ... diff --git a/bin/scripts/chan.def b/bin/scripts/chan.def new file mode 100644 index 0000000..4c16220 --- /dev/null +++ b/bin/scripts/chan.def @@ -0,0 +1,12 @@ + +// Script to write on channels +// Arguments: +// ========== +// @def: text to write +// @0: channel name +// @1: language name/number + +#permission=10 +SET,lang ${@1} +DEFAULT,lang 0 +SENDCHATMESSAGE,14,{${lang}},{${@def}},{${@0}} \ No newline at end of file diff --git a/src/Client/Channel.cpp b/src/Client/Channel.cpp deleted file mode 100644 index e8553fa..0000000 --- a/src/Client/Channel.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#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/DefScript/DefScript.cpp b/src/Client/DefScript/DefScript.cpp index 025a41b..16aa80b 100644 --- a/src/Client/DefScript/DefScript.cpp +++ b/src/Client/DefScript/DefScript.cpp @@ -65,6 +65,8 @@ DefScriptFunctionTable *DefScriptPackage::_GetFunctionTable(void) const //{"follow",&DefScriptPackage::SCfollow}, {"savecache",&DefScriptPackage::SCsavecache}, {"sendchatmessage",&DefScriptPackage::SCSendChatMessage}, + {"joinchannel",&DefScriptPackage::SCjoinchannel}, + {"leavechannel",&DefScriptPackage::SCleavechannel}, // table termination {NULL,NULL} diff --git a/src/Client/DefScript/DefScript.h b/src/Client/DefScript/DefScript.h index a581c32..b89ecb1 100644 --- a/src/Client/DefScript/DefScript.h +++ b/src/Client/DefScript/DefScript.h @@ -145,6 +145,8 @@ private: bool SCemote(CmdSet); bool SCfollow(CmdSet); bool SCshdn(CmdSet); + bool SCjoinchannel(CmdSet); + bool SCleavechannel(CmdSet); // Own variable declarations std::map my_usrPermissionMap; diff --git a/src/Client/DefScript/DefScriptFunctions.cpp b/src/Client/DefScript/DefScriptFunctions.cpp index 47a83f2..c227dde 100644 --- a/src/Client/DefScript/DefScriptFunctions.cpp +++ b/src/Client/DefScript/DefScriptFunctions.cpp @@ -32,7 +32,10 @@ bool DefScriptPackage::func_loaddef(CmdSet Set){ bool result=false; std::string fn; if(Set.arg[0].empty()) + { result=LoadByName(Set.defaultarg); + fn=(scPath + Set.defaultarg).append(".def"); + } else { std::string::size_type pos = Set.arg[0].find('/'); @@ -42,16 +45,19 @@ bool DefScriptPackage::func_loaddef(CmdSet Set){ fn=Set.arg[0]; result=LoadScriptFromFile(fn,Set.defaultarg); } - //if(!result && curIsDebug) - // std::cout << "Could not load script '" << Set->defaultarg << "' [" << fn << "]\n"; - return result; + if(!result) + std::cout << "Could not load script '" << Set.defaultarg << "' [" << fn << "]\n"; + return true; } bool DefScriptPackage::func_reloaddef(CmdSet Set){ bool result=false; std::string fn; if(Set.arg[0].empty()) + { result=LoadByName(Set.defaultarg); + fn=(scPath + Set.defaultarg).append(".def"); + } else { std::string::size_type pos = Set.arg[0].find('/'); @@ -61,9 +67,9 @@ bool DefScriptPackage::func_reloaddef(CmdSet Set){ fn=Set.arg[0]; result=LoadScriptFromFile(fn,Set.defaultarg); } - //if(!result && curIsDebug) - // std::cout << "Could not load script '" << Set->defaultarg << "' [" << fn << "]\n"; - return result; + if(!result) + std::cout << "Could not load script '" << Set.defaultarg << "' [" << fn << "]\n"; + return true; } bool DefScriptPackage::func_unset(CmdSet Set){ diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index bb417bd..470bdc7 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -7,6 +7,7 @@ #include "Opcodes.h" #include "SharedDefines.h" #include "WorldSession.h" +#include "Channel.h" bool DefScriptPackage::SCshdn(CmdSet Set) { @@ -70,8 +71,6 @@ bool DefScriptPackage::SCemote(CmdSet Set){ uint32 id=atoi(Set.defaultarg.c_str()); ((PseuInstance*)parentMethod)->GetWSession()->SendEmote(id); return true; - - } bool DefScriptPackage::SCfollow(CmdSet Set){ @@ -92,6 +91,30 @@ bool DefScriptPackage::SCfollow(CmdSet Set){ } +bool DefScriptPackage::SCjoinchannel(CmdSet Set){ + if(Set.defaultarg.empty()) + return true; + if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid())) + { + log("Invalid Script call: SCjoinchannel: WorldSession not valid"); + return false; + } + ((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Join(Set.defaultarg,Set.arg[0]); + return true; +} + +bool DefScriptPackage::SCleavechannel(CmdSet Set){ + if(Set.defaultarg.empty()) + return true; + if(!(((PseuInstance*)parentMethod)->GetWSession() && ((PseuInstance*)parentMethod)->GetWSession()->IsValid())) + { + log("Invalid Script call: SCleavechannel: WorldSession not valid"); + return false; + } + ((PseuInstance*)parentMethod)->GetWSession()->GetChannels()->Leave(Set.defaultarg); + return true; +} + void DefScriptPackage::My_LoadUserPermissions(VarSet &vs) { diff --git a/src/Client/World/CMSGConstructor.cpp b/src/Client/World/CMSGConstructor.cpp index 00aa0dc..7595765 100644 --- a/src/Client/World/CMSGConstructor.cpp +++ b/src/Client/World/CMSGConstructor.cpp @@ -4,6 +4,7 @@ #include "Opcodes.h" #include "Player.h" #include "WorldSession.h" +#include "Channel.h" void WorldSession::SendChatMessage(uint32 type, uint32 lang, std::string msg, std::string to){ if((!_valid) || (!_logged) || msg.empty()) @@ -24,7 +25,7 @@ void WorldSession::SendChatMessage(uint32 type, uint32 lang, std::string msg, st packet<IsOnChannel(to)) + if(to.empty() /*|| !_channels->IsOnChannel(to)*/) return; packet< +#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); +} + +void Channel::Leave(std::string channel) +{ + for(std::vector::iterator i = channels.begin(); i != channels.end(); i++) + { + if (*i == channel) + { + // Send leave channel request + WorldPacket worldPacket; + worldPacket.SetOpcode(CMSG_LEAVE_CHANNEL); + worldPacket << channel; + _worldSession->SendWorldPacket(worldPacket); + return; + } + } + log("Can't leave channel \"%s\": not joined",channel.c_str()); +} + +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++) + { + if (*i == channel) + { + return true; + } + } + return false; +} + +void Channel::HandleNotifyOpcode(WorldPacket &packet) +{ + uint8 code; + uint64 guid; + + std::string channel, name; + + packet >> code >> 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"; + } + } + + logdetail("%s joined channel %s", 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"; + } + } + + logdetail("%s leaved channel %s", channel.c_str()); + break; + + // You joined channel successfully + case 0x02: + log("Joined channel %s", channel.c_str()); + channels.push_back(channel); + break; + + // You leaved channel successfully + case 0x03: + for(std::vector::iterator i = channels.begin(); i != channels.end(); i++) + { + if(*i == channel) + { + channels.erase(i); + break; + } + } + log("Left channel %s", channel.c_str()); + break; + + // Wrong password while trying to join channel + case 0x04: + log("Could not join channel %s (Wrong password)", channel.c_str()); + break; + + // Not on channel while trying to write to channel etc. + case 0x05: + log("You are not on channel %s", channel.c_str()); + break; + } + + // 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/World/Channel.h similarity index 78% rename from src/Client/Channel.h rename to src/Client/World/Channel.h index 82606b6..6f734da 100644 --- a/src/Client/Channel.h +++ b/src/Client/World/Channel.h @@ -6,13 +6,6 @@ #include "WorldPacket.h" #include "WorldSession.h" -struct ChannelStruct -{ - std::string channel; - std::string password; - bool joined; -}; - class Channel { public: @@ -30,7 +23,7 @@ public: // TODO: Add Kick/Ban/Mode/Owner/Mute/Invite and all that stuff private: - std::vectorchannels; + std::vector channels; WorldSession *_worldSession; }; diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 5f31e33..3ca84e4 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -8,7 +8,8 @@ #include "WorldSocket.h" #include "NameTables.h" #include "RealmSocket.h" -#include "../Chat.h" +#include "Chat.h" +#include "Channel.h" #include "WorldSession.h" @@ -23,6 +24,7 @@ WorldSession::WorldSession(PseuInstance *in) _myGUID=0; // i dont have a guid yet plrNameCache.ReadFromFile(); // load names/guids of known players _deleteme = false; + _channels = new Channel(this); //... } @@ -37,6 +39,7 @@ WorldSession::~WorldSession() } _OnLeaveWorld(); + delete _channels; //delete _socket; the socket will be deleted by its handler!! } @@ -136,6 +139,7 @@ OpcodeHandler *WorldSession::_GetOpcodeHandlerTable() const {SMSG_PONG, &WorldSession::_HandlePongOpcode}, {SMSG_TRADE_STATUS, &WorldSession::_HandleTradeStatusOpcode}, {SMSG_GROUP_INVITE, &WorldSession::_HandleGroupInviteOpcode}, + {SMSG_CHANNEL_NOTIFY, &WorldSession::_HandleChannelNotifyOpcode}, // movement opcodes {MSG_MOVE_SET_FACING, &WorldSession::_HandleMovementOpcode}, @@ -353,14 +357,17 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket) uint8 type=0; uint32 lang=0; uint64 target_guid=0; - uint32 msglen=0; - std::string msg,ext; + uint32 msglen=0,unk; + std::string msg,channel=""; bool isCmd=false; recvPacket >> type >> lang; if (type == CHAT_MSG_CHANNEL) - recvPacket >> ext; // extract channel name + { + recvPacket >> channel; // extract channel name + recvPacket >> unk; + } recvPacket >> target_guid; std::string plrname; @@ -380,12 +387,21 @@ void WorldSession::_HandleMessageChatOpcode(WorldPacket& recvPacket) recvPacket >> target_guid; recvPacket >> msglen >> msg; - if (type == CHAT_MSG_SYSTEM){ + if (type == CHAT_MSG_SYSTEM) + { log("SYSMSG: \"%s\"",msg.c_str()); - } else if (type==CHAT_MSG_WHISPER ){ - log("W:WHISP: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); - } else { - log("W:CHAT: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + } + else if (type==CHAT_MSG_WHISPER ) + { + log("WHISP: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + } + else if (type==CHAT_MSG_CHANNEL ) + { + log("CHANNEL [%s]: %s [%s]: %s",channel.c_str(),plrname.c_str(),LookupName(lang,langNames),msg.c_str()); + } + else + { + log("CHAT: %s [%s]: %s",plrname.c_str(),LookupName(lang,langNames),msg.c_str()); } if(target_guid!=_myGUID && msg.length()>1 && msg.at(0)=='-' && GetInstance()->GetConf()->allowgamecmd) @@ -527,4 +543,9 @@ void WorldSession::_HandleTelePortAckOpcode(WorldPacket& recvPacket) response.SetOpcode(MSG_MOVE_FALL_LAND); response << uint32(0) << uint32(0) << x << y << z << o << uint32(0); SendWorldPacket(response); +} + +void WorldSession::_HandleChannelNotifyOpcode(WorldPacket& recvPacket) +{ + _channels->HandleNotifyOpcode(recvPacket); } \ No newline at end of file diff --git a/src/Client/World/WorldSession.h b/src/Client/World/WorldSession.h index 310aa48..13b1738 100644 --- a/src/Client/World/WorldSession.h +++ b/src/Client/World/WorldSession.h @@ -11,7 +11,7 @@ class WorldSocket; class WorldPacket; -class PingerThread; +class Channel; struct OpcodeHandler { @@ -46,6 +46,7 @@ public: void SetFollowTarget(uint64 guid); uint64 GetFollowTarget(void) { return _followGUID; } uint64 GetGuid(void) { return _myGUID; } + Channel *GetChannels(void) { return _channels; } // CMSGConstructor @@ -75,8 +76,9 @@ private: void _HandlePongOpcode(WorldPacket& recvPacket); void _HandleTradeStatusOpcode(WorldPacket& recvPacket); void _HandleGroupInviteOpcode(WorldPacket& recvPacket); - void _HandleTelePortAckOpcode(WorldPacket& recvPacket); + void _HandleChannelNotifyOpcode(WorldPacket& recvPacket); + PlayerEnum _player; // The connected character @@ -85,6 +87,7 @@ private: ZThread::LockedQueue pktQueue; bool _valid,_authed,_logged,_deleteme; // world status SocketHandler _sh; // handles the WorldSocket + Channel *_channels; uint64 _targetGUID,_followGUID,_myGUID; }; diff --git a/src/PseuWoW.vcproj b/src/PseuWoW.vcproj index c6f521a..f9f76fc 100644 --- a/src/PseuWoW.vcproj +++ b/src/PseuWoW.vcproj @@ -263,6 +263,12 @@ + + + + diff --git a/src/shared/SysDefs.h b/src/shared/SysDefs.h index f0889e1..9d3b952 100644 --- a/src/shared/SysDefs.h +++ b/src/shared/SysDefs.h @@ -38,11 +38,10 @@ #endif #if COMPILER == COMPILER_MICROSOFT - # pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data - # pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the debug information - #ifndef _DEBUG - # pragma warning( disable : 4244 ) // conversion from 'uint64' to 'int16', possible loss of data - #endif +# pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data +# pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the debug information +# pragma warning( disable : 4800 ) // conversion to bool, performance warning +# pragma warning( disable : 4244 ) // conversion from 'uint64' to 'int16', possible loss of data #endif //////////////////////////////////// diff --git a/todo_tofix_someday.txt b/todo_tofix_someday.txt index e75aac4..431138f 100644 --- a/todo_tofix_someday.txt +++ b/todo_tofix_someday.txt @@ -2,10 +2,3 @@ realm login: - use the correct IP in CLIENT_LOGON_CHALLENGE, and not 127.0.0.1 - use correct timezone, maybe settable via conf file later on - define the crc_hash as it should be - -controller: -- complete recoding - -shared: --fix CircularBuffer::IncreaseSize() (its BUGGED and corrupts the data) -