From efd90b56b761219af6425b1c7a2cdd3b6ffb4de2 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Thu, 27 Dec 2007 21:41:48 +0000 Subject: * Optimized usings * shortened references * Removed redundant 'this' * Normalized EOF --- .../Environment/Modules/AvatarFactoryModule.cs | 17 +- OpenSim/Region/Environment/Modules/ChatModule.cs | 10 +- .../Environment/Modules/ScriptsHttpRequests.cs | 260 ++++++++++----------- OpenSim/Region/Environment/Modules/SunModule.cs | 37 +-- .../Environment/Modules/TextureDownloadModule.cs | 42 ++-- .../Region/Environment/Modules/WorldCommModule.cs | 4 +- OpenSim/Region/Environment/Modules/XMLRPCModule.cs | 9 +- 7 files changed, 191 insertions(+), 188 deletions(-) (limited to 'OpenSim/Region/Environment/Modules') diff --git a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs index 0b95aee..c31a79b 100644 --- a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs +++ b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs @@ -27,11 +27,12 @@ */ using System; -using libsecondlife; using System.Collections.Generic; +using libsecondlife; using Nini.Config; using OpenSim.Framework; using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Console; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; @@ -59,9 +60,9 @@ namespace OpenSim.Region.Environment.Modules { m_avatarsAppearance[avatarId] = appearance; } - catch (System.NullReferenceException) + catch (NullReferenceException) { - OpenSim.Framework.Console.MainLog.Instance.Error("AVATAR", "Unable to load appearance for uninitialized avatar"); + MainLog.Instance.Error("AVATAR", "Unable to load appearance for uninitialized avatar"); } return true; } @@ -98,17 +99,17 @@ namespace OpenSim.Region.Environment.Modules public void NewClient(IClientAPI client) { - client.OnAvatarNowWearing += AvatarIsWearing; + client.OnAvatarNowWearing += AvatarIsWearing; } public void RemoveClient(IClientAPI client) { - // client.OnAvatarNowWearing -= AvatarIsWearing; + // client.OnAvatarNowWearing -= AvatarIsWearing; } public void AvatarIsWearing(Object sender, AvatarWearingArgs e) { - IClientAPI clientView = (IClientAPI)sender; + IClientAPI clientView = (IClientAPI) sender; CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId); if (profile != null) { @@ -127,7 +128,7 @@ namespace OpenSim.Region.Environment.Modules { assetId = baseItem.assetID; //temporary dictionary storage. This should be storing to a database - + if (m_avatarsAppearance.ContainsKey(clientView.AgentId)) { AvatarAppearance avatAppearance = m_avatarsAppearance[clientView.AgentId]; @@ -158,4 +159,4 @@ namespace OpenSim.Region.Environment.Modules return visualParams; } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs index 069eb3f..d6df978 100644 --- a/OpenSim/Region/Environment/Modules/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/ChatModule.cs @@ -176,10 +176,10 @@ namespace OpenSim.Region.Environment.Modules foreach (Scene s in m_scenes) { s.ForEachScenePresence(delegate(ScenePresence presence) - { - TrySendChatMessage(presence, fromPos, regionPos, - fromAgentID, fromName, e.Type, message); - }); + { + TrySendChatMessage(presence, fromPos, regionPos, + fromAgentID, fromName, e.Type, message); + }); } } } @@ -373,4 +373,4 @@ namespace OpenSim.Region.Environment.Modules m_tcp.Close(); } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs b/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs index d47004b..f8798dc 100644 --- a/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs +++ b/OpenSim/Region/Environment/Modules/ScriptsHttpRequests.cs @@ -27,18 +27,15 @@ */ using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Text; -using OpenSim.Region.Environment.Interfaces; -using OpenSim.Region.Environment.Scenes; -using System.Collections; -using System.Collections.Generic; using System.Threading; using libsecondlife; using Nini.Config; -using Nwc.XmlRpc; -using OpenSim.Framework.Servers; +using OpenSim.Region.Environment.Interfaces; +using OpenSim.Region.Environment.Scenes; /***************************************************** * @@ -85,120 +82,120 @@ using OpenSim.Framework.Servers; namespace OpenSim.Region.Environment.Modules { - public class ScriptHTTPRequests : IRegionModule, IHttpRequests - { - private Scene m_scene; - private Queue rpcQueue = new Queue(); - private object HttpListLock = new object(); - private string m_name = "HttpScriptRequests"; - private int httpTimeout = 300; - - // - private Dictionary m_pendingRequests; - - public ScriptHTTPRequests() - { - } - - public void Initialise(Scene scene, IConfigSource config) - { - m_scene = scene; - - m_scene.RegisterModuleInterface(this); - - m_pendingRequests = new Dictionary(); - } - - public void PostInitialise() - { - } - - public void Close() - { - } - - public string Name - { - get { return m_name; } - } - - public bool IsSharedModule - { - get { return true; } - } - - public LLUUID MakeHttpRequest(string url, string parameters, string body) { - return LLUUID.Zero; - } - - public LLUUID StartHttpRequest(uint localID, LLUUID itemID, string url, List parameters, string body) - { - LLUUID reqID = LLUUID.Random(); - HttpRequestClass htc = new HttpRequestClass(); - - // Parameters are expected in {key, value, ... , key, value} - if( parameters != null ) - { - string[] parms = parameters.ToArray(); - for (int i = 0; i < parms.Length / 2; i += 2) + public class ScriptHTTPRequests : IRegionModule, IHttpRequests + { + private Scene m_scene; + private Queue rpcQueue = new Queue(); + private object HttpListLock = new object(); + private string m_name = "HttpScriptRequests"; + private int httpTimeout = 300; + + // + private Dictionary m_pendingRequests; + + public ScriptHTTPRequests() + { + } + + public void Initialise(Scene scene, IConfigSource config) + { + m_scene = scene; + + m_scene.RegisterModuleInterface(this); + + m_pendingRequests = new Dictionary(); + } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public string Name + { + get { return m_name; } + } + + public bool IsSharedModule + { + get { return true; } + } + + public LLUUID MakeHttpRequest(string url, string parameters, string body) + { + return LLUUID.Zero; + } + + public LLUUID StartHttpRequest(uint localID, LLUUID itemID, string url, List parameters, string body) + { + LLUUID reqID = LLUUID.Random(); + HttpRequestClass htc = new HttpRequestClass(); + + // Parameters are expected in {key, value, ... , key, value} + if (parameters != null) + { + string[] parms = parameters.ToArray(); + for (int i = 0; i < parms.Length/2; i += 2) { - switch( Int32.Parse(parms[i]) ) + switch (Int32.Parse(parms[i])) { case HttpRequestClass.HTTP_METHOD: - htc.httpMethod = parms[i + 1]; - break; + htc.httpMethod = parms[i + 1]; + break; case HttpRequestClass.HTTP_MIMETYPE: - - htc.httpMIMEType = parms[i + 1]; - break; + + htc.httpMIMEType = parms[i + 1]; + break; case HttpRequestClass.HTTP_BODY_MAXLENGTH: - - // TODO implement me - break; + + // TODO implement me + break; case HttpRequestClass.HTTP_VERIFY_CERT: - - // TODO implement me - break; + + // TODO implement me + break; } } - } - - htc.localID = localID; - htc.itemID = itemID; - htc.url = url; - htc.reqID = reqID; - htc.httpTimeout = httpTimeout; - htc.outbound_body = body; - - lock (HttpListLock) - { - m_pendingRequests.Add(reqID, htc); - } - - htc.process(); - - return reqID; - } - - public void StopHttpRequest(uint m_localID, LLUUID m_itemID) - { - lock (HttpListLock) - { - - HttpRequestClass tmpReq; - if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq)) - { - tmpReq.Stop(); - m_pendingRequests.Remove(m_itemID); - } - } - } - - /* + } + + htc.localID = localID; + htc.itemID = itemID; + htc.url = url; + htc.reqID = reqID; + htc.httpTimeout = httpTimeout; + htc.outbound_body = body; + + lock (HttpListLock) + { + m_pendingRequests.Add(reqID, htc); + } + + htc.process(); + + return reqID; + } + + public void StopHttpRequest(uint m_localID, LLUUID m_itemID) + { + lock (HttpListLock) + { + HttpRequestClass tmpReq; + if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq)) + { + tmpReq.Stop(); + m_pendingRequests.Remove(m_itemID); + } + } + } + + /* * TODO * Not sure how important ordering is is here - the next first * one completed in the list is returned, based soley on its list @@ -206,10 +203,11 @@ namespace OpenSim.Region.Environment.Modules * finsihed. I thought about setting up a queue for this, but * it will need some refactoring and this works 'enough' right now */ - public HttpRequestClass GetNextCompletedRequest() - { - lock (HttpListLock) - { + + public HttpRequestClass GetNextCompletedRequest() + { + lock (HttpListLock) + { foreach (LLUUID luid in m_pendingRequests.Keys) { HttpRequestClass tmpReq; @@ -225,18 +223,16 @@ namespace OpenSim.Region.Environment.Modules } } return null; - } - - - } + } + } - // - // HTTP REAQUEST - // This class was originally in LSLLongCmdHandler - // - // TODO: setter/getter methods, maybe pass some in - // constructor - // + // + // HTTP REAQUEST + // This class was originally in LSLLongCmdHandler + // + // TODO: setter/getter methods, maybe pass some in + // constructor + // public class HttpRequestClass { @@ -280,9 +276,9 @@ namespace OpenSim.Region.Environment.Modules * TODO: More work on the response codes. Right now * returning 200 for success or 499 for exception */ + public void SendRequest() { - HttpWebResponse response = null; StringBuilder sb = new StringBuilder(); byte[] buf = new byte[8192]; @@ -292,14 +288,14 @@ namespace OpenSim.Region.Environment.Modules try { request = (HttpWebRequest) - WebRequest.Create(url); + WebRequest.Create(url); request.Method = httpMethod; request.ContentType = httpMIMEType; request.Timeout = httpTimeout; // execute the request response = (HttpWebResponse) - request.GetResponse(); + request.GetResponse(); Stream resStream = response.GetResponseStream(); @@ -317,11 +313,9 @@ namespace OpenSim.Region.Environment.Modules // continue building the string sb.Append(tempString); } - } - while (count > 0); // any more data to read? + } while (count > 0); // any more data to read? response_body = sb.ToString(); - } catch (Exception e) { @@ -333,7 +327,6 @@ namespace OpenSim.Region.Environment.Modules status = 200; finished = true; - } public void Stop() @@ -342,8 +335,9 @@ namespace OpenSim.Region.Environment.Modules { httpThread.Abort(); } - catch (Exception) { } + catch (Exception) + { + } } } - - } \ No newline at end of file +} \ No newline at end of file diff --git a/OpenSim/Region/Environment/Modules/SunModule.cs b/OpenSim/Region/Environment/Modules/SunModule.cs index 233c83c..bd6cd63 100644 --- a/OpenSim/Region/Environment/Modules/SunModule.cs +++ b/OpenSim/Region/Environment/Modules/SunModule.cs @@ -28,13 +28,12 @@ using System; using System.Collections.Generic; +using libsecondlife; using Nini.Config; -using OpenSim.Region.Environment.Interfaces; -using OpenSim.Region.Environment.Scenes; using OpenSim.Framework; using OpenSim.Framework.Console; -using libsecondlife; - +using OpenSim.Region.Environment.Interfaces; +using OpenSim.Region.Environment.Scenes; namespace OpenSim.Region.Environment.Modules { @@ -55,17 +54,20 @@ namespace OpenSim.Region.Environment.Modules { m_start = DateTime.Now.Ticks; m_frame = 0; - + // Just in case they don't have the stanzas - try { + try + { m_day_length = config.Configs["Sun"].GetDouble("day_length", m_real_day); m_frame_mod = config.Configs["Sun"].GetInt("frame_rate", m_default_frame); - } catch (Exception) { + } + catch (Exception) + { m_day_length = m_real_day; m_frame_mod = m_default_frame; } - - m_dilation = (int)(m_real_day / m_day_length); + + m_dilation = (int) (m_real_day/m_day_length); m_scene = scene; m_log = MainLog.Instance; scene.EventManager.OnFrame += SunUpdate; @@ -94,10 +96,11 @@ namespace OpenSim.Region.Environment.Modules { client.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f)); } - + public void SunUpdate() { - if (m_frame < m_frame_mod) { + if (m_frame < m_frame_mod) + { m_frame++; return; } @@ -115,20 +118,20 @@ namespace OpenSim.Region.Environment.Modules // time when the simulator starts, then run time forward // faster based on time dilation factor. This means that // ticks don't get out of hand - private double HourOfTheDay() + private double HourOfTheDay() { - long m_addticks = (DateTime.Now.Ticks - m_start) * m_dilation; + long m_addticks = (DateTime.Now.Ticks - m_start)*m_dilation; DateTime dt = new DateTime(m_start + m_addticks); - return (double)dt.Hour + ((double)dt.Minute / 60.0); + return (double) dt.Hour + ((double) dt.Minute/60.0); } - private LLVector3 SunPos(double hour) + private LLVector3 SunPos(double hour) { // now we have our radian position - double rad = (hour / m_real_day) * 2 * Math.PI - (Math.PI / 2.0); + double rad = (hour/m_real_day)*2*Math.PI - (Math.PI/2.0); double z = Math.Sin(rad); double x = Math.Cos(rad); - return new LLVector3((float)x, 0f, (float)z); + return new LLVector3((float) x, 0f, (float) z); } // TODO: clear this out. This is here so that I remember to diff --git a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs index 0adace1..813be8d 100644 --- a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs +++ b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs @@ -32,6 +32,7 @@ using libsecondlife; using libsecondlife.Packets; using Nini.Config; using OpenSim.Framework; +using OpenSim.Framework.Console; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; @@ -48,7 +49,8 @@ namespace OpenSim.Region.Environment.Modules private BlockingQueue QueueSenders = new BlockingQueue(); - private Dictionary m_userTextureServices = new Dictionary(); + private Dictionary m_userTextureServices = + new Dictionary(); private Thread m_thread; @@ -72,7 +74,6 @@ namespace OpenSim.Region.Environment.Modules m_scene = scene; m_scene.EventManager.OnNewClient += NewClient; } - } public void PostInitialise() @@ -115,7 +116,7 @@ namespace OpenSim.Region.Environment.Modules public void TextureRequest(Object sender, TextureRequestArgs e) { - IClientAPI client = (IClientAPI)sender; + IClientAPI client = (IClientAPI) sender; UserTextureDownloadService textureService; if (TryGetUserTextureService(client.AgentId, out textureService)) { @@ -175,7 +176,8 @@ namespace OpenSim.Region.Environment.Modules { if (!m_textureSenders.ContainsKey(e.RequestedAssetID)) { - TextureSender requestHandler = new TextureSender(client, e.RequestedAssetID, e.DiscardLevel, e.PacketNumber); + TextureSender requestHandler = + new TextureSender(client, e.RequestedAssetID, e.DiscardLevel, e.PacketNumber); m_textureSenders.Add(e.RequestedAssetID, requestHandler); m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback); } @@ -183,7 +185,8 @@ namespace OpenSim.Region.Environment.Modules { m_textureSenders[e.RequestedAssetID].UpdateRequest(e.DiscardLevel, e.PacketNumber); m_textureSenders[e.RequestedAssetID].counter = 0; - if ((m_textureSenders[e.RequestedAssetID].ImageLoaded) && (m_textureSenders[e.RequestedAssetID].Sending ==false)) + if ((m_textureSenders[e.RequestedAssetID].ImageLoaded) && + (m_textureSenders[e.RequestedAssetID].Sending == false)) { m_textureSenders[e.RequestedAssetID].Sending = true; m_sharedSendersQueue.Enqueue(m_textureSenders[e.RequestedAssetID]); @@ -256,7 +259,7 @@ namespace OpenSim.Region.Environment.Modules { m_asset = asset; NumPackets = CalculateNumPackets(asset.Data.Length); - PacketCounter = (int)StartPacketNumber; + PacketCounter = (int) StartPacketNumber; ImageLoaded = true; } @@ -264,14 +267,15 @@ namespace OpenSim.Region.Environment.Modules { RequestedDiscardLevel = discardLevel; StartPacketNumber = packetNumber; - PacketCounter = (int)StartPacketNumber; + PacketCounter = (int) StartPacketNumber; } public bool SendTexturePacket() { SendPacket(); counter++; - if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets / (RequestedDiscardLevel + 1)))) ) + if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || + ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1))))) { return true; } @@ -290,7 +294,7 @@ namespace OpenSim.Region.Environment.Modules im.Header.Reliable = false; im.ImageID.Packets = 1; im.ImageID.ID = m_asset.FullID; - im.ImageID.Size = (uint)m_asset.Data.Length; + im.ImageID.Size = (uint) m_asset.Data.Length; im.ImageData.Data = m_asset.Data; im.ImageID.Codec = 2; RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); @@ -300,9 +304,9 @@ namespace OpenSim.Region.Environment.Modules { ImageDataPacket im = new ImageDataPacket(); im.Header.Reliable = false; - im.ImageID.Packets = (ushort)(NumPackets); + im.ImageID.Packets = (ushort) (NumPackets); im.ImageID.ID = m_asset.FullID; - im.ImageID.Size = (uint)m_asset.Data.Length; + im.ImageID.Size = (uint) m_asset.Data.Length; im.ImageData.Data = new byte[600]; Array.Copy(m_asset.Data, 0, im.ImageData.Data, 0, 600); im.ImageID.Codec = 2; @@ -314,18 +318,20 @@ namespace OpenSim.Region.Environment.Modules { ImagePacketPacket im = new ImagePacketPacket(); im.Header.Reliable = false; - im.ImageID.Packet = (ushort)(PacketCounter); + im.ImageID.Packet = (ushort) (PacketCounter); im.ImageID.ID = m_asset.FullID; - int size = m_asset.Data.Length - 600 - (1000 * (PacketCounter - 1)); + int size = m_asset.Data.Length - 600 - (1000*(PacketCounter - 1)); if (size > 1000) size = 1000; im.ImageData.Data = new byte[size]; try { - Array.Copy(m_asset.Data, 600 + (1000 * (PacketCounter - 1)), im.ImageData.Data, 0, size); + Array.Copy(m_asset.Data, 600 + (1000*(PacketCounter - 1)), im.ImageData.Data, 0, size); } - catch (System.ArgumentOutOfRangeException) + catch (ArgumentOutOfRangeException) { - OpenSim.Framework.Console.MainLog.Instance.Warn("TEXTURE", "Unable to separate texture into multiple packets: Array bounds failure on asset:" + m_asset.FullID.ToString() + "- TextureDownloadModule.cs. line:328"); + MainLog.Instance.Warn("TEXTURE", + "Unable to separate texture into multiple packets: Array bounds failure on asset:" + + m_asset.FullID.ToString() + "- TextureDownloadModule.cs. line:328"); return; } RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); @@ -342,14 +348,12 @@ namespace OpenSim.Region.Environment.Modules { //over 600 bytes so split up file int restData = (length - 600); - int restPackets = ((restData + 999) / 1000); + int restPackets = ((restData + 999)/1000); numPackets = restPackets; } return numPackets; } } - - } } \ No newline at end of file diff --git a/OpenSim/Region/Environment/Modules/WorldCommModule.cs b/OpenSim/Region/Environment/Modules/WorldCommModule.cs index 0dad998..6b9ae46 100644 --- a/OpenSim/Region/Environment/Modules/WorldCommModule.cs +++ b/OpenSim/Region/Environment/Modules/WorldCommModule.cs @@ -135,7 +135,7 @@ namespace OpenSim.Region.Environment.Modules { m_listenerManager.Remove(handle); } - + // This method scans nearby objects and determines if they are listeners, // and if so if this message fits the filter. If it does, then // enqueue the message for delivery to the objects listen event handler. @@ -490,4 +490,4 @@ namespace OpenSim.Region.Environment.Modules return m_id; } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Environment/Modules/XMLRPCModule.cs b/OpenSim/Region/Environment/Modules/XMLRPCModule.cs index f13b2bb..481ba3f 100644 --- a/OpenSim/Region/Environment/Modules/XMLRPCModule.cs +++ b/OpenSim/Region/Environment/Modules/XMLRPCModule.cs @@ -33,10 +33,10 @@ using System.Threading; using libsecondlife; using Nini.Config; using Nwc.XmlRpc; +using OpenSim.Framework.Console; using OpenSim.Framework.Servers; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; -using OpenSim.Framework.Console; /***************************************************** * @@ -116,15 +116,16 @@ namespace OpenSim.Region.Environment.Modules public void PostInitialise() { - if ( IsEnabled() ) + if (IsEnabled()) { m_openChannels = new Dictionary(); m_pendingResponse = new Dictionary(); // Start http server // Attach xmlrpc handlers - m_log.Verbose("REMOTE_DATA", "Starting XMLRPC Server on port " + m_remoteDataPort + " for llRemoteData commands."); - BaseHttpServer httpServer = new BaseHttpServer((uint)m_remoteDataPort); + m_log.Verbose("REMOTE_DATA", + "Starting XMLRPC Server on port " + m_remoteDataPort + " for llRemoteData commands."); + BaseHttpServer httpServer = new BaseHttpServer((uint) m_remoteDataPort); httpServer.AddXmlRPCHandler("llRemoteData", XmlRpcRemoteData); httpServer.Start(); } -- cgit v1.1