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