From 8e3b2392d129d727bfd00a2d9faa08d9e5be92de Mon Sep 17 00:00:00 2001
From: MW
Date: Tue, 28 Aug 2007 14:21:17 +0000
Subject: Start of trying to make Region/Scene more modular. Added preliminary
IRegionModule interface. Also have a work in progress way of Modules
registering optional API methods (kind of like Apache optional functions).
But there must be a cleaner/nicer way in c# of doing these than the current
way. Added three work in progress modules: ChatModule (simple handles in
world chat, but by moving this to a module, we could support other types of
chat modules, ie like a irc - opensim bridge module. ) , AvatarProfilesModule
and XferModule. Moved most of the code from Scene.ModifyTerrain() into the
BasicTerrain library, as the start of trying to make that more modular.
Stopped Child agents showing up as part of the "show users" command.
---
.../Environment/Modules/AvatarProfilesModule.cs | 61 ++++++++
OpenSim/Region/Environment/Modules/ChatModule.cs | 165 +++++++++++++++++++++
2 files changed, 226 insertions(+)
create mode 100644 OpenSim/Region/Environment/Modules/AvatarProfilesModule.cs
create mode 100644 OpenSim/Region/Environment/Modules/ChatModule.cs
(limited to 'OpenSim/Region/Environment/Modules')
diff --git a/OpenSim/Region/Environment/Modules/AvatarProfilesModule.cs b/OpenSim/Region/Environment/Modules/AvatarProfilesModule.cs
new file mode 100644
index 0000000..1427c58
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/AvatarProfilesModule.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using libsecondlife;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Region.Environment.Scenes;
+using OpenSim.Region.Environment.Interfaces;
+
+namespace OpenSim.Region.Environment.Modules
+{
+ public class AvatarProfilesModule :IRegionModule
+ {
+
+ private Scene m_scene;
+
+ public AvatarProfilesModule()
+ {
+
+ }
+
+ public void Initialise(Scene scene)
+ {
+ m_scene = scene;
+ m_scene.EventManager.OnNewClient += NewClient;
+ }
+
+ public void PostInitialise()
+ {
+
+ }
+
+ public void CloseDown()
+ {
+
+ }
+
+ public string GetName()
+ {
+ return "AvatarProfilesModule";
+ }
+
+ public void NewClient(IClientAPI client)
+ {
+ client.OnRequestAvatarProperties += RequestAvatarProperty;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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);
+ }
+ }
+}
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs
new file mode 100644
index 0000000..703fe65
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/ChatModule.cs
@@ -0,0 +1,165 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+using System.IO;
+using libsecondlife;
+using OpenSim.Region.Environment.Scenes;
+using OpenSim.Region.Environment.Interfaces;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Utilities;
+
+namespace OpenSim.Region.Environment.Modules
+{
+ public class ChatModule :IRegionModule
+ {
+ private Scene m_scene;
+
+ private string m_server = "irc2.choopa.net";
+
+ private int m_port = 6668;
+ private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
+ private string m_nick = "OpenSimBoT";
+ private string m_channel = "#opensim";
+
+ private NetworkStream m_stream;
+ private TcpClient m_irc;
+ private StreamWriter m_ircWriter;
+ private StreamReader m_ircReader;
+
+ private Thread pingSender;
+
+ private bool connected = false;
+
+ public ChatModule()
+ {
+
+ }
+
+ public void Initialise(Scene scene)
+ {
+ m_scene = scene;
+ m_scene.EventManager.OnNewClient += NewClient;
+
+ //should register a optional API Method, so other modules can send chat messages using this module
+ }
+
+ public void PostInitialise()
+ {
+ try
+ {
+ m_irc = new TcpClient(m_server, m_port);
+ m_stream = m_irc.GetStream();
+ m_ircReader = new StreamReader(m_stream);
+ m_ircWriter = new StreamWriter(m_stream);
+
+ pingSender = new Thread(new ThreadStart(this.PingRun));
+ pingSender.Start();
+
+ m_ircWriter.WriteLine(m_user);
+ m_ircWriter.Flush();
+ m_ircWriter.WriteLine("NICK " + m_nick);
+ m_ircWriter.Flush();
+ m_ircWriter.WriteLine("JOIN " + m_channel);
+ m_ircWriter.Flush();
+ connected = true;
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.ToString());
+ }
+ }
+
+ public void CloseDown()
+ {
+ m_ircWriter.Close();
+ m_ircReader.Close();
+ m_irc.Close();
+ }
+
+ public string GetName()
+ {
+ return "ChatModule";
+ }
+
+ public void NewClient(IClientAPI client)
+ {
+ client.OnChatFromViewer += SimChat;
+ }
+
+ public void PingRun()
+ {
+ while (true)
+ {
+ m_ircWriter.WriteLine("PING :" + m_server);
+ m_ircWriter.Flush();
+ Thread.Sleep(15000);
+ }
+ }
+
+ public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
+ {
+ ScenePresence avatar = null;
+ avatar = m_scene.RequestAvatar(fromAgentID);
+ if (avatar != null)
+ {
+ fromPos = avatar.AbsolutePosition;
+ fromName = avatar.Firstname + " " + avatar.Lastname;
+ avatar = null;
+ }
+
+ if (connected)
+ {
+ m_ircWriter.WriteLine("MSG " + m_channel +" :" + fromName + ", " + Util.FieldToString(message));
+ m_ircWriter.Flush();
+ }
+
+ m_scene.ForEachScenePresence(delegate(ScenePresence presence)
+ {
+ int dis = -1000;
+
+ //err ??? the following code seems to be request a scenePresence when it already has a ref to it
+ avatar = m_scene.RequestAvatar(presence.ControllingClient.AgentId);
+ if (avatar != null)
+ {
+ dis = (int)avatar.AbsolutePosition.GetDistanceTo(fromPos);
+ }
+
+ switch (type)
+ {
+ case 0: // Whisper
+ if ((dis < 10) && (dis > -10))
+ {
+ //should change so the message is sent through the avatar rather than direct to the ClientView
+ presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
+ fromAgentID);
+ }
+ break;
+ case 1: // Say
+ if ((dis < 30) && (dis > -30))
+ {
+ //Console.WriteLine("sending chat");
+ presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
+ fromAgentID);
+ }
+ break;
+ case 2: // Shout
+ if ((dis < 100) && (dis > -100))
+ {
+ presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
+ fromAgentID);
+ }
+ break;
+
+ case 0xff: // Broadcast
+ presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
+ fromAgentID);
+ break;
+ }
+ });
+ }
+
+ }
+}
--
cgit v1.1