lludp ChatFromSimulator enconding; some simplification

0.9.1.0-post-fixes
UbitUmarov 2019-03-18 18:58:07 +00:00
parent 84187975bd
commit 6fd7b931b1
2 changed files with 88 additions and 33 deletions

View File

@ -913,24 +913,60 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
buf.DataLength = 80 + len; buf.DataLength = 80 + len;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Unknown, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Unknown);
} }
public void SendChatMessage( static private readonly byte[] ChatFromSimulatorHeader = new byte[] {
string message, byte type, Vector3 fromPos, string fromName, Helpers.MSG_RELIABLE,
UUID fromAgentID, UUID ownerID, byte source, byte audible) 0, 0, 0, 0, // sequence number
{ 0, // extra
ChatFromSimulatorPacket reply = (ChatFromSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator); 0xff, 0xff, 0, 139 // ID 139 (low frequency bigendian)
reply.ChatData.Audible = audible; };
reply.ChatData.Message = Util.StringToBytes1024(message);
reply.ChatData.ChatType = type;
reply.ChatData.SourceType = source;
reply.ChatData.Position = fromPos;
reply.ChatData.FromName = Util.StringToBytes256(fromName);
reply.ChatData.OwnerID = ownerID;
reply.ChatData.SourceID = fromAgentID;
OutPacket(reply, ThrottleOutPacketType.Unknown); public void SendChatMessage(string message, byte chattype, Vector3 fromPos, string fromName,
UUID sourceID, UUID ownerID, byte sourcetype, byte audible)
{
UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
byte[] data = buf.Data;
//setup header
Buffer.BlockCopy(ChatFromSimulatorHeader, 0, data, 0, 10);
byte[] fname = Util.StringToBytes256(fromName);
int len = fname.Length;
int pos = 11;
if (len == 0)
data[10] = 0;
else
{
data[10] = (byte)len;
Buffer.BlockCopy(fname, 0, data, 11, len);
pos += len;
}
sourceID.ToBytes(data, pos); pos += 16;
ownerID.ToBytes(data, pos); pos += 16;
data[pos++] = sourcetype;
data[pos++] = chattype;
data[pos++] = audible;
fromPos.ToBytes(data, pos); pos += 12;
byte[] msg = Util.StringToBytes1024(message);
len = msg.Length;
if (len == 0)
{
data[pos++] = 0;
data[pos++] = 0;
}
else
{
data[pos++] = (byte)len;
data[pos++] = (byte)(len >> 8);
Buffer.BlockCopy(msg, 0, data, pos, len); pos += len;
}
buf.DataLength = pos;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Unknown);
} }
/// <summary> /// <summary>
@ -1336,7 +1372,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
data[9] = (byte)(datasize >> 8); data[9] = (byte)(datasize >> 8);
buf.DataLength = bitpack.BytePos + 1; buf.DataLength = bitpack.BytePos + 1;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
// start another // start another
buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint); buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
@ -1364,7 +1400,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
data[9] = (byte)(datasize >> 8); data[9] = (byte)(datasize >> 8);
buf.DataLength = bitpack.BytePos + 1; buf.DataLength = bitpack.BytePos + 1;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
} }
catch (Exception e) catch (Exception e)
@ -1645,7 +1681,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
buf.DataLength = lastpos; buf.DataLength = lastpos;
// send it // send it
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
buf = newbuf; buf = newbuf;
data = buf.Data; data = buf.Data;
@ -1661,7 +1697,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
data[countpos] = (byte)count; data[countpos] = (byte)count;
buf.DataLength = pos; buf.DataLength = pos;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
} }
} }
@ -1757,7 +1793,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
buf.DataLength = lastpos; buf.DataLength = lastpos;
// send it // send it
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
buf = newbuf; buf = newbuf;
data = buf.Data; data = buf.Data;
@ -1786,7 +1822,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
data[pos++] = 0; data[pos++] = 0;
buf.DataLength = pos; buf.DataLength = pos;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Land);
} }
} }
@ -4122,8 +4158,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
data[pos++] = 0; // no physical avatar events data[pos++] = 0; // no physical avatar events
buf.DataLength = pos; buf.DataLength = pos;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority, m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority);
null, false, false);
} }
public void SendObjectAnimations(UUID[] animations, int[] seqs, UUID senderId) public void SendObjectAnimations(UUID[] animations, int[] seqs, UUID senderId)
@ -4180,7 +4215,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
CreatePrimUpdateBlock(ent as SceneObjectPart, (ScenePresence)SceneAgent, zc); CreatePrimUpdateBlock(ent as SceneObjectPart, (ScenePresence)SceneAgent, zc);
buf.DataLength = zc.Finish(); buf.DataLength = zc.Finish();
m_udpServer.SendUDPPacket(m_udpClient, buf, ptype , null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ptype);
} }
public void SendEntityTerseUpdateImmediate(ISceneEntity ent) public void SendEntityTerseUpdateImmediate(ISceneEntity ent)
@ -4275,7 +4310,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
} }
buf.DataLength = pos; buf.DataLength = pos;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
} }
#endregion Avatar Packet/Data Sending Methods #endregion Avatar Packet/Data Sending Methods
@ -5332,7 +5367,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
//m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
// delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false); // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
buf = newbuf; buf = newbuf;
zc.Data = buf.Data; zc.Data = buf.Data;
zc.ZeroCount = 0; zc.ZeroCount = 0;
@ -5353,7 +5388,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
buf.DataLength = zc.Finish(); buf.DataLength = zc.Finish();
//m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
// delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false); // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
} }
} }
@ -5373,7 +5408,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
//tau.Add(new ObjectPropertyUpdate((ISceneEntity) eu, (uint)eu.Flags, true, false)); //tau.Add(new ObjectPropertyUpdate((ISceneEntity) eu, (uint)eu.Flags, true, false));
//m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, //m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task,
// delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false); // delegate (OutgoingPacket oPacket) { ResendPrimUpdates(tau, oPacket); }, false, false);
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, false); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task);
} }
} }

