master
Christopher 2020-06-17 14:50:17 +02:00
parent 3312e24fcb
commit c2ac78f809
1 changed files with 126 additions and 0 deletions

126
src/CreativeRegionGuide.cs Normal file
View File

@ -0,0 +1,126 @@
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
[assembly: Addin("CreativeRegionGuide", "0.1")]
[assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
namespace OpenSim.Modules.AdvancedRegionScriptFunktions
{
class CreativeRegionGuide : INonSharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Scene m_scene = null;
private IConfig m_config = null;
private bool m_enable = false;
private string m_server = "http://regions.4creative.net/?api=register";
private string m_description = "";
private string m_image = "";
private string m_homeURL = "";
private Timer m_timer = null;
public string Name
{
get { return "CreativeRegionGuide"; }
}
public Type ReplaceableInterface
{
get { return null; }
}
public void AddRegion(Scene scene)
{
}
public void Close()
{
}
public void Initialise(IConfigSource source)
{
m_config = source.Configs["Guide"];
if(m_config != null)
{
m_enable = m_config.GetBoolean("enable", m_enable);
m_server = m_config.GetString("server", m_server);
}
}
public void RegionLoaded(Scene scene)
{
m_scene = scene;
if (!m_enable)
return;
m_log.Info("[" + Name + "]: Load region " + scene.Name);
m_enable = m_config.GetBoolean("Region_" + m_scene.Name + ".Enable", m_enable);
m_description = m_config.GetString("Region_" + m_scene.Name + ".Description", String.Empty);
m_image = m_config.GetString("Region_" + m_scene.Name + ".ImageUUID", String.Empty);
m_homeURL = m_config.GetString("Region_" + m_scene.Name + ".HomeURL", String.Empty);
if (!m_enable)
return;
m_log.Info("[" + Name + "]: Enable region " + scene.Name);
m_timer = new Timer();
m_timer.Interval = 60000;
m_timer.Elapsed += runTimer;
m_timer.Start();
}
private void runTimer(object sender, ElapsedEventArgs e)
{
try
{
InitiateSSLTrust();
WebClient _client = new WebClient();
_client.DownloadString(m_server + "&");
}
catch
{
}
}
public void RemoveRegion(Scene scene)
{
}
public static void InitiateSSLTrust()
{
try
{
//Change SSL checks so that all checks pass
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}