diff options
Diffstat (limited to 'OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs')
-rw-r--r-- | OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs | 266 |
1 files changed, 133 insertions, 133 deletions
diff --git a/OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs b/OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs index 5bf7ff9..5646be4 100644 --- a/OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs +++ b/OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs | |||
@@ -1,133 +1,133 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Text; | 3 | using System.Text; |
4 | using libsecondlife; | 4 | using libsecondlife; |
5 | using libsecondlife.Packets; | 5 | using libsecondlife.Packets; |
6 | 6 | ||
7 | namespace OpenSim.Framework.Utilities | 7 | namespace OpenSim.Framework.Utilities |
8 | { | 8 | { |
9 | public class Util | 9 | public class Util |
10 | { | 10 | { |
11 | private static Random randomClass = new Random(); | 11 | private static Random randomClass = new Random(); |
12 | private static uint nextXferID = 5000; | 12 | private static uint nextXferID = 5000; |
13 | private static object XferLock = new object(); | 13 | private static object XferLock = new object(); |
14 | 14 | ||
15 | public static ulong UIntsToLong(uint X, uint Y) | 15 | public static ulong UIntsToLong(uint X, uint Y) |
16 | { | 16 | { |
17 | return Helpers.UIntsToLong(X, Y); | 17 | return Helpers.UIntsToLong(X, Y); |
18 | } | 18 | } |
19 | 19 | ||
20 | public static Random RandomClass | 20 | public static Random RandomClass |
21 | { | 21 | { |
22 | get | 22 | get |
23 | { | 23 | { |
24 | return randomClass; | 24 | return randomClass; |
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | public static uint GetNextXferID() | 28 | public static uint GetNextXferID() |
29 | { | 29 | { |
30 | uint id = 0; | 30 | uint id = 0; |
31 | lock(XferLock) | 31 | lock(XferLock) |
32 | { | 32 | { |
33 | id = nextXferID; | 33 | id = nextXferID; |
34 | nextXferID++; | 34 | nextXferID++; |
35 | } | 35 | } |
36 | return id; | 36 | return id; |
37 | } | 37 | } |
38 | 38 | ||
39 | //public static int fast_distance2d(int x, int y) | 39 | //public static int fast_distance2d(int x, int y) |
40 | //{ | 40 | //{ |
41 | // x = System.Math.Abs(x); | 41 | // x = System.Math.Abs(x); |
42 | // y = System.Math.Abs(y); | 42 | // y = System.Math.Abs(y); |
43 | 43 | ||
44 | // int min = System.Math.Min(x, y); | 44 | // int min = System.Math.Min(x, y); |
45 | 45 | ||
46 | // return (x + y - (min >> 1) - (min >> 2) + (min >> 4)); | 46 | // return (x + y - (min >> 1) - (min >> 2) + (min >> 4)); |
47 | //} | 47 | //} |
48 | 48 | ||
49 | public static string FieldToString(byte[] bytes) | 49 | public static string FieldToString(byte[] bytes) |
50 | { | 50 | { |
51 | return FieldToString(bytes, String.Empty); | 51 | return FieldToString(bytes, String.Empty); |
52 | } | 52 | } |
53 | 53 | ||
54 | /// <summary> | 54 | /// <summary> |
55 | /// Convert a variable length field (byte array) to a string, with a | 55 | /// Convert a variable length field (byte array) to a string, with a |
56 | /// field name prepended to each line of the output | 56 | /// field name prepended to each line of the output |
57 | /// </summary> | 57 | /// </summary> |
58 | /// <remarks>If the byte array has unprintable characters in it, a | 58 | /// <remarks>If the byte array has unprintable characters in it, a |
59 | /// hex dump will be put in the string instead</remarks> | 59 | /// hex dump will be put in the string instead</remarks> |
60 | /// <param name="bytes">The byte array to convert to a string</param> | 60 | /// <param name="bytes">The byte array to convert to a string</param> |
61 | /// <param name="fieldName">A field name to prepend to each line of output</param> | 61 | /// <param name="fieldName">A field name to prepend to each line of output</param> |
62 | /// <returns>An ASCII string or a string containing a hex dump, minus | 62 | /// <returns>An ASCII string or a string containing a hex dump, minus |
63 | /// the null terminator</returns> | 63 | /// the null terminator</returns> |
64 | public static string FieldToString(byte[] bytes, string fieldName) | 64 | public static string FieldToString(byte[] bytes, string fieldName) |
65 | { | 65 | { |
66 | // Check for a common case | 66 | // Check for a common case |
67 | if (bytes.Length == 0) return String.Empty; | 67 | if (bytes.Length == 0) return String.Empty; |
68 | 68 | ||
69 | StringBuilder output = new StringBuilder(); | 69 | StringBuilder output = new StringBuilder(); |
70 | bool printable = true; | 70 | bool printable = true; |
71 | 71 | ||
72 | for (int i = 0; i < bytes.Length; ++i) | 72 | for (int i = 0; i < bytes.Length; ++i) |
73 | { | 73 | { |
74 | // Check if there are any unprintable characters in the array | 74 | // Check if there are any unprintable characters in the array |
75 | if ((bytes[i] < 0x20 || bytes[i] > 0x7E) && bytes[i] != 0x09 | 75 | if ((bytes[i] < 0x20 || bytes[i] > 0x7E) && bytes[i] != 0x09 |
76 | && bytes[i] != 0x0D && bytes[i] != 0x0A && bytes[i] != 0x00) | 76 | && bytes[i] != 0x0D && bytes[i] != 0x0A && bytes[i] != 0x00) |
77 | { | 77 | { |
78 | printable = false; | 78 | printable = false; |
79 | break; | 79 | break; |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | if (printable) | 83 | if (printable) |
84 | { | 84 | { |
85 | if (fieldName.Length > 0) | 85 | if (fieldName.Length > 0) |
86 | { | 86 | { |
87 | output.Append(fieldName); | 87 | output.Append(fieldName); |
88 | output.Append(": "); | 88 | output.Append(": "); |
89 | } | 89 | } |
90 | 90 | ||
91 | if (bytes[bytes.Length - 1] == 0x00) | 91 | if (bytes[bytes.Length - 1] == 0x00) |
92 | output.Append(UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1)); | 92 | output.Append(UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1)); |
93 | else | 93 | else |
94 | output.Append(UTF8Encoding.UTF8.GetString(bytes)); | 94 | output.Append(UTF8Encoding.UTF8.GetString(bytes)); |
95 | } | 95 | } |
96 | else | 96 | else |
97 | { | 97 | { |
98 | for (int i = 0; i < bytes.Length; i += 16) | 98 | for (int i = 0; i < bytes.Length; i += 16) |
99 | { | 99 | { |
100 | if (i != 0) | 100 | if (i != 0) |
101 | output.Append(Environment.NewLine); | 101 | output.Append(Environment.NewLine); |
102 | if (fieldName.Length > 0) | 102 | if (fieldName.Length > 0) |
103 | { | 103 | { |
104 | output.Append(fieldName); | 104 | output.Append(fieldName); |
105 | output.Append(": "); | 105 | output.Append(": "); |
106 | } | 106 | } |
107 | 107 | ||
108 | for (int j = 0; j < 16; j++) | 108 | for (int j = 0; j < 16; j++) |
109 | { | 109 | { |
110 | if ((i + j) < bytes.Length) | 110 | if ((i + j) < bytes.Length) |
111 | output.Append(String.Format("{0:X2} ", bytes[i + j])); | 111 | output.Append(String.Format("{0:X2} ", bytes[i + j])); |
112 | else | 112 | else |
113 | output.Append(" "); | 113 | output.Append(" "); |
114 | } | 114 | } |
115 | 115 | ||
116 | for (int j = 0; j < 16 && (i + j) < bytes.Length; j++) | 116 | for (int j = 0; j < 16 && (i + j) < bytes.Length; j++) |
117 | { | 117 | { |
118 | if (bytes[i + j] >= 0x20 && bytes[i + j] < 0x7E) | 118 | if (bytes[i + j] >= 0x20 && bytes[i + j] < 0x7E) |
119 | output.Append((char)bytes[i + j]); | 119 | output.Append((char)bytes[i + j]); |
120 | else | 120 | else |
121 | output.Append("."); | 121 | output.Append("."); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | return output.ToString(); | 126 | return output.ToString(); |
127 | } | 127 | } |
128 | public Util() | 128 | public Util() |
129 | { | 129 | { |
130 | 130 | ||
131 | } | 131 | } |
132 | } | 132 | } |
133 | } | 133 | } |