Closed StackerDEV closed 6 years ago
the player name is retrieved at https://github.com/jackpoz/BotFarm/blob/592dbc9dbb58c06175bffecfced56eba42107c9a/Client/World/Network/PacketHandlers/ChatHandlers.cs#L84 by sending CMSG_NAME_QUERY to the server. You need to wait for the server to send the response packet back with the name.
If you post your code on github I can take a look.
Alright I see, I removed that part of the code during testing, because as a GM player messages come from another handler (SMSG_GM_MESSAGECHAT). But it seems here is where it went wrong. var sender = packet.ReadUInt64(); stays 0. I changed this to var sender = guid; It now works like intended. Also ReadCString in Extensions.cs returns null when BinaryReader header is SMSG_MESSAGECHAT because those packets start with a \0 so it goes out of the while loop when reading the first byte which is \0 and the stringbuilder returns nothing because it does a break when letter == 0.
I came up with a simple workaround for that (it works for as far I tested with whisper and guild chat). https://pastebin.com/xc7ker6M
thanks for the heads up, I'll look into it. I think I'll check on TC the structure of both packets too just to be sure.
https://github.com/jackpoz/BotFarm/commit/1c6fa57a16f049cfcd6ad444ed7fae8297af9a9b is supposed to fix most issues about SMSG_MESSAGECHAT and SMSG_GM_MESSAGECHAT, tested ingame with:
SMSG_GM_MESSAGECHAT already sends the GM name in the packet and that's handled now instead of going through CMSG_NAME_QUERY (which I guess doesn't return the name anyway for GMs).
Let me know if you find any issue.
Yep, SMSG_GM_MESSAGECHAT indeed sends the GM name.
Here is how I handle channel for SMSG_GM. (Not the best way to do it but it works). Have not tested the rest yet.
ChatChannel channelChat = new ChatChannel();
channelChat.Type = type;
var senderChat = guid;
ChatMessage messageChannel = new ChatMessage();
StringBuilder bSender = new StringBuilder();
StringBuilder bChannel = new StringBuilder();
StringBuilder bMessage = new StringBuilder();
packet.BaseStream.Position = 0;
int length = (int)packet.BaseStream.Length;
byte[] dump = packet.ReadBytes(length);
var ChanName = "";
int index = 0;
for (int i = 21; i < (length - 2); i++)
{
if ((char)dump[i] != 0x00)
{
if (index == 0) { bSender.Append((char)dump[i]); }
if (index == 1) { bChannel.Append((char)dump[i]); }
if (index == 2) { bMessage.Append((char)dump[i]); }
}
else
{
index += 1;
if(index == 2) { i += 12; };
}
}
channelChat.ChannelName = bChannel.ToString();
messageChannel.Message = bMessage.ToString();
messageChannel.Language = lang;
messageChannel.ChatTag = 0;
messageChannel.Sender = channelChat;
messageChannel.Sender.Sender = bSender.ToString();
Game.UI.PresentChatMessage(messageChannel);
Could also use readbyte, not sure what the best way is.
well https://github.com/jackpoz/BotFarm/commit/1c6fa57a16f049cfcd6ad444ed7fae8297af9a9b follows the same code as the one in TrinityCore so it handles pretty much all possible cases
Will try to use the original code then. For now I am not focusing on the project but other things so, just wanted to give you a small update. But thanks jackpoz!
I was trying to make a simple chat client just for fun using botfarm, most messages work. But often if GM's or some players chat sender GUID is read from the packet, but when trying to resolve the name using Game.World.PlayerNameLookup.TryGetValue(guid, out senderName); senderName stays null. Any idea why this is? Players in a nearby position and some other players not nearby do resolve and it works, so this is really strange. I assume it's a bug since while I was debugging the application I found out that even in the MiniWoW assistant client some things aren't handled the way it should and it may be because GUID is missing as well?