Skip to content

Commit

Permalink
Fix issue with long chat messages. (#1637)
Browse files Browse the repository at this point in the history
Fix issue with chat type being sent improperly to the client.
  • Loading branch information
Slushnas authored and gmriggs committed Apr 3, 2019
1 parent a17e94c commit 6ce451b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 43 deletions.
29 changes: 29 additions & 0 deletions Source/ACE.Entity/Enum/ChatNetworkBlobType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace ACE.Entity.Enum
{
/// <summary>
/// The ChatNetworkBlobType identifies the type of Turbine Chat message.<para />
/// Used with F7DE: Turbine Chat
/// </summary>
public enum ChatNetworkBlobType
{
NETBLOB_UNKNOWN = 0,

/// <summary>
/// Server -> Client
/// </summary>
NETBLOB_EVENT_BINARY = 1,
NETBLOB_EVENT_XMLRPC = 2,

/// <summary>
/// Client -> Server
/// </summary>
NETBLOB_REQUEST_BINARY = 3,
NETBLOB_REQUEST_XMLRPC = 4,

/// <summary>
/// Server -> Client
/// </summary>
NETBLOB_RESPONSE_BINARY = 5,
NETBLOB_RESPONSE_XMLRPC = 6,
}
}
21 changes: 21 additions & 0 deletions Source/ACE.Entity/Enum/ChatType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ACE.Entity.Enum
{
public enum ChatType
{
Undef,
Allegiance,
General,
Trade,
LFG,
Roleplay,
Society,
SocietyCelHan,
SocietyEldWeb,
SocietyRadBlo,
Olthoi
}
}
24 changes: 0 additions & 24 deletions Source/ACE.Entity/Enum/TurbineChatType.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace ACE.Server.Network.GameMessages.Messages
{
public class GameMessageTurbineChat : GameMessage
{
public GameMessageTurbineChat(TurbineChatType turbineChatType, uint channel, string senderName, string message, uint senderID)
public GameMessageTurbineChat(ChatNetworkBlobType chatNetworkBlobType, uint channel, string senderName, string message, uint senderID, ChatType chatType)
: base(GameMessageOpcode.TurbineChat, GameMessageGroup.LoginQueue)
{
/*uint messageSize; // the number of bytes that follow after this DWORD
TurbineChatType type; // the type of data contained in this message
ChatNetworkBlobType type; // the type of data contained in this message
uint blobDispatchType; // 1?
int targetType; // 1?
int targetID; // Unique ID? Both ID's always match. These numbers change between 0x000B0000 - 0x000B00FF I think.
Expand All @@ -19,9 +19,9 @@ public GameMessageTurbineChat(TurbineChatType turbineChatType, uint channel, str
int cookie; // 0?
uint payloadSize; // the number of bytes that follow after this DWORD
// Select one section based on the value of TurbineChatType
// Select one section based on the value of ChatNetworkBlobType
// 0x1 - TurbineChatType.InboundMessage
// 0x1 - ChatNetworkBlobType.NETBLOB_EVENT_BINARY
// Select one section based on the value of blobDispatchType
Expand All @@ -34,7 +34,7 @@ public GameMessageTurbineChat(TurbineChatType turbineChatType, uint channel, str
int hResult;
uint chatType;
// 0x3 - TurbineChatType.OutboundMessage
// 0x3 - ChatNetworkBlobType.NETBLOB_REQUEST_BINARY
// Select one section based on the value of blobDispatchType
Expand All @@ -49,7 +49,7 @@ public GameMessageTurbineChat(TurbineChatType turbineChatType, uint channel, str
int hResult;
uint chatType;
// 0x2 - SendToRoomByIDRequest, this is the only one used by the client i believe
// 0x2 - SendToRoomByIDRequest, this is the only one used by the client I believe
uint contextID;
uint responseID = 2;
uint methodID = 2;
Expand All @@ -60,7 +60,7 @@ public GameMessageTurbineChat(TurbineChatType turbineChatType, uint channel, str
int hResult;
uint chatType;
// 0x5 - TurbineChatType.OutboundMessageAck - inbound acknowledgement to client of outbound message
// 0x5 - ChatNetworkBlobType.NETBLOB_RESPONSE_BINARY - inbound acknowledgement to client of outbound message
// Select one section based on the value of blobDispatchType
Expand All @@ -76,11 +76,11 @@ public GameMessageTurbineChat(TurbineChatType turbineChatType, uint channel, str
uint methodID = 2; // type of request, should be 2 here
int hResult;*/

if (turbineChatType == TurbineChatType.InboundMessage)
if (chatNetworkBlobType == ChatNetworkBlobType.NETBLOB_EVENT_BINARY)
{
var firstSizePos = Writer.BaseStream.Position;
Writer.Write(0u); // Bytes to follow
Writer.Write((uint)turbineChatType);
Writer.Write((uint)chatNetworkBlobType);
Writer.Write(1u);
Writer.Write(1u);
Writer.Write(0x000B00B5); // Unique ID? Both ID's always match. These numbers change between 0x000B0000 - 0x000B00FF I think.
Expand All @@ -92,22 +92,28 @@ public GameMessageTurbineChat(TurbineChatType turbineChatType, uint channel, str

Writer.Write(channel);

Writer.Write((byte)senderName.Length);
if (senderName.Length < 128)
Writer.Write((byte)senderName.Length);
else
Writer.Write((ushort)(0x80 | (message.Length << 8)));
Writer.Write(Encoding.Unicode.GetBytes(senderName));

Writer.Write((byte)message.Length);
if (message.Length < 128)
Writer.Write((byte)message.Length);
else
Writer.Write((ushort)(0x80 | (message.Length << 8)));
Writer.Write(Encoding.Unicode.GetBytes(message));

Writer.Write(0x0Cu);
Writer.Write(senderID);
Writer.Write(0u);
Writer.Write(1u);
Writer.Write((uint)chatType);

Writer.WritePosition((uint)(Writer.BaseStream.Position - firstSizePos + 4), firstSizePos);
Writer.WritePosition((uint)(Writer.BaseStream.Position - secondSizePos + 4), secondSizePos);
}
else
Console.WriteLine($"Unhandled GameMessageTurbineChat TurbineChatType: 0x{(uint)turbineChatType:X4}");
Console.WriteLine($"Unhandled GameMessageTurbineChat ChatNetworkBlobType: 0x{(uint)chatNetworkBlobType:X4}");
}
}
}
17 changes: 11 additions & 6 deletions Source/ACE.Server/Network/Handlers/TurbineChatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class TurbineChatHandler
public static void TurbineChatReceived(ClientMessage clientMessage, Session session)
{
clientMessage.Payload.ReadUInt32(); // Bytes to follow
var turbineChatType = (TurbineChatType)clientMessage.Payload.ReadUInt32();
var chatBlobType = (ChatNetworkBlobType)clientMessage.Payload.ReadUInt32();
clientMessage.Payload.ReadUInt32(); // Always 2
clientMessage.Payload.ReadUInt32(); // Always 1
clientMessage.Payload.ReadUInt32(); // Always 0
Expand All @@ -25,29 +25,34 @@ public static void TurbineChatReceived(ClientMessage clientMessage, Session sess
clientMessage.Payload.ReadUInt32(); // Always 0
clientMessage.Payload.ReadUInt32(); // Bytes to follow

if (turbineChatType == TurbineChatType.OutboundMessage)
if (chatBlobType == ChatNetworkBlobType.NETBLOB_REQUEST_BINARY)
{
clientMessage.Payload.ReadUInt32(); // 0x01 - 0x71 (maybe higher), typically though 0x01 - 0x0F
clientMessage.Payload.ReadUInt32(); // Always 2
clientMessage.Payload.ReadUInt32(); // Always 2
var channelID = clientMessage.Payload.ReadUInt32();

var messageLen = clientMessage.Payload.ReadByte();
int messageLen = clientMessage.Payload.ReadByte();
if ((messageLen & 0x80) > 0) // PackedByte
{
byte lowbyte = clientMessage.Payload.ReadByte();
messageLen = ((messageLen & 0x7F) << 8) | lowbyte;
}
var messageBytes = clientMessage.Payload.ReadBytes(messageLen * 2);
var message = Encoding.Unicode.GetString(messageBytes);

clientMessage.Payload.ReadUInt32(); // Always 0x0C
var senderID = clientMessage.Payload.ReadUInt32();
clientMessage.Payload.ReadUInt32(); // Always 0
clientMessage.Payload.ReadUInt32(); // Always 1 or 2
var chatType = (ChatType)clientMessage.Payload.ReadUInt32();

if (channelID == TurbineChatChannel.Society)
{
ChatPacket.SendServerMessage(session, "You do not belong to a society.", ChatMessageType.Broadcast); // I don't know if this is how it was done on the live servers
return;
}

var gameMessageTurbineChat = new GameMessageTurbineChat(TurbineChatType.InboundMessage, channelID, session.Player.Name, message, senderID);
var gameMessageTurbineChat = new GameMessageTurbineChat(ChatNetworkBlobType.NETBLOB_EVENT_BINARY, channelID, session.Player.Name, message, senderID, chatType);

var allegiance = AllegianceManager.FindAllegiance(channelID);
if (allegiance != null)
Expand Down Expand Up @@ -92,7 +97,7 @@ public static void TurbineChatReceived(ClientMessage clientMessage, Session sess
}
}
else
Console.WriteLine($"Unhandled TurbineChatHandler TurbineChatType: 0x{(uint)turbineChatType:X4}");
Console.WriteLine($"Unhandled TurbineChatHandler ChatNetworkBlobType: 0x{(uint)chatBlobType:X4}");
}
}
}

0 comments on commit 6ce451b

Please sign in to comment.