View File

@ -989,6 +989,26 @@ namespace OpenSim.Region.ClientStack.LindenUDP
SendPacketFinal(outgoingPacket); SendPacketFinal(outgoingPacket);
} }
public void SendUDPPacket(LLUDPClient udpClient, UDPPacketBuffer buffer, ThrottleOutPacketType category)
{
bool highPriority = false;
if (category != ThrottleOutPacketType.Unknown && (category & ThrottleOutPacketType.HighPriority) != 0)
{
category = (ThrottleOutPacketType)((int)category & 127);
highPriority = true;
}
OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, null);
// If we were not provided a method for handling unacked, use the UDPServer default method
if ((outgoingPacket.Buffer.Data[0] & Helpers.MSG_RELIABLE) != 0)
outgoingPacket.UnackedMethod = delegate (OutgoingPacket oPacket) { ResendUnacked(oPacket); };
if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, false, highPriority))
SendPacketFinal(outgoingPacket);
}
static private readonly byte[] PacketAckHeader = new byte[] { static private readonly byte[] PacketAckHeader = new byte[] {
0, 0,
0, 0, 0, 0, // sequence number 0, 0, 0, 0, // sequence number
@ -1018,7 +1038,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{ {
data[10] = 255; data[10] = 255;
buf.DataLength = pos; buf.DataLength = pos;
SendUDPPacket(udpClient, buf, ThrottleOutPacketType.Unknown, null, false, false); SendUDPPacket(udpClient, buf, ThrottleOutPacketType.Unknown);
buf = GetNewUDPBuffer(udpClient.RemoteEndPoint); buf = GetNewUDPBuffer(udpClient.RemoteEndPoint);
Buffer.BlockCopy(PacketAckHeader, 0, buf.Data, 0, 10); Buffer.BlockCopy(PacketAckHeader, 0, buf.Data, 0, 10);
@ -1031,7 +1051,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{ {
data[10] = (byte)count; data[10] = (byte)count;
buf.DataLength = pos; buf.DataLength = pos;
SendUDPPacket(udpClient, buf, ThrottleOutPacketType.Unknown, null, false, false); SendUDPPacket(udpClient, buf, ThrottleOutPacketType.Unknown);
} }
} }
@ -1057,7 +1077,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
data[11] = 0; data[11] = 0;
buf.DataLength = 12; buf.DataLength = 12;
SendUDPPacket(udpClient, buf, ThrottleOutPacketType.Unknown, null, false, false); SendUDPPacket(udpClient, buf, ThrottleOutPacketType.Unknown);
udpClient.m_lastStartpingTimeMS = Util.GetTimeStampMS(); udpClient.m_lastStartpingTimeMS = Util.GetTimeStampMS();
} }
@ -1078,7 +1098,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
data[7] = pingID; data[7] = pingID;
buf.DataLength = 8; buf.DataLength = 8;
SendUDPPacket(udpClient, buf, ThrottleOutPacketType.Unknown, null, false, false); SendUDPPacket(udpClient, buf, ThrottleOutPacketType.Unknown);
} }
public void HandleUnacked(LLClientView client) public void HandleUnacked(LLClientView client)