corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) 2006-2014, openmetaverse.org
3 * All rights reserved.
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 *
8 * - Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * - Neither the name of the openmetaverse.org nor the names
11 * of its contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26  
27 using System;
28 using System.Collections.Generic;
29 using System.Threading;
30 using OpenMetaverse;
31 using OpenMetaverse.Utilities;
32  
33 namespace VoiceTest
34 {
35 public class VoiceException: Exception
36 {
37 public bool LoggedIn = false;
38  
39 public VoiceException(string msg): base(msg)
40 {
41 }
42  
43 public VoiceException(string msg, bool loggedIn): base(msg)
44 {
45 LoggedIn = loggedIn;
46 }
47 }
48  
49 class VoiceTest
50 {
51 static AutoResetEvent EventQueueRunningEvent = new AutoResetEvent(false);
52 static AutoResetEvent ProvisionEvent = new AutoResetEvent(false);
53 static AutoResetEvent ParcelVoiceInfoEvent = new AutoResetEvent(false);
54 static string VoiceAccount = String.Empty;
55 static string VoicePassword = String.Empty;
56 static string VoiceRegionName = String.Empty;
57 static int VoiceLocalID = 0;
58 static string VoiceChannelURI = String.Empty;
59  
60 static void Main(string[] args)
61 {
62 if (args.Length < 3)
63 {
64 Console.WriteLine("Usage: VoiceTest.exe [firstname] [lastname] [password]");
65 return;
66 }
67  
68 string firstName = args[0];
69 string lastName = args[1];
70 string password = args[2];
71  
72  
73 GridClient client = new GridClient();
74 client.Settings.MULTIPLE_SIMS = false;
75 Settings.LOG_LEVEL = Helpers.LogLevel.None;
76 client.Settings.LOG_RESENDS = false;
77 client.Settings.STORE_LAND_PATCHES = true;
78 client.Settings.ALWAYS_DECODE_OBJECTS = true;
79 client.Settings.ALWAYS_REQUEST_OBJECTS = true;
80 client.Settings.SEND_AGENT_UPDATES = true;
81  
82 string loginURI = client.Settings.LOGIN_SERVER;
83 if (4 == args.Length) {
84 loginURI = args[3];
85 }
86  
87 VoiceManager voice = new VoiceManager(client);
88 voice.OnProvisionAccount += voice_OnProvisionAccount;
89 voice.OnParcelVoiceInfo += voice_OnParcelVoiceInfo;
90  
91 client.Network.EventQueueRunning += client_OnEventQueueRunning;
92  
93 try {
94 if (!voice.ConnectToDaemon()) throw new VoiceException("Failed to connect to the voice daemon");
95  
96 List<string> captureDevices = voice.CaptureDevices();
97  
98 Console.WriteLine("Capture Devices:");
99 for (int i = 0; i < captureDevices.Count; i++)
100 Console.WriteLine(String.Format("{0}. \"{1}\"", i, captureDevices[i]));
101 Console.WriteLine();
102  
103 List<string> renderDevices = voice.RenderDevices();
104  
105 Console.WriteLine("Render Devices:");
106 for (int i = 0; i < renderDevices.Count; i++)
107 Console.WriteLine(String.Format("{0}. \"{1}\"", i, renderDevices[i]));
108 Console.WriteLine();
109  
110  
111 // Login
112 Console.WriteLine("Logging into the grid as " + firstName + " " + lastName + "...");
113 LoginParams loginParams =
114 client.Network.DefaultLoginParams(firstName, lastName, password, "Voice Test", "1.0.0");
115 loginParams.URI = loginURI;
116 if (!client.Network.Login(loginParams))
117 throw new VoiceException("Login to SL failed: " + client.Network.LoginMessage);
118 Console.WriteLine("Logged in: " + client.Network.LoginMessage);
119  
120  
121 Console.WriteLine("Creating voice connector...");
122 int status;
123 string connectorHandle = voice.CreateConnector(out status);
124 if (String.IsNullOrEmpty(connectorHandle))
125 throw new VoiceException("Failed to create a voice connector, error code: " + status, true);
126 Console.WriteLine("Voice connector handle: " + connectorHandle);
127  
128  
129 Console.WriteLine("Waiting for OnEventQueueRunning");
130 if (!EventQueueRunningEvent.WaitOne(45 * 1000, false))
131 throw new VoiceException("EventQueueRunning event did not occur", true);
132 Console.WriteLine("EventQueue running");
133  
134  
135 Console.WriteLine("Asking the current simulator to create a provisional account...");
136 if (!voice.RequestProvisionAccount())
137 throw new VoiceException("Failed to request a provisional account", true);
138 if (!ProvisionEvent.WaitOne(120 * 1000, false))
139 throw new VoiceException("Failed to create a provisional account", true);
140 Console.WriteLine("Provisional account created. Username: " + VoiceAccount +
141 ", Password: " + VoicePassword);
142  
143  
144 Console.WriteLine("Logging in to voice server " + voice.VoiceServer);
145 string accountHandle = voice.Login(VoiceAccount, VoicePassword, connectorHandle, out status);
146 if (String.IsNullOrEmpty(accountHandle))
147 throw new VoiceException("Login failed, error code: " + status, true);
148 Console.WriteLine("Login succeeded, account handle: " + accountHandle);
149  
150  
151 if (!voice.RequestParcelVoiceInfo())
152 throw new Exception("Failed to request parcel voice info");
153 if (!ParcelVoiceInfoEvent.WaitOne(45 * 1000, false))
154 throw new VoiceException("Failed to obtain parcel info voice", true);
155  
156  
157 Console.WriteLine("Parcel Voice Info obtained. Region name {0}, local parcel ID {1}, channel URI {2}",
158 VoiceRegionName, VoiceLocalID, VoiceChannelURI);
159  
160 client.Network.Logout();
161 }
162 catch(Exception e)
163 {
164 Console.WriteLine(e.Message);
165 if (e is VoiceException && (e as VoiceException).LoggedIn)
166 {
167 client.Network.Logout();
168 }
169  
170 }
171 Console.WriteLine("Press any key to continue...");
172 Console.ReadKey();
173 }
174  
175 static void client_OnEventQueueRunning(object sender, EventQueueRunningEventArgs e)
176 {
177 EventQueueRunningEvent.Set();
178 }
179  
180 static void voice_OnProvisionAccount(string username, string password)
181 {
182 VoiceAccount = username;
183 VoicePassword = password;
184  
185 ProvisionEvent.Set();
186 }
187  
188 static void voice_OnParcelVoiceInfo(string regionName, int localID, string channelURI)
189 {
190 VoiceRegionName = regionName;
191 VoiceLocalID = localID;
192 VoiceChannelURI = channelURI;
193  
194 ParcelVoiceInfoEvent.Set();
195 }
196 }
197 }