Skip to content

Commit

Permalink
Begin to refactor the LSL script implementation for easier editing, r…
Browse files Browse the repository at this point in the history
…eading, and sanity.
  • Loading branch information
zontreck committed Nov 16, 2023
1 parent 4083fab commit d690db7
Show file tree
Hide file tree
Showing 10 changed files with 3,370 additions and 3,210 deletions.
112 changes: 112 additions & 0 deletions OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL/Chat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.ScriptEngine.Interfaces;
using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
using OpenSim.Region.ScriptEngine.Shared.ScriptBase;

namespace OpenSim.Region.ScriptEngine.Shared.Api.LSL
{
public partial class LSL_Api: MarshalByRefObject, ILSL_Api, IScriptApi
{

public void llWhisper(int channelID, string text)
{
byte[] binText = Utils.StringToBytesNoTerm(text, 1023);
World.SimChat(binText,
ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);

IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
if (wComm != null)
wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText), m_host.AbsolutePosition);
}


public void llSay(int channelID, string text)
{

if (channelID == 0)
// m_SayShoutCount++;
CheckSayShoutTime();

if (m_SayShoutCount >= 11)
ScriptSleep(2000);

if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
{
Console.WriteLine(text);
}
else
{
byte[] binText = Utils.StringToBytesNoTerm(text, 1023);
World.SimChat(binText,
ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);

IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
if (wComm != null)
wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText), m_host.AbsolutePosition);
}
}

public void llShout(int channelID, string text)
{

if (channelID == 0)
// m_SayShoutCount++;
CheckSayShoutTime();

if (m_SayShoutCount >= 11)
ScriptSleep(2000);

byte[] binText = Utils.StringToBytesNoTerm(text, 1023);

World.SimChat(binText,
ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);

IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
if (wComm != null)
wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText), m_host.AbsolutePosition);
}

public void llRegionSay(int channelID, string text)
{
if (channelID == 0)
{
Error("llRegionSay", "Cannot use on channel 0");
return;
}

byte[] binText = Utils.StringToBytesNoTerm(text, 1023);

// debug channel is also sent to avatars
if (channelID == ScriptBaseClass.DEBUG_CHANNEL)
{
World.SimChat(binText,
ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
}

IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
if (wComm != null)
wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, Util.UTF8.GetString(binText));
}

public void llRegionSayTo(string target, int channel, string msg)
{
if (channel == ScriptBaseClass.DEBUG_CHANNEL)
return;

if(UUID.TryParse(target, out UUID TargetID) && TargetID.IsNotZero())
{
IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
if (wComm != null)
{
if (msg.Length > 1023)
msg = msg.Substring(0, 1023);

wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
}
}
}
}
}
88 changes: 88 additions & 0 deletions OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL/HTTP.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using OpenMetaverse;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.ScriptEngine.Interfaces;
using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
using OpenSim.Region.ScriptEngine.Shared.ScriptBase;

namespace OpenSim.Region.ScriptEngine.Shared.Api.LSL
{
public partial class LSL_Api: MarshalByRefObject, ILSL_Api, IScriptApi
{

public void llSetContentType(LSL_Key reqid, LSL_Integer type)

Check failure on line 13 in OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL/HTTP.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'LSL_Key' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 13 in OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL/HTTP.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'LSL_Integer' could not be found (are you missing a using directive or an assembly reference?)
{

if (m_UrlModule == null)
return;

if(!UUID.TryParse(reqid, out UUID id) || id.IsZero())
return;

// Make sure the content type is text/plain to start with
m_UrlModule.HttpContentType(id, "text/plain");

// Is the object owner online and in the region
ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
if (agent == null || agent.IsChildAgent || agent.IsDeleted)
return; // Fail if the owner is not in the same region

// Is it the embeded browser?
string userAgent = m_UrlModule.GetHttpHeader(id, "user-agent");
if(string.IsNullOrEmpty(userAgent))
return;

if (userAgent.IndexOf("SecondLife") < 0)
return; // Not the embedded browser

// Use the IP address of the client and check against the request
// seperate logins from the same IP will allow all of them to get non-text/plain as long
// as the owner is in the region. Same as SL!
string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
if (string.IsNullOrEmpty(logonFromIPAddress))
return;

string requestFromIPAddress = m_UrlModule.GetHttpHeader(id, "x-remote-ip");
//m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
if (requestFromIPAddress == null)
return;

requestFromIPAddress = requestFromIPAddress.Trim();

// If the request isnt from the same IP address then the request cannot be from the owner
if (!requestFromIPAddress.Equals(logonFromIPAddress))
return;

switch (type)
{
case ScriptBaseClass.CONTENT_TYPE_HTML:
m_UrlModule.HttpContentType(id, "text/html");
break;
case ScriptBaseClass.CONTENT_TYPE_XML:
m_UrlModule.HttpContentType(id, "application/xml");
break;
case ScriptBaseClass.CONTENT_TYPE_XHTML:
m_UrlModule.HttpContentType(id, "application/xhtml+xml");
break;
case ScriptBaseClass.CONTENT_TYPE_ATOM:
m_UrlModule.HttpContentType(id, "application/atom+xml");
break;
case ScriptBaseClass.CONTENT_TYPE_JSON:
m_UrlModule.HttpContentType(id, "application/json");
break;
case ScriptBaseClass.CONTENT_TYPE_LLSD:
m_UrlModule.HttpContentType(id, "application/llsd+xml");
break;
case ScriptBaseClass.CONTENT_TYPE_FORM:
m_UrlModule.HttpContentType(id, "application/x-www-form-urlencoded");
break;
case ScriptBaseClass.CONTENT_TYPE_RSS:
m_UrlModule.HttpContentType(id, "application/rss+xml");
break;
default:
m_UrlModule.HttpContentType(id, "text/plain");
break;
}
}
}
}
Loading

0 comments on commit d690db7

Please sign in to comment.