diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs index 8ed2cf1..0b008a9 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Text; | ||
29 | using OpenSim.Framework; | 30 | using OpenSim.Framework; |
30 | using Nini.Config; | 31 | using Nini.Config; |
31 | using OpenMetaverse; | 32 | using OpenMetaverse; |
@@ -275,5 +276,86 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
275 | v.ToBytes(m_tmp, 0); | 276 | v.ToBytes(m_tmp, 0); |
276 | AddBytes(m_tmp, 16); | 277 | AddBytes(m_tmp, 16); |
277 | } | 278 | } |
279 | |||
280 | // maxlen <= 255 and includes null termination byte | ||
281 | public void AddShortString(string str, int maxlen) | ||
282 | { | ||
283 | if (String.IsNullOrEmpty(str)) | ||
284 | { | ||
285 | AddZeros(1); | ||
286 | return; | ||
287 | } | ||
288 | |||
289 | --maxlen; // account for null term | ||
290 | bool NullTerm = str.EndsWith("\0"); | ||
291 | |||
292 | byte[] data = Util.UTF8.GetBytes(str); | ||
293 | int len = data.Length; | ||
294 | if(NullTerm) | ||
295 | --len; | ||
296 | |||
297 | if(len <= maxlen) | ||
298 | { | ||
299 | AddByte((byte)(len + 1)); | ||
300 | AddBytes(data, len); | ||
301 | AddZeros(1); | ||
302 | return; | ||
303 | } | ||
304 | |||
305 | if ((data[maxlen] & 0x80) != 0) | ||
306 | { | ||
307 | while (maxlen > 0 && (data[maxlen] & 0xc0) != 0xc0) | ||
308 | maxlen--; | ||
309 | } | ||
310 | AddByte((byte)(maxlen + 1)); | ||
311 | AddBytes(data, maxlen); | ||
312 | AddZeros(1); | ||
313 | } | ||
314 | // maxlen <= 255 and includes null termination byte, maxchars == max len of utf8 source | ||
315 | public void AddShortString(string str, int maxchars, int maxlen) | ||
316 | { | ||
317 | if (String.IsNullOrEmpty(str)) | ||
318 | { | ||
319 | AddZeros(1); | ||
320 | return; | ||
321 | } | ||
322 | |||
323 | --maxlen; // account for null term | ||
324 | bool NullTerm = false; | ||
325 | byte[] data; | ||
326 | |||
327 | if (str.Length > maxchars) | ||
328 | { | ||
329 | data = Util.UTF8.GetBytes(str.Substring(0,maxchars)); | ||
330 | } | ||
331 | else | ||
332 | { | ||
333 | NullTerm = str.EndsWith("\0"); | ||
334 | data = Util.UTF8.GetBytes(str); | ||
335 | } | ||
336 | |||
337 | int len = data.Length; | ||
338 | if (NullTerm) | ||
339 | --len; | ||
340 | |||
341 | if (len <= maxlen) | ||
342 | { | ||
343 | AddByte((byte)(len + 1)); | ||
344 | AddBytes(data, len); | ||
345 | AddZeros(1); | ||
346 | return; | ||
347 | } | ||
348 | |||
349 | if ((data[maxlen] & 0x80) != 0) | ||
350 | { | ||
351 | while (maxlen > 0 && (data[maxlen] & 0xc0) != 0xc0) | ||
352 | maxlen--; | ||
353 | } | ||
354 | |||
355 | AddByte((byte)(maxlen + 1)); | ||
356 | AddBytes(data, maxlen); | ||
357 | AddZeros(1); | ||
358 | } | ||
359 | |||
278 | } | 360 | } |
279 | } | 361 | } |