diff options
author | Adam Frisby | 2007-10-19 22:02:07 +0000 |
---|---|---|
committer | Adam Frisby | 2007-10-19 22:02:07 +0000 |
commit | 1313544ac7761ec7d84c14009fc95d5d7316004d (patch) | |
tree | 39a7bd27f07bb96859f5d09436d7e81e99f951a9 | |
parent | enable IRC bridge via runtime configuration (diff) | |
download | opensim-SC-1313544ac7761ec7d84c14009fc95d5d7316004d.zip opensim-SC-1313544ac7761ec7d84c14009fc95d5d7316004d.tar.gz opensim-SC-1313544ac7761ec7d84c14009fc95d5d7316004d.tar.bz2 opensim-SC-1313544ac7761ec7d84c14009fc95d5d7316004d.tar.xz |
* Major structural change: Begun converting Events to use (caller, args) syntax to conform with .NET guidelines.
* OnChatFromViewer has been converted as an example.
* Bug: SimpleApp's NPC client does not implement a Scene property and will likely crash with a NullReferenceException when it attempts to chat.
-rw-r--r-- | OpenSim/Framework/General/Interfaces/IClientAPI.cs | 102 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs | 12 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/ClientView.cs | 7 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Interfaces/ISimChat.cs | 2 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Modules/ChatModule.cs | 76 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Modules/WorldCommModule.cs | 11 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs | 17 | ||||
-rw-r--r-- | OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs | 10 |
8 files changed, 209 insertions, 28 deletions
diff --git a/OpenSim/Framework/General/Interfaces/IClientAPI.cs b/OpenSim/Framework/General/Interfaces/IClientAPI.cs index bedea9e..0dad91f 100644 --- a/OpenSim/Framework/General/Interfaces/IClientAPI.cs +++ b/OpenSim/Framework/General/Interfaces/IClientAPI.cs | |||
@@ -34,8 +34,108 @@ using OpenSim.Framework.Types; | |||
34 | 34 | ||
35 | namespace OpenSim.Framework.Interfaces | 35 | namespace OpenSim.Framework.Interfaces |
36 | { | 36 | { |
37 | // Base Args Interface | ||
38 | public interface IEventArgs | ||
39 | { | ||
40 | IScene Scene | ||
41 | { | ||
42 | get; | ||
43 | set; | ||
44 | } | ||
45 | |||
46 | IClientAPI Sender | ||
47 | { | ||
48 | get; | ||
49 | set; | ||
50 | } | ||
51 | } | ||
52 | |||
37 | public delegate void ViewerEffectEventHandler(IClientAPI sender, ViewerEffectPacket.EffectBlock[] effectBlock); | 53 | public delegate void ViewerEffectEventHandler(IClientAPI sender, ViewerEffectPacket.EffectBlock[] effectBlock); |
38 | public delegate void ChatFromViewer(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, LLUUID fromAgentID); | 54 | |
55 | public delegate void ChatFromViewer(Object sender, ChatFromViewerArgs e); | ||
56 | |||
57 | public enum ChatTypeEnum { Whisper = 0, Say = 1, Shout = 2, Broadcast = 0xFF }; | ||
58 | |||
59 | /// <summary> | ||
60 | /// ChatFromViewer Arguments | ||
61 | /// </summary> | ||
62 | public class ChatFromViewerArgs : EventArgs, IEventArgs | ||
63 | { | ||
64 | protected string m_message; | ||
65 | protected ChatTypeEnum m_type; | ||
66 | protected int m_channel; | ||
67 | protected LLVector3 m_position; | ||
68 | protected string m_from; | ||
69 | |||
70 | protected IClientAPI m_sender; | ||
71 | protected IScene m_scene; | ||
72 | |||
73 | /// <summary> | ||
74 | /// The message sent by the user | ||
75 | /// </summary> | ||
76 | public string Message | ||
77 | { | ||
78 | get { return m_message; } | ||
79 | set { m_message = value; } | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// The type of message, eg say, shout, broadcast. | ||
84 | /// </summary> | ||
85 | public ChatTypeEnum Type | ||
86 | { | ||
87 | get { return m_type; } | ||
88 | set { m_type = value; } | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Which channel was this message sent on? Different channels may have different listeners. Public chat is on channel zero. | ||
93 | /// </summary> | ||
94 | public int Channel | ||
95 | { | ||
96 | get { return m_channel; } | ||
97 | set { m_channel = value; } | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// The position of the sender at the time of the message broadcast. | ||
102 | /// </summary> | ||
103 | public LLVector3 Position | ||
104 | { | ||
105 | get { return m_position; } | ||
106 | set { m_position = value; } | ||
107 | } | ||
108 | |||
109 | /// <summary> | ||
110 | /// The name of the sender (needed for scripts) | ||
111 | /// </summary> | ||
112 | public string From | ||
113 | { | ||
114 | get { return m_from; } | ||
115 | set { m_from = value; } | ||
116 | } | ||
117 | |||
118 | /// <summary> | ||
119 | /// The client responsible for sending the message, or null. | ||
120 | /// </summary> | ||
121 | public IClientAPI Sender | ||
122 | { | ||
123 | get { return m_sender; } | ||
124 | set { m_sender = value; } | ||
125 | } | ||
126 | |||
127 | public IScene Scene | ||
128 | { | ||
129 | get { return m_scene; } | ||
130 | set { m_scene = value; } | ||
131 | } | ||
132 | |||
133 | public ChatFromViewerArgs() | ||
134 | { | ||
135 | m_position = new LLVector3(); | ||
136 | } | ||
137 | } | ||
138 | |||
39 | public delegate void ImprovedInstantMessage(LLUUID fromAgentID, LLUUID fromAgentSession, LLUUID toAgentID, LLUUID imSessionID, uint timestamp, string fromAgentName, string message, byte dialog); // Cut down from full list | 139 | public delegate void ImprovedInstantMessage(LLUUID fromAgentID, LLUUID fromAgentSession, LLUUID toAgentID, LLUUID imSessionID, uint timestamp, string fromAgentName, string message, byte dialog); // Cut down from full list |
40 | public delegate void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 pos); | 140 | public delegate void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 pos); |
41 | public delegate void ModifyTerrain(float height, float seconds, byte size, byte action, float north, float west, IClientAPI remoteClient); | 141 | public delegate void ModifyTerrain(float height, float seconds, byte size, byte action, float north, float west, IClientAPI remoteClient); |
diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs index d92127f..05b1118 100644 --- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs +++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs | |||
@@ -100,7 +100,17 @@ namespace OpenSim.Region.ClientStack | |||
100 | 100 | ||
101 | if (OnChatFromViewer != null) | 101 | if (OnChatFromViewer != null) |
102 | { | 102 | { |
103 | this.OnChatFromViewer(message, type, channel, fromPos, fromName, fromAgentID); | 103 | ChatFromViewerArgs args = new ChatFromViewerArgs(); |
104 | args.Channel = channel; | ||
105 | args.From = fromName; | ||
106 | args.Message = Util.FieldToString(message); | ||
107 | args.Type = (ChatTypeEnum)type; | ||
108 | args.Position = fromPos; | ||
109 | |||
110 | args.Scene = Scene; | ||
111 | args.Sender = this; | ||
112 | |||
113 | this.OnChatFromViewer(this, args); | ||
104 | } | 114 | } |
105 | break; | 115 | break; |
106 | case PacketType.ImprovedInstantMessage: | 116 | case PacketType.ImprovedInstantMessage: |
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index 2489739..cf4072c 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs | |||
@@ -68,7 +68,14 @@ namespace OpenSim.Region.ClientStack | |||
68 | //private AgentAssetUpload UploadAssets; | 68 | //private AgentAssetUpload UploadAssets; |
69 | private LLUUID newAssetFolder = LLUUID.Zero; | 69 | private LLUUID newAssetFolder = LLUUID.Zero; |
70 | private int debug = 0; | 70 | private int debug = 0; |
71 | |||
71 | protected IScene m_scene; | 72 | protected IScene m_scene; |
73 | |||
74 | public IScene Scene | ||
75 | { | ||
76 | get { return m_scene; } | ||
77 | } | ||
78 | |||
72 | private ClientManager m_clientManager; | 79 | private ClientManager m_clientManager; |
73 | private AssetCache m_assetCache; | 80 | private AssetCache m_assetCache; |
74 | // private InventoryCache m_inventoryCache; | 81 | // private InventoryCache m_inventoryCache; |
diff --git a/OpenSim/Region/Environment/Interfaces/ISimChat.cs b/OpenSim/Region/Environment/Interfaces/ISimChat.cs index 4ec55ff..583d8b2 100644 --- a/OpenSim/Region/Environment/Interfaces/ISimChat.cs +++ b/OpenSim/Region/Environment/Interfaces/ISimChat.cs | |||
@@ -32,6 +32,6 @@ namespace OpenSim.Region.Environment.Interfaces | |||
32 | { | 32 | { |
33 | public interface ISimChat | 33 | public interface ISimChat |
34 | { | 34 | { |
35 | void SimChat(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, LLUUID fromAgentID); | 35 | void SimChat(System.Object sender, OpenSim.Framework.Interfaces.ChatFromViewerArgs e); |
36 | } | 36 | } |
37 | } | 37 | } |
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs index 7db4f4b..594d5b4 100644 --- a/OpenSim/Region/Environment/Modules/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/ChatModule.cs | |||
@@ -33,15 +33,16 @@ using System.Threading; | |||
33 | using libsecondlife; | 33 | using libsecondlife; |
34 | using OpenSim.Framework.Interfaces; | 34 | using OpenSim.Framework.Interfaces; |
35 | using OpenSim.Framework.Utilities; | 35 | using OpenSim.Framework.Utilities; |
36 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Region.Environment.Interfaces; | 37 | using OpenSim.Region.Environment.Interfaces; |
37 | using OpenSim.Region.Environment.Scenes; | 38 | using OpenSim.Region.Environment.Scenes; |
38 | using Nini.Config; | ||
39 | 39 | ||
40 | namespace OpenSim.Region.Environment.Modules | 40 | namespace OpenSim.Region.Environment.Modules |
41 | { | 41 | { |
42 | public class ChatModule : IRegionModule, ISimChat | 42 | public class ChatModule : IRegionModule, ISimChat |
43 | { | 43 | { |
44 | private Scene m_scene; | 44 | private Scene m_scene; |
45 | private LogBase m_log; | ||
45 | 46 | ||
46 | private string m_server = null; | 47 | private string m_server = null; |
47 | private int m_port = 6668; | 48 | private int m_port = 6668; |
@@ -65,10 +66,12 @@ namespace OpenSim.Region.Environment.Modules | |||
65 | m_nick = "OSimBot" + Util.RandomClass.Next(1, 99); | 66 | m_nick = "OSimBot" + Util.RandomClass.Next(1, 99); |
66 | m_irc = null; | 67 | m_irc = null; |
67 | m_ircWriter = null; | 68 | m_ircWriter = null; |
68 | m_ircReader = null; | 69 | m_ircReader = null; |
70 | |||
71 | m_log = OpenSim.Framework.Console.MainLog.Instance; | ||
69 | } | 72 | } |
70 | 73 | ||
71 | public void Initialise(Scene scene, IConfigSource config) | 74 | public void Initialise(Scene scene, Nini.Config.IConfigSource config) |
72 | { | 75 | { |
73 | try { | 76 | try { |
74 | m_server = config.Configs["IRC"].GetString("server"); | 77 | m_server = config.Configs["IRC"].GetString("server"); |
@@ -175,41 +178,80 @@ namespace OpenSim.Region.Environment.Modules | |||
175 | } | 178 | } |
176 | } | 179 | } |
177 | 180 | ||
178 | public void SimChat(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, | 181 | public void SimChat(Object sender, ChatFromViewerArgs e) |
179 | LLUUID fromAgentID) | ||
180 | { | 182 | { |
181 | ScenePresence avatar = null; | 183 | ScenePresence avatar = null; |
182 | avatar = m_scene.GetScenePresence(fromAgentID); | 184 | |
185 | //TODO: Move ForEachScenePresence and others into IScene. | ||
186 | Scene scene = (Scene)e.Scene; | ||
187 | |||
188 | //TODO: Remove the need for this check | ||
189 | if (scene == null) | ||
190 | scene = m_scene; | ||
191 | |||
192 | // Filled in since it's easier than rewriting right now. | ||
193 | LLVector3 fromPos = e.Position; | ||
194 | string fromName = e.From; | ||
195 | string message = e.Message; | ||
196 | byte type = (byte)e.Type; | ||
197 | LLUUID fromAgentID = LLUUID.Zero; | ||
198 | |||
199 | if (e.Sender != null) | ||
200 | avatar = scene.GetScenePresence(e.Sender.AgentId); | ||
201 | |||
183 | if (avatar != null) | 202 | if (avatar != null) |
184 | { | 203 | { |
185 | fromPos = avatar.AbsolutePosition; | 204 | fromPos = avatar.AbsolutePosition; |
186 | fromName = avatar.Firstname + " " + avatar.Lastname; | 205 | fromName = avatar.Firstname + " " + avatar.Lastname; |
206 | fromAgentID = e.Sender.AgentId; | ||
187 | avatar = null; | 207 | avatar = null; |
188 | } | 208 | } |
209 | |||
210 | string typeName; | ||
211 | switch (e.Type) | ||
212 | { | ||
213 | case ChatTypeEnum.Broadcast: | ||
214 | typeName = "broadcasts"; | ||
215 | break; | ||
216 | case ChatTypeEnum.Say: | ||
217 | typeName = "says"; | ||
218 | break; | ||
219 | case ChatTypeEnum.Shout: | ||
220 | typeName = "shouts"; | ||
221 | break; | ||
222 | case ChatTypeEnum.Whisper: | ||
223 | typeName = "whispers"; | ||
224 | break; | ||
225 | default: | ||
226 | typeName = "unknown"; | ||
227 | break; | ||
228 | } | ||
229 | |||
230 | m_log.Verbose("CHAT", fromName + " (" + e.Channel + ") " + typeName + ": " + e.Message); | ||
189 | 231 | ||
190 | if (connected) | 232 | if (connected) |
191 | { | 233 | { |
192 | m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + ">: " + | 234 | m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + ">: " + |
193 | Util.FieldToString(message)); | 235 | e.Message); |
194 | m_ircWriter.Flush(); | 236 | m_ircWriter.Flush(); |
195 | } | 237 | } |
196 | 238 | ||
197 | if (channel == 0) | 239 | if (e.Channel == 0) |
198 | { | 240 | { |
199 | m_scene.ForEachScenePresence(delegate(ScenePresence presence) | 241 | scene.ForEachScenePresence(delegate(ScenePresence presence) |
200 | { | 242 | { |
201 | int dis = -1000; | 243 | int dis = -1000; |
202 | 244 | ||
203 | //err ??? the following code seems to be request a scenePresence when it already has a ref to it | 245 | //err ??? the following code seems to be request a scenePresence when it already has a ref to it |
204 | avatar = m_scene.GetScenePresence(presence.ControllingClient.AgentId); | 246 | avatar = scene.GetScenePresence(presence.ControllingClient.AgentId); |
205 | if (avatar != null) | 247 | if (avatar != null) |
206 | { | 248 | { |
207 | dis = (int) avatar.AbsolutePosition.GetDistanceTo(fromPos); | 249 | dis = (int) avatar.AbsolutePosition.GetDistanceTo(fromPos); |
208 | } | 250 | } |
209 | 251 | ||
210 | switch (type) | 252 | switch (e.Type) |
211 | { | 253 | { |
212 | case 0: // Whisper | 254 | case ChatTypeEnum.Whisper: |
213 | if ((dis < 10) && (dis > -10)) | 255 | if ((dis < 10) && (dis > -10)) |
214 | { | 256 | { |
215 | //should change so the message is sent through the avatar rather than direct to the ClientView | 257 | //should change so the message is sent through the avatar rather than direct to the ClientView |
@@ -220,7 +262,7 @@ namespace OpenSim.Region.Environment.Modules | |||
220 | fromAgentID); | 262 | fromAgentID); |
221 | } | 263 | } |
222 | break; | 264 | break; |
223 | case 1: // Say | 265 | case ChatTypeEnum.Say: |
224 | if ((dis < 30) && (dis > -30)) | 266 | if ((dis < 30) && (dis > -30)) |
225 | { | 267 | { |
226 | //Console.WriteLine("sending chat"); | 268 | //Console.WriteLine("sending chat"); |
@@ -231,7 +273,7 @@ namespace OpenSim.Region.Environment.Modules | |||
231 | fromAgentID); | 273 | fromAgentID); |
232 | } | 274 | } |
233 | break; | 275 | break; |
234 | case 2: // Shout | 276 | case ChatTypeEnum.Shout: |
235 | if ((dis < 100) && (dis > -100)) | 277 | if ((dis < 100) && (dis > -100)) |
236 | { | 278 | { |
237 | presence.ControllingClient.SendChatMessage(message, | 279 | presence.ControllingClient.SendChatMessage(message, |
@@ -242,7 +284,7 @@ namespace OpenSim.Region.Environment.Modules | |||
242 | } | 284 | } |
243 | break; | 285 | break; |
244 | 286 | ||
245 | case 0xff: // Broadcast | 287 | case ChatTypeEnum.Broadcast: |
246 | presence.ControllingClient.SendChatMessage(message, type, | 288 | presence.ControllingClient.SendChatMessage(message, type, |
247 | fromPos, | 289 | fromPos, |
248 | fromName, | 290 | fromName, |
diff --git a/OpenSim/Region/Environment/Modules/WorldCommModule.cs b/OpenSim/Region/Environment/Modules/WorldCommModule.cs index 765f1b4..cf5bba3 100644 --- a/OpenSim/Region/Environment/Modules/WorldCommModule.cs +++ b/OpenSim/Region/Environment/Modules/WorldCommModule.cs | |||
@@ -119,13 +119,12 @@ namespace OpenSim.Region.Environment.Modules | |||
119 | client.OnChatFromViewer += DeliverClientMessage; | 119 | client.OnChatFromViewer += DeliverClientMessage; |
120 | } | 120 | } |
121 | 121 | ||
122 | private void DeliverClientMessage(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, | 122 | private void DeliverClientMessage(Object sender, ChatFromViewerArgs e) |
123 | LLUUID fromAgentID) | ||
124 | { | 123 | { |
125 | ASCIIEncoding ae = new ASCIIEncoding(); | 124 | DeliverMessage(e.Sender.AgentId.ToString(), |
126 | 125 | (int)e.Type, e.Channel, | |
127 | DeliverMessage(fromAgentID.ToString(), type, channel, fromName, ae.GetString(message)); | 126 | e.Sender.FirstName + " " + e.Sender.LastName, |
128 | 127 | e.Message); | |
129 | } | 128 | } |
130 | 129 | ||
131 | public int Listen(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) | 130 | public int Listen(uint localID, LLUUID itemID, LLUUID hostID, int channel, string name, string id, string msg) |
diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index df8b190..71f8037 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs | |||
@@ -70,7 +70,22 @@ namespace OpenSim.Region.Environment.Scenes | |||
70 | { | 70 | { |
71 | if (m_simChatModule != null) | 71 | if (m_simChatModule != null) |
72 | { | 72 | { |
73 | m_simChatModule.SimChat(message, type, channel, fromPos, fromName, fromAgentID); | 73 | ChatFromViewerArgs args = new ChatFromViewerArgs(); |
74 | |||
75 | args.Message = OpenSim.Framework.Utilities.Util.FieldToString(message); | ||
76 | args.Channel = channel; | ||
77 | args.Type = (ChatTypeEnum)type; | ||
78 | args.Position = fromPos; | ||
79 | |||
80 | ScenePresence user = this.GetScenePresence(fromAgentID); | ||
81 | if (user != null) | ||
82 | args.Sender = user.ControllingClient; | ||
83 | else | ||
84 | args.Sender = null; | ||
85 | |||
86 | args.From = fromName; | ||
87 | |||
88 | m_simChatModule.SimChat(this, args); | ||
74 | } | 89 | } |
75 | } | 90 | } |
76 | 91 | ||
diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index c9c663e..1460b81 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs | |||
@@ -245,7 +245,15 @@ namespace SimpleApp | |||
245 | { | 245 | { |
246 | if (OnChatFromViewer != null) | 246 | if (OnChatFromViewer != null) |
247 | { | 247 | { |
248 | this.OnChatFromViewer(enc.GetBytes("Kind of quiet around here, isn't it! \0"), 2, 0, new LLVector3(128, 128, 26), this.FirstName + " " + this.LastName, this.AgentId); | 248 | ChatFromViewerArgs args = new ChatFromViewerArgs(); |
249 | args.Message = "Kinda quiet around here, isn't it?"; | ||
250 | args.Channel = 0; | ||
251 | args.From = this.FirstName + " " + this.LastName; | ||
252 | args.Position = new LLVector3(128, 128, 26); | ||
253 | args.Sender = this; | ||
254 | args.Type = ChatTypeEnum.Shout; | ||
255 | |||
256 | this.OnChatFromViewer(this, args); | ||
249 | } | 257 | } |
250 | count = -1; | 258 | count = -1; |
251 | 259 | ||