aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/OpenSimClient.cs
diff options
context:
space:
mode:
authorgareth2007-03-06 15:57:36 +0000
committergareth2007-03-06 15:57:36 +0000
commitd828af7036fd11a4a1f678b2b7e51bdb6380087a (patch)
tree99544eb8c363afeccd0da17ba67970b8cc505d14 /src/OpenSimClient.cs
parentAdded sandbox mode and setup facility (diff)
downloadopensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.zip
opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.gz
opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.bz2
opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.xz
Implemented local console and VERY rough skeleton for TCP/Worldchat console
Implemented seperate logging (but no packetlog or chat yet)
Diffstat (limited to 'src/OpenSimClient.cs')
-rw-r--r--src/OpenSimClient.cs45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/OpenSimClient.cs b/src/OpenSimClient.cs
index 6b00a0f..0e956c3 100644
--- a/src/OpenSimClient.cs
+++ b/src/OpenSimClient.cs
@@ -49,7 +49,7 @@ namespace OpenSim
49 public world.Avatar ClientAvatar; 49 public world.Avatar ClientAvatar;
50 private UseCircuitCodePacket cirpack; 50 private UseCircuitCodePacket cirpack;
51 private Thread ClientThread; 51 private Thread ClientThread;
52 private EndPoint userEP; 52 public EndPoint userEP;
53 private BlockingQueue<QueItem> PacketQueue; 53 private BlockingQueue<QueItem> PacketQueue;
54 private BlockingQueue<TransferRequestPacket> AssetRequests; 54 private BlockingQueue<TransferRequestPacket> AssetRequests;
55 private Dictionary<uint, uint> PendingAcks = new Dictionary<uint, uint>(); 55 private Dictionary<uint, uint> PendingAcks = new Dictionary<uint, uint>();
@@ -81,9 +81,9 @@ namespace OpenSim
81 81
82 public void AssetLoader() { 82 public void AssetLoader() {
83 if(OpenSim_Main.cfg.sandbox==false) { 83 if(OpenSim_Main.cfg.sandbox==false) {
84 Console.WriteLine("OpenSimClient.cs:AssetLoader() - Starting new thread"); 84 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:AssetLoader() - Starting new thread");
85 TransferRequestPacket reqPacket = AssetRequests.Dequeue(); 85 TransferRequestPacket reqPacket = AssetRequests.Dequeue();
86 Console.WriteLine("OpenSimClient.cs:AssetLoader() - Got a request, processing it"); 86 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:AssetLoader() - Got a request, processing it");
87 LLUUID AssetID = new LLUUID(reqPacket.TransferInfo.Params, 0); 87 LLUUID AssetID = new LLUUID(reqPacket.TransferInfo.Params, 0);
88 WebRequest AssetLoad = WebRequest.Create(OpenSim_Main.cfg.AssetURL + "getasset/" + OpenSim_Main.cfg.AssetSendKey + "/" + AssetID + "/data"); 88 WebRequest AssetLoad = WebRequest.Create(OpenSim_Main.cfg.AssetURL + "getasset/" + OpenSim_Main.cfg.AssetSendKey + "/" + AssetID + "/data");
89 WebResponse AssetResponse = AssetLoad.GetResponse(); 89 WebResponse AssetResponse = AssetLoad.GetResponse();
@@ -131,7 +131,12 @@ namespace OpenSim
131 AssetResponse.Close(); 131 AssetResponse.Close();
132 } 132 }
133 } 133 }
134 134
135 public void Logout() {
136 // TODO - kill any AssetLoaders
137 ClientThread.Abort();
138 }
139
135 public void ProcessInPacket(Packet Pack) { 140 public void ProcessInPacket(Packet Pack) {
136 ack_pack(Pack); 141 ack_pack(Pack);
137 switch(Pack.Type) { 142 switch(Pack.Type) {
@@ -146,7 +151,7 @@ namespace OpenSim
146 ClientAvatar.SendInitialAppearance(); 151 ClientAvatar.SendInitialAppearance();
147 break; 152 break;
148 case PacketType.TransferRequest: 153 case PacketType.TransferRequest:
149 Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request"); 154 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request");
150 // We put transfer requests into a big queue and then spawn a thread for each new one 155 // We put transfer requests into a big queue and then spawn a thread for each new one
151 TransferRequestPacket transfer = (TransferRequestPacket)Pack; 156 TransferRequestPacket transfer = (TransferRequestPacket)Pack;
152 AssetRequests.Enqueue(transfer); 157 AssetRequests.Enqueue(transfer);
@@ -154,7 +159,7 @@ namespace OpenSim
154 AssetLoaderThread.Start(); 159 AssetLoaderThread.Start();
155 break; 160 break;
156 case PacketType.LogoutRequest: 161 case PacketType.LogoutRequest:
157 Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got a logout request"); 162 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got a logout request");
158 lock(OpenSim_Main.local_world.Entities) { 163 lock(OpenSim_Main.local_world.Entities) {
159 OpenSim_Main.local_world.Entities.Remove(this.AgentID); 164 OpenSim_Main.local_world.Entities.Remove(this.AgentID);
160 } 165 }
@@ -166,7 +171,7 @@ namespace OpenSim
166 String grTest = sr.ReadLine(); 171 String grTest = sr.ReadLine();
167 sr.Close(); 172 sr.Close();
168 GridResponse.Close(); 173 GridResponse.Close();
169 Console.WriteLine("DEBUG: " + grTest); 174 OpenSim_Main.localcons.WriteLine("DEBUG: " + grTest);
170 } 175 }
171 this.ClientThread.Abort(); 176 this.ClientThread.Abort();
172 break; 177 break;
@@ -207,8 +212,6 @@ namespace OpenSim
207 { 212 {
208 if (now - packet.TickCount > RESEND_TIMEOUT) 213 if (now - packet.TickCount > RESEND_TIMEOUT)
209 { 214 {
210 Console.WriteLine("Resending " + packet.Type.ToString() + " packet, " +
211 (now - packet.TickCount) + "ms have passed", Helpers.LogLevel.Info);
212 215
213 packet.Header.Resent = true; 216 packet.Header.Resent = true;
214 OutPacket(packet); 217 OutPacket(packet);
@@ -225,12 +228,10 @@ namespace OpenSim
225 { 228 {
226 if (PendingAcks.Count > 250) 229 if (PendingAcks.Count > 250)
227 { 230 {
228 // FIXME: Handle the odd case where we have too many pending ACKs queued up
229 Console.WriteLine("Too many ACKs queued up!", Helpers.LogLevel.Error);
230 return; 231 return;
231 } 232 }
232 233
233 Console.WriteLine("Sending PacketAck"); 234 OpenSim_Main.localcons.WriteLine("Sending PacketAck");
234 235
235 236
236 int i = 0; 237 int i = 0;
@@ -319,7 +320,6 @@ namespace OpenSim
319 } 320 }
320 } 321 }
321 322
322 Console.WriteLine("OUT: \n" + Pack.ToString());
323 323
324 byte[] ZeroOutBuffer = new byte[4096]; 324 byte[] ZeroOutBuffer = new byte[4096];
325 byte[] sendbuffer; 325 byte[] sendbuffer;
@@ -333,7 +333,7 @@ namespace OpenSim
333 OpenSim_Main.Server.SendTo(sendbuffer, sendbuffer.Length, SocketFlags.None,userEP); 333 OpenSim_Main.Server.SendTo(sendbuffer, sendbuffer.Length, SocketFlags.None,userEP);
334 } 334 }
335 } catch (Exception) { 335 } catch (Exception) {
336 Console.WriteLine("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " + userEP.ToString() + " - killing thread"); 336 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " + userEP.ToString() + " - killing thread");
337 ClientThread.Abort(); 337 ClientThread.Abort();
338 } 338 }
339 339
@@ -347,7 +347,7 @@ namespace OpenSim
347 { 347 {
348 foreach (uint ack in NewPack.Header.AckList) 348 foreach (uint ack in NewPack.Header.AckList)
349 { 349 {
350 Console.WriteLine("Got appended ack: "+ack); 350 OpenSim_Main.localcons.WriteLine("Got appended ack: "+ack);
351 NeedAck.Remove(ack); 351 NeedAck.Remove(ack);
352 } 352 }
353 } 353 }
@@ -362,7 +362,6 @@ namespace OpenSim
362 { 362 {
363 foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets) 363 foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
364 { 364 {
365 Console.WriteLine("Got PacketAck: "+block.ID);
366 NeedAck.Remove(block.ID); 365 NeedAck.Remove(block.ID);
367 } 366 }
368 } 367 }
@@ -391,7 +390,7 @@ namespace OpenSim
391 } 390 }
392 391
393 public OpenSimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack) { 392 public OpenSimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack) {
394 Console.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request"); 393 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request");
395 cirpack = initialcirpack; 394 cirpack = initialcirpack;
396 userEP = remoteEP; 395 userEP = remoteEP;
397 PacketQueue = new BlockingQueue<QueItem>(); 396 PacketQueue = new BlockingQueue<QueItem>();
@@ -406,7 +405,7 @@ namespace OpenSim
406 } 405 }
407 406
408 private void ClientLoop() { 407 private void ClientLoop() {
409 Console.WriteLine("OpenSimClient.cs:ClientLoop() - Entered loop"); 408 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:ClientLoop() - Entered loop");
410 while(true) { 409 while(true) {
411 QueItem nextPacket = PacketQueue.Dequeue(); 410 QueItem nextPacket = PacketQueue.Dequeue();
412 if(nextPacket.Incoming) 411 if(nextPacket.Incoming)
@@ -423,7 +422,7 @@ namespace OpenSim
423 } 422 }
424 423
425 private void InitNewClient() { 424 private void InitNewClient() {
426 Console.WriteLine("OpenSimClient.cs:InitNewClient() - Adding viewer agent to world"); 425 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:InitNewClient() - Adding viewer agent to world");
427 OpenSim_Main.local_world.AddViewerAgent(this); 426 OpenSim_Main.local_world.AddViewerAgent(this);
428 world.Entity tempent=OpenSim_Main.local_world.Entities[this.AgentID]; 427 world.Entity tempent=OpenSim_Main.local_world.Entities[this.AgentID];
429 this.ClientAvatar=(world.Avatar)tempent; 428 this.ClientAvatar=(world.Avatar)tempent;
@@ -431,23 +430,23 @@ namespace OpenSim
431 430
432 private void AuthUser() { 431 private void AuthUser() {
433 if(OpenSim_Main.cfg.sandbox==false) { 432 if(OpenSim_Main.cfg.sandbox==false) {
434 Console.WriteLine("OpenSimClient.cs:AuthUser() - Authenticating new user request with grid"); 433 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:AuthUser() - Authenticating new user request with grid");
435 WebRequest CheckSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + cirpack.CircuitCode.ID.ToString() + "/" + cirpack.CircuitCode.Code.ToString() + "/exists"); 434 WebRequest CheckSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + cirpack.CircuitCode.ID.ToString() + "/" + cirpack.CircuitCode.Code.ToString() + "/exists");
436 Console.WriteLine(OpenSim_Main.cfg.GridURL); 435 OpenSim_Main.localcons.WriteLine(OpenSim_Main.cfg.GridURL);
437 WebResponse GridResponse = CheckSession.GetResponse(); 436 WebResponse GridResponse = CheckSession.GetResponse();
438 StreamReader sr = new StreamReader(GridResponse.GetResponseStream()); 437 StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
439 String grTest = sr.ReadLine(); 438 String grTest = sr.ReadLine();
440 sr.Close(); 439 sr.Close();
441 GridResponse.Close(); 440 GridResponse.Close();
442 if(String.IsNullOrEmpty(grTest) || grTest.Equals("1")) { // YAY! Valid login 441 if(String.IsNullOrEmpty(grTest) || grTest.Equals("1")) { // YAY! Valid login
443 Console.WriteLine("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString()); 442 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString());
444 this.AgentID=cirpack.CircuitCode.ID; 443 this.AgentID=cirpack.CircuitCode.ID;
445 this.SessionID=cirpack.CircuitCode.SessionID; 444 this.SessionID=cirpack.CircuitCode.SessionID;
446 this.CircuitCode=cirpack.CircuitCode.Code; 445 this.CircuitCode=cirpack.CircuitCode.Code;
447 InitNewClient(); 446 InitNewClient();
448 ClientLoop(); 447 ClientLoop();
449 } else { // Invalid 448 } else { // Invalid
450 Console.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString()); 449 OpenSim_Main.localcons.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString());
451 ClientThread.Abort(); 450 ClientThread.Abort();
452 } 451 }
453 } else { 452 } else {