Disallow bulk uploads if money module is present and upload cost
is set and the user hasn't got sufficient funds.
0.6.0-stable
Melanie Thielker 2008-08-23 00:44:06 +00:00
parent 50bf3618a3
commit 5d6f92fb96
5 changed files with 80 additions and 6 deletions

View File

@ -34,6 +34,9 @@ using libsecondlife;
using log4net;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Servers;
using OpenSim.Framework;
using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Framework.Communications.Capabilities
{
@ -606,6 +609,29 @@ namespace OpenSim.Framework.Communications.Capabilities
/// <returns></returns>
public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest)
{
if (llsdRequest.asset_type == "texture" ||
llsdRequest.asset_type == "animation" ||
llsdRequest.asset_type == "sound")
{
IClientAPI client = GetClient(m_agentID);
Scene scene = (Scene)client.Scene;
IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>();
if(mm != null)
{
if(!mm.UploadCovered(client))
{
client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
errorResponse.uploader = "";
errorResponse.state = "error";
return errorResponse;
}
}
}
//Console.WriteLine("asset upload request via CAPS" + llsdRequest.inventory_type +" , "+ llsdRequest.asset_type);
string assetName = llsdRequest.name;

View File

@ -36,7 +36,10 @@ namespace OpenSim.Region.Environment.Interfaces
{
bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID,
int amount);
int GetBalance(IClientAPI client);
void ApplyUploadCharge(LLUUID agentID);
bool UploadCovered(IClientAPI client);
event ObjectPaid OnObjectPaid;
}

View File

@ -261,6 +261,23 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type,
byte[] data, bool storeLocal, bool tempFile)
{
if ((AssetType)type == AssetType.Texture ||
(AssetType)type == AssetType.Sound ||
(AssetType)type == AssetType.TextureTGA ||
(AssetType)type == AssetType.Animation)
{
Scene scene = (Scene)remoteClient.Scene;
IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>();
if (mm != null)
{
if (!mm.UploadCovered(remoteClient))
{
remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
return;
}
}
}
// Console.WriteLine("asset upload of " + assetID);
AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
@ -288,4 +305,4 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
transactions.HandleXfer(xferID, packetID, data);
}
}
}
}

View File

@ -266,11 +266,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
scene.SetObjectCapacity(ObjectCapacity);
}
/// <summary>
/// New Client Event Handler
/// </summary>
/// <param name="client"></param>
private void OnNewClient(IClientAPI client)
private void GetClientFunds(IClientAPI client)
{
// Here we check if we're in grid mode
// I imagine that the 'check balance'
@ -343,6 +339,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
CheckExistAndRefreshFunds(client.AgentId);
}
}
/// <summary>
/// New Client Event Handler
/// </summary>
/// <param name="client"></param>
private void OnNewClient(IClientAPI client)
{
GetClientFunds(client);
// Subscribe to Money messages
client.OnEconomyDataRequest += EconomyDataRequestHandler;
client.OnMoneyBalanceRequest += SendMoneyBalance;
@ -1525,6 +1531,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
DeadAvatar.Scene.TeleportClientHome(DeadAvatar.UUID, DeadAvatar.ControllingClient);
}
public int GetBalance(IClientAPI client)
{
GetClientFunds(client);
lock(m_KnownClientFunds)
{
if (!m_KnownClientFunds.ContainsKey(client.AgentId))
return 0;
return m_KnownClientFunds[client.AgentId];
}
}
public bool UploadCovered(IClientAPI client)
{
if (GetBalance(client) < PriceUpload)
return false;
return true;
}
#endregion
}

View File

@ -668,6 +668,7 @@
<Reference name="System.Xml"/>
<Reference name="System.Web"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Region.Environment"/>
<Reference name="OpenSim.Framework.AssetLoader.Filesystem"/>
<Reference name="OpenSim.Data" />
<Reference name="OpenSim.Framework.Servers"/>