aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ChatModule.cs
diff options
context:
space:
mode:
authorlbsa712007-10-10 18:24:13 +0000
committerlbsa712007-10-10 18:24:13 +0000
commita40e7100a232827cffb813bbbbe9374324ad3448 (patch)
tree7f16f392d653f155ca90d5477c842db9c881f3ed /OpenSim/Region/Environment/Modules/ChatModule.cs
parentAdded unit tests, based on nunit for the IInventoryData (diff)
downloadopensim-SC-a40e7100a232827cffb813bbbbe9374324ad3448.zip
opensim-SC-a40e7100a232827cffb813bbbbe9374324ad3448.tar.gz
opensim-SC-a40e7100a232827cffb813bbbbe9374324ad3448.tar.bz2
opensim-SC-a40e7100a232827cffb813bbbbe9374324ad3448.tar.xz
* Gave ModuleLoader some good lovin'
* Introduced ModuleLoader.PickupModules that currently picks up IRegionModule:s from /bin * Made LogBase thread-safe (or at least not thread-ignorant) * Ignored some genned files
Diffstat (limited to 'OpenSim/Region/Environment/Modules/ChatModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/ChatModule.cs426
1 files changed, 213 insertions, 213 deletions
diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs
index 2eac7d6..453fa76 100644
--- a/OpenSim/Region/Environment/Modules/ChatModule.cs
+++ b/OpenSim/Region/Environment/Modules/ChatModule.cs
@@ -1,214 +1,214 @@
1using System; 1using System;
2using System.IO; 2using System.IO;
3using System.Net.Sockets; 3using System.Net.Sockets;
4using System.Threading; 4using System.Threading;
5using libsecondlife; 5using libsecondlife;
6using OpenSim.Framework.Interfaces; 6using OpenSim.Framework.Interfaces;
7using OpenSim.Framework.Utilities; 7using OpenSim.Framework.Utilities;
8using OpenSim.Region.Environment.Interfaces; 8using OpenSim.Region.Environment.Interfaces;
9using OpenSim.Region.Environment.Scenes; 9using OpenSim.Region.Environment.Scenes;
10 10
11namespace OpenSim.Region.Environment.Modules 11namespace OpenSim.Region.Environment.Modules
12{ 12{
13 public class ChatModule : IRegionModule, ISimChat 13 public class ChatModule : IRegionModule, ISimChat
14 { 14 {
15 private Scene m_scene; 15 private Scene m_scene;
16 16
17 private string m_server = "irc2.choopa.net"; 17 private string m_server = "irc2.choopa.net";
18 18
19 // private int m_port = 6668; 19 // private int m_port = 6668;
20 //private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot"; 20 //private string m_user = "USER OpenSimBot 8 * :I'm a OpenSim to irc bot";
21 private string m_nick = "OSimBot"; 21 private string m_nick = "OSimBot";
22 private string m_channel = "#opensim"; 22 private string m_channel = "#opensim";
23 23
24 // private NetworkStream m_stream; 24 // private NetworkStream m_stream;
25 private TcpClient m_irc; 25 private TcpClient m_irc;
26 private StreamWriter m_ircWriter; 26 private StreamWriter m_ircWriter;
27 private StreamReader m_ircReader; 27 private StreamReader m_ircReader;
28 28
29 // private Thread pingSender; 29 // private Thread pingSender;
30 // private Thread listener; 30 // private Thread listener;
31 31
32 private bool connected = false; 32 private bool connected = false;
33 33
34 public ChatModule() 34 public ChatModule()
35 { 35 {
36 m_nick = "OSimBot" + Util.RandomClass.Next(1, 99); 36 m_nick = "OSimBot" + Util.RandomClass.Next(1, 99);
37 m_irc = null; 37 m_irc = null;
38 m_ircWriter = null; 38 m_ircWriter = null;
39 m_ircReader = null; 39 m_ircReader = null;
40 } 40 }
41 41
42 public void Initialise(Scene scene) 42 public void Initialise(Scene scene)
43 { 43 {
44 m_scene = scene; 44 m_scene = scene;
45 m_scene.EventManager.OnNewClient += NewClient; 45 m_scene.EventManager.OnNewClient += NewClient;
46 46
47 m_scene.RegisterModuleInterface<ISimChat>(this); 47 m_scene.RegisterModuleInterface<ISimChat>(this);
48 } 48 }
49 49
50 public void PostInitialise() 50 public void PostInitialise()
51 { 51 {
52 /* 52 /*
53 try 53 try
54 { 54 {
55 m_irc = new TcpClient(m_server, m_port); 55 m_irc = new TcpClient(m_server, m_port);
56 m_stream = m_irc.GetStream(); 56 m_stream = m_irc.GetStream();
57 m_ircReader = new StreamReader(m_stream); 57 m_ircReader = new StreamReader(m_stream);
58 m_ircWriter = new StreamWriter(m_stream); 58 m_ircWriter = new StreamWriter(m_stream);
59 59
60 pingSender = new Thread(new ThreadStart(this.PingRun)); 60 pingSender = new Thread(new ThreadStart(this.PingRun));
61 pingSender.Start(); 61 pingSender.Start();
62 62
63 listener = new Thread(new ThreadStart(this.ListenerRun)); 63 listener = new Thread(new ThreadStart(this.ListenerRun));
64 listener.Start(); 64 listener.Start();
65 65
66 m_ircWriter.WriteLine(m_user); 66 m_ircWriter.WriteLine(m_user);
67 m_ircWriter.Flush(); 67 m_ircWriter.Flush();
68 m_ircWriter.WriteLine("NICK " + m_nick); 68 m_ircWriter.WriteLine("NICK " + m_nick);
69 m_ircWriter.Flush(); 69 m_ircWriter.Flush();
70 m_ircWriter.WriteLine("JOIN " + m_channel); 70 m_ircWriter.WriteLine("JOIN " + m_channel);
71 m_ircWriter.Flush(); 71 m_ircWriter.Flush();
72 connected = true; 72 connected = true;
73 } 73 }
74 catch (Exception e) 74 catch (Exception e)
75 { 75 {
76 Console.WriteLine(e.ToString()); 76 Console.WriteLine(e.ToString());
77 } 77 }
78 */ 78 */
79 } 79 }
80 80
81 public void CloseDown() 81 public void Close()
82 { 82 {
83 m_ircWriter.Close(); 83 m_ircWriter.Close();
84 m_ircReader.Close(); 84 m_ircReader.Close();
85 m_irc.Close(); 85 m_irc.Close();
86 } 86 }
87 87
88 public string GetName() 88 public string Name
89 { 89 {
90 return "ChatModule"; 90 get { return "ChatModule"; }
91 } 91 }
92 92
93 public bool IsSharedModule() 93 public bool IsSharedModule
94 { 94 {
95 return false; 95 get { return false; }
96 } 96 }
97 97
98 public void NewClient(IClientAPI client) 98 public void NewClient(IClientAPI client)
99 { 99 {
100 client.OnChatFromViewer += SimChat; 100 client.OnChatFromViewer += SimChat;
101 } 101 }
102 102
103 public void PingRun() 103 public void PingRun()
104 { 104 {
105 while (true) 105 while (true)
106 { 106 {
107 m_ircWriter.WriteLine("PING :" + m_server); 107 m_ircWriter.WriteLine("PING :" + m_server);
108 m_ircWriter.Flush(); 108 m_ircWriter.Flush();
109 Thread.Sleep(15000); 109 Thread.Sleep(15000);
110 } 110 }
111 } 111 }
112 112
113 public void ListenerRun() 113 public void ListenerRun()
114 { 114 {
115 string inputLine; 115 string inputLine;
116 LLVector3 pos = new LLVector3(128, 128, 20); 116 LLVector3 pos = new LLVector3(128, 128, 20);
117 while (true) 117 while (true)
118 { 118 {
119 while ((inputLine = m_ircReader.ReadLine()) != null) 119 while ((inputLine = m_ircReader.ReadLine()) != null)
120 { 120 {
121 Console.WriteLine(inputLine); 121 Console.WriteLine(inputLine);
122 if (inputLine.Contains(m_channel)) 122 if (inputLine.Contains(m_channel))
123 { 123 {
124 string mess = inputLine.Substring(inputLine.IndexOf(m_channel)); 124 string mess = inputLine.Substring(inputLine.IndexOf(m_channel));
125 m_scene.Broadcast(delegate(IClientAPI client) 125 m_scene.Broadcast(delegate(IClientAPI client)
126 { 126 {
127 client.SendChatMessage( 127 client.SendChatMessage(
128 Helpers.StringToField(mess), 255, pos, "IRC:", 128 Helpers.StringToField(mess), 255, pos, "IRC:",
129 LLUUID.Zero); 129 LLUUID.Zero);
130 }); 130 });
131 } 131 }
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 public void SimChat(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName, 136 public void SimChat(byte[] message, byte type, int channel, LLVector3 fromPos, string fromName,
137 LLUUID fromAgentID) 137 LLUUID fromAgentID)
138 { 138 {
139 ScenePresence avatar = null; 139 ScenePresence avatar = null;
140 avatar = m_scene.GetScenePresence(fromAgentID); 140 avatar = m_scene.GetScenePresence(fromAgentID);
141 if (avatar != null) 141 if (avatar != null)
142 { 142 {
143 fromPos = avatar.AbsolutePosition; 143 fromPos = avatar.AbsolutePosition;
144 fromName = avatar.Firstname + " " + avatar.Lastname; 144 fromName = avatar.Firstname + " " + avatar.Lastname;
145 avatar = null; 145 avatar = null;
146 } 146 }
147 147
148 if (connected) 148 if (connected)
149 { 149 {
150 m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + ">: " + 150 m_ircWriter.WriteLine("PRIVMSG " + m_channel + " :" + "<" + fromName + ">: " +
151 Util.FieldToString(message)); 151 Util.FieldToString(message));
152 m_ircWriter.Flush(); 152 m_ircWriter.Flush();
153 } 153 }
154 154
155 if (channel == 0) 155 if (channel == 0)
156 { 156 {
157 m_scene.ForEachScenePresence(delegate(ScenePresence presence) 157 m_scene.ForEachScenePresence(delegate(ScenePresence presence)
158 { 158 {
159 int dis = -1000; 159 int dis = -1000;
160 160
161 //err ??? the following code seems to be request a scenePresence when it already has a ref to it 161 //err ??? the following code seems to be request a scenePresence when it already has a ref to it
162 avatar = m_scene.GetScenePresence(presence.ControllingClient.AgentId); 162 avatar = m_scene.GetScenePresence(presence.ControllingClient.AgentId);
163 if (avatar != null) 163 if (avatar != null)
164 { 164 {
165 dis = (int) avatar.AbsolutePosition.GetDistanceTo(fromPos); 165 dis = (int) avatar.AbsolutePosition.GetDistanceTo(fromPos);
166 } 166 }
167 167
168 switch (type) 168 switch (type)
169 { 169 {
170 case 0: // Whisper 170 case 0: // Whisper
171 if ((dis < 10) && (dis > -10)) 171 if ((dis < 10) && (dis > -10))
172 { 172 {
173 //should change so the message is sent through the avatar rather than direct to the ClientView 173 //should change so the message is sent through the avatar rather than direct to the ClientView
174 presence.ControllingClient.SendChatMessage(message, 174 presence.ControllingClient.SendChatMessage(message,
175 type, 175 type,
176 fromPos, 176 fromPos,
177 fromName, 177 fromName,
178 fromAgentID); 178 fromAgentID);
179 } 179 }
180 break; 180 break;
181 case 1: // Say 181 case 1: // Say
182 if ((dis < 30) && (dis > -30)) 182 if ((dis < 30) && (dis > -30))
183 { 183 {
184 //Console.WriteLine("sending chat"); 184 //Console.WriteLine("sending chat");
185 presence.ControllingClient.SendChatMessage(message, 185 presence.ControllingClient.SendChatMessage(message,
186 type, 186 type,
187 fromPos, 187 fromPos,
188 fromName, 188 fromName,
189 fromAgentID); 189 fromAgentID);
190 } 190 }
191 break; 191 break;
192 case 2: // Shout 192 case 2: // Shout
193 if ((dis < 100) && (dis > -100)) 193 if ((dis < 100) && (dis > -100))
194 { 194 {
195 presence.ControllingClient.SendChatMessage(message, 195 presence.ControllingClient.SendChatMessage(message,
196 type, 196 type,
197 fromPos, 197 fromPos,
198 fromName, 198 fromName,
199 fromAgentID); 199 fromAgentID);
200 } 200 }
201 break; 201 break;
202 202
203 case 0xff: // Broadcast 203 case 0xff: // Broadcast
204 presence.ControllingClient.SendChatMessage(message, type, 204 presence.ControllingClient.SendChatMessage(message, type,
205 fromPos, 205 fromPos,
206 fromName, 206 fromName,
207 fromAgentID); 207 fromAgentID);
208 break; 208 break;
209 } 209 }
210 }); 210 });
211 } 211 }
212 } 212 }
213 } 213 }
214} \ No newline at end of file 214} \ No newline at end of file