aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/TRPC_Remote.cs
diff options
context:
space:
mode:
authorTedd Hansen2008-09-12 18:42:02 +0000
committerTedd Hansen2008-09-12 18:42:02 +0000
commitb41acfb4cfe51c22ada1a234c60d64ef80fde330 (patch)
tree313bb2e29cc6dd518062c16ca2d209a7d54be011 /OpenSim/Region/ScriptEngine/Common/TRPC_Remote.cs
parent* Fix a missing .UUID in llInstantMessage (diff)
downloadopensim-SC_OLD-b41acfb4cfe51c22ada1a234c60d64ef80fde330.zip
opensim-SC_OLD-b41acfb4cfe51c22ada1a234c60d64ef80fde330.tar.gz
opensim-SC_OLD-b41acfb4cfe51c22ada1a234c60d64ef80fde330.tar.bz2
opensim-SC_OLD-b41acfb4cfe51c22ada1a234c60d64ef80fde330.tar.xz
Cut of remote server as AppDomains and even WCF can do it better (better means less code in this case)
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/TRPC_Remote.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/TRPC_Remote.cs204
1 files changed, 0 insertions, 204 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/TRPC_Remote.cs b/OpenSim/Region/ScriptEngine/Common/TRPC_Remote.cs
deleted file mode 100644
index b02f2f5..0000000
--- a/OpenSim/Region/ScriptEngine/Common/TRPC_Remote.cs
+++ /dev/null
@@ -1,204 +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 OpenSim 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.Diagnostics;
31using System.Net;
32using System.Text;
33using System.Web;
34using OpenMetaverse;
35using OpenSim.Region.ScriptEngine.Common.TRPC;
36
37namespace OpenSim.Region.ScriptEngine.Common
38{
39 public class TRPC_Remote
40 {
41 public readonly int MaxQueueSize = 1024 * 10;
42 public readonly TCPCommon.ServerAndClientInterface TCPS;
43
44 public delegate void ReceiveCommandDelegate(int ID, string Command, params object[] p);
45 public event ReceiveCommandDelegate ReceiveCommand;
46 Dictionary<string, Type> TypeDictionary = new Dictionary<string, Type>();
47 Type[] Types =
48 {
49 typeof(String),
50 typeof(Int16),
51 typeof(Int32),
52 typeof(Int64),
53 typeof(Double),
54 typeof(Decimal),
55 typeof(Array),
56 typeof(UUID),
57 typeof(UInt16),
58 typeof(UInt32),
59 typeof(UInt64)
60 };
61
62 // TODO: Maybe we should move queue into TCPSocket so we won't have to keep one queue instance per connection
63 private Dictionary<int, InQueueStruct> InQueue = new Dictionary<int, InQueueStruct>();
64 private class InQueueStruct
65 {
66 public byte[] Queue;
67 public int QueueSize;
68 public object QueueLockObject = new object();
69 }
70
71 public TRPC_Remote(TCPCommon.ServerAndClientInterface TCPClientOrServer)
72 {
73 TCPS = TCPClientOrServer;
74 TCPS.Close += new TCPCommon.CloseDelegate(TCPS_Close);
75 TCPS.ClientConnected += new TCPCommon.ClientConnectedDelegate(TCPS_ClientConnected);
76 TCPS.DataReceived += new TCPCommon.DataReceivedDelegate(TCPS_DataReceived);
77 //TCPS.StartListen();
78
79 // Make a lookup dictionary for types
80 foreach (Type t in Types)
81 {
82 TypeDictionary.Add(t.ToString(), t);
83 }
84 }
85
86 void TCPS_ClientConnected(int ID, EndPoint Remote)
87 {
88 // Create a incoming queue for this connection
89 InQueueStruct iq = new InQueueStruct();
90 iq.Queue = new byte[MaxQueueSize];
91 iq.QueueSize = 0;
92 InQueue.Add(ID, iq);
93 }
94
95 void TCPS_Close(int ID)
96 {
97 // Remove queue
98 InQueue.Remove(ID);
99 }
100
101 void TCPS_DataReceived(int ID, byte[] data, int offset, int length)
102 {
103 // Copy new data to incoming queue
104 lock (InQueue[ID].QueueLockObject)
105 {
106 Array.Copy(data, offset, InQueue[ID].Queue, InQueue[ID].QueueSize, length);
107 InQueue[ID].QueueSize += length;
108
109 // Process incoming queue
110 ProcessQueue(ID);
111 }
112 }
113
114 private void ProcessQueue(int ID)
115 {
116 // This is just a temp implementation -- not so fast :)
117
118 InQueueStruct myIQS = InQueue[ID];
119 if (myIQS.QueueSize == 0)
120 return;
121
122 string receivedData = Encoding.UTF8.GetString(myIQS.Queue, 0, myIQS.QueueSize);
123 Debug.WriteLine("RAW: " + receivedData);
124
125 byte newLine = 10;
126 while (true)
127 {
128 bool ShouldProcess = false;
129 int lineEndPos = 0;
130
131 // Look for newline
132 for (int i = 0; i < myIQS.QueueSize; i++)
133 {
134 if (myIQS.Queue[i] == newLine)
135 {
136 ShouldProcess = true;
137 lineEndPos = i;
138 break;
139 }
140 }
141
142 // Process it?
143 if (!ShouldProcess)
144 return;
145 // Yes
146 string cmdLine = Encoding.ASCII.GetString(myIQS.Queue, 0, lineEndPos);
147 Debug.WriteLine("Command: " + cmdLine);
148
149 // Fix remaining queue in an inefficient way
150 byte[] newQueue = new byte[MaxQueueSize];
151 Array.Copy(myIQS.Queue, lineEndPos, newQueue, 0, myIQS.QueueSize - lineEndPos);
152 myIQS.Queue = newQueue;
153 myIQS.QueueSize -= (lineEndPos + 1);
154
155 // Now back to the command
156 string[] parts = cmdLine.Split(',');
157 if (parts.Length > 0)
158 {
159 string cmd = parts[0];
160 int paramCount = parts.Length - 1;
161 object[] param = null;
162
163 if (paramCount > 0)
164 {
165 // Process all parameters (decoding them from URL encoding)
166 param = new object[paramCount];
167 for (int i = 1; i < parts.Length; i++)
168 {
169 string[] spl;
170 spl = HttpUtility.UrlDecode(parts[i]).Split('|');
171 string t = spl[0];
172 param[i - 1] = Convert.ChangeType(spl[1], TypeLookup(t));
173 }
174 }
175
176 ReceiveCommand(ID, cmd, param);
177 }
178 }
179 }
180
181 private Type TypeLookup(string t)
182 {
183 Type ret = TypeDictionary[t];
184 if (ret != null)
185 return ret;
186 return typeof(object);
187 }
188
189 public void SendCommand(int ID, string Command, params object[] p)
190 {
191 // Call PacketFactory to have it create a packet for us
192
193 //string[] tmpP = new string[p.Length];
194 string tmpStr = Command;
195 for (int i = 0; i < p.Length; i++)
196 {
197 tmpStr += "," + p[i].GetType().ToString() + "|" + HttpUtility.UrlEncode(p[i].ToString()); // .Replace(",", "%44")
198 }
199 tmpStr += "\n";
200 byte[] byteData = Encoding.UTF8.GetBytes(tmpStr);
201 TCPS.Send(ID, byteData, 0, byteData.Length);
202 }
203 }
204}