aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs160
1 files changed, 0 insertions, 160 deletions
diff --git a/OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs b/OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs
deleted file mode 100644
index f2383bc..0000000
--- a/OpenSim/Grid/Manager/OpenGridServices.Manager/Util.cs
+++ /dev/null
@@ -1,160 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33
34namespace OpenSim.Framework.Utilities
35{
36 public class Util
37 {
38 private static Random randomClass = new Random();
39 private static uint nextXferID = 5000;
40 private static object XferLock = new object();
41
42 public static ulong UIntsToLong(uint X, uint Y)
43 {
44 return Helpers.UIntsToLong(X, Y);
45 }
46
47 public static Random RandomClass
48 {
49 get
50 {
51 return randomClass;
52 }
53 }
54
55 public static uint GetNextXferID()
56 {
57 uint id = 0;
58 lock (XferLock)
59 {
60 id = nextXferID;
61 nextXferID++;
62 }
63 return id;
64 }
65
66 //public static int fast_distance2d(int x, int y)
67 //{
68 // x = System.Math.Abs(x);
69 // y = System.Math.Abs(y);
70
71 // int min = System.Math.Min(x, y);
72
73 // return (x + y - (min >> 1) - (min >> 2) + (min >> 4));
74 //}
75
76 public static string FieldToString(byte[] bytes)
77 {
78 return FieldToString(bytes, String.Empty);
79 }
80
81 /// <summary>
82 /// Convert a variable length field (byte array) to a string, with a
83 /// field name prepended to each line of the output
84 /// </summary>
85 /// <remarks>If the byte array has unprintable characters in it, a
86 /// hex dump will be put in the string instead</remarks>
87 /// <param name="bytes">The byte array to convert to a string</param>
88 /// <param name="fieldName">A field name to prepend to each line of output</param>
89 /// <returns>An ASCII string or a string containing a hex dump, minus
90 /// the null terminator</returns>
91 public static string FieldToString(byte[] bytes, string fieldName)
92 {
93 // Check for a common case
94 if (bytes.Length == 0) return String.Empty;
95
96 StringBuilder output = new StringBuilder();
97 bool printable = true;
98
99 for (int i = 0; i < bytes.Length; ++i)
100 {
101 // Check if there are any unprintable characters in the array
102 if ((bytes[i] < 0x20 || bytes[i] > 0x7E) && bytes[i] != 0x09
103 && bytes[i] != 0x0D && bytes[i] != 0x0A && bytes[i] != 0x00)
104 {
105 printable = false;
106 break;
107 }
108 }
109
110 if (printable)
111 {
112 if (fieldName.Length > 0)
113 {
114 output.Append(fieldName);
115 output.Append(": ");
116 }
117
118 if (bytes[bytes.Length - 1] == 0x00)
119 output.Append(UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length - 1));
120 else
121 output.Append(UTF8Encoding.UTF8.GetString(bytes));
122 }
123 else
124 {
125 for (int i = 0; i < bytes.Length; i += 16)
126 {
127 if (i != 0)
128 output.Append(Environment.NewLine);
129 if (fieldName.Length > 0)
130 {
131 output.Append(fieldName);
132 output.Append(": ");
133 }
134
135 for (int j = 0; j < 16; j++)
136 {
137 if ((i + j) < bytes.Length)
138 output.Append(String.Format("{0:X2} ", bytes[i + j]));
139 else
140 output.Append(" ");
141 }
142
143 for (int j = 0; j < 16 && (i + j) < bytes.Length; j++)
144 {
145 if (bytes[i + j] >= 0x20 && bytes[i + j] < 0x7E)
146 output.Append((char)bytes[i + j]);
147 else
148 output.Append(".");
149 }
150 }
151 }
152
153 return output.ToString();
154 }
155
156 public Util()
157 {
158 }
159 }
160}