* Rex merge, region modules.
parent
3dfb31a49c
commit
db76041e4e
|
@ -0,0 +1,286 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class AgentAssetTransactionModule : IRegionModule, IAgentAssetTransactions
|
||||
{
|
||||
private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
|
||||
private Scene m_scene = null;
|
||||
private bool m_dumpAssetsToFile = false;
|
||||
|
||||
private AgentAssetTransactionsManager m_transactionManager;
|
||||
|
||||
public AgentAssetTransactionModule()
|
||||
{
|
||||
// System.Console.WriteLine("creating AgentAssetTransactionModule");
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
|
||||
{
|
||||
// System.Console.WriteLine("initialising AgentAssetTransactionModule");
|
||||
RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
|
||||
scene.RegisterModuleInterface<IAgentAssetTransactions>(this);
|
||||
|
||||
scene.EventManager.OnNewClient += NewClient;
|
||||
}
|
||||
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
if (config.Configs["StandAlone"] != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_dumpAssetsToFile = config.Configs["StandAlone"].GetBoolean("dump_assets_to_file", false);
|
||||
m_transactionManager = new AgentAssetTransactionsManager(m_scene, m_dumpAssetsToFile);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
m_transactionManager = new AgentAssetTransactionsManager(m_scene, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_transactionManager = new AgentAssetTransactionsManager(m_scene, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "AgentTransactionModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnAssetUploadRequest += m_transactionManager.HandleUDPUploadRequest;
|
||||
client.OnXferReceive += m_transactionManager.HandleXfer;
|
||||
}
|
||||
|
||||
public void HandleItemCreationFromTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
|
||||
uint callbackID, string description, string name, sbyte invType,
|
||||
sbyte type, byte wearableType, uint nextOwnerMask)
|
||||
{
|
||||
m_transactionManager.HandleItemCreationFromTransaction(remoteClient, transactionID, folderID, callbackID, description, name, invType, type, wearableType, nextOwnerMask);
|
||||
}
|
||||
|
||||
public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, LLUUID transactionID,
|
||||
InventoryItemBase item)
|
||||
{
|
||||
m_transactionManager.HandleItemUpdateFromTransaction(remoteClient, transactionID, item);
|
||||
}
|
||||
|
||||
public void RemoveAgentAssetTransactions(LLUUID userID)
|
||||
{
|
||||
m_transactionManager.RemoveAgentAssetTransactions(userID);
|
||||
}
|
||||
}
|
||||
|
||||
//should merge this classes and clean up
|
||||
public class AgentAssetTransactionsManager
|
||||
{
|
||||
private static readonly log4net.ILog m_log
|
||||
= log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
// Fields
|
||||
public Scene MyScene;
|
||||
|
||||
/// <summary>
|
||||
/// Each agent has its own singleton collection of transactions
|
||||
/// </summary>
|
||||
private Dictionary<LLUUID, AgentAssetTransactions> AgentTransactions =
|
||||
new Dictionary<LLUUID, AgentAssetTransactions>();
|
||||
|
||||
/// <summary>
|
||||
/// Should we dump uploaded assets to the filesystem?
|
||||
/// </summary>
|
||||
private bool m_dumpAssetsToFile;
|
||||
|
||||
public AgentAssetTransactionsManager(Scene scene, bool dumpAssetsToFile)
|
||||
{
|
||||
MyScene = scene;
|
||||
m_dumpAssetsToFile = dumpAssetsToFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the collection of asset transactions for the given user. If one does not already exist, it
|
||||
/// is created.
|
||||
/// </summary>
|
||||
/// <param name="userID"></param>
|
||||
/// <returns></returns>
|
||||
private AgentAssetTransactions GetUserTransactions(LLUUID userID)
|
||||
{
|
||||
lock (AgentTransactions)
|
||||
{
|
||||
if (!AgentTransactions.ContainsKey(userID))
|
||||
{
|
||||
AgentAssetTransactions transactions
|
||||
= new AgentAssetTransactions(userID, this, m_dumpAssetsToFile);
|
||||
AgentTransactions.Add(userID, transactions);
|
||||
}
|
||||
|
||||
return AgentTransactions[userID];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the given agent asset transactions. This should be called when a client is departing
|
||||
/// from a scene (and hence won't be making any more transactions here).
|
||||
/// </summary>
|
||||
/// <param name="userID"></param>
|
||||
public void RemoveAgentAssetTransactions(LLUUID userID)
|
||||
{
|
||||
// m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID);
|
||||
|
||||
lock (AgentTransactions)
|
||||
{
|
||||
AgentTransactions.Remove(userID);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an inventory item from data that has been received through a transaction.
|
||||
///
|
||||
/// This is called when new clothing or body parts are created. It may also be called in other
|
||||
/// situations.
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="transactionID"></param>
|
||||
/// <param name="folderID"></param>
|
||||
/// <param name="callbackID"></param>
|
||||
/// <param name="description"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="invType"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="wearableType"></param>
|
||||
/// <param name="nextOwnerMask"></param>
|
||||
public void HandleItemCreationFromTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
|
||||
uint callbackID, string description, string name, sbyte invType,
|
||||
sbyte type, byte wearableType, uint nextOwnerMask)
|
||||
{
|
||||
m_log.DebugFormat(
|
||||
"[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name);
|
||||
|
||||
AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
|
||||
|
||||
transactions.RequestCreateInventoryItem(
|
||||
remoteClient, transactionID, folderID, callbackID, description,
|
||||
name, invType, type, wearableType, nextOwnerMask);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update an inventory item with data that has been received through a transaction.
|
||||
///
|
||||
/// This is called when clothing or body parts are updated (for instance, with new textures or
|
||||
/// colours). It may also be called in other situations.
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="transactionID"></param>
|
||||
/// <param name="item"></param>
|
||||
public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, LLUUID transactionID,
|
||||
InventoryItemBase item)
|
||||
{
|
||||
m_log.DebugFormat(
|
||||
"[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}",
|
||||
item.inventoryName);
|
||||
|
||||
AgentAssetTransactions transactions
|
||||
= GetUserTransactions(remoteClient.AgentId);
|
||||
|
||||
transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request that a client (agent) begin an asset transfer.
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="assetID"></param>
|
||||
/// <param name="transaction"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="data"></param></param>
|
||||
/// <param name="tempFile"></param>
|
||||
public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type,
|
||||
byte[] data, bool storeLocal, bool tempFile)
|
||||
{
|
||||
// Console.WriteLine("asset upload of " + assetID);
|
||||
AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
|
||||
|
||||
AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
|
||||
if (uploader != null)
|
||||
{
|
||||
|
||||
if (uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle asset transfer data packets received in response to the asset upload request in
|
||||
/// HandleUDPUploadRequest()
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="xferID"></param>
|
||||
/// <param name="packetID"></param>
|
||||
/// <param name="data"></param>
|
||||
public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
|
||||
{
|
||||
AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
|
||||
|
||||
transactions.HandleXfer(xferID, packetID, data);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,408 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using libsecondlife;
|
||||
using libsecondlife.Packets;
|
||||
using OpenSim.Framework.Servers;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Communications.Cache;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Manage asset transactions for a single agent.
|
||||
/// </summary>
|
||||
public class AgentAssetTransactions
|
||||
{
|
||||
//private static readonly log4net.ILog m_log
|
||||
// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
// Fields
|
||||
public LLUUID UserID;
|
||||
public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>();
|
||||
public AgentAssetTransactionsManager Manager;
|
||||
private bool m_dumpAssetsToFile;
|
||||
|
||||
// Methods
|
||||
public AgentAssetTransactions(LLUUID agentID, AgentAssetTransactionsManager manager, bool dumpAssetsToFile)
|
||||
{
|
||||
UserID = agentID;
|
||||
Manager = manager;
|
||||
m_dumpAssetsToFile = dumpAssetsToFile;
|
||||
}
|
||||
|
||||
public AssetXferUploader RequestXferUploader(LLUUID transactionID)
|
||||
{
|
||||
if (!XferUploaders.ContainsKey(transactionID))
|
||||
{
|
||||
AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);
|
||||
|
||||
lock (XferUploaders)
|
||||
{
|
||||
XferUploaders.Add(transactionID, uploader);
|
||||
}
|
||||
|
||||
return uploader;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void HandleXfer(ulong xferID, uint packetID, byte[] data)
|
||||
{
|
||||
// AssetXferUploader uploaderFound = null;
|
||||
|
||||
lock (XferUploaders)
|
||||
{
|
||||
foreach (AssetXferUploader uploader in XferUploaders.Values)
|
||||
{
|
||||
if (uploader.XferID == xferID)
|
||||
{
|
||||
uploader.HandleXferPacket(xferID, packetID, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
|
||||
uint callbackID, string description, string name, sbyte invType,
|
||||
sbyte type, byte wearableType, uint nextOwnerMask)
|
||||
{
|
||||
if (XferUploaders.ContainsKey(transactionID))
|
||||
{
|
||||
XferUploaders[transactionID].RequestCreateInventoryItem(remoteClient, transactionID, folderID,
|
||||
callbackID, description, name, invType, type,
|
||||
wearableType, nextOwnerMask);
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID,
|
||||
InventoryItemBase item)
|
||||
{
|
||||
if (XferUploaders.ContainsKey(transactionID))
|
||||
{
|
||||
XferUploaders[transactionID].RequestUpdateInventoryItem(remoteClient, transactionID, item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get an uploaded asset. If the data is successfully retrieved, the transaction will be removed.
|
||||
/// </summary>
|
||||
/// <param name="transactionID"></param>
|
||||
/// <returns>The asset if the upload has completed, null if it has not.</returns>
|
||||
public AssetBase GetTransactionAsset(LLUUID transactionID)
|
||||
{
|
||||
if (XferUploaders.ContainsKey(transactionID))
|
||||
{
|
||||
AssetXferUploader uploader = XferUploaders[transactionID];
|
||||
AssetBase asset = uploader.GetAssetData();
|
||||
|
||||
lock (XferUploaders)
|
||||
{
|
||||
XferUploaders.Remove(transactionID);
|
||||
}
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Nested Types
|
||||
public class AssetXferUploader
|
||||
{
|
||||
// Fields
|
||||
public bool AddToInventory;
|
||||
public AssetBase Asset;
|
||||
public LLUUID InventFolder = LLUUID.Zero;
|
||||
private IClientAPI ourClient;
|
||||
public LLUUID TransactionID = LLUUID.Zero;
|
||||
public bool UploadComplete;
|
||||
public ulong XferID;
|
||||
private string m_name = String.Empty;
|
||||
private string m_description = String.Empty;
|
||||
private sbyte type = 0;
|
||||
private sbyte invType = 0;
|
||||
private uint nextPerm = 0;
|
||||
private bool m_finished = false;
|
||||
private bool m_createItem = false;
|
||||
private AgentAssetTransactions m_userTransactions;
|
||||
private bool m_storeLocal;
|
||||
private bool m_dumpAssetToFile;
|
||||
|
||||
public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile)
|
||||
{
|
||||
m_userTransactions = transactions;
|
||||
m_dumpAssetToFile = dumpAssetToFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process transfer data received from the client.
|
||||
/// </summary>
|
||||
/// <param name="xferID"></param>
|
||||
/// <param name="packetID"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns>
|
||||
public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data)
|
||||
{
|
||||
if (XferID == xferID)
|
||||
{
|
||||
if (Asset.Data.Length > 1)
|
||||
{
|
||||
byte[] destinationArray = new byte[Asset.Data.Length + data.Length];
|
||||
Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length);
|
||||
Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length);
|
||||
Asset.Data = destinationArray;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] buffer2 = new byte[data.Length - 4];
|
||||
Array.Copy(data, 4, buffer2, 0, data.Length - 4);
|
||||
Asset.Data = buffer2;
|
||||
}
|
||||
ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket();
|
||||
newPack.XferID.ID = xferID;
|
||||
newPack.XferID.Packet = packetID;
|
||||
ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
|
||||
if ((packetID & 0x80000000) != 0)
|
||||
{
|
||||
SendCompleteMessage();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialise asset transfer from the client
|
||||
/// </summary>
|
||||
/// <param name="xferID"></param>
|
||||
/// <param name="packetID"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns>True if the transfer is complete, false otherwise</returns>
|
||||
public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data,
|
||||
bool storeLocal, bool tempFile)
|
||||
{
|
||||
ourClient = remoteClient;
|
||||
Asset = new AssetBase();
|
||||
Asset.FullID = assetID;
|
||||
Asset.InvType = type;
|
||||
Asset.Type = type;
|
||||
Asset.Data = data;
|
||||
Asset.Name = "blank";
|
||||
Asset.Description = "empty";
|
||||
Asset.Local = storeLocal;
|
||||
Asset.Temporary = tempFile;
|
||||
|
||||
TransactionID = transaction;
|
||||
m_storeLocal = storeLocal;
|
||||
if (Asset.Data.Length > 2)
|
||||
{
|
||||
SendCompleteMessage();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RequestStartXfer();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void RequestStartXfer()
|
||||
{
|
||||
UploadComplete = false;
|
||||
XferID = Util.GetNextXferID();
|
||||
RequestXferPacket newPack = new RequestXferPacket();
|
||||
newPack.XferID.ID = XferID;
|
||||
newPack.XferID.VFileType = Asset.Type;
|
||||
newPack.XferID.VFileID = Asset.FullID;
|
||||
newPack.XferID.FilePath = 0;
|
||||
newPack.XferID.Filename = new byte[0];
|
||||
ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
|
||||
}
|
||||
|
||||
protected void SendCompleteMessage()
|
||||
{
|
||||
UploadComplete = true;
|
||||
AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
|
||||
newPack.AssetBlock.Type = Asset.Type;
|
||||
newPack.AssetBlock.Success = true;
|
||||
newPack.AssetBlock.UUID = Asset.FullID;
|
||||
ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset);
|
||||
m_finished = true;
|
||||
if (m_createItem)
|
||||
{
|
||||
DoCreateItem();
|
||||
}
|
||||
else if (m_storeLocal)
|
||||
{
|
||||
m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
|
||||
}
|
||||
|
||||
// Console.WriteLine("upload complete "+ this.TransactionID);
|
||||
|
||||
if (m_dumpAssetToFile)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
string filename =
|
||||
String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day,
|
||||
now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type);
|
||||
SaveAssetToFile(filename, Asset.Data);
|
||||
}
|
||||
}
|
||||
|
||||
///Left this in and commented in case there are unforseen issues
|
||||
//private void SaveAssetToFile(string filename, byte[] data)
|
||||
//{
|
||||
// FileStream fs = File.Create(filename);
|
||||
// BinaryWriter bw = new BinaryWriter(fs);
|
||||
// bw.Write(data);
|
||||
// bw.Close();
|
||||
// fs.Close();
|
||||
//}
|
||||
private void SaveAssetToFile(string filename, byte[] data)
|
||||
{
|
||||
string assetPath = "UserAssets";
|
||||
if (!Directory.Exists(assetPath))
|
||||
{
|
||||
Directory.CreateDirectory(assetPath);
|
||||
}
|
||||
FileStream fs = File.Create(Path.Combine(assetPath, filename));
|
||||
BinaryWriter bw = new BinaryWriter(fs);
|
||||
bw.Write(data);
|
||||
bw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
|
||||
uint callbackID, string description, string name, sbyte invType,
|
||||
sbyte type, byte wearableType, uint nextOwnerMask)
|
||||
{
|
||||
if (TransactionID == transactionID)
|
||||
{
|
||||
InventFolder = folderID;
|
||||
m_name = name;
|
||||
m_description = description;
|
||||
this.type = type;
|
||||
this.invType = invType;
|
||||
nextPerm = nextOwnerMask;
|
||||
Asset.Name = name;
|
||||
Asset.Description = description;
|
||||
Asset.Type = type;
|
||||
Asset.InvType = invType;
|
||||
m_createItem = true;
|
||||
if (m_finished)
|
||||
{
|
||||
DoCreateItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID,
|
||||
InventoryItemBase item)
|
||||
{
|
||||
if (TransactionID == transactionID)
|
||||
{
|
||||
CachedUserInfo userInfo =
|
||||
m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
|
||||
remoteClient.AgentId);
|
||||
|
||||
if (userInfo != null)
|
||||
{
|
||||
LLUUID assetID = LLUUID.Combine(transactionID, remoteClient.SecureSessionId);
|
||||
|
||||
AssetBase asset
|
||||
= m_userTransactions.Manager.MyScene.CommsManager.AssetCache.GetAsset(
|
||||
assetID, (item.assetType == (int) AssetType.Texture ? true : false));
|
||||
|
||||
if (asset == null)
|
||||
{
|
||||
asset = m_userTransactions.GetTransactionAsset(transactionID);
|
||||
}
|
||||
|
||||
if (asset != null && asset.FullID == assetID)
|
||||
{
|
||||
asset.Name = item.inventoryName;
|
||||
asset.Description = item.inventoryDescription;
|
||||
asset.InvType = (sbyte) item.invType;
|
||||
asset.Type = (sbyte) item.assetType;
|
||||
item.assetID = asset.FullID;
|
||||
|
||||
m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
|
||||
}
|
||||
|
||||
userInfo.UpdateItem(remoteClient.AgentId, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DoCreateItem()
|
||||
{
|
||||
//really need to fix this call, if lbsa71 saw this he would die.
|
||||
m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset);
|
||||
CachedUserInfo userInfo =
|
||||
m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId);
|
||||
if (userInfo != null)
|
||||
{
|
||||
InventoryItemBase item = new InventoryItemBase();
|
||||
item.avatarID = ourClient.AgentId;
|
||||
item.creatorsID = ourClient.AgentId;
|
||||
item.inventoryID = LLUUID.Random();
|
||||
item.assetID = Asset.FullID;
|
||||
item.inventoryDescription = m_description;
|
||||
item.inventoryName = m_name;
|
||||
item.assetType = type;
|
||||
item.invType = invType;
|
||||
item.parentFolderID = InventFolder;
|
||||
item.inventoryBasePermissions = 2147483647;
|
||||
item.inventoryCurrentPermissions = 2147483647;
|
||||
item.inventoryNextPermissions = nextPerm;
|
||||
|
||||
userInfo.AddItem(ourClient.AgentId, item);
|
||||
ourClient.SendInventoryItemCreateUpdate(item);
|
||||
}
|
||||
}
|
||||
|
||||
public AssetBase GetAssetData()
|
||||
{
|
||||
if (m_finished)
|
||||
{
|
||||
return Asset;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,244 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using OpenSim.Framework;
|
||||
using TribalMedia.Framework.Data;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class AppearanceRowMapper : BaseRowMapper<AvatarAppearance>
|
||||
{
|
||||
|
||||
public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj)
|
||||
: base(schema, obj)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class AppearanceTableMapper : BaseTableMapper<AppearanceRowMapper, Guid>
|
||||
{
|
||||
public AppearanceTableMapper(BaseDatabaseConnector database, string tableName)
|
||||
: base(database, tableName)
|
||||
{
|
||||
BaseSchema<AppearanceRowMapper> rowMapperSchema = new BaseSchema<AppearanceRowMapper>(this);
|
||||
m_schema = rowMapperSchema;
|
||||
|
||||
m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("UUID",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.ScenePresenceID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.ScenePresenceID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<uint>("Serial",
|
||||
delegate(AppearanceRowMapper mapper) { return (uint)mapper.Object.WearablesSerial; },
|
||||
delegate(AppearanceRowMapper mapper, uint value) { mapper.Object.WearablesSerial = (int)value; });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem0",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{
|
||||
if (mapper.Object.Wearables == null)
|
||||
{
|
||||
mapper.Object.Wearables = new OpenSim.Framework.AvatarWearable[13];
|
||||
for (int i = 0; i < 13; i++)
|
||||
{
|
||||
mapper.Object.Wearables[i] = new AvatarWearable();
|
||||
}
|
||||
}
|
||||
mapper.Object.Wearables[0].ItemID = new libsecondlife.LLUUID(value.ToString());
|
||||
});
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset0",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[0].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem1",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[1].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset1",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[1].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem2",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[2].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset2",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[2].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem3",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[3].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset3",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[3].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem4",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[4].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset4",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[4].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem5",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[5].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset5",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[5].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem6",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[6].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset6",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[6].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem7",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[7].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset7",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[7].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem8",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[8].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset8",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[8].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem9",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[9].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset9",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[9].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem10",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[10].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset10",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[10].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem11",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[11].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset11",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[11].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableItem12",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].ItemID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[12].ItemID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
rowMapperSchema.AddMapping<Guid>("WearableAsset12",
|
||||
delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].AssetID.UUID; },
|
||||
delegate(AppearanceRowMapper mapper, Guid value)
|
||||
{ mapper.Object.Wearables[12].AssetID = new libsecondlife.LLUUID(value.ToString()); });
|
||||
|
||||
}
|
||||
|
||||
public bool Add(Guid userID, AvatarAppearance appearance)
|
||||
{
|
||||
AppearanceRowMapper mapper = CreateRowMapper(appearance);
|
||||
return Add(mapper);
|
||||
}
|
||||
|
||||
public bool Update(Guid userID, AvatarAppearance appearance)
|
||||
{
|
||||
AppearanceRowMapper mapper = CreateRowMapper(appearance);
|
||||
return Update(appearance.ScenePresenceID.UUID, mapper);
|
||||
}
|
||||
|
||||
protected AppearanceRowMapper CreateRowMapper(AvatarAppearance appearance)
|
||||
{
|
||||
return new AppearanceRowMapper(m_schema, appearance);
|
||||
}
|
||||
|
||||
protected AppearanceRowMapper CreateRowMapper()
|
||||
{
|
||||
return CreateRowMapper(new AvatarAppearance());
|
||||
}
|
||||
|
||||
protected AppearanceRowMapper FromReader(BaseDataReader reader, AvatarAppearance appearance)
|
||||
{
|
||||
AppearanceRowMapper mapper = CreateRowMapper(appearance);
|
||||
mapper.FillObject(reader);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public override AppearanceRowMapper FromReader(BaseDataReader reader)
|
||||
{
|
||||
AppearanceRowMapper mapper = CreateRowMapper();
|
||||
mapper.FillObject(reader);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public bool TryGetValue(Guid presenceID, out AvatarAppearance val)
|
||||
{
|
||||
AppearanceRowMapper mapper;
|
||||
if (TryGetValue(presenceID, out mapper))
|
||||
{
|
||||
val = mapper.Object;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
val = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,72 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class AssetDownloadModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
|
||||
public AssetDownloadModule()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_scene.EventManager.OnNewClient += NewClient;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "AssetDownloadModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class AssetDownloadModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
|
||||
public AssetDownloadModule()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_scene.EventManager.OnNewClient += NewClient;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "AssetDownloadModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,162 +1,339 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
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;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class AvatarFactoryModule : IAvatarFactory
|
||||
{
|
||||
private Scene m_scene = null;
|
||||
private Dictionary<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>();
|
||||
|
||||
public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance)
|
||||
{
|
||||
if (m_avatarsAppearance.ContainsKey(avatarId))
|
||||
{
|
||||
appearance = m_avatarsAppearance[avatarId];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AvatarWearable[] wearables;
|
||||
byte[] visualParams;
|
||||
GetDefaultAvatarAppearance(out wearables, out visualParams);
|
||||
appearance = new AvatarAppearance(avatarId, wearables, visualParams);
|
||||
try
|
||||
{
|
||||
m_avatarsAppearance[avatarId] = appearance;
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
MainLog.Instance.Error("AVATAR", "Unable to load appearance for uninitialized avatar");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource source)
|
||||
{
|
||||
scene.RegisterModuleInterface<IAvatarFactory>(this);
|
||||
scene.EventManager.OnNewClient += NewClient;
|
||||
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Default Avatar Factory"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnAvatarNowWearing += AvatarIsWearing;
|
||||
}
|
||||
|
||||
public void RemoveClient(IClientAPI client)
|
||||
{
|
||||
// client.OnAvatarNowWearing -= AvatarIsWearing;
|
||||
}
|
||||
|
||||
public void AvatarIsWearing(Object sender, AvatarWearingArgs e)
|
||||
{
|
||||
IClientAPI clientView = (IClientAPI) sender;
|
||||
CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId);
|
||||
if (profile != null)
|
||||
{
|
||||
if (profile.RootFolder != null)
|
||||
{
|
||||
//Todo look up the assetid from the inventory cache for each itemId that is in AvatarWearingArgs
|
||||
// then store assetid and itemId and wearable type in a database
|
||||
foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
|
||||
{
|
||||
if (wear.Type < 13)
|
||||
{
|
||||
LLUUID assetId;
|
||||
|
||||
InventoryItemBase baseItem = profile.RootFolder.HasItem(wear.ItemID);
|
||||
if (baseItem != null)
|
||||
{
|
||||
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];
|
||||
avatAppearance.Wearables[wear.Type].AssetID = assetId;
|
||||
avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams)
|
||||
{
|
||||
visualParams = GetDefaultVisualParams();
|
||||
wearables = AvatarWearable.DefaultWearables;
|
||||
}
|
||||
|
||||
private static byte[] GetDefaultVisualParams()
|
||||
{
|
||||
byte[] visualParams;
|
||||
visualParams = new byte[218];
|
||||
for (int i = 0; i < 218; i++)
|
||||
{
|
||||
visualParams[i] = 100;
|
||||
}
|
||||
return visualParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
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;
|
||||
using OpenSim.Framework.Data;
|
||||
using TribalMedia.Framework.Data;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class AvatarFactoryModule : IAvatarFactory
|
||||
{
|
||||
private Scene m_scene = null;
|
||||
private readonly Dictionary<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>();
|
||||
|
||||
private bool m_enablePersist = false;
|
||||
private string m_connectionString;
|
||||
private bool m_configured = false;
|
||||
private BaseDatabaseConnector m_databaseMapper;
|
||||
private AppearanceTableMapper m_appearanceMapper;
|
||||
|
||||
private Dictionary<LLUUID, EventWaitHandle> m_fetchesInProgress = new Dictionary<LLUUID, EventWaitHandle>();
|
||||
private object m_syncLock = new object();
|
||||
|
||||
public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance)
|
||||
{
|
||||
|
||||
//should only let one thread at a time do this part
|
||||
EventWaitHandle waitHandle = null;
|
||||
bool fetchInProgress = false;
|
||||
lock (m_syncLock)
|
||||
{
|
||||
appearance = CheckCache(avatarId);
|
||||
if (appearance != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//not in cache so check to see if another thread is already fetching it
|
||||
if (m_fetchesInProgress.TryGetValue(avatarId, out waitHandle))
|
||||
{
|
||||
fetchInProgress = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fetchInProgress = false;
|
||||
|
||||
//no thread already fetching this appearance, so add a wait handle to list
|
||||
//for any following threads that want the same appearance
|
||||
waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
m_fetchesInProgress.Add(avatarId, waitHandle);
|
||||
}
|
||||
}
|
||||
|
||||
if (fetchInProgress)
|
||||
{
|
||||
waitHandle.WaitOne();
|
||||
appearance = CheckCache(avatarId);
|
||||
if (appearance != null)
|
||||
{
|
||||
waitHandle = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
waitHandle = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
|
||||
//this is the first thread to request this appearance
|
||||
//so let it check the db and if not found then create a default appearance
|
||||
//and add that to the cache
|
||||
appearance = CheckDatabase(avatarId);
|
||||
if (appearance != null)
|
||||
{
|
||||
//appearance has now been added to cache so lets pulse any waiting threads
|
||||
lock (m_syncLock)
|
||||
{
|
||||
m_fetchesInProgress.Remove(avatarId);
|
||||
waitHandle.Set();
|
||||
}
|
||||
// waitHandle.Close();
|
||||
waitHandle = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
//not found a appearance for the user, so create a new default one
|
||||
appearance = CreateDefault(avatarId);
|
||||
if (appearance != null)
|
||||
{
|
||||
//update database
|
||||
if (m_enablePersist)
|
||||
{
|
||||
m_appearanceMapper.Add(avatarId.UUID, appearance);
|
||||
}
|
||||
|
||||
//add appearance to dictionary cache
|
||||
lock (m_avatarsAppearance)
|
||||
{
|
||||
m_avatarsAppearance[avatarId] = appearance;
|
||||
}
|
||||
|
||||
//appearance has now been added to cache so lets pulse any waiting threads
|
||||
lock (m_syncLock)
|
||||
{
|
||||
m_fetchesInProgress.Remove(avatarId);
|
||||
waitHandle.Set();
|
||||
}
|
||||
// waitHandle.Close();
|
||||
waitHandle = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//something went wrong, so release the wait handle and remove it
|
||||
//all waiting threads will fail to find cached appearance
|
||||
//but its better for them to fail than wait for ever
|
||||
lock (m_syncLock)
|
||||
{
|
||||
m_fetchesInProgress.Remove(avatarId);
|
||||
waitHandle.Set();
|
||||
}
|
||||
//waitHandle.Close();
|
||||
waitHandle = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AvatarAppearance CreateDefault(LLUUID avatarId)
|
||||
{
|
||||
AvatarAppearance appearance = null;
|
||||
AvatarWearable[] wearables;
|
||||
byte[] visualParams;
|
||||
GetDefaultAvatarAppearance(out wearables, out visualParams);
|
||||
appearance = new AvatarAppearance(avatarId, wearables, visualParams);
|
||||
|
||||
return appearance;
|
||||
}
|
||||
|
||||
private AvatarAppearance CheckDatabase(LLUUID avatarId)
|
||||
{
|
||||
AvatarAppearance appearance = null;
|
||||
if (m_enablePersist)
|
||||
{
|
||||
if (m_appearanceMapper.TryGetValue(avatarId.UUID, out appearance))
|
||||
{
|
||||
appearance.VisualParams = GetDefaultVisualParams();
|
||||
appearance.TextureEntry = AvatarAppearance.GetDefaultTextureEntry();
|
||||
lock (m_avatarsAppearance)
|
||||
{
|
||||
m_avatarsAppearance[avatarId] = appearance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return appearance;
|
||||
}
|
||||
|
||||
private AvatarAppearance CheckCache(LLUUID avatarId)
|
||||
{
|
||||
AvatarAppearance appearance = null;
|
||||
lock (m_avatarsAppearance)
|
||||
{
|
||||
if (m_avatarsAppearance.ContainsKey(avatarId))
|
||||
{
|
||||
appearance = m_avatarsAppearance[avatarId];
|
||||
}
|
||||
}
|
||||
return appearance;
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource source)
|
||||
{
|
||||
scene.RegisterModuleInterface<IAvatarFactory>(this);
|
||||
scene.EventManager.OnNewClient += NewClient;
|
||||
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
|
||||
if (!m_configured)
|
||||
{
|
||||
m_configured = true;
|
||||
try
|
||||
{
|
||||
m_enablePersist = source.Configs["Startup"].GetBoolean("appearance_persist", false);
|
||||
m_connectionString = source.Configs["Startup"].GetString("appearance_connection_string", "");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
if (m_enablePersist)
|
||||
{
|
||||
m_databaseMapper = new MySQLDatabaseMapper(m_connectionString);
|
||||
m_appearanceMapper = new AppearanceTableMapper(m_databaseMapper, "AvatarAppearance");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "Default Avatar Factory"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnAvatarNowWearing += AvatarIsWearing;
|
||||
}
|
||||
|
||||
public void RemoveClient(IClientAPI client)
|
||||
{
|
||||
// client.OnAvatarNowWearing -= AvatarIsWearing;
|
||||
}
|
||||
|
||||
public void AvatarIsWearing(Object sender, AvatarWearingArgs e)
|
||||
{
|
||||
IClientAPI clientView = (IClientAPI)sender;
|
||||
CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId);
|
||||
if (profile != null)
|
||||
{
|
||||
if (profile.RootFolder != null)
|
||||
{
|
||||
if (m_avatarsAppearance.ContainsKey(clientView.AgentId))
|
||||
{
|
||||
AvatarAppearance avatAppearance = null;
|
||||
lock (m_avatarsAppearance)
|
||||
{
|
||||
avatAppearance = m_avatarsAppearance[clientView.AgentId];
|
||||
}
|
||||
|
||||
foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
|
||||
{
|
||||
if (wear.Type < 13)
|
||||
{
|
||||
if (wear.ItemID == LLUUID.Zero)
|
||||
{
|
||||
avatAppearance.Wearables[wear.Type].ItemID = LLUUID.Zero;
|
||||
avatAppearance.Wearables[wear.Type].AssetID = LLUUID.Zero;
|
||||
|
||||
UpdateDatabase(clientView.AgentId, avatAppearance);
|
||||
}
|
||||
else
|
||||
{
|
||||
LLUUID assetId;
|
||||
|
||||
InventoryItemBase baseItem = profile.RootFolder.HasItem(wear.ItemID);
|
||||
if (baseItem != null)
|
||||
{
|
||||
assetId = baseItem.assetID;
|
||||
avatAppearance.Wearables[wear.Type].AssetID = assetId;
|
||||
avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID;
|
||||
|
||||
UpdateDatabase(clientView.AgentId, avatAppearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateDatabase(LLUUID userID, AvatarAppearance avatAppearance)
|
||||
{
|
||||
if (m_enablePersist)
|
||||
{
|
||||
m_appearanceMapper.Update(userID.UUID, avatAppearance);
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams)
|
||||
{
|
||||
visualParams = GetDefaultVisualParams();
|
||||
wearables = AvatarWearable.DefaultWearables;
|
||||
}
|
||||
|
||||
private static byte[] GetDefaultVisualParams()
|
||||
{
|
||||
byte[] visualParams;
|
||||
visualParams = new byte[218];
|
||||
for (int i = 0; i < 218; i++)
|
||||
{
|
||||
visualParams[i] = 100;
|
||||
}
|
||||
return visualParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,94 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class AvatarProfilesModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
|
||||
public AvatarProfilesModule()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_scene.EventManager.OnNewClient += NewClient;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "AvatarProfilesModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnRequestAvatarProperties += RequestAvatarProperty;
|
||||
}
|
||||
|
||||
public void RemoveClient(IClientAPI client)
|
||||
{
|
||||
client.OnRequestAvatarProperties -= RequestAvatarProperty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="avatarID"></param>
|
||||
public void RequestAvatarProperty(IClientAPI remoteClient, LLUUID avatarID)
|
||||
{
|
||||
string about = "OpenSim crash test dummy";
|
||||
string bornOn = "Before now";
|
||||
string flAbout = "First life? What is one of those? OpenSim is my life!";
|
||||
LLUUID partner = new LLUUID("11111111-1111-0000-0000-000100bba000");
|
||||
remoteClient.SendAvatarProperties(avatarID, about, bornOn, "", flAbout, 0, LLUUID.Zero, LLUUID.Zero, "",
|
||||
partner);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class AvatarProfilesModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
|
||||
public AvatarProfilesModule()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_scene.EventManager.OnNewClient += NewClient;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "AvatarProfilesModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnRequestAvatarProperties += RequestAvatarProperty;
|
||||
}
|
||||
|
||||
public void RemoveClient(IClientAPI client)
|
||||
{
|
||||
client.OnRequestAvatarProperties -= RequestAvatarProperty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="avatarID"></param>
|
||||
public void RequestAvatarProperty(IClientAPI remoteClient, LLUUID avatarID)
|
||||
{
|
||||
string about = "OpenSim crash test dummy";
|
||||
string bornOn = "Before now";
|
||||
string flAbout = "First life? What is one of those? OpenSim is my life!";
|
||||
LLUUID partner = new LLUUID("11111111-1111-0000-0000-000100bba000");
|
||||
remoteClient.SendAvatarProperties(avatarID, about, bornOn, System.String.Empty, flAbout, 0, LLUUID.Zero, LLUUID.Zero, System.String.Empty,
|
||||
partner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,318 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using libsecondlife;
|
||||
using MoneyTransferArgs = OpenSim.Region.Environment.Scenes.EventManager.MoneyTransferArgs;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class BetaGridLikeMoneyModule: IRegionModule
|
||||
{
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Dictionary<ulong,Scene> m_scenel = new Dictionary<ulong,Scene>();
|
||||
|
||||
private IConfigSource m_gConfig;
|
||||
|
||||
private bool m_keepMoneyAcrossLogins = true;
|
||||
|
||||
private int m_minFundsBeforeRefresh = 100;
|
||||
|
||||
private int m_stipend = 1000;
|
||||
|
||||
private bool m_enabled = true;
|
||||
|
||||
|
||||
|
||||
private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>();
|
||||
|
||||
|
||||
|
||||
private bool gridmode = false;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_gConfig = config;
|
||||
ReadConfigAndPopulate();
|
||||
|
||||
if (m_enabled)
|
||||
{
|
||||
lock (m_scenel)
|
||||
{
|
||||
|
||||
if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
|
||||
{
|
||||
m_scenel[scene.RegionInfo.RegionHandle] = scene;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
|
||||
}
|
||||
}
|
||||
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
|
||||
scene.EventManager.OnClientClosed += ClientClosed;
|
||||
}
|
||||
}
|
||||
private void ReadConfigAndPopulate()
|
||||
{
|
||||
IConfig startupConfig = m_gConfig.Configs["Startup"];
|
||||
gridmode = startupConfig.GetBoolean("gridmode", false);
|
||||
m_enabled = (startupConfig.GetString("moneymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule");
|
||||
|
||||
}
|
||||
|
||||
private void OnNewClient(IClientAPI client)
|
||||
{
|
||||
// Here we check if we're in grid mode
|
||||
// I imagine that the 'check balance'
|
||||
// function for the client should be here or shortly after
|
||||
|
||||
if (gridmode)
|
||||
{
|
||||
CheckExistAndRefreshFunds(client.AgentId);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckExistAndRefreshFunds(client.AgentId);
|
||||
}
|
||||
|
||||
// Subscribe to Money messages
|
||||
client.OnMoneyBalanceRequest += SendMoneyBalance;
|
||||
client.OnLogout += ClientClosed;
|
||||
|
||||
}
|
||||
|
||||
public void ClientClosed(LLUUID AgentID)
|
||||
{
|
||||
lock (m_KnownClientFunds)
|
||||
{
|
||||
if (!m_keepMoneyAcrossLogins)
|
||||
m_KnownClientFunds.Remove(AgentID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void MoneyTransferAction (Object osender, MoneyTransferArgs e)
|
||||
{
|
||||
IClientAPI sender = null;
|
||||
IClientAPI receiver = null;
|
||||
|
||||
sender = LocateClientObject(e.sender);
|
||||
if (sender != null)
|
||||
{
|
||||
|
||||
|
||||
receiver = LocateClientObject(e.reciever);
|
||||
bool transactionresult = doMoneyTranfer(e.sender, e.reciever, e.amount);
|
||||
|
||||
if (e.sender != e.reciever)
|
||||
{
|
||||
if (sender != null)
|
||||
{
|
||||
sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
|
||||
}
|
||||
}
|
||||
|
||||
if (receiver != null)
|
||||
{
|
||||
receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.reciever));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" + e.sender.ToString() + " Reciver: " + e.reciever.ToString() + " Amount: " + e.amount.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool doMoneyTranfer(LLUUID Sender, LLUUID Receiver, int amount)
|
||||
{
|
||||
bool result = false;
|
||||
if (amount >= 0)
|
||||
{
|
||||
lock (m_KnownClientFunds)
|
||||
{
|
||||
// If we don't know about the sender, then the sender can't
|
||||
// actually be here and therefore this is likely fraud or outdated.
|
||||
if (m_KnownClientFunds.ContainsKey(Sender))
|
||||
{
|
||||
// Does the sender have enough funds to give?
|
||||
if (m_KnownClientFunds[Sender] >= amount)
|
||||
{
|
||||
// Subtract the funds from the senders account
|
||||
m_KnownClientFunds[Sender] -= amount;
|
||||
|
||||
// do we know about the receiver?
|
||||
if (!m_KnownClientFunds.ContainsKey(Receiver))
|
||||
{
|
||||
// Make a record for them so they get the updated balance when they login
|
||||
CheckExistAndRefreshFunds(Receiver);
|
||||
}
|
||||
|
||||
//Add the amount to the Receiver's funds
|
||||
m_KnownClientFunds[Receiver] += amount;
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// These below are redundant to make this clearer to read
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private IClientAPI LocateClientObject(LLUUID AgentID)
|
||||
{
|
||||
ScenePresence tPresence = null;
|
||||
IClientAPI rclient = null;
|
||||
|
||||
lock (m_scenel)
|
||||
{
|
||||
foreach (Scene _scene in m_scenel.Values)
|
||||
{
|
||||
tPresence = _scene.GetScenePresence(AgentID);
|
||||
if (tPresence != null)
|
||||
{
|
||||
if (!tPresence.IsChildAgent)
|
||||
{
|
||||
rclient = tPresence.ControllingClient;
|
||||
}
|
||||
}
|
||||
if (rclient != null)
|
||||
{
|
||||
return rclient;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ClientClosed(IClientAPI client)
|
||||
{
|
||||
ClientClosed(client.AgentId);
|
||||
}
|
||||
|
||||
public void SendMoneyBalance(IClientAPI client, LLUUID agentID, LLUUID SessionID, LLUUID TransactionID)
|
||||
{
|
||||
if (client.AgentId == agentID && client.SessionId == SessionID)
|
||||
{
|
||||
|
||||
int returnfunds = 0;
|
||||
|
||||
try
|
||||
{
|
||||
returnfunds = GetFundsForAgentID(agentID);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
client.SendAlertMessage(e.Message + " ");
|
||||
}
|
||||
|
||||
client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds);
|
||||
}
|
||||
else
|
||||
{
|
||||
client.SendAlertMessage("Unable to send your money balance to you!");
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckExistAndRefreshFunds(LLUUID agentID)
|
||||
{
|
||||
lock (m_KnownClientFunds)
|
||||
{
|
||||
if (!m_KnownClientFunds.ContainsKey(agentID))
|
||||
{
|
||||
m_KnownClientFunds.Add(agentID, m_stipend);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh)
|
||||
{
|
||||
m_KnownClientFunds[agentID] = m_stipend;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private int GetFundsForAgentID(LLUUID AgentID)
|
||||
{
|
||||
int returnfunds = 0;
|
||||
lock (m_KnownClientFunds)
|
||||
{
|
||||
if (m_KnownClientFunds.ContainsKey(AgentID))
|
||||
{
|
||||
returnfunds = m_KnownClientFunds[AgentID];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unable to get funds.");
|
||||
}
|
||||
}
|
||||
return returnfunds;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "BetaGridLikeMoneyModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,190 +1,190 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class DynamicTextureModule : IRegionModule, IDynamicTextureManager
|
||||
{
|
||||
private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
|
||||
|
||||
private Dictionary<string, IDynamicTextureRender> RenderPlugins =
|
||||
new Dictionary<string, IDynamicTextureRender>();
|
||||
|
||||
private Dictionary<LLUUID, DynamicTextureUpdater> Updaters = new Dictionary<LLUUID, DynamicTextureUpdater>();
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
|
||||
{
|
||||
RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
|
||||
scene.RegisterModuleInterface<IDynamicTextureManager>(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "DynamicTextureModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void RegisterRender(string handleType, IDynamicTextureRender render)
|
||||
{
|
||||
if (!RenderPlugins.ContainsKey(handleType))
|
||||
{
|
||||
RenderPlugins.Add(handleType, render);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnData(LLUUID id, byte[] data)
|
||||
{
|
||||
if (Updaters.ContainsKey(id))
|
||||
{
|
||||
DynamicTextureUpdater updater = Updaters[id];
|
||||
if (RegisteredScenes.ContainsKey(updater.SimUUID))
|
||||
{
|
||||
Scene scene = RegisteredScenes[updater.SimUUID];
|
||||
updater.DataReceived(data, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
|
||||
string extraParams, int updateTimer)
|
||||
{
|
||||
if (RenderPlugins.ContainsKey(contentType))
|
||||
{
|
||||
//Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType);
|
||||
|
||||
DynamicTextureUpdater updater = new DynamicTextureUpdater();
|
||||
updater.SimUUID = simID;
|
||||
updater.PrimID = primID;
|
||||
updater.ContentType = contentType;
|
||||
updater.Url = url;
|
||||
updater.UpdateTimer = updateTimer;
|
||||
updater.UpdaterID = LLUUID.Random();
|
||||
updater.Params = extraParams;
|
||||
|
||||
if (!Updaters.ContainsKey(updater.UpdaterID))
|
||||
{
|
||||
Updaters.Add(updater.UpdaterID, updater);
|
||||
}
|
||||
|
||||
RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams);
|
||||
return updater.UpdaterID;
|
||||
}
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
|
||||
string extraParams, int updateTimer)
|
||||
{
|
||||
if (RenderPlugins.ContainsKey(contentType))
|
||||
{
|
||||
DynamicTextureUpdater updater = new DynamicTextureUpdater();
|
||||
updater.SimUUID = simID;
|
||||
updater.PrimID = primID;
|
||||
updater.ContentType = contentType;
|
||||
updater.BodyData = data;
|
||||
updater.UpdateTimer = updateTimer;
|
||||
updater.UpdaterID = LLUUID.Random();
|
||||
updater.Params = extraParams;
|
||||
|
||||
if (!Updaters.ContainsKey(updater.UpdaterID))
|
||||
{
|
||||
Updaters.Add(updater.UpdaterID, updater);
|
||||
}
|
||||
|
||||
RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams);
|
||||
return updater.UpdaterID;
|
||||
}
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
public class DynamicTextureUpdater
|
||||
{
|
||||
public LLUUID SimUUID;
|
||||
public LLUUID UpdaterID;
|
||||
public string ContentType;
|
||||
public string Url;
|
||||
public string BodyData;
|
||||
public LLUUID PrimID;
|
||||
public int UpdateTimer;
|
||||
public LLUUID LastAssetID;
|
||||
public string Params;
|
||||
|
||||
public DynamicTextureUpdater()
|
||||
{
|
||||
LastAssetID = LLUUID.Zero;
|
||||
UpdateTimer = 0;
|
||||
BodyData = null;
|
||||
}
|
||||
|
||||
public void DataReceived(byte[] data, Scene scene)
|
||||
{
|
||||
//TODO delete the last asset(data), if it was a dynamic texture
|
||||
byte[] assetData = new byte[data.Length];
|
||||
Array.Copy(data, assetData, data.Length);
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.FullID = LLUUID.Random();
|
||||
asset.Data = assetData;
|
||||
asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000);
|
||||
asset.Type = 0;
|
||||
asset.Description = "dynamic image";
|
||||
asset.Local = false;
|
||||
asset.Temporary = false;
|
||||
scene.AssetCache.AddAsset(asset);
|
||||
|
||||
LastAssetID = asset.FullID;
|
||||
|
||||
SceneObjectPart part = scene.GetSceneObjectPart(PrimID);
|
||||
part.Shape.Textures = new LLObject.TextureEntry(asset.FullID);
|
||||
part.ScheduleFullUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class DynamicTextureModule : IRegionModule, IDynamicTextureManager
|
||||
{
|
||||
private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
|
||||
|
||||
private Dictionary<string, IDynamicTextureRender> RenderPlugins =
|
||||
new Dictionary<string, IDynamicTextureRender>();
|
||||
|
||||
private Dictionary<LLUUID, DynamicTextureUpdater> Updaters = new Dictionary<LLUUID, DynamicTextureUpdater>();
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
|
||||
{
|
||||
RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
|
||||
scene.RegisterModuleInterface<IDynamicTextureManager>(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "DynamicTextureModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void RegisterRender(string handleType, IDynamicTextureRender render)
|
||||
{
|
||||
if (!RenderPlugins.ContainsKey(handleType))
|
||||
{
|
||||
RenderPlugins.Add(handleType, render);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnData(LLUUID id, byte[] data)
|
||||
{
|
||||
if (Updaters.ContainsKey(id))
|
||||
{
|
||||
DynamicTextureUpdater updater = Updaters[id];
|
||||
if (RegisteredScenes.ContainsKey(updater.SimUUID))
|
||||
{
|
||||
Scene scene = RegisteredScenes[updater.SimUUID];
|
||||
updater.DataReceived(data, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
|
||||
string extraParams, int updateTimer)
|
||||
{
|
||||
if (RenderPlugins.ContainsKey(contentType))
|
||||
{
|
||||
//Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType);
|
||||
|
||||
DynamicTextureUpdater updater = new DynamicTextureUpdater();
|
||||
updater.SimUUID = simID;
|
||||
updater.PrimID = primID;
|
||||
updater.ContentType = contentType;
|
||||
updater.Url = url;
|
||||
updater.UpdateTimer = updateTimer;
|
||||
updater.UpdaterID = LLUUID.Random();
|
||||
updater.Params = extraParams;
|
||||
|
||||
if (!Updaters.ContainsKey(updater.UpdaterID))
|
||||
{
|
||||
Updaters.Add(updater.UpdaterID, updater);
|
||||
}
|
||||
|
||||
RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams);
|
||||
return updater.UpdaterID;
|
||||
}
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
|
||||
string extraParams, int updateTimer)
|
||||
{
|
||||
if (RenderPlugins.ContainsKey(contentType))
|
||||
{
|
||||
DynamicTextureUpdater updater = new DynamicTextureUpdater();
|
||||
updater.SimUUID = simID;
|
||||
updater.PrimID = primID;
|
||||
updater.ContentType = contentType;
|
||||
updater.BodyData = data;
|
||||
updater.UpdateTimer = updateTimer;
|
||||
updater.UpdaterID = LLUUID.Random();
|
||||
updater.Params = extraParams;
|
||||
|
||||
if (!Updaters.ContainsKey(updater.UpdaterID))
|
||||
{
|
||||
Updaters.Add(updater.UpdaterID, updater);
|
||||
}
|
||||
|
||||
RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams);
|
||||
return updater.UpdaterID;
|
||||
}
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
public class DynamicTextureUpdater
|
||||
{
|
||||
public LLUUID SimUUID;
|
||||
public LLUUID UpdaterID;
|
||||
public string ContentType;
|
||||
public string Url;
|
||||
public string BodyData;
|
||||
public LLUUID PrimID;
|
||||
public int UpdateTimer;
|
||||
public LLUUID LastAssetID;
|
||||
public string Params;
|
||||
|
||||
public DynamicTextureUpdater()
|
||||
{
|
||||
LastAssetID = LLUUID.Zero;
|
||||
UpdateTimer = 0;
|
||||
BodyData = null;
|
||||
}
|
||||
|
||||
public void DataReceived(byte[] data, Scene scene)
|
||||
{
|
||||
//TODO delete the last asset(data), if it was a dynamic texture
|
||||
byte[] assetData = new byte[data.Length];
|
||||
Array.Copy(data, assetData, data.Length);
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.FullID = LLUUID.Random();
|
||||
asset.Data = assetData;
|
||||
asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000);
|
||||
asset.Type = 0;
|
||||
asset.Description = "dynamic image";
|
||||
asset.Local = false;
|
||||
asset.Temporary = true;
|
||||
scene.AssetCache.AddAsset(asset);
|
||||
|
||||
LastAssetID = asset.FullID;
|
||||
|
||||
SceneObjectPart part = scene.GetSceneObjectPart(PrimID);
|
||||
part.Shape.Textures = new LLObject.TextureEntry(asset.FullID);
|
||||
part.ScheduleFullUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
internal class EmailModule
|
||||
{
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
internal class EmailModule
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,233 +1,222 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using libsecondlife;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class FriendsModule : IRegionModule
|
||||
{
|
||||
|
||||
private LogBase m_log;
|
||||
|
||||
private Scene m_scene;
|
||||
|
||||
Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_log = MainLog.Instance;
|
||||
m_scene = scene;
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage;
|
||||
}
|
||||
|
||||
private void OnNewClient(IClientAPI client)
|
||||
{
|
||||
// All friends establishment protocol goes over instant message
|
||||
// There's no way to send a message from the sim
|
||||
// to a user to 'add a friend' without causing dialog box spam
|
||||
//
|
||||
// The base set of friends are added when the user signs on in their XMLRPC response
|
||||
// Generated by LoginService. The friends are retreived from the database by the UserManager
|
||||
|
||||
// Subscribe to instant messages
|
||||
client.OnInstantMessage += OnInstantMessage;
|
||||
client.OnApproveFriendRequest += OnApprovedFriendRequest;
|
||||
client.OnDenyFriendRequest += OnDenyFriendRequest;
|
||||
client.OnTerminateFriendship += OnTerminateFriendship;
|
||||
|
||||
|
||||
}
|
||||
private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID,
|
||||
LLUUID fromAgentSession, LLUUID toAgentID,
|
||||
LLUUID imSessionID, uint timestamp, string fromAgentName,
|
||||
string message, byte dialog, bool fromGroup, byte offline,
|
||||
uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
|
||||
byte[] binaryBucket)
|
||||
{
|
||||
// Friend Requests go by Instant Message.. using the dialog param
|
||||
// https://wiki.secondlife.com/wiki/ImprovedInstantMessage
|
||||
|
||||
// 38 == Offer friendship
|
||||
if (dialog == (byte)38)
|
||||
{
|
||||
LLUUID friendTransactionID = LLUUID.Random();
|
||||
|
||||
m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
|
||||
|
||||
m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.fromAgentID = fromAgentID.UUID;
|
||||
msg.fromAgentSession = fromAgentSession.UUID;
|
||||
msg.toAgentID = toAgentID.UUID;
|
||||
msg.imSessionID = friendTransactionID.UUID; // This is the item we're mucking with here
|
||||
m_log.Verbose("FRIEND","Filling Session: " + msg.imSessionID.ToString());
|
||||
msg.timestamp = timestamp;
|
||||
if (client != null)
|
||||
{
|
||||
msg.fromAgentName = client.FirstName + " " + client.LastName;// fromAgentName;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
|
||||
}
|
||||
msg.message = message;
|
||||
msg.dialog = dialog;
|
||||
msg.fromGroup = fromGroup;
|
||||
msg.offline = offline;
|
||||
msg.ParentEstateID = ParentEstateID;
|
||||
msg.Position = new sLLVector3(Position);
|
||||
msg.RegionID = RegionID.UUID;
|
||||
msg.binaryBucket = binaryBucket;
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
}
|
||||
if (dialog == (byte)39)
|
||||
{
|
||||
m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
|
||||
}
|
||||
if (dialog == (byte)40)
|
||||
{
|
||||
m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
}
|
||||
|
||||
// 39 == Accept Friendship
|
||||
|
||||
// 40 == Decline Friendship
|
||||
|
||||
}
|
||||
|
||||
private void OnApprovedFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders)
|
||||
{
|
||||
if (m_pendingFriendRequests.ContainsKey(transactionID))
|
||||
{
|
||||
// Found Pending Friend Request with that Transaction..
|
||||
|
||||
// Compose response to other agent.
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.toAgentID = m_pendingFriendRequests[transactionID].UUID;
|
||||
msg.fromAgentID = agentID.UUID;
|
||||
msg.fromAgentName = client.FirstName + " " + client.LastName;
|
||||
msg.fromAgentSession = client.SessionId.UUID;
|
||||
msg.fromGroup = false;
|
||||
msg.imSessionID = transactionID.UUID;
|
||||
msg.message = agentID.UUID.ToString();
|
||||
msg.ParentEstateID = 0;
|
||||
msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
|
||||
msg.RegionID = m_scene.RegionInfo.RegionID.UUID;
|
||||
msg.dialog = (byte)39;// Approved friend request
|
||||
msg.Position = new sLLVector3();
|
||||
msg.offline = (byte)0;
|
||||
msg.binaryBucket = new byte[0];
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
m_scene.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1);
|
||||
m_pendingFriendRequests.Remove(transactionID);
|
||||
|
||||
// TODO: Inform agent that the friend is online
|
||||
}
|
||||
}
|
||||
private void OnDenyFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders)
|
||||
{
|
||||
if (m_pendingFriendRequests.ContainsKey(transactionID))
|
||||
{
|
||||
// Found Pending Friend Request with that Transaction..
|
||||
|
||||
// Compose response to other agent.
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.toAgentID = m_pendingFriendRequests[transactionID].UUID;
|
||||
msg.fromAgentID = agentID.UUID;
|
||||
msg.fromAgentName = client.FirstName + " " + client.LastName;
|
||||
msg.fromAgentSession = client.SessionId.UUID;
|
||||
msg.fromGroup = false;
|
||||
msg.imSessionID = transactionID.UUID;
|
||||
msg.message = agentID.UUID.ToString();
|
||||
msg.ParentEstateID = 0;
|
||||
msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
|
||||
msg.RegionID = m_scene.RegionInfo.RegionID.UUID;
|
||||
msg.dialog = (byte)40;// Deny friend request
|
||||
msg.Position = new sLLVector3();
|
||||
msg.offline = (byte)0;
|
||||
msg.binaryBucket = new byte[0];
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
m_pendingFriendRequests.Remove(transactionID);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID)
|
||||
{
|
||||
m_scene.StoreRemoveFriendship(agent, exfriendID);
|
||||
// TODO: Inform the client that the ExFriend is offline
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
// Trigger the above event handler
|
||||
OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
|
||||
new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
|
||||
msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
|
||||
new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
|
||||
msg.binaryBucket);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "FriendsModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using libsecondlife;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class FriendsModule : IRegionModule
|
||||
{
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Scene m_scene;
|
||||
|
||||
Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage;
|
||||
}
|
||||
|
||||
private void OnNewClient(IClientAPI client)
|
||||
{
|
||||
// All friends establishment protocol goes over instant message
|
||||
// There's no way to send a message from the sim
|
||||
// to a user to 'add a friend' without causing dialog box spam
|
||||
//
|
||||
// The base set of friends are added when the user signs on in their XMLRPC response
|
||||
// Generated by LoginService. The friends are retreived from the database by the UserManager
|
||||
|
||||
// Subscribe to instant messages
|
||||
client.OnInstantMessage += OnInstantMessage;
|
||||
client.OnApproveFriendRequest += OnApprovedFriendRequest;
|
||||
client.OnDenyFriendRequest += OnDenyFriendRequest;
|
||||
client.OnTerminateFriendship += OnTerminateFriendship;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID,
|
||||
LLUUID fromAgentSession, LLUUID toAgentID,
|
||||
LLUUID imSessionID, uint timestamp, string fromAgentName,
|
||||
string message, byte dialog, bool fromGroup, byte offline,
|
||||
uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
|
||||
byte[] binaryBucket)
|
||||
{
|
||||
// Friend Requests go by Instant Message.. using the dialog param
|
||||
// https://wiki.secondlife.com/wiki/ImprovedInstantMessage
|
||||
|
||||
// 38 == Offer friendship
|
||||
if (dialog == (byte)38)
|
||||
{
|
||||
LLUUID friendTransactionID = LLUUID.Random();
|
||||
|
||||
m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
|
||||
|
||||
m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.fromAgentID = fromAgentID.UUID;
|
||||
msg.fromAgentSession = fromAgentSession.UUID;
|
||||
msg.toAgentID = toAgentID.UUID;
|
||||
msg.imSessionID = friendTransactionID.UUID; // This is the item we're mucking with here
|
||||
m_log.Info("[FRIEND]: Filling Session: " + msg.imSessionID.ToString());
|
||||
msg.timestamp = timestamp;
|
||||
if (client != null)
|
||||
{
|
||||
msg.fromAgentName = client.FirstName + " " + client.LastName;// fromAgentName;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
|
||||
}
|
||||
msg.message = message;
|
||||
msg.dialog = dialog;
|
||||
msg.fromGroup = fromGroup;
|
||||
msg.offline = offline;
|
||||
msg.ParentEstateID = ParentEstateID;
|
||||
msg.Position = new sLLVector3(Position);
|
||||
msg.RegionID = RegionID.UUID;
|
||||
msg.binaryBucket = binaryBucket;
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
}
|
||||
|
||||
// 39 == Accept Friendship
|
||||
if (dialog == (byte)39)
|
||||
{
|
||||
m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
}
|
||||
|
||||
// 40 == Decline Friendship
|
||||
if (dialog == (byte)40)
|
||||
{
|
||||
m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnApprovedFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders)
|
||||
{
|
||||
if (m_pendingFriendRequests.ContainsKey(transactionID))
|
||||
{
|
||||
// Found Pending Friend Request with that Transaction..
|
||||
|
||||
// Compose response to other agent.
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.toAgentID = m_pendingFriendRequests[transactionID].UUID;
|
||||
msg.fromAgentID = agentID.UUID;
|
||||
msg.fromAgentName = client.FirstName + " " + client.LastName;
|
||||
msg.fromAgentSession = client.SessionId.UUID;
|
||||
msg.fromGroup = false;
|
||||
msg.imSessionID = transactionID.UUID;
|
||||
msg.message = agentID.UUID.ToString();
|
||||
msg.ParentEstateID = 0;
|
||||
msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
|
||||
msg.RegionID = m_scene.RegionInfo.RegionID.UUID;
|
||||
msg.dialog = (byte)39;// Approved friend request
|
||||
msg.Position = new sLLVector3();
|
||||
msg.offline = (byte)0;
|
||||
msg.binaryBucket = new byte[0];
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
m_scene.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1);
|
||||
m_pendingFriendRequests.Remove(transactionID);
|
||||
|
||||
// TODO: Inform agent that the friend is online
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDenyFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders)
|
||||
{
|
||||
if (m_pendingFriendRequests.ContainsKey(transactionID))
|
||||
{
|
||||
// Found Pending Friend Request with that Transaction..
|
||||
|
||||
// Compose response to other agent.
|
||||
GridInstantMessage msg = new GridInstantMessage();
|
||||
msg.toAgentID = m_pendingFriendRequests[transactionID].UUID;
|
||||
msg.fromAgentID = agentID.UUID;
|
||||
msg.fromAgentName = client.FirstName + " " + client.LastName;
|
||||
msg.fromAgentSession = client.SessionId.UUID;
|
||||
msg.fromGroup = false;
|
||||
msg.imSessionID = transactionID.UUID;
|
||||
msg.message = agentID.UUID.ToString();
|
||||
msg.ParentEstateID = 0;
|
||||
msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
|
||||
msg.RegionID = m_scene.RegionInfo.RegionID.UUID;
|
||||
msg.dialog = (byte)40;// Deny friend request
|
||||
msg.Position = new sLLVector3();
|
||||
msg.offline = (byte)0;
|
||||
msg.binaryBucket = new byte[0];
|
||||
m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
|
||||
m_pendingFriendRequests.Remove(transactionID);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID)
|
||||
{
|
||||
m_scene.StoreRemoveFriendship(agent, exfriendID);
|
||||
// TODO: Inform the client that the ExFriend is offline
|
||||
}
|
||||
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
// Trigger the above event handler
|
||||
OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
|
||||
new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
|
||||
msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
|
||||
new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
|
||||
msg.binaryBucket);
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "FriendsModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,62 +1,279 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class GroupsModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "GroupsModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using libsecondlife;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class GroupsModule : IRegionModule
|
||||
{
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private List<Scene> m_scene = new List<Scene>();
|
||||
private Dictionary<LLUUID, IClientAPI> m_iclientmap = new Dictionary<LLUUID, IClientAPI>();
|
||||
private Dictionary<LLUUID, GroupData> m_groupmap = new Dictionary<LLUUID, GroupData>();
|
||||
private Dictionary<LLUUID, GroupList> m_grouplistmap = new Dictionary<LLUUID, GroupList>();
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
lock (m_scene)
|
||||
{
|
||||
m_scene.Add(scene);
|
||||
}
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
scene.EventManager.OnClientClosed += OnClientClosed;
|
||||
scene.EventManager.OnGridInstantMessageToGroupsModule += OnGridInstantMessage;
|
||||
//scene.EventManager.
|
||||
}
|
||||
private void OnNewClient(IClientAPI client)
|
||||
{
|
||||
// All friends establishment protocol goes over instant message
|
||||
// There's no way to send a message from the sim
|
||||
// to a user to 'add a friend' without causing dialog box spam
|
||||
//
|
||||
// The base set of friends are added when the user signs on in their XMLRPC response
|
||||
// Generated by LoginService. The friends are retreived from the database by the UserManager
|
||||
|
||||
// Subscribe to instant messages
|
||||
client.OnInstantMessage += OnInstantMessage;
|
||||
client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
|
||||
lock (m_iclientmap)
|
||||
{
|
||||
if (!m_iclientmap.ContainsKey(client.AgentId))
|
||||
{
|
||||
m_iclientmap.Add(client.AgentId, client);
|
||||
}
|
||||
}
|
||||
GroupData OpenSimulatorGroup = new GroupData();
|
||||
OpenSimulatorGroup.ActiveGroupTitle = "OpenSimulator Tester";
|
||||
OpenSimulatorGroup.GroupID = new LLUUID("00000000-68f9-1111-024e-222222111120");
|
||||
OpenSimulatorGroup.GroupMembers.Add(client.AgentId);
|
||||
OpenSimulatorGroup.groupName = "OpenSimulator Testing";
|
||||
OpenSimulatorGroup.ActiveGroupPowers = GroupPowers.LandAllowSetHome;
|
||||
OpenSimulatorGroup.GroupTitles.Add("OpenSimulator Tester");
|
||||
lock (m_groupmap)
|
||||
{
|
||||
if (!m_groupmap.ContainsKey(client.AgentId))
|
||||
{
|
||||
m_groupmap.Add(client.AgentId, OpenSimulatorGroup);
|
||||
}
|
||||
}
|
||||
GroupList testGroupList = new GroupList();
|
||||
testGroupList.m_GroupList.Add(new LLUUID("00000000-68f9-1111-024e-222222111120"));
|
||||
|
||||
lock (m_grouplistmap)
|
||||
{
|
||||
if (!m_grouplistmap.ContainsKey(client.AgentId))
|
||||
{
|
||||
m_grouplistmap.Add(client.AgentId, testGroupList);
|
||||
}
|
||||
}
|
||||
m_log.Info("[GROUP]: Adding " + client.FirstName + " " + client.LastName + " to OpenSimulator Tester group");
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnAgentDataUpdateRequest(IClientAPI remoteClient, LLUUID AgentID, LLUUID SessionID)
|
||||
{
|
||||
string firstname = remoteClient.FirstName;
|
||||
string lastname = remoteClient.LastName;
|
||||
|
||||
LLUUID ActiveGroupID = LLUUID.Zero;
|
||||
uint ActiveGroupPowers = 0;
|
||||
string ActiveGroupName = "";
|
||||
string ActiveGroupTitle = "";
|
||||
|
||||
bool foundUser = false;
|
||||
|
||||
lock (m_iclientmap)
|
||||
{
|
||||
if (m_iclientmap.ContainsKey(remoteClient.AgentId))
|
||||
{
|
||||
foundUser = true;
|
||||
}
|
||||
}
|
||||
if (foundUser)
|
||||
{
|
||||
lock (m_groupmap)
|
||||
{
|
||||
if (m_groupmap.ContainsKey(remoteClient.AgentId))
|
||||
{
|
||||
GroupData grp = m_groupmap[remoteClient.AgentId];
|
||||
if (grp != null)
|
||||
{
|
||||
ActiveGroupID = grp.GroupID;
|
||||
ActiveGroupName = grp.groupName;
|
||||
ActiveGroupPowers = grp.groupPowers;
|
||||
ActiveGroupTitle = grp.ActiveGroupTitle;
|
||||
}
|
||||
|
||||
//remoteClient.SendAgentDataUpdate(AgentID, ActiveGroupID, firstname, lastname, ActiveGroupPowers, ActiveGroupName, ActiveGroupTitle);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
|
||||
LLUUID fromAgentSession, LLUUID toAgentID,
|
||||
LLUUID imSessionID, uint timestamp, string fromAgentName,
|
||||
string message, byte dialog, bool fromGroup, byte offline,
|
||||
uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
|
||||
byte[] binaryBucket)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
// Trigger the above event handler
|
||||
OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
|
||||
new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
|
||||
msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
|
||||
new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
|
||||
msg.binaryBucket);
|
||||
}
|
||||
|
||||
private void OnClientClosed(LLUUID agentID)
|
||||
{
|
||||
lock (m_iclientmap)
|
||||
{
|
||||
if (m_iclientmap.ContainsKey(agentID))
|
||||
{
|
||||
IClientAPI cli = m_iclientmap[agentID];
|
||||
if (cli != null)
|
||||
{
|
||||
m_log.Info("[GROUP]: Removing all reference to groups for " + cli.FirstName + " " + cli.LastName);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Info("[GROUP]: Removing all reference to groups for " + agentID.ToString());
|
||||
}
|
||||
m_iclientmap.Remove(agentID);
|
||||
}
|
||||
}
|
||||
|
||||
lock (m_groupmap)
|
||||
{
|
||||
if (m_groupmap.ContainsKey(agentID))
|
||||
{
|
||||
m_groupmap.Remove(agentID);
|
||||
}
|
||||
}
|
||||
|
||||
lock (m_grouplistmap)
|
||||
{
|
||||
if (m_grouplistmap.ContainsKey(agentID))
|
||||
{
|
||||
m_grouplistmap.Remove(agentID);
|
||||
}
|
||||
}
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
m_log.Info("[GROUP]: Shutting down group module.");
|
||||
lock (m_iclientmap)
|
||||
{
|
||||
m_iclientmap.Clear();
|
||||
}
|
||||
|
||||
lock (m_groupmap)
|
||||
{
|
||||
m_groupmap.Clear();
|
||||
}
|
||||
|
||||
lock (m_grouplistmap)
|
||||
{
|
||||
m_grouplistmap.Clear();
|
||||
}
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "GroupsModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
}
|
||||
public class GroupData
|
||||
{
|
||||
public LLUUID GroupID;
|
||||
public string groupName;
|
||||
public string ActiveGroupTitle;
|
||||
public List<string> GroupTitles;
|
||||
public List<LLUUID> GroupMembers;
|
||||
public uint groupPowers = (uint)(GroupPowers.LandAllowLandmark | GroupPowers.LandAllowSetHome);
|
||||
|
||||
public GroupPowers ActiveGroupPowers
|
||||
{
|
||||
set
|
||||
{
|
||||
groupPowers = (uint) value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return (GroupPowers)groupPowers;
|
||||
}
|
||||
}
|
||||
|
||||
public GroupData()
|
||||
{
|
||||
GroupTitles = new List<string>();
|
||||
GroupMembers = new List<LLUUID>();
|
||||
}
|
||||
|
||||
}
|
||||
public class GroupList
|
||||
{
|
||||
public List<LLUUID> m_GroupList;
|
||||
public GroupList()
|
||||
{
|
||||
m_GroupList = new List<LLUUID>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,134 +1,127 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class InstantMessageModule : IRegionModule
|
||||
{
|
||||
private List<Scene> m_scenes = new List<Scene>();
|
||||
private LogBase m_log;
|
||||
|
||||
public InstantMessageModule()
|
||||
{
|
||||
m_log = MainLog.Instance;
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (!m_scenes.Contains(scene))
|
||||
{
|
||||
m_scenes.Add(scene);
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
scene.EventManager.OnGridInstantMessageToIMModule += OnGridInstantMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNewClient(IClientAPI client)
|
||||
{
|
||||
client.OnInstantMessage += OnInstantMessage;
|
||||
}
|
||||
|
||||
private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID,
|
||||
LLUUID fromAgentSession, LLUUID toAgentID,
|
||||
LLUUID imSessionID, uint timestamp, string fromAgentName,
|
||||
string message, byte dialog, bool fromGroup, byte offline,
|
||||
uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
|
||||
byte[] binaryBucket)
|
||||
{
|
||||
|
||||
bool FriendDialog = ((dialog == (byte)38) || (dialog == (byte)39) || (dialog == (byte)40));
|
||||
|
||||
// IM dialogs need to be pre-processed and have their sessionID filled by the server
|
||||
// so the sim can match the transaction on the return packet.
|
||||
|
||||
// Don't send a Friend Dialog IM with a LLUUID.Zero session.
|
||||
if (!(FriendDialog && imSessionID == LLUUID.Zero))
|
||||
{
|
||||
foreach (Scene scene in m_scenes)
|
||||
{
|
||||
if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
|
||||
{
|
||||
// Local message
|
||||
ScenePresence user = (ScenePresence)scene.Entities[toAgentID];
|
||||
if (!user.IsChildAgent)
|
||||
{
|
||||
user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
|
||||
toAgentID, imSessionID, fromAgentName, dialog,
|
||||
timestamp);
|
||||
// Message sent
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Still here, try send via Grid
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Trusty OSG1 called method. This method also gets called from the FriendsModule
|
||||
// Turns out the sim has to send an instant message to the user to get it to show an accepted friend.
|
||||
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
// Trigger the above event handler
|
||||
OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
|
||||
new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
|
||||
msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
|
||||
new LLVector3(msg.Position.x,msg.Position.y,msg.Position.z), new LLUUID(msg.RegionID),
|
||||
msg.binaryBucket);
|
||||
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "InstantMessageModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class InstantMessageModule : IRegionModule
|
||||
{
|
||||
private List<Scene> m_scenes = new List<Scene>();
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (!m_scenes.Contains(scene))
|
||||
{
|
||||
m_scenes.Add(scene);
|
||||
scene.EventManager.OnNewClient += OnNewClient;
|
||||
scene.EventManager.OnGridInstantMessageToIMModule += OnGridInstantMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNewClient(IClientAPI client)
|
||||
{
|
||||
client.OnInstantMessage += OnInstantMessage;
|
||||
}
|
||||
|
||||
private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID,
|
||||
LLUUID fromAgentSession, LLUUID toAgentID,
|
||||
LLUUID imSessionID, uint timestamp, string fromAgentName,
|
||||
string message, byte dialog, bool fromGroup, byte offline,
|
||||
uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
|
||||
byte[] binaryBucket)
|
||||
{
|
||||
bool FriendDialog = ((dialog == (byte)38) || (dialog == (byte)39) || (dialog == (byte)40));
|
||||
|
||||
// IM dialogs need to be pre-processed and have their sessionID filled by the server
|
||||
// so the sim can match the transaction on the return packet.
|
||||
|
||||
// Don't send a Friend Dialog IM with a LLUUID.Zero session.
|
||||
if (!(FriendDialog && imSessionID == LLUUID.Zero))
|
||||
{
|
||||
foreach (Scene scene in m_scenes)
|
||||
{
|
||||
if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence)
|
||||
{
|
||||
// Local message
|
||||
ScenePresence user = (ScenePresence)scene.Entities[toAgentID];
|
||||
if (!user.IsChildAgent)
|
||||
{
|
||||
user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message,
|
||||
toAgentID, imSessionID, fromAgentName, dialog,
|
||||
timestamp);
|
||||
// Message sent
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Still here, try send via Grid
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Trusty OSG1 called method. This method also gets called from the FriendsModule
|
||||
// Turns out the sim has to send an instant message to the user to get it to show an accepted friend.
|
||||
|
||||
private void OnGridInstantMessage(GridInstantMessage msg)
|
||||
{
|
||||
// Trigger the above event handler
|
||||
OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
|
||||
new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
|
||||
msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
|
||||
new LLVector3(msg.Position.x,msg.Position.y,msg.Position.z), new LLUUID(msg.RegionID),
|
||||
msg.binaryBucket);
|
||||
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "InstantMessageModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,62 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class InventoryModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "InventoryModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class InventoryModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "InventoryModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,149 +1,177 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenJPEGNet;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class LoadImageURLModule : IRegionModule, IDynamicTextureRender
|
||||
{
|
||||
private string m_name = "LoadImageURL";
|
||||
private IDynamicTextureManager m_textureManager;
|
||||
private Scene m_scene;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
|
||||
m_textureManager.RegisterRender(GetContentType(), this);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public string GetContentType()
|
||||
{
|
||||
return ("image");
|
||||
}
|
||||
|
||||
public bool SupportsAsynchronous()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] ConvertUrl(string url, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] ConvertStream(Stream data, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
|
||||
{
|
||||
MakeHttpRequest(url, id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private void MakeHttpRequest(string url, LLUUID requestID)
|
||||
{
|
||||
WebRequest request = HttpWebRequest.Create(url);
|
||||
RequestState state = new RequestState((HttpWebRequest) request, requestID);
|
||||
IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state);
|
||||
|
||||
TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
|
||||
state.TimeOfRequest = (int) t.TotalSeconds;
|
||||
}
|
||||
|
||||
private void HttpRequestReturn(IAsyncResult result)
|
||||
{
|
||||
RequestState state = (RequestState) result.AsyncState;
|
||||
WebRequest request = (WebRequest) state.Request;
|
||||
HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(result);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Bitmap image = new Bitmap(response.GetResponseStream());
|
||||
Bitmap resize = new Bitmap(image, new Size(512, 512));
|
||||
byte[] imageJ2000 = OpenJPEG.EncodeFromImage(resize, true);
|
||||
|
||||
m_textureManager.ReturnData(state.RequestID, imageJ2000);
|
||||
}
|
||||
}
|
||||
|
||||
public class RequestState
|
||||
{
|
||||
public HttpWebRequest Request = null;
|
||||
public LLUUID RequestID = LLUUID.Zero;
|
||||
public int TimeOfRequest = 0;
|
||||
|
||||
public RequestState(HttpWebRequest request, LLUUID requestID)
|
||||
{
|
||||
Request = request;
|
||||
RequestID = requestID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenJPEGNet;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class LoadImageURLModule : IRegionModule, IDynamicTextureRender
|
||||
{
|
||||
private string m_name = "LoadImageURL";
|
||||
private IDynamicTextureManager m_textureManager;
|
||||
private Scene m_scene;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
|
||||
m_textureManager.RegisterRender(GetContentType(), this);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public string GetContentType()
|
||||
{
|
||||
return ("image");
|
||||
}
|
||||
|
||||
public bool SupportsAsynchronous()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] ConvertUrl(string url, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] ConvertStream(Stream data, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
|
||||
{
|
||||
MakeHttpRequest(url, id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private void MakeHttpRequest(string url, LLUUID requestID)
|
||||
{
|
||||
WebRequest request = HttpWebRequest.Create(url);
|
||||
RequestState state = new RequestState((HttpWebRequest) request, requestID);
|
||||
IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state);
|
||||
|
||||
TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
|
||||
state.TimeOfRequest = (int) t.TotalSeconds;
|
||||
}
|
||||
|
||||
private void HttpRequestReturn(IAsyncResult result)
|
||||
{
|
||||
RequestState state = (RequestState) result.AsyncState;
|
||||
WebRequest request = (WebRequest) state.Request;
|
||||
HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(result);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Bitmap image = new Bitmap(response.GetResponseStream());
|
||||
Size newsize;
|
||||
|
||||
// TODO: make this a bit less hard coded
|
||||
if ((image.Height < 64) && (image.Width < 64))
|
||||
{
|
||||
newsize = new Size(32, 32);
|
||||
}
|
||||
else if ((image.Height < 128) && (image.Width < 128))
|
||||
{
|
||||
newsize = new Size(64, 64);
|
||||
}
|
||||
else if ((image.Height <256) && (image.Width < 256))
|
||||
{
|
||||
newsize = new Size(128, 128);
|
||||
}
|
||||
else if ((image.Height < 512 && image.Width < 512))
|
||||
{
|
||||
newsize = new Size(256, 256);
|
||||
}
|
||||
else if ((image.Height < 1024 && image.Width < 1024))
|
||||
{
|
||||
newsize = new Size(512, 512);
|
||||
}
|
||||
else
|
||||
{
|
||||
newsize = new Size(1024,1024);
|
||||
}
|
||||
|
||||
Bitmap resize = new Bitmap(image, newsize);
|
||||
byte[] imageJ2000 = OpenJPEG.EncodeFromImage(resize, true);
|
||||
|
||||
m_textureManager.ReturnData(state.RequestID, imageJ2000);
|
||||
}
|
||||
}
|
||||
|
||||
public class RequestState
|
||||
{
|
||||
public HttpWebRequest Request = null;
|
||||
public LLUUID RequestID = LLUUID.Zero;
|
||||
public int TimeOfRequest = 0;
|
||||
|
||||
public RequestState(HttpWebRequest request, LLUUID requestID)
|
||||
{
|
||||
Request = request;
|
||||
RequestID = requestID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,343 +1,361 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
/*****************************************************
|
||||
*
|
||||
* ScriptsHttpRequests
|
||||
*
|
||||
* Implements the llHttpRequest and http_response
|
||||
* callback.
|
||||
*
|
||||
* Some stuff was already in LSLLongCmdHandler, and then
|
||||
* there was this file with a stub class in it. So,
|
||||
* I am moving some of the objects and functions out of
|
||||
* LSLLongCmdHandler, such as the HttpRequestClass, the
|
||||
* start and stop methods, and setting up pending and
|
||||
* completed queues. These are processed in the
|
||||
* LSLLongCmdHandler polling loop. Similiar to the
|
||||
* XMLRPCModule, since that seems to work.
|
||||
*
|
||||
* //TODO
|
||||
*
|
||||
* This probably needs some throttling mechanism but
|
||||
* its wide open right now. This applies to both
|
||||
* number of requests and data volume.
|
||||
*
|
||||
* Linden puts all kinds of header fields in the requests.
|
||||
* Not doing any of that:
|
||||
* User-Agent
|
||||
* X-SecondLife-Shard
|
||||
* X-SecondLife-Object-Name
|
||||
* X-SecondLife-Object-Key
|
||||
* X-SecondLife-Region
|
||||
* X-SecondLife-Local-Position
|
||||
* X-SecondLife-Local-Velocity
|
||||
* X-SecondLife-Local-Rotation
|
||||
* X-SecondLife-Owner-Name
|
||||
* X-SecondLife-Owner-Key
|
||||
*
|
||||
* HTTPS support
|
||||
*
|
||||
* Configurable timeout?
|
||||
* Configurable max repsonse size?
|
||||
* Configurable
|
||||
*
|
||||
* **************************************************/
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class ScriptHTTPRequests : IRegionModule, IHttpRequests
|
||||
{
|
||||
private Scene m_scene;
|
||||
private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>();
|
||||
private object HttpListLock = new object();
|
||||
private string m_name = "HttpScriptRequests";
|
||||
private int httpTimeout = 300;
|
||||
|
||||
// <request id, HttpRequestClass>
|
||||
private Dictionary<LLUUID, HttpRequestClass> m_pendingRequests;
|
||||
|
||||
public ScriptHTTPRequests()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
|
||||
m_scene.RegisterModuleInterface<IHttpRequests>(this);
|
||||
|
||||
m_pendingRequests = new Dictionary<LLUUID, HttpRequestClass>();
|
||||
}
|
||||
|
||||
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<string> 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]))
|
||||
{
|
||||
case HttpRequestClass.HTTP_METHOD:
|
||||
|
||||
htc.httpMethod = parms[i + 1];
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_MIMETYPE:
|
||||
|
||||
htc.httpMIMEType = parms[i + 1];
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_BODY_MAXLENGTH:
|
||||
|
||||
// TODO implement me
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_VERIFY_CERT:
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* Not sure how important ordering is is here - the next first
|
||||
* one completed in the list is returned, based soley on its list
|
||||
* position, not the order in which the request was started or
|
||||
* 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)
|
||||
{
|
||||
foreach (LLUUID luid in m_pendingRequests.Keys)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
|
||||
if (m_pendingRequests.TryGetValue(luid, out tmpReq))
|
||||
{
|
||||
if (tmpReq.finished)
|
||||
{
|
||||
m_pendingRequests.Remove(luid);
|
||||
return tmpReq;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// HTTP REAQUEST
|
||||
// This class was originally in LSLLongCmdHandler
|
||||
//
|
||||
// TODO: setter/getter methods, maybe pass some in
|
||||
// constructor
|
||||
//
|
||||
|
||||
public class HttpRequestClass
|
||||
{
|
||||
// Constants for parameters
|
||||
public const int HTTP_METHOD = 0;
|
||||
public const int HTTP_MIMETYPE = 1;
|
||||
public const int HTTP_BODY_MAXLENGTH = 2;
|
||||
public const int HTTP_VERIFY_CERT = 3;
|
||||
|
||||
// Parameter members and default values
|
||||
public string httpMethod = "GET";
|
||||
public string httpMIMEType = "text/plain;charset=utf-8";
|
||||
public int httpBodyMaxLen = 2048; // not implemented
|
||||
public bool httpVerifyCert = true; // not implemented
|
||||
|
||||
// Request info
|
||||
public uint localID;
|
||||
public LLUUID itemID;
|
||||
public LLUUID reqID;
|
||||
public int httpTimeout;
|
||||
public string url;
|
||||
public string outbound_body;
|
||||
public DateTime next;
|
||||
public int status;
|
||||
public bool finished;
|
||||
public List<string> response_metadata;
|
||||
public string response_body;
|
||||
public HttpWebRequest request;
|
||||
private Thread httpThread;
|
||||
|
||||
public void process()
|
||||
{
|
||||
httpThread = new Thread(SendRequest);
|
||||
httpThread.Name = "HttpRequestThread";
|
||||
httpThread.Priority = ThreadPriority.BelowNormal;
|
||||
httpThread.IsBackground = true;
|
||||
httpThread.Start();
|
||||
}
|
||||
|
||||
/*
|
||||
* 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];
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
try
|
||||
{
|
||||
request = (HttpWebRequest)
|
||||
WebRequest.Create(url);
|
||||
request.Method = httpMethod;
|
||||
request.ContentType = httpMIMEType;
|
||||
|
||||
request.Timeout = httpTimeout;
|
||||
// execute the request
|
||||
response = (HttpWebResponse)
|
||||
request.GetResponse();
|
||||
|
||||
Stream resStream = response.GetResponseStream();
|
||||
|
||||
do
|
||||
{
|
||||
// fill the buffer with data
|
||||
count = resStream.Read(buf, 0, buf.Length);
|
||||
|
||||
// make sure we read some data
|
||||
if (count != 0)
|
||||
{
|
||||
// translate from bytes to ASCII text
|
||||
tempString = Encoding.ASCII.GetString(buf, 0, count);
|
||||
|
||||
// continue building the string
|
||||
sb.Append(tempString);
|
||||
}
|
||||
} while (count > 0); // any more data to read?
|
||||
|
||||
response_body = sb.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
status = 499;
|
||||
response_body = e.Message;
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
|
||||
status = 200;
|
||||
finished = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
try
|
||||
{
|
||||
httpThread.Abort();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
/*****************************************************
|
||||
*
|
||||
* ScriptsHttpRequests
|
||||
*
|
||||
* Implements the llHttpRequest and http_response
|
||||
* callback.
|
||||
*
|
||||
* Some stuff was already in LSLLongCmdHandler, and then
|
||||
* there was this file with a stub class in it. So,
|
||||
* I am moving some of the objects and functions out of
|
||||
* LSLLongCmdHandler, such as the HttpRequestClass, the
|
||||
* start and stop methods, and setting up pending and
|
||||
* completed queues. These are processed in the
|
||||
* LSLLongCmdHandler polling loop. Similiar to the
|
||||
* XMLRPCModule, since that seems to work.
|
||||
*
|
||||
* //TODO
|
||||
*
|
||||
* This probably needs some throttling mechanism but
|
||||
* its wide open right now. This applies to both
|
||||
* number of requests and data volume.
|
||||
*
|
||||
* Linden puts all kinds of header fields in the requests.
|
||||
* Not doing any of that:
|
||||
* User-Agent
|
||||
* X-SecondLife-Shard
|
||||
* X-SecondLife-Object-Name
|
||||
* X-SecondLife-Object-Key
|
||||
* X-SecondLife-Region
|
||||
* X-SecondLife-Local-Position
|
||||
* X-SecondLife-Local-Velocity
|
||||
* X-SecondLife-Local-Rotation
|
||||
* X-SecondLife-Owner-Name
|
||||
* X-SecondLife-Owner-Key
|
||||
*
|
||||
* HTTPS support
|
||||
*
|
||||
* Configurable timeout?
|
||||
* Configurable max repsonse size?
|
||||
* Configurable
|
||||
*
|
||||
* **************************************************/
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class ScriptHTTPRequests : IRegionModule, IHttpRequests
|
||||
{
|
||||
private Scene m_scene;
|
||||
private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>();
|
||||
private object HttpListLock = new object();
|
||||
private string m_name = "HttpScriptRequests";
|
||||
private int httpTimeout = 30000;
|
||||
|
||||
// <request id, HttpRequestClass>
|
||||
private Dictionary<LLUUID, HttpRequestClass> m_pendingRequests;
|
||||
|
||||
public ScriptHTTPRequests()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
|
||||
m_scene.RegisterModuleInterface<IHttpRequests>(this);
|
||||
|
||||
m_pendingRequests = new Dictionary<LLUUID, HttpRequestClass>();
|
||||
}
|
||||
|
||||
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<string> 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]))
|
||||
{
|
||||
case HttpRequestClass.HTTP_METHOD:
|
||||
|
||||
htc.httpMethod = parms[i + 1];
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_MIMETYPE:
|
||||
|
||||
htc.httpMIMEType = parms[i + 1];
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_BODY_MAXLENGTH:
|
||||
|
||||
// TODO implement me
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_VERIFY_CERT:
|
||||
|
||||
// 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)
|
||||
{
|
||||
if(m_pendingRequests != null) {
|
||||
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
|
||||
* position, not the order in which the request was started or
|
||||
* 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)
|
||||
{
|
||||
foreach (LLUUID luid in m_pendingRequests.Keys)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
|
||||
if (m_pendingRequests.TryGetValue(luid, out tmpReq))
|
||||
{
|
||||
if (tmpReq.finished)
|
||||
{
|
||||
return tmpReq;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void RemoveCompletedRequest(LLUUID id)
|
||||
{
|
||||
lock (HttpListLock)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
if (m_pendingRequests.TryGetValue(id, out tmpReq))
|
||||
{
|
||||
tmpReq.Stop();
|
||||
tmpReq = null;
|
||||
m_pendingRequests.Remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// HTTP REAQUEST
|
||||
// This class was originally in LSLLongCmdHandler
|
||||
//
|
||||
// TODO: setter/getter methods, maybe pass some in
|
||||
// constructor
|
||||
//
|
||||
|
||||
public class HttpRequestClass
|
||||
{
|
||||
// Constants for parameters
|
||||
public const int HTTP_METHOD = 0;
|
||||
public const int HTTP_MIMETYPE = 1;
|
||||
public const int HTTP_BODY_MAXLENGTH = 2;
|
||||
public const int HTTP_VERIFY_CERT = 3;
|
||||
|
||||
// Parameter members and default values
|
||||
public string httpMethod = "GET";
|
||||
public string httpMIMEType = "text/plain;charset=utf-8";
|
||||
public int httpBodyMaxLen = 2048; // not implemented
|
||||
public bool httpVerifyCert = true; // not implemented
|
||||
|
||||
// Request info
|
||||
public uint localID;
|
||||
public LLUUID itemID;
|
||||
public LLUUID reqID;
|
||||
public int httpTimeout;
|
||||
public string url;
|
||||
public string outbound_body;
|
||||
public DateTime next;
|
||||
public int status;
|
||||
public bool finished;
|
||||
public List<string> response_metadata;
|
||||
public string response_body;
|
||||
public HttpWebRequest request;
|
||||
private Thread httpThread;
|
||||
|
||||
public void process()
|
||||
{
|
||||
httpThread = new Thread(SendRequest);
|
||||
httpThread.Name = "HttpRequestThread";
|
||||
httpThread.Priority = ThreadPriority.BelowNormal;
|
||||
httpThread.IsBackground = true;
|
||||
finished = false;
|
||||
httpThread.Start();
|
||||
OpenSim.Framework.ThreadTracker.Add(httpThread);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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];
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
try
|
||||
{
|
||||
request = (HttpWebRequest)
|
||||
WebRequest.Create(url);
|
||||
request.Method = httpMethod;
|
||||
request.ContentType = httpMIMEType;
|
||||
|
||||
request.Timeout = httpTimeout;
|
||||
// execute the request
|
||||
response = (HttpWebResponse)
|
||||
request.GetResponse();
|
||||
|
||||
Stream resStream = response.GetResponseStream();
|
||||
|
||||
do
|
||||
{
|
||||
// fill the buffer with data
|
||||
count = resStream.Read(buf, 0, buf.Length);
|
||||
|
||||
// make sure we read some data
|
||||
if (count != 0)
|
||||
{
|
||||
// translate from bytes to ASCII text
|
||||
tempString = Encoding.ASCII.GetString(buf, 0, count);
|
||||
|
||||
// continue building the string
|
||||
sb.Append(tempString);
|
||||
}
|
||||
} while (count > 0); // any more data to read?
|
||||
|
||||
response_body = sb.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
status = 499;
|
||||
response_body = e.Message;
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
|
||||
status = 200;
|
||||
finished = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
try
|
||||
{
|
||||
httpThread.Abort();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,194 +1,194 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class SunModule : IRegionModule
|
||||
{
|
||||
private const double m_real_day = 24.0;
|
||||
private const int m_default_frame = 100;
|
||||
private int m_frame_mod;
|
||||
private double m_day_length;
|
||||
private int m_dilation;
|
||||
private int m_frame;
|
||||
private long m_start;
|
||||
|
||||
private Scene m_scene;
|
||||
private LogBase m_log;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_start = DateTime.Now.Ticks;
|
||||
m_frame = 0;
|
||||
|
||||
// Just in case they don't have the stanzas
|
||||
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)
|
||||
{
|
||||
m_day_length = m_real_day;
|
||||
m_frame_mod = m_default_frame;
|
||||
}
|
||||
|
||||
m_dilation = (int) (m_real_day/m_day_length);
|
||||
m_scene = scene;
|
||||
m_log = MainLog.Instance;
|
||||
scene.EventManager.OnFrame += SunUpdate;
|
||||
scene.EventManager.OnNewClient += SunToClient;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "SunModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void SunToClient(IClientAPI client)
|
||||
{
|
||||
client.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f));
|
||||
}
|
||||
|
||||
public void SunUpdate()
|
||||
{
|
||||
if (m_frame < m_frame_mod)
|
||||
{
|
||||
m_frame++;
|
||||
return;
|
||||
}
|
||||
// m_log.Verbose("SUN","I've got an update {0} => {1}", m_scene.RegionsInfo.RegionName, HourOfTheDay());
|
||||
List<ScenePresence> avatars = m_scene.GetAvatars();
|
||||
foreach (ScenePresence avatar in avatars)
|
||||
{
|
||||
avatar.ControllingClient.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f));
|
||||
}
|
||||
m_frame = 0;
|
||||
}
|
||||
|
||||
// Hour of the Day figures out the hour of the day as a float.
|
||||
// The intent here is that we seed hour of the day with real
|
||||
// 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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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 z = Math.Sin(rad);
|
||||
double x = Math.Cos(rad);
|
||||
return new LLVector3((float) x, 0f, (float) z);
|
||||
}
|
||||
|
||||
// TODO: clear this out. This is here so that I remember to
|
||||
// figure out if we need those other packet fields that I've
|
||||
// left out so far
|
||||
//
|
||||
// public void SendViewerTime(int phase)
|
||||
// {
|
||||
// Console.WriteLine("SunPhase: {0}", phase);
|
||||
// SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket();
|
||||
// //viewertime.TimeInfo.SecPerDay = 86400;
|
||||
// // viewertime.TimeInfo.SecPerYear = 31536000;
|
||||
// viewertime.TimeInfo.SecPerDay = 1000;
|
||||
// viewertime.TimeInfo.SecPerYear = 365000;
|
||||
// viewertime.TimeInfo.SunPhase = 1;
|
||||
// int sunPhase = (phase + 2)/2;
|
||||
// if ((sunPhase < 6) || (sunPhase > 36))
|
||||
// {
|
||||
// viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
|
||||
// Console.WriteLine("sending night");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (sunPhase < 12)
|
||||
// {
|
||||
// sunPhase = 12;
|
||||
// }
|
||||
// sunPhase = sunPhase - 12;
|
||||
//
|
||||
// float yValue = 0.1f*(sunPhase);
|
||||
// Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
|
||||
// if (yValue > 1.2f)
|
||||
// {
|
||||
// yValue = yValue - 1.2f;
|
||||
// }
|
||||
// if (yValue > 1)
|
||||
// {
|
||||
// yValue = 1;
|
||||
// }
|
||||
// if (yValue < 0)
|
||||
// {
|
||||
// yValue = 0;
|
||||
// }
|
||||
// if (sunPhase < 14)
|
||||
// {
|
||||
// yValue = 1 - yValue;
|
||||
// }
|
||||
// if (sunPhase < 12)
|
||||
// {
|
||||
// yValue *= -1;
|
||||
// }
|
||||
// viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
|
||||
// Console.WriteLine("sending sun update " + yValue);
|
||||
// }
|
||||
// viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
|
||||
// viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch();
|
||||
// // OutPacket(viewertime);
|
||||
// }
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class SunModule : IRegionModule
|
||||
{
|
||||
//private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private const double m_real_day = 24.0;
|
||||
private const int m_default_frame = 100;
|
||||
private int m_frame_mod;
|
||||
private double m_day_length;
|
||||
private int m_dilation;
|
||||
private int m_frame;
|
||||
private long m_start;
|
||||
|
||||
private Scene m_scene;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_start = DateTime.Now.Ticks;
|
||||
m_frame = 0;
|
||||
|
||||
// Just in case they don't have the stanzas
|
||||
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)
|
||||
{
|
||||
m_day_length = m_real_day;
|
||||
m_frame_mod = m_default_frame;
|
||||
}
|
||||
|
||||
m_dilation = (int) (m_real_day/m_day_length);
|
||||
m_scene = scene;
|
||||
scene.EventManager.OnFrame += SunUpdate;
|
||||
scene.EventManager.OnNewClient += SunToClient;
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "SunModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void SunToClient(IClientAPI client)
|
||||
{
|
||||
client.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f));
|
||||
}
|
||||
|
||||
public void SunUpdate()
|
||||
{
|
||||
if (m_frame < m_frame_mod)
|
||||
{
|
||||
m_frame++;
|
||||
return;
|
||||
}
|
||||
// m_log.InfoFormat("[SUN]: I've got an update {0} => {1}", m_scene.RegionsInfo.RegionName, HourOfTheDay());
|
||||
List<ScenePresence> avatars = m_scene.GetAvatars();
|
||||
foreach (ScenePresence avatar in avatars)
|
||||
{
|
||||
avatar.ControllingClient.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f));
|
||||
}
|
||||
m_frame = 0;
|
||||
}
|
||||
|
||||
// Hour of the Day figures out the hour of the day as a float.
|
||||
// The intent here is that we seed hour of the day with real
|
||||
// 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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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 z = Math.Sin(rad);
|
||||
double x = Math.Cos(rad);
|
||||
return new LLVector3((float) x, 0f, (float) z);
|
||||
}
|
||||
|
||||
// TODO: clear this out. This is here so that I remember to
|
||||
// figure out if we need those other packet fields that I've
|
||||
// left out so far
|
||||
//
|
||||
// public void SendViewerTime(int phase)
|
||||
// {
|
||||
// Console.WriteLine("SunPhase: {0}", phase);
|
||||
// SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket();
|
||||
// //viewertime.TimeInfo.SecPerDay = 86400;
|
||||
// // viewertime.TimeInfo.SecPerYear = 31536000;
|
||||
// viewertime.TimeInfo.SecPerDay = 1000;
|
||||
// viewertime.TimeInfo.SecPerYear = 365000;
|
||||
// viewertime.TimeInfo.SunPhase = 1;
|
||||
// int sunPhase = (phase + 2)/2;
|
||||
// if ((sunPhase < 6) || (sunPhase > 36))
|
||||
// {
|
||||
// viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
|
||||
// Console.WriteLine("sending night");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (sunPhase < 12)
|
||||
// {
|
||||
// sunPhase = 12;
|
||||
// }
|
||||
// sunPhase = sunPhase - 12;
|
||||
//
|
||||
// float yValue = 0.1f*(sunPhase);
|
||||
// Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
|
||||
// if (yValue > 1.2f)
|
||||
// {
|
||||
// yValue = yValue - 1.2f;
|
||||
// }
|
||||
// if (yValue > 1)
|
||||
// {
|
||||
// yValue = 1;
|
||||
// }
|
||||
// if (yValue < 0)
|
||||
// {
|
||||
// yValue = 0;
|
||||
// }
|
||||
// if (sunPhase < 14)
|
||||
// {
|
||||
// yValue = 1 - yValue;
|
||||
// }
|
||||
// if (sunPhase < 12)
|
||||
// {
|
||||
// yValue *= -1;
|
||||
// }
|
||||
// viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
|
||||
// Console.WriteLine("sending sun update " + yValue);
|
||||
// }
|
||||
// viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
|
||||
// viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch();
|
||||
// // OutPacket(viewertime);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
internal class TeleportModule
|
||||
{
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
internal class TeleportModule
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using Nini.Config;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Modules;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using libsecondlife;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Terrain
|
||||
{
|
||||
/// <summary>
|
||||
/// A new version of the old Channel class, simplified
|
||||
/// </summary>
|
||||
public class TerrainChannel : ITerrainChannel
|
||||
{
|
||||
private double[,] map;
|
||||
|
||||
public int Width
|
||||
{
|
||||
get { return map.GetLength(0); }
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get { return map.GetLength(1); }
|
||||
}
|
||||
|
||||
public TerrainChannel Copy()
|
||||
{
|
||||
TerrainChannel copy = new TerrainChannel(false);
|
||||
copy.map = (double[,])this.map.Clone();
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
public double this[int x, int y]
|
||||
{
|
||||
get
|
||||
{
|
||||
return map[x, y];
|
||||
}
|
||||
set
|
||||
{
|
||||
map[x, y] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public TerrainChannel()
|
||||
{
|
||||
map = new double[Constants.RegionSize, Constants.RegionSize];
|
||||
}
|
||||
|
||||
public TerrainChannel(bool createMap)
|
||||
{
|
||||
if (createMap)
|
||||
map = new double[Constants.RegionSize, Constants.RegionSize];
|
||||
}
|
||||
|
||||
public TerrainChannel(int w, int h)
|
||||
{
|
||||
map = new double[w, h];
|
||||
}
|
||||
}
|
||||
|
||||
public class TerrainModule : IRegionModule
|
||||
{
|
||||
Scene m_scene;
|
||||
|
||||
private IConfigSource m_gConfig;
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_gConfig = config;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "TerrainModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,174 +1,216 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
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;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
//this is a first attempt, to start breaking the mess thats called the assetcache up.
|
||||
// basically this should be the texture sending (to clients) code moved out of assetcache
|
||||
//and some small clean up
|
||||
// but on first tests it didn't seem to work very well so is currently not in use.
|
||||
public class TextureDownloadModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
private List<Scene> m_scenes = new List<Scene>();
|
||||
|
||||
private readonly BlockingQueue<TextureSender> m_queueSenders = new BlockingQueue<TextureSender>();
|
||||
|
||||
private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices =
|
||||
new Dictionary<LLUUID, UserTextureDownloadService>();
|
||||
|
||||
private Thread m_thread;
|
||||
|
||||
public TextureDownloadModule()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (m_scene == null)
|
||||
{
|
||||
//Console.WriteLine("Creating Texture download module");
|
||||
m_thread = new Thread(new ThreadStart(ProcessTextureSenders));
|
||||
m_thread.IsBackground = true;
|
||||
m_thread.Start();
|
||||
}
|
||||
|
||||
if (!m_scenes.Contains(scene))
|
||||
{
|
||||
m_scenes.Add(scene);
|
||||
m_scene = scene;
|
||||
m_scene.EventManager.OnNewClient += NewClient;
|
||||
m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence;
|
||||
}
|
||||
}
|
||||
|
||||
private void EventManager_OnRemovePresence(LLUUID agentId)
|
||||
{
|
||||
UserTextureDownloadService textureService;
|
||||
|
||||
lock (m_userTextureServices)
|
||||
{
|
||||
if( m_userTextureServices.TryGetValue( agentId, out textureService ))
|
||||
{
|
||||
textureService.Close();
|
||||
|
||||
m_userTextureServices.Remove(agentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "TextureDownloadModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnRequestTexture += TextureRequest;
|
||||
}
|
||||
|
||||
private bool TryGetUserTextureService(LLUUID userID, out UserTextureDownloadService textureService)
|
||||
{
|
||||
lock (m_userTextureServices)
|
||||
{
|
||||
if (m_userTextureServices.TryGetValue(userID, out textureService))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
textureService = new UserTextureDownloadService(m_scene, m_queueSenders);
|
||||
m_userTextureServices.Add(userID, textureService);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void TextureRequest(Object sender, TextureRequestArgs e)
|
||||
{
|
||||
IClientAPI client = (IClientAPI) sender;
|
||||
UserTextureDownloadService textureService;
|
||||
if (TryGetUserTextureService(client.AgentId, out textureService))
|
||||
{
|
||||
textureService.HandleTextureRequest(client, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void ProcessTextureSenders()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
TextureSender sender = m_queueSenders.Dequeue();
|
||||
if (sender.Cancel)
|
||||
{
|
||||
TextureSent(sender);
|
||||
|
||||
sender.Cancel = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool finished = sender.SendTexturePacket();
|
||||
if (finished)
|
||||
{
|
||||
TextureSent(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_queueSenders.Enqueue(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TextureSent(TextureSender sender)
|
||||
{
|
||||
sender.Sending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
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;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
//this is a first attempt, to start breaking the mess thats called the assetcache up.
|
||||
// basically this should be the texture sending (to clients) code moved out of assetcache
|
||||
//and some small clean up
|
||||
public class TextureDownloadModule : IRegionModule
|
||||
{
|
||||
//private static readonly log4net.ILog m_log
|
||||
// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Scene m_scene;
|
||||
private List<Scene> m_scenes = new List<Scene>();
|
||||
|
||||
/// <summary>
|
||||
/// There is one queue for all textures waiting to be sent, regardless of the requesting user.
|
||||
/// </summary>
|
||||
private readonly BlockingQueue<TextureSender> m_queueSenders = new BlockingQueue<TextureSender>();
|
||||
|
||||
/// <summary>
|
||||
/// Each user has their own texture download service.
|
||||
/// </summary>
|
||||
private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices =
|
||||
new Dictionary<LLUUID, UserTextureDownloadService>();
|
||||
|
||||
private Thread m_thread;
|
||||
|
||||
public TextureDownloadModule()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (m_scene == null)
|
||||
{
|
||||
//Console.WriteLine("Creating Texture download module");
|
||||
m_thread = new Thread(new ThreadStart(ProcessTextureSenders));
|
||||
m_thread.Name = "ProcessTextureSenderThread";
|
||||
m_thread.IsBackground = true;
|
||||
m_thread.Start();
|
||||
OpenSim.Framework.ThreadTracker.Add(m_thread);
|
||||
}
|
||||
|
||||
if (!m_scenes.Contains(scene))
|
||||
{
|
||||
m_scenes.Add(scene);
|
||||
m_scene = scene;
|
||||
m_scene.EventManager.OnNewClient += NewClient;
|
||||
m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanup the texture service related objects for the removed presence.
|
||||
/// </summary>
|
||||
/// <param name="agentId"> </param>
|
||||
private void EventManager_OnRemovePresence(LLUUID agentId)
|
||||
{
|
||||
UserTextureDownloadService textureService;
|
||||
|
||||
lock (m_userTextureServices)
|
||||
{
|
||||
if (m_userTextureServices.TryGetValue(agentId, out textureService))
|
||||
{
|
||||
textureService.Close();
|
||||
|
||||
m_userTextureServices.Remove(agentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "TextureDownloadModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnRequestTexture += TextureRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does this user have a registered texture download service?
|
||||
/// </summary>
|
||||
/// <param name="userID"></param>
|
||||
/// <param name="textureService"></param>
|
||||
/// <returns>Always returns true, since a service is created if one does not already exist</returns>
|
||||
private bool TryGetUserTextureService(LLUUID userID, out UserTextureDownloadService textureService)
|
||||
{
|
||||
lock (m_userTextureServices)
|
||||
{
|
||||
if (m_userTextureServices.TryGetValue(userID, out textureService))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
textureService = new UserTextureDownloadService(m_scene, m_queueSenders);
|
||||
m_userTextureServices.Add(userID, textureService);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the process of requesting a given texture.
|
||||
/// </summary>
|
||||
/// <param name="sender"> </param>
|
||||
/// <param name="e"></param>
|
||||
public void TextureRequest(Object sender, TextureRequestArgs e)
|
||||
{
|
||||
IClientAPI client = (IClientAPI) sender;
|
||||
UserTextureDownloadService textureService;
|
||||
if (TryGetUserTextureService(client.AgentId, out textureService))
|
||||
{
|
||||
textureService.HandleTextureRequest(client, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entry point for the thread dedicated to processing the texture queue.
|
||||
/// </summary>
|
||||
public void ProcessTextureSenders()
|
||||
{
|
||||
TextureSender sender = null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
sender = m_queueSenders.Dequeue();
|
||||
|
||||
if (sender.Cancel)
|
||||
{
|
||||
TextureSent(sender);
|
||||
|
||||
sender.Cancel = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool finished = sender.SendTexturePacket();
|
||||
if (finished)
|
||||
{
|
||||
TextureSent(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_queueSenders.Enqueue(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure that any sender we currently have can get garbage collected
|
||||
sender = null;
|
||||
|
||||
//m_log.InfoFormat("[TEXTURE DOWNLOAD] Texture sender queue size: {0}", m_queueSenders.Count());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the texture has finished sending.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
private void TextureSent(TextureSender sender)
|
||||
{
|
||||
sender.Sending = false;
|
||||
//m_log.DebugFormat("[TEXTURE DOWNLOAD]: Removing download stat for {0}", sender.assetID);
|
||||
m_scene.AddPendingDownloads(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,136 +1,204 @@
|
|||
using System;
|
||||
using libsecondlife;
|
||||
using libsecondlife.Packets;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class TextureSender
|
||||
{
|
||||
public int counter = 0;
|
||||
private AssetBase m_asset;
|
||||
public long DataPointer = 0;
|
||||
public int NumPackets = 0;
|
||||
public int PacketCounter = 0;
|
||||
public bool Cancel = false;
|
||||
public bool ImageLoaded = false;
|
||||
|
||||
public bool Sending = false;
|
||||
|
||||
public IClientAPI RequestUser;
|
||||
public LLUUID RequestedAssetID;
|
||||
public int RequestedDiscardLevel = -1;
|
||||
public uint StartPacketNumber = 0;
|
||||
|
||||
// private int m_sentDiscardLevel = -1;
|
||||
|
||||
public TextureSender(IClientAPI client, LLUUID textureID, int discardLevel, uint packetNumber)
|
||||
{
|
||||
RequestUser = client;
|
||||
RequestedAssetID = textureID;
|
||||
RequestedDiscardLevel = discardLevel;
|
||||
StartPacketNumber = packetNumber;
|
||||
}
|
||||
|
||||
public void TextureReceived(AssetBase asset)
|
||||
{
|
||||
m_asset = asset;
|
||||
NumPackets = CalculateNumPackets(asset.Data.Length);
|
||||
PacketCounter = (int) StartPacketNumber;
|
||||
ImageLoaded = true;
|
||||
}
|
||||
|
||||
public void UpdateRequest(int discardLevel, uint packetNumber)
|
||||
{
|
||||
RequestedDiscardLevel = discardLevel;
|
||||
StartPacketNumber = packetNumber;
|
||||
PacketCounter = (int) StartPacketNumber;
|
||||
}
|
||||
|
||||
public bool SendTexturePacket()
|
||||
{
|
||||
SendPacket();
|
||||
counter++;
|
||||
if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) ||
|
||||
((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1)))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SendPacket()
|
||||
{
|
||||
if (PacketCounter <= NumPackets)
|
||||
{
|
||||
if (PacketCounter == 0)
|
||||
{
|
||||
if (NumPackets == 0)
|
||||
{
|
||||
ImageDataPacket im = new ImageDataPacket();
|
||||
im.Header.Reliable = false;
|
||||
im.ImageID.Packets = 1;
|
||||
im.ImageID.ID = m_asset.FullID;
|
||||
im.ImageID.Size = (uint) m_asset.Data.Length;
|
||||
im.ImageData.Data = m_asset.Data;
|
||||
im.ImageID.Codec = 2;
|
||||
RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
|
||||
PacketCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageDataPacket im = new ImageDataPacket();
|
||||
im.Header.Reliable = false;
|
||||
im.ImageID.Packets = (ushort) (NumPackets);
|
||||
im.ImageID.ID = m_asset.FullID;
|
||||
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;
|
||||
RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
|
||||
PacketCounter++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImagePacketPacket im = new ImagePacketPacket();
|
||||
im.Header.Reliable = false;
|
||||
im.ImageID.Packet = (ushort) (PacketCounter);
|
||||
im.ImageID.ID = m_asset.FullID;
|
||||
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);
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
MainLog.Instance.Error("TEXTURE",
|
||||
"Unable to separate texture into multiple packets: Array bounds failure on asset:" +
|
||||
m_asset.FullID.ToString() );
|
||||
return;
|
||||
}
|
||||
RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
|
||||
PacketCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int CalculateNumPackets(int length)
|
||||
{
|
||||
int numPackets = 0;
|
||||
|
||||
if (length > 600)
|
||||
{
|
||||
//over 600 bytes so split up file
|
||||
int restData = (length - 600);
|
||||
int restPackets = ((restData + 999)/1000);
|
||||
numPackets = restPackets;
|
||||
}
|
||||
|
||||
return numPackets;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using libsecondlife;
|
||||
using libsecondlife.Packets;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
/// <summary>
|
||||
/// A TextureSender handles the process of receiving a texture requested by the client from the
|
||||
/// AssetCache, and then sending that texture back to the client.
|
||||
/// </summary>
|
||||
public class TextureSender
|
||||
{
|
||||
private static readonly log4net.ILog m_log
|
||||
= log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// Records the number of times texture send has been called.
|
||||
/// </summary>
|
||||
public int counter = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the texture asset to send.
|
||||
/// </summary>
|
||||
private AssetBase m_asset;
|
||||
|
||||
//public LLUUID assetID { get { return m_asset.FullID; } }
|
||||
|
||||
/// <summary>
|
||||
/// This is actually the number of extra packets required to send the texture data! We always assume
|
||||
/// at least one is required.
|
||||
/// </summary>
|
||||
private int NumPackets = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the packet number to send next. In this case, each packet is 1000 bytes long and starts
|
||||
/// at the 600th byte (0th indexed).
|
||||
/// </summary>
|
||||
private int PacketCounter = 0;
|
||||
|
||||
public bool Cancel = false;
|
||||
public bool ImageLoaded = false;
|
||||
public bool Sending = false;
|
||||
|
||||
private IClientAPI RequestUser;
|
||||
|
||||
private int RequestedDiscardLevel = -1;
|
||||
private uint StartPacketNumber = 0;
|
||||
|
||||
public TextureSender(IClientAPI client, int discardLevel, uint packetNumber)
|
||||
{
|
||||
RequestUser = client;
|
||||
RequestedDiscardLevel = discardLevel;
|
||||
StartPacketNumber = packetNumber;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load up the texture data to send.
|
||||
/// </summary>
|
||||
/// <param name="asset">
|
||||
/// A <see cref="AssetBase"/>
|
||||
/// </param>
|
||||
public void TextureReceived(AssetBase asset)
|
||||
{
|
||||
m_asset = asset;
|
||||
NumPackets = CalculateNumPackets(asset.Data.Length);
|
||||
PacketCounter = (int) StartPacketNumber;
|
||||
ImageLoaded = true;
|
||||
}
|
||||
|
||||
public void UpdateRequest(int discardLevel, uint packetNumber)
|
||||
{
|
||||
RequestedDiscardLevel = discardLevel;
|
||||
StartPacketNumber = packetNumber;
|
||||
PacketCounter = (int) StartPacketNumber;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a texture packet to the client.
|
||||
/// </summary>
|
||||
/// <returns>True if the last packet has been sent, false otherwise.</returns>
|
||||
public bool SendTexturePacket()
|
||||
{
|
||||
SendPacket();
|
||||
counter++;
|
||||
if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) ||
|
||||
((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1)))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a texture packet to the client.
|
||||
/// </summary>
|
||||
private void SendPacket()
|
||||
{
|
||||
if (PacketCounter <= NumPackets)
|
||||
{
|
||||
if (PacketCounter == 0)
|
||||
{
|
||||
if (NumPackets == 0)
|
||||
{
|
||||
ImageDataPacket im = new ImageDataPacket();
|
||||
im.Header.Reliable = false;
|
||||
im.ImageID.Packets = 1;
|
||||
im.ImageID.ID = m_asset.FullID;
|
||||
im.ImageID.Size = (uint) m_asset.Data.Length;
|
||||
im.ImageData.Data = m_asset.Data;
|
||||
im.ImageID.Codec = 2;
|
||||
RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
|
||||
PacketCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageDataPacket im = new ImageDataPacket();
|
||||
im.Header.Reliable = false;
|
||||
im.ImageID.Packets = (ushort) (NumPackets);
|
||||
im.ImageID.ID = m_asset.FullID;
|
||||
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;
|
||||
RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
|
||||
PacketCounter++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImagePacketPacket im = new ImagePacketPacket();
|
||||
im.Header.Reliable = false;
|
||||
im.ImageID.Packet = (ushort) (PacketCounter);
|
||||
im.ImageID.ID = m_asset.FullID;
|
||||
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);
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
m_log.Error("[TEXTURE]: Unable to separate texture into multiple packets: Array bounds failure on asset:" +
|
||||
m_asset.FullID.ToString() );
|
||||
return;
|
||||
}
|
||||
RequestUser.OutPacket(im, ThrottleOutPacketType.Texture);
|
||||
PacketCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the number of packets that will be required to send the texture loaded into this sender
|
||||
/// This is actually the number of 1000 byte packets not including an initial 600 byte packet...
|
||||
/// </summary>
|
||||
/// <param name="length"></param>
|
||||
/// <returns></returns>
|
||||
private int CalculateNumPackets(int length)
|
||||
{
|
||||
int numPackets = 0;
|
||||
|
||||
if (length > 600)
|
||||
{
|
||||
//over 600 bytes so split up file
|
||||
int restData = (length - 600);
|
||||
int restPackets = ((restData + 999)/1000);
|
||||
numPackets = restPackets;
|
||||
}
|
||||
|
||||
return numPackets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
/// <summary>
|
||||
/// Version 2.0 - Very hacky compared to the original. Will fix original and release as 0.3 later.
|
||||
/// </summary>
|
||||
public class TreePopulatorModule : IRegionModule
|
||||
{
|
||||
private Scene m_scene;
|
||||
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private List<LLUUID> m_trees;
|
||||
|
||||
public double m_tree_density = 50.0; // Aim for this many per region
|
||||
public double m_tree_updates = 1000.0; // MS between updates
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_tree_density = config.Configs["Trees"].GetDouble("tree_density", m_tree_density);
|
||||
}
|
||||
catch (Exception)
|
||||
{ }
|
||||
|
||||
m_trees = new List<LLUUID>();
|
||||
m_scene = scene;
|
||||
|
||||
m_scene.EventManager.OnPluginConsole += new EventManager.OnPluginConsoleDelegate(EventManager_OnPluginConsole);
|
||||
|
||||
System.Timers.Timer CalculateTrees = new System.Timers.Timer(m_tree_updates);
|
||||
CalculateTrees.Elapsed += new System.Timers.ElapsedEventHandler(CalculateTrees_Elapsed);
|
||||
CalculateTrees.Start();
|
||||
m_log.Debug("[TREES]: Initialised tree module");
|
||||
}
|
||||
|
||||
void EventManager_OnPluginConsole(string[] args)
|
||||
{
|
||||
if (args[0] == "tree")
|
||||
{
|
||||
m_log.Debug("[TREES]: New tree planting");
|
||||
CreateTree(new LLVector3(128.0f, 128.0f, 0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
void growTrees()
|
||||
{
|
||||
foreach (LLUUID tree in m_trees)
|
||||
{
|
||||
if (m_scene.Entities.ContainsKey(tree))
|
||||
{
|
||||
SceneObjectPart s_tree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart;
|
||||
|
||||
// 100 seconds to grow 1m
|
||||
s_tree.Scale += new LLVector3(0.1f, 0.1f, 0.1f);
|
||||
s_tree.SendFullUpdateToAllClients();
|
||||
//s_tree.ScheduleTerseUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_trees.Remove(tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void seedTrees()
|
||||
{
|
||||
foreach (LLUUID tree in m_trees)
|
||||
{
|
||||
if (m_scene.Entities.ContainsKey(tree))
|
||||
{
|
||||
SceneObjectPart s_tree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart;
|
||||
|
||||
if (s_tree.Scale.X > 0.5)
|
||||
{
|
||||
if (Util.RandomClass.NextDouble() > 0.75)
|
||||
{
|
||||
SpawnChild(s_tree);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_trees.Remove(tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void killTrees()
|
||||
{
|
||||
foreach (LLUUID tree in m_trees)
|
||||
{
|
||||
double killLikelyhood = 0.0;
|
||||
|
||||
if (m_scene.Entities.ContainsKey(tree))
|
||||
{
|
||||
SceneObjectPart selectedTree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart;
|
||||
double selectedTreeScale = Math.Sqrt(Math.Pow(selectedTree.Scale.X, 2) +
|
||||
Math.Pow(selectedTree.Scale.Y, 2) +
|
||||
Math.Pow(selectedTree.Scale.Z, 2));
|
||||
|
||||
foreach (LLUUID picktree in m_trees)
|
||||
{
|
||||
if (picktree != tree)
|
||||
{
|
||||
SceneObjectPart pickedTree = ((SceneObjectGroup)m_scene.Entities[picktree]).RootPart;
|
||||
|
||||
double pickedTreeScale = Math.Sqrt(Math.Pow(pickedTree.Scale.X, 2) +
|
||||
Math.Pow(pickedTree.Scale.Y, 2) +
|
||||
Math.Pow(pickedTree.Scale.Z, 2));
|
||||
|
||||
double pickedTreeDistance = Math.Sqrt(Math.Pow(Math.Abs(pickedTree.AbsolutePosition.X - selectedTree.AbsolutePosition.X), 2) +
|
||||
Math.Pow(Math.Abs(pickedTree.AbsolutePosition.Y - selectedTree.AbsolutePosition.Y), 2) +
|
||||
Math.Pow(Math.Abs(pickedTree.AbsolutePosition.Z - selectedTree.AbsolutePosition.Z), 2));
|
||||
|
||||
killLikelyhood += (selectedTreeScale / (pickedTreeScale * pickedTreeDistance)) * 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Util.RandomClass.NextDouble() < killLikelyhood)
|
||||
{
|
||||
m_scene.RemoveEntity(selectedTree.ParentGroup);
|
||||
m_trees.Remove(selectedTree.ParentGroup.UUID);
|
||||
|
||||
m_scene.ForEachClient(delegate(IClientAPI controller)
|
||||
{
|
||||
controller.SendKillObject(m_scene.RegionInfo.RegionHandle,
|
||||
selectedTree.LocalID);
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedTree.SetText(killLikelyhood.ToString(), new Axiom.Math.Vector3(1.0f, 1.0f, 1.0f), 1.0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_trees.Remove(tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnChild(SceneObjectPart s_tree)
|
||||
{
|
||||
LLVector3 position = new LLVector3();
|
||||
|
||||
position.X = s_tree.AbsolutePosition.X + (1 * (-1 * Util.RandomClass.Next(1)));
|
||||
if (position.X > 255)
|
||||
position.X = 255;
|
||||
if (position.X < 0)
|
||||
position.X = 0;
|
||||
position.Y = s_tree.AbsolutePosition.Y + (1 * (-1 * Util.RandomClass.Next(1)));
|
||||
if (position.Y > 255)
|
||||
position.Y = 255;
|
||||
if (position.Y < 0)
|
||||
position.Y = 0;
|
||||
|
||||
double randX = ((Util.RandomClass.NextDouble() * 2.0) - 1.0) * (s_tree.Scale.X * 3);
|
||||
double randY = ((Util.RandomClass.NextDouble() * 2.0) - 1.0) * (s_tree.Scale.X * 3);
|
||||
|
||||
position.X += (float)randX;
|
||||
position.Y += (float)randY;
|
||||
|
||||
CreateTree(position);
|
||||
}
|
||||
|
||||
private void CreateTree(LLVector3 position)
|
||||
{
|
||||
position.Z = (float)m_scene.Terrain.heightmap.Get((int)position.X, (int)position.Y);
|
||||
|
||||
SceneObjectGroup tree =
|
||||
m_scene.AddTree(new LLVector3(0.1f, 0.1f, 0.1f),
|
||||
LLQuaternion.Identity,
|
||||
position,
|
||||
Tree.Cypress1,
|
||||
false);
|
||||
|
||||
m_trees.Add(tree.UUID);
|
||||
tree.SendGroupFullUpdate();
|
||||
}
|
||||
|
||||
void CalculateTrees_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
growTrees();
|
||||
seedTrees();
|
||||
killTrees();
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "TreePopulatorModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,109 +1,191 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class UserTextureDownloadService
|
||||
{
|
||||
private readonly Dictionary<LLUUID, TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender>();
|
||||
private readonly BlockingQueue<TextureSender> m_sharedSendersQueue;
|
||||
private readonly Scene m_scene;
|
||||
|
||||
public UserTextureDownloadService(Scene scene, BlockingQueue<TextureSender> sharedQueue)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_sharedSendersQueue = sharedQueue;
|
||||
}
|
||||
|
||||
public void HandleTextureRequest(IClientAPI client, TextureRequestArgs e)
|
||||
{
|
||||
TextureSender textureSender;
|
||||
|
||||
//TODO: should be working out the data size/ number of packets to be sent for each discard level
|
||||
if ((e.DiscardLevel >= 0) || (e.Priority != 0))
|
||||
{
|
||||
lock (m_textureSenders)
|
||||
{
|
||||
if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender))
|
||||
{
|
||||
textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber);
|
||||
|
||||
if ((textureSender.ImageLoaded) &&
|
||||
(textureSender.Sending == false))
|
||||
{
|
||||
EnqueueTextureSender(textureSender);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TextureSender requestHandler =
|
||||
new TextureSender(client, e.RequestedAssetID, e.DiscardLevel, e.PacketNumber);
|
||||
m_textureSenders.Add(e.RequestedAssetID, requestHandler);
|
||||
m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lock (m_textureSenders)
|
||||
{
|
||||
if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender))
|
||||
{
|
||||
textureSender.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TextureCallback(LLUUID textureID, AssetBase asset)
|
||||
{
|
||||
lock (m_textureSenders)
|
||||
{
|
||||
TextureSender textureSender;
|
||||
|
||||
if (m_textureSenders.TryGetValue(textureID, out textureSender))
|
||||
{
|
||||
if (!textureSender.ImageLoaded)
|
||||
{
|
||||
textureSender.TextureReceived(asset);
|
||||
|
||||
EnqueueTextureSender(textureSender);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Got a texture with no sender object to handle it, this shouldn't happen");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnqueueTextureSender(TextureSender textureSender)
|
||||
{
|
||||
textureSender.Cancel = false;
|
||||
textureSender.Sending = true;
|
||||
textureSender.counter = 0;
|
||||
|
||||
if (!m_sharedSendersQueue.Contains(textureSender))
|
||||
{
|
||||
m_sharedSendersQueue.Enqueue(textureSender);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Close()
|
||||
{
|
||||
lock (m_textureSenders)
|
||||
{
|
||||
foreach( TextureSender textureSender in m_textureSenders.Values )
|
||||
{
|
||||
textureSender.Cancel = true;
|
||||
}
|
||||
|
||||
m_textureSenders.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
/// <summary>
|
||||
/// This module sets up texture senders in response to client texture requests, and places them on a
|
||||
/// processing queue once those senders have the appropriate data (i.e. a texture retrieved from the
|
||||
/// asset cache).
|
||||
/// </summary>
|
||||
public class UserTextureDownloadService
|
||||
{
|
||||
private static readonly log4net.ILog m_log
|
||||
= log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
/// <summary>
|
||||
/// Holds texture senders before they have received the appropriate texture from the asset cache.
|
||||
/// </summary>
|
||||
private readonly Dictionary<LLUUID, TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender>();
|
||||
|
||||
/// <summary>
|
||||
/// Texture Senders are placed in this queue once they have received their texture from the asset
|
||||
/// cache. Another module actually invokes the send.
|
||||
/// </summary>
|
||||
private readonly BlockingQueue<TextureSender> m_sharedSendersQueue;
|
||||
|
||||
private readonly Scene m_scene;
|
||||
|
||||
public UserTextureDownloadService(Scene scene, BlockingQueue<TextureSender> sharedQueue)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_sharedSendersQueue = sharedQueue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle a texture request. This involves creating a texture sender and placing it on the
|
||||
/// previously passed in shared queue.
|
||||
/// </summary>
|
||||
/// <param name="client"> </param>
|
||||
/// <param name="e"></param>
|
||||
public void HandleTextureRequest(IClientAPI client, TextureRequestArgs e)
|
||||
{
|
||||
TextureSender textureSender;
|
||||
|
||||
//TODO: should be working out the data size/ number of packets to be sent for each discard level
|
||||
if ((e.DiscardLevel >= 0) || (e.Priority != 0))
|
||||
{
|
||||
lock (m_textureSenders)
|
||||
{
|
||||
if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender))
|
||||
{
|
||||
// If we've received new non UUID information for this request and it hasn't dispatched
|
||||
// yet, then update the request accordingly.
|
||||
textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_log.DebugFormat("[USER TEXTURE DOWNLOAD]: Adding download stat {0}", e.RequestedAssetID);
|
||||
m_scene.AddPendingDownloads(1);
|
||||
|
||||
TextureSender requestHandler =
|
||||
new TextureSender(client, e.DiscardLevel, e.PacketNumber);
|
||||
m_textureSenders.Add(e.RequestedAssetID, requestHandler);
|
||||
|
||||
m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lock (m_textureSenders)
|
||||
{
|
||||
if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender))
|
||||
{
|
||||
textureSender.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The callback for the asset cache when a texture has been retrieved. This method queues the
|
||||
/// texture sender for processing.
|
||||
/// </summary>
|
||||
/// <param name="textureID"></param>
|
||||
/// <param name="asset"></param>
|
||||
public void TextureCallback(LLUUID textureID, AssetBase texture)
|
||||
{
|
||||
lock (m_textureSenders)
|
||||
{
|
||||
TextureSender textureSender;
|
||||
|
||||
if (m_textureSenders.TryGetValue(textureID, out textureSender))
|
||||
{
|
||||
if (null != texture)
|
||||
{
|
||||
if (!textureSender.ImageLoaded)
|
||||
{
|
||||
textureSender.TextureReceived(texture);
|
||||
EnqueueTextureSender(textureSender);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Right now, leaving it up to lower level asset server code to post the fact that
|
||||
// this texture could not be found
|
||||
|
||||
// TODO Send packet back to the client telling it not to expect the texture
|
||||
|
||||
//m_log.DebugFormat("[USER TEXTURE DOWNLOAD]: Removing download stat for {0}", textureID);
|
||||
m_scene.AddPendingDownloads(-1);
|
||||
}
|
||||
|
||||
//m_log.InfoFormat("[TEXTURE SENDER] Removing texture sender with uuid {0}", textureID);
|
||||
m_textureSenders.Remove(textureID);
|
||||
//m_log.InfoFormat("[TEXTURE SENDER] Current texture senders in dictionary: {0}", m_textureSenders.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat(
|
||||
"Got a texture uuid {0} with no sender object to handle it, this shouldn't happen",
|
||||
textureID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Place a ready texture sender on the processing queue.
|
||||
/// </summary>
|
||||
/// <param name="textureSender"></param>
|
||||
private void EnqueueTextureSender(TextureSender textureSender)
|
||||
{
|
||||
textureSender.Cancel = false;
|
||||
textureSender.Sending = true;
|
||||
textureSender.counter = 0;
|
||||
|
||||
if (!m_sharedSendersQueue.Contains(textureSender))
|
||||
{
|
||||
m_sharedSendersQueue.Enqueue(textureSender);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close this module.
|
||||
/// </summary>
|
||||
internal void Close()
|
||||
{
|
||||
lock (m_textureSenders)
|
||||
{
|
||||
foreach( TextureSender textureSender in m_textureSenders.Values )
|
||||
{
|
||||
textureSender.Cancel = true;
|
||||
}
|
||||
|
||||
m_textureSenders.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,202 +1,226 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class XferModule : IRegionModule, IXfer
|
||||
{
|
||||
public Dictionary<string, byte[]> NewFiles = new Dictionary<string, byte[]>();
|
||||
public Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>();
|
||||
|
||||
private Scene m_scene;
|
||||
|
||||
public XferModule()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_scene.EventManager.OnNewClient += NewClient;
|
||||
|
||||
m_scene.RegisterModuleInterface<IXfer>(this);
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "XferModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnRequestXfer += RequestXfer;
|
||||
client.OnConfirmXfer += AckPacket;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="xferID"></param>
|
||||
/// <param name="fileName"></param>
|
||||
public void RequestXfer(IClientAPI remoteClient, ulong xferID, string fileName)
|
||||
{
|
||||
lock (NewFiles)
|
||||
{
|
||||
if (NewFiles.ContainsKey(fileName))
|
||||
{
|
||||
if (!Transfers.ContainsKey(xferID))
|
||||
{
|
||||
byte[] fileData = NewFiles[fileName];
|
||||
XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient);
|
||||
Transfers.Add(xferID, transaction);
|
||||
NewFiles.Remove(fileName);
|
||||
transaction.StartSend();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AckPacket(IClientAPI remoteClient, ulong xferID, uint packet)
|
||||
{
|
||||
if (Transfers.ContainsKey(xferID))
|
||||
{
|
||||
Transfers[xferID].AckPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public bool AddNewFile(string fileName, byte[] data)
|
||||
{
|
||||
lock (NewFiles)
|
||||
{
|
||||
if (NewFiles.ContainsKey(fileName))
|
||||
{
|
||||
NewFiles[fileName] = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
NewFiles.Add(fileName, data);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public class XferDownLoad
|
||||
{
|
||||
public byte[] Data = new byte[0];
|
||||
public string FileName = "";
|
||||
public ulong XferID = 0;
|
||||
public int DataPointer = 0;
|
||||
public uint Packet = 0;
|
||||
public IClientAPI Client;
|
||||
public uint Serial = 1;
|
||||
private bool complete = false;
|
||||
|
||||
public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client)
|
||||
{
|
||||
FileName = fileName;
|
||||
Data = data;
|
||||
XferID = xferID;
|
||||
Client = client;
|
||||
}
|
||||
|
||||
public XferDownLoad()
|
||||
{
|
||||
}
|
||||
|
||||
public void StartSend()
|
||||
{
|
||||
if (Data.Length < 1000)
|
||||
{
|
||||
// for now (testing ) we only support files under 1000 bytes
|
||||
byte[] transferData = new byte[Data.Length + 4];
|
||||
Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4);
|
||||
Array.Copy(Data, 0, transferData, 4, Data.Length);
|
||||
Client.SendXferPacket(XferID, 0 + 0x80000000, transferData);
|
||||
complete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] transferData = new byte[1000 + 4];
|
||||
Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4);
|
||||
Array.Copy(Data, 0, transferData, 4, 1000);
|
||||
Client.SendXferPacket(XferID, 0, transferData);
|
||||
Packet++;
|
||||
DataPointer = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
public void AckPacket(uint packet)
|
||||
{
|
||||
if (!complete)
|
||||
{
|
||||
if ((Data.Length - DataPointer) > 1000)
|
||||
{
|
||||
byte[] transferData = new byte[1000];
|
||||
Array.Copy(Data, DataPointer, transferData, 0, 1000);
|
||||
Client.SendXferPacket(XferID, Packet, transferData);
|
||||
Packet++;
|
||||
DataPointer += 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] transferData = new byte[Data.Length - DataPointer];
|
||||
Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer);
|
||||
uint endPacket = Packet |= (uint) 0x80000000;
|
||||
Client.SendXferPacket(XferID, endPacket, transferData);
|
||||
Packet++;
|
||||
DataPointer += (Data.Length - DataPointer);
|
||||
complete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules
|
||||
{
|
||||
public class XferModule : IRegionModule, IXfer
|
||||
{
|
||||
public Dictionary<string, byte[]> NewFiles = new Dictionary<string, byte[]>();
|
||||
public Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>();
|
||||
|
||||
private Scene m_scene;
|
||||
|
||||
public XferModule()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
m_scene.EventManager.OnNewClient += NewClient;
|
||||
|
||||
m_scene.RegisterModuleInterface<IXfer>(this);
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "XferModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void NewClient(IClientAPI client)
|
||||
{
|
||||
client.OnRequestXfer += RequestXfer;
|
||||
client.OnConfirmXfer += AckPacket;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="xferID"></param>
|
||||
/// <param name="fileName"></param>
|
||||
public void RequestXfer(IClientAPI remoteClient, ulong xferID, string fileName)
|
||||
{
|
||||
lock (NewFiles)
|
||||
{
|
||||
if (NewFiles.ContainsKey(fileName))
|
||||
{
|
||||
if (!Transfers.ContainsKey(xferID))
|
||||
{
|
||||
byte[] fileData = NewFiles[fileName];
|
||||
XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient);
|
||||
Transfers.Add(xferID, transaction);
|
||||
NewFiles.Remove(fileName);
|
||||
|
||||
if (transaction.StartSend())
|
||||
{
|
||||
Transfers.Remove(xferID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AckPacket(IClientAPI remoteClient, ulong xferID, uint packet)
|
||||
{
|
||||
if (Transfers.ContainsKey(xferID))
|
||||
{
|
||||
if (Transfers[xferID].AckPacket(packet))
|
||||
{
|
||||
{
|
||||
Transfers.Remove(xferID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool AddNewFile(string fileName, byte[] data)
|
||||
{
|
||||
lock (NewFiles)
|
||||
{
|
||||
if (NewFiles.ContainsKey(fileName))
|
||||
{
|
||||
NewFiles[fileName] = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
NewFiles.Add(fileName, data);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public class XferDownLoad
|
||||
{
|
||||
public byte[] Data = new byte[0];
|
||||
public string FileName = String.Empty;
|
||||
public ulong XferID = 0;
|
||||
public int DataPointer = 0;
|
||||
public uint Packet = 0;
|
||||
public IClientAPI Client;
|
||||
public uint Serial = 1;
|
||||
private bool complete;
|
||||
|
||||
public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client)
|
||||
{
|
||||
FileName = fileName;
|
||||
Data = data;
|
||||
XferID = xferID;
|
||||
Client = client;
|
||||
}
|
||||
|
||||
public XferDownLoad()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a transfer
|
||||
/// </summary>
|
||||
/// <returns>True if the transfer is complete, false if not</returns>
|
||||
public bool StartSend()
|
||||
{
|
||||
if (Data.Length < 1000)
|
||||
{
|
||||
// for now (testing ) we only support files under 1000 bytes
|
||||
byte[] transferData = new byte[Data.Length + 4];
|
||||
Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4);
|
||||
Array.Copy(Data, 0, transferData, 4, Data.Length);
|
||||
Client.SendXferPacket(XferID, 0 + 0x80000000, transferData);
|
||||
|
||||
complete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] transferData = new byte[1000 + 4];
|
||||
Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4);
|
||||
Array.Copy(Data, 0, transferData, 4, 1000);
|
||||
Client.SendXferPacket(XferID, 0, transferData);
|
||||
Packet++;
|
||||
DataPointer = 1000;
|
||||
}
|
||||
|
||||
return complete;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Respond to an ack packet from the client
|
||||
/// </summary>
|
||||
/// <param name="packet"></param>
|
||||
/// <returns>True if the transfer is complete, false otherwise</returns>
|
||||
public bool AckPacket(uint packet)
|
||||
{
|
||||
if (!complete)
|
||||
{
|
||||
if ((Data.Length - DataPointer) > 1000)
|
||||
{
|
||||
byte[] transferData = new byte[1000];
|
||||
Array.Copy(Data, DataPointer, transferData, 0, 1000);
|
||||
Client.SendXferPacket(XferID, Packet, transferData);
|
||||
Packet++;
|
||||
DataPointer += 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] transferData = new byte[Data.Length - DataPointer];
|
||||
Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer);
|
||||
uint endPacket = Packet |= (uint) 0x80000000;
|
||||
Client.SendXferPacket(XferID, endPacket, transferData);
|
||||
Packet++;
|
||||
DataPointer += (Data.Length - DataPointer);
|
||||
|
||||
complete = true;
|
||||
}
|
||||
}
|
||||
|
||||
return complete;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue