aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ChatModule.cs
diff options
context:
space:
mode:
authorSean Dague2007-10-19 20:27:34 +0000
committerSean Dague2007-10-19 20:27:34 +0000
commit139994757c7dab04dd03801266525e8c53395a5e (patch)
tree003ec2557de6dd80dbe1e7bc78efe8958d02d5ae /OpenSim/Region/Environment/Modules/ChatModule.cs
parent* Test thy commits! (oops, sorry!) (diff)
downloadopensim-SC_OLD-139994757c7dab04dd03801266525e8c53395a5e.zip
opensim-SC_OLD-139994757c7dab04dd03801266525e8c53395a5e.tar.gz
opensim-SC_OLD-139994757c7dab04dd03801266525e8c53395a5e.tar.bz2
opensim-SC_OLD-139994757c7dab04dd03801266525e8c53395a5e.tar.xz
changes to pass nini config object to the modules that get
loaded so that they may read out any bits they are interested in
Diffstat (limited to 'OpenSim/Region/Environment/Modules/ChatModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/ChatModule.cs485
1 files changed, 243 insertions, 242 deletions
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs
index 6b8050e..a85a12c 100644
--- a/OpenSim/Region/Environment/Modules/ChatModule.cs
+++ b/OpenSim/Region/Environment/Modules/ChatModule.cs
@@ -1,242 +1,243 @@
1/* 1/*
2* Copyright (c) Contributors, http://opensimulator.org/ 2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.IO; 30using System.IO;
31using System.Net.Sockets; 31using System.Net.Sockets;
32using System.Threading; 32using System.Threading;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Framework.Interfaces; 34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Utilities; 35using OpenSim.Framework.Utilities;
36using OpenSim.Region.Environment.Interfaces; 36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes; 37using OpenSim.Region.Environment.Scenes;
38 38using Nini.Config;
39namespace OpenSim.Region.Environment.Modules 39
40{ 40namespace OpenSim.Region.Environment.Modules
41 public class ChatModule : IRegionModule, ISimChat 41{
42 { 42 public class ChatModule : IRegionModule, ISimChat
43 private Scene m_scene; 43 {
44 44 private Scene m_scene;
45 private string m_server = "irc2.choopa.net"; 45
46 46 private string m_server = "irc2.choopa.net";
47 // private int m_port = 6668; 47
48 //private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot"; 48 // private int m_port = 6668;
49 private string m_nick = "OSimBot"; 49 //private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
50 private string m_channel = "#opensim"; 50 private string m_nick = "OSimBot";
51 51 private string m_channel = "#opensim";
52 // private NetworkStream m_stream; 52
53 private TcpClient m_irc; 53 // private NetworkStream m_stream;
54 private StreamWriter m_ircWriter; 54 private TcpClient m_irc;
55 private StreamReader m_ircReader; 55 private StreamWriter m_ircWriter;
56 56 private StreamReader m_ircReader;
57 // private Thread pingSender; 57
58 // private Thread listener; 58 // private Thread pingSender;
59 59 // private Thread listener;
60 private bool connected = false; 60
61 61 private bool connected = false;
62 public ChatModule() 62
63 { 63 public ChatModule()
64 m_nick = "OSimBot" + Util.RandomClass.Next(1, 99); 64 {
65 m_irc = null; 65 m_nick = "OSimBot" + Util.RandomClass.Next(1, 99);
66 m_ircWriter = null; 66 m_irc = null;
67 m_ircReader = null; 67 m_ircWriter = null;
68 } 68 m_ircReader = null;
69 69 }
70 public void Initialise(Scene scene) 70
71 { 71 public void Initialise(Scene scene, IConfigSource config)
72 m_scene = scene; 72 {
73 m_scene.EventManager.OnNewClient += NewClient; 73 m_scene = scene;
74 74 m_scene.EventManager.OnNewClient += NewClient;
75 m_scene.RegisterModuleInterface<ISimChat>(this); 75
76 } 76 m_scene.RegisterModuleInterface<ISimChat>(this);
77 77 }
78 public void PostInitialise() 78
79 { 79 public void PostInitialise()
80 /* 80 {
81 try 81 /*
82 { 82 try
83 m_irc = new TcpClient(m_server, m_port); 83 {
84 m_stream = m_irc.GetStream(); 84 m_irc = new TcpClient(m_server, m_port);
85 m_ircReader = new StreamReader(m_stream); 85 m_stream = m_irc.GetStream();
86 m_ircWriter = new StreamWriter(m_stream); 86 m_ircReader = new StreamReader(m_stream);
87 87 m_ircWriter = new StreamWriter(m_stream);
88 pingSender = new Thread(new ThreadStart(this.PingRun)); 88
89 pingSender.Start(); 89 pingSender = new Thread(new ThreadStart(this.PingRun));
90 90 pingSender.Start();
91 listener = new Thread(new ThreadStart(this.ListenerRun)); 91
92 listener.Start(); 92 listener = new Thread(new ThreadStart(this.ListenerRun));
93 93 listener.Start();
94 m_ircWriter.WriteLine(m_user); 94
95 m_ircWriter.Flush(); 95 m_ircWriter.WriteLine(m_user);
96 m_ircWriter.WriteLine("NICK " + m_nick); 96 m_ircWriter.Flush();
97 m_ircWriter.Flush(); 97 m_ircWriter.WriteLine("NICK " + m_nick);
98 m_ircWriter.WriteLine("JOIN " + m_channel); 98 m_ircWriter.Flush();
99 m_ircWriter.Flush(); 99 m_ircWriter.WriteLine("JOIN " + m_channel);
100 connected = true; 100 m_ircWriter.Flush();
101 } 101 connected = true;
102 catch (Exception e) 102 }
103 { 103 catch (Exception e)
104 Console.WriteLine(e.ToString()); 104 {
105 } 105 Console.WriteLine(e.ToString());
106 */ 106 }
107 } 107 */
108 108 }
109 public void Close() 109
110 { 110 public void Close()
111 m_ircWriter.Close(); 111 {
112 m_ircReader.Close(); 112 m_ircWriter.Close();
113 m_irc.Close(); 113 m_ircReader.Close();
114 } 114 m_irc.Close();
115 115 }
116 public string Name 116
117 { 117 public string Name
118 get { return "ChatModule"; } 118 {
119 } 119 get { return "ChatModule"; }
120 120 }
121 public bool IsSharedModule 121
122 { 122 public bool IsSharedModule
123 get { return false; } 123 {
124 } 124 get { return false; }
125 125 }
126 public void NewClient(IClientAPI client) 126
127 { 127 public void NewClient(IClientAPI client)
128 client.OnChatFromViewer += SimChat; 128 {
129 } 129 client.OnChatFromViewer += SimChat;
130 130 }
131 public void PingRun() 131
132 { 132 public void PingRun()
133 while (true) 133 {
134 { 134 while (true)
135 m_ircWriter.WriteLine("PING :" + m_server); 135 {
136 m_ircWriter.Flush(); 136 m_ircWriter.WriteLine("PING :" + m_server);
137 Thread.Sleep(15000); 137 m_ircWriter.Flush();
138 } 138 Thread.Sleep(15000);
139 } 139 }
140 140 }
141 public void ListenerRun() 141
142 { 142 public void ListenerRun()
143 string inputLine; 143 {
144 LLVector3 pos = new LLVector3(128, 128, 20); 144 string inputLine;
145 while (true) 145 LLVector3 pos = new LLVector3(128, 128, 20);
146 { 146 while (true)
147 while ((inputLine = m_ircReader.ReadLine()) != null) 147 {
148 { 148 while ((inputLine = m_ircReader.ReadLine()) != null)
149 Console.WriteLine(inputLine); 149 {
150 if (inputLine.Contains(m_channel)) 150 Console.WriteLine(inputLine);
151 { 151 if (inputLine.Contains(m_channel))
152 string mess = inputLine.Substring(inputLine.IndexOf(m_channel)); 152 {
153 m_scene.Broadcast(delegate(IClientAPI client) 153 string mess = inputLine.Substring(inputLine.IndexOf(m_channel));
154 { 154 m_scene.Broadcast(delegate(IClientAPI client)
155 client.SendChatMessage( 155 {
156 Helpers.StringToField(mess), 255, pos, "IRC:", 156 client.SendChatMessage(
157 LLUUID.Zero); 157 Helpers.StringToField(mess), 255, pos, "IRC:",
158 }); 158 LLUUID.Zero);
159 } 159 });
160 } 160 }
161 } 161 }
162 } 162 }
163 163 }
164 public void SimChat(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, 164
165 LLUUID fromAgentID) 165 public void SimChat(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName,
166 { 166 LLUUID fromAgentID)
167 ScenePresence avatar = null; 167 {
168 avatar = m_scene.GetScenePresence(fromAgentID); 168 ScenePresence avatar = null;
169 if (avatar != null) 169 avatar = m_scene.GetScenePresence(fromAgentID);
170 { 170 if (avatar != null)
171 fromPos = avatar.AbsolutePosition; 171 {
172 fromName = avatar.Firstname + " " + avatar.Lastname; 172 fromPos = avatar.AbsolutePosition;
173 avatar = null; 173 fromName = avatar.Firstname + " " + avatar.Lastname;
174 } 174 avatar = null;
175 175 }
176 if (connected) 176
177 { 177 if (connected)
178 m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + ">: " + 178 {
179 Util.FieldToString(message)); 179 m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + ">: " +
180 m_ircWriter.Flush(); 180 Util.FieldToString(message));
181 } 181 m_ircWriter.Flush();
182 182 }
183 if (channel == 0) 183
184 { 184 if (channel == 0)
185 m_scene.ForEachScenePresence(delegate(ScenePresence presence) 185 {
186 { 186 m_scene.ForEachScenePresence(delegate(ScenePresence presence)
187 int dis = -1000; 187 {
188 188 int dis = -1000;
189 //err ??? the following code seems to be request a scenePresence when it already has a ref to it 189
190 avatar = m_scene.GetScenePresence(presence.ControllingClient.AgentId); 190 //err ??? the following code seems to be request a scenePresence when it already has a ref to it
191 if (avatar != null) 191 avatar = m_scene.GetScenePresence(presence.ControllingClient.AgentId);
192 { 192 if (avatar != null)
193 dis = (int) avatar.AbsolutePosition.GetDistanceTo(fromPos); 193 {
194 } 194 dis = (int) avatar.AbsolutePosition.GetDistanceTo(fromPos);
195 195 }
196 switch (type) 196
197 { 197 switch (type)
198 case 0: // Whisper 198 {
199 if ((dis < 10) && (dis > -10)) 199 case 0: // Whisper
200 { 200 if ((dis < 10) && (dis > -10))
201 //should change so the message is sent through the avatar rather than direct to the ClientView 201 {
202 presence.ControllingClient.SendChatMessage(message, 202 //should change so the message is sent through the avatar rather than direct to the ClientView
203 type, 203 presence.ControllingClient.SendChatMessage(message,
204 fromPos, 204 type,
205 fromName, 205 fromPos,
206 fromAgentID); 206 fromName,
207 } 207 fromAgentID);
208 break; 208 }
209 case 1: // Say 209 break;
210 if ((dis < 30) && (dis > -30)) 210 case 1: // Say
211 { 211 if ((dis < 30) && (dis > -30))
212 //Console.WriteLine("sending chat"); 212 {
213 presence.ControllingClient.SendChatMessage(message, 213 //Console.WriteLine("sending chat");
214 type, 214 presence.ControllingClient.SendChatMessage(message,
215 fromPos, 215 type,
216 fromName, 216 fromPos,
217 fromAgentID); 217 fromName,
218 } 218 fromAgentID);
219 break; 219 }
220 case 2: // Shout 220 break;
221 if ((dis < 100) && (dis > -100)) 221 case 2: // Shout
222 { 222 if ((dis < 100) && (dis > -100))
223 presence.ControllingClient.SendChatMessage(message, 223 {
224 type, 224 presence.ControllingClient.SendChatMessage(message,
225 fromPos, 225 type,
226 fromName, 226 fromPos,
227 fromAgentID); 227 fromName,
228 } 228 fromAgentID);
229 break; 229 }
230 230 break;
231 case 0xff: // Broadcast 231
232 presence.ControllingClient.SendChatMessage(message, type, 232 case 0xff: // Broadcast
233 fromPos, 233 presence.ControllingClient.SendChatMessage(message, type,
234 fromName, 234 fromPos,
235 fromAgentID); 235 fromName,
236 break; 236 fromAgentID);
237 } 237 break;
238 }); 238 }
239 } 239 });
240 } 240 }
241 } 241 }
242} 242 }
243}