aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/VoiceChat/VoiceClient.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/VoiceChat/VoiceClient.cs196
1 files changed, 0 insertions, 196 deletions
diff --git a/OpenSim/Region/Environment/Modules/VoiceChat/VoiceClient.cs b/OpenSim/Region/Environment/Modules/VoiceChat/VoiceClient.cs
deleted file mode 100644
index 4a0b130..0000000
--- a/OpenSim/Region/Environment/Modules/VoiceChat/VoiceClient.cs
+++ /dev/null
@@ -1,196 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using System.Collections.Generic;
31using System.Text;
32using System.Net.Sockets;
33using OpenSim.Region.Environment.Scenes;
34using libsecondlife;
35
36namespace OpenSim.Region.Environment.Modules.VoiceChat
37{
38 /**
39 * Represents a single voiceclient instance
40 **/
41 public class VoiceClient
42 {
43 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
44
45 public Socket m_socket;
46 public LLUUID m_clientId;
47 public bool m_authenticated = false;
48
49 protected VoicePacketHeader m_header = null;
50 protected int m_headerBytesReceived = 0;
51
52 protected int m_offset = 0;
53 protected int m_supportedCodecs = 0;
54
55 protected byte[] m_buffer = null;
56 protected byte[] m_headerBytes = new byte[5];
57
58 protected bool m_enabled = true;
59
60 protected VoiceChatServer m_server;
61
62 public VoiceClient(Socket socket, VoiceChatServer server)
63 {
64 m_socket = socket;
65 m_server = server;
66 }
67
68 public void OnDataReceived(byte[] data, int byteCount)
69 {
70 int offset = 0;
71 while (offset < byteCount)
72 {
73 if (m_header == null)
74 {
75 if (m_headerBytesReceived < 5)
76 {
77 m_headerBytes[m_headerBytesReceived++] = data[offset++];
78 }
79 else if (m_headerBytesReceived == 5)
80 {
81 m_header = new VoicePacketHeader();
82 m_header.Parse(m_headerBytes);
83 if (m_header.length > 65535)
84 {
85 throw new Exception("Packet size " + m_header.length + " > 65535");
86 }
87
88 m_buffer = new byte[m_header.length];
89 m_offset = 0;
90 m_headerBytesReceived = 0;
91 }
92 }
93 else
94 {
95 int bytesToCopy = m_header.length-m_offset;
96 if (bytesToCopy > byteCount - offset)
97 bytesToCopy = byteCount - offset;
98
99 Buffer.BlockCopy(data, offset, m_buffer, m_offset, bytesToCopy);
100
101 offset += bytesToCopy;
102 m_offset += bytesToCopy;
103
104 if (m_offset == m_header.length)
105 {
106 ParsePacket(m_header.type, m_buffer);
107 m_header = null;
108 }
109 }
110 }
111 }
112
113 void ParsePacket(byte type, byte[] data)
114 {
115 switch (type)
116 {
117 case 0: //LOGIN
118 ParseLogin(data);
119 break;
120
121 case 1: //AUDIODATA
122 if (m_authenticated)
123 {
124 VoicePacket packet = new VoicePacket(data);
125 packet.m_clientId = m_clientId;
126 m_server.BroadcastVoice(packet);
127 }
128 else
129 {
130 m_log.Warn("[VOICECHAT]: Got unauthorized audio data from " +
131 m_socket.RemoteEndPoint.ToString());
132 m_socket.Close();
133 }
134 break;
135
136 case 3: //ENABLEVOIP
137 if (data[0] == 0)
138 {
139 m_log.Warn("[VOICECHAT]: VoiceChat has been disabled for " + m_clientId);
140 m_enabled = false;
141 }
142 else
143 {
144 m_log.Warn("[VOICECHAT]: VoiceChat has been enabled for " + m_clientId);
145 m_enabled = true;
146 }
147 break;
148
149
150 default:
151 throw new Exception("Invalid packet received");
152 }
153 }
154
155 void ParseLogin(byte[] data)
156 {
157 m_clientId = new LLUUID(data, 0);
158
159 m_supportedCodecs = data[16];
160 m_supportedCodecs |= data[17] << 8;
161 m_supportedCodecs |= data[18] << 16;
162 m_supportedCodecs |= data[19] << 24;
163
164 if (m_server.AddClient(this, m_clientId))
165 {
166 m_log.Info("[VOICECHAT]: Client authenticated succesfully: " + m_clientId);
167 m_authenticated = true;
168 }
169 else
170 {
171 throw new Exception("Unable to authenticate with id " + m_clientId);
172 }
173 }
174
175 public bool IsEnabled()
176 {
177 return m_enabled;
178 }
179
180 public bool IsCodecSupported(int codec)
181 {
182 if ((m_supportedCodecs & codec) != 0)
183 return true;
184
185 return false;
186 }
187
188 public void SendTo(byte[] data)
189 {
190 if (m_authenticated)
191 {
192 //ServerStatus.ReportOutPacketTcp(m_socket.Send(data));
193 }
194 }
195 }
196}