aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ExportBot/ClientManager.cs
diff options
context:
space:
mode:
authorgareth2007-05-14 03:13:47 +0000
committergareth2007-05-14 03:13:47 +0000
commit64a98c736848de6099254f23483058668273c1a5 (patch)
treea8f2624277e48814531750db0ec07a8d64c1f740 /ExportBot/ClientManager.cs
parentAdded skeleton for grid management agent (diff)
downloadopensim-SC-64a98c736848de6099254f23483058668273c1a5.zip
opensim-SC-64a98c736848de6099254f23483058668273c1a5.tar.gz
opensim-SC-64a98c736848de6099254f23483058668273c1a5.tar.bz2
opensim-SC-64a98c736848de6099254f23483058668273c1a5.tar.xz
Finished off adding the new management API to gridserver
Updated VersionInfo.cs finally Updated prebuild and rebuilt nant build files Completed Management agent basics
Diffstat (limited to 'ExportBot/ClientManager.cs')
-rw-r--r--ExportBot/ClientManager.cs322
1 files changed, 0 insertions, 322 deletions
diff --git a/ExportBot/ClientManager.cs b/ExportBot/ClientManager.cs
deleted file mode 100644
index 79528ed..0000000
--- a/ExportBot/ClientManager.cs
+++ /dev/null
@@ -1,322 +0,0 @@
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using System.Xml;
5using System.Threading;
6using libsecondlife;
7using libsecondlife.Packets;
8using libsecondlife.AssetSystem;
9
10namespace libsecondlife.TestClient
11{
12 public class LoginDetails
13 {
14 public string FirstName;
15 public string LastName;
16 public string Password;
17 public string StartLocation;
18 public string MasterName;
19 public LLUUID MasterKey;
20 }
21
22 public class StartPosition
23 {
24 public string sim;
25 public int x;
26 public int y;
27 public int z;
28
29 public StartPosition()
30 {
31 this.sim = null;
32 this.x = 0;
33 this.y = 0;
34 this.z = 0;
35 }
36 }
37
38 public class ClientManager
39 {
40 public Dictionary<LLUUID, SecondLife> Clients = new Dictionary<LLUUID, SecondLife>();
41 public Dictionary<Simulator, Dictionary<uint, Primitive>> SimPrims = new Dictionary<Simulator, Dictionary<uint, Primitive>>();
42
43 public bool Running = true;
44
45 public static SecondLife MainClient;
46
47 string contactPerson = String.Empty;
48 private LLUUID resolvedMasterKey = LLUUID.Zero;
49 private ManualResetEvent keyResolution = new ManualResetEvent(false);
50
51 /// <summary>
52 ///
53 /// </summary>
54 /// <param name="accounts"></param>
55 public ClientManager(List<LoginDetails> accounts, string c)
56 {
57 this.contactPerson = c;
58 foreach (LoginDetails account in accounts)
59 Login(account);
60 }
61
62 public ClientManager(List<LoginDetails> accounts, string c, string s)
63 {
64 this.contactPerson = c;
65 char sep = '/';
66 string[] startbits = s.Split(sep);
67
68 foreach (LoginDetails account in accounts)
69 {
70 account.StartLocation = NetworkManager.StartLocation(startbits[0], Int32.Parse(startbits[1]),
71 Int32.Parse(startbits[2]), Int32.Parse(startbits[3]));
72 Login(account);
73 }
74 }
75
76 public string ExportAvatarRestMethod( string request, string path, string param )
77 {
78 Console.WriteLine("Got a request to export an avatar!");
79 DoCommandAll("Executing exportoutfitcommand " + param + " " + param + ".xml", null, null);
80
81 MainClient.Self.InstantMessage(new LLUUID(param), "(automated bot message) Your avatar has been copied OK, if you wish to use it to create your account please type yes, otherwise ignore this message. Note that you are responsible for obtaining all copyright permissions for textures etc on your avatar", new LLUUID(param));
82
83 return "OK";
84 }
85
86
87 /// <summary>
88 ///
89 /// </summary>
90 /// <param name="account"></param>
91 /// <returns></returns>
92 public TestClient Login(LoginDetails account)
93 {
94 // Check if this client is already logged in
95 foreach (TestClient c in Clients.Values)
96 {
97 if (c.Self.FirstName == account.FirstName && c.Self.LastName == account.LastName)
98 {
99 Logout(c);
100 break;
101 }
102 }
103
104 TestClient client = new TestClient(this);
105
106 // Optimize the throttle
107 client.Throttle.Wind = 0;
108 client.Throttle.Cloud = 0;
109 client.Throttle.Land = 1000000;
110 client.Throttle.Task = 1000000;
111
112 client.SimPrims = SimPrims;
113 client.MasterName = account.MasterName;
114 client.MasterKey = account.MasterKey;
115
116 if (!String.IsNullOrEmpty(account.StartLocation))
117 {
118 if (!client.Network.Login(account.FirstName, account.LastName, account.Password, "TestClient",
119 account.StartLocation, contactPerson))
120 {
121 Console.WriteLine("Failed to login " + account.FirstName + " " + account.LastName + ": " +
122 client.Network.LoginMessage);
123 }
124 }
125 else
126 {
127 if (!client.Network.Login(account.FirstName, account.LastName, account.Password, "TestClient",
128 contactPerson))
129 {
130 Console.WriteLine("Failed to login " + account.FirstName + " " + account.LastName + ": " +
131 client.Network.LoginStatusMessage);
132 }
133 }
134
135 if (client.Network.Connected)
136 {
137 if (account.MasterKey == LLUUID.Zero && !String.IsNullOrEmpty(account.MasterName))
138 {
139 Console.WriteLine("Resolving {0}'s UUID", account.MasterName);
140 // Find master's key from name
141 DirectoryManager.DirPeopleReplyCallback callback = new DirectoryManager.DirPeopleReplyCallback(KeyResolvHandler);
142 client.Directory.OnDirPeopleReply += callback;
143 client.Directory.StartPeopleSearch(DirectoryManager.DirFindFlags.People, account.MasterName);
144 if (keyResolution.WaitOne(TimeSpan.FromMinutes(1), false))
145 {
146 account.MasterKey = resolvedMasterKey;
147 Console.WriteLine("\"{0}\" resolved to {1}", account.MasterName, account.MasterKey);
148 }
149 else
150 {
151 Console.WriteLine("Unable to obtain UUID for \"{0}\". No master will be used. Try specifying a key with --masterkey.", account.MasterName);
152 }
153 client.Directory.OnDirPeopleReply -= callback;
154 keyResolution.Reset();
155 }
156
157 client.MasterKey = account.MasterKey;
158
159 Clients[client.Network.AgentID] = client;
160
161 MainClient = client;
162 Console.WriteLine("Logged in " + client.ToString());
163 }
164
165 return client;
166 }
167
168 private void KeyResolvHandler(LLUUID queryid, List<DirectoryManager.AgentSearchData> matches)
169 {
170 LLUUID master = matches[0].AgentID;
171 if (matches.Count > 1)
172 {
173 Console.WriteLine("Possible masters:");
174 for (int i = 0; i < matches.Count; ++i)
175 {
176 Console.WriteLine("{0}: {1}", i, matches[i].FirstName + " " + matches[i].LastName);
177 }
178 Console.Write("Ambiguous master, choose one:");
179 string read = Console.ReadLine();
180 while (read != null)
181 {
182 int choice = 0;
183 if (int.TryParse(read, out choice))
184 {
185 master = matches[choice].AgentID;
186 break;
187 }
188 else
189 {
190 Console.WriteLine("Responce misunderstood.");
191 Console.Write("Type the corresponding number:");
192 }
193 read = Console.ReadLine();
194 }
195 }
196 resolvedMasterKey = master;
197 keyResolution.Set();
198 }
199
200 /// <summary>
201 ///
202 /// </summary>
203 /// <param name="args"></param>
204 /// <returns></returns>
205 public TestClient Login(string[] args)
206 {
207 LoginDetails account = new LoginDetails();
208 account.FirstName = args[0];
209 account.LastName = args[1];
210 account.Password = args[2];
211
212 if (args.Length == 4)
213 {
214 account.StartLocation = NetworkManager.StartLocation(args[3], 128, 128, 40);
215 }
216
217 return Login(account);
218 }
219
220 /// <summary>
221 ///
222 /// </summary>
223 public void Run()
224 {
225 Console.WriteLine("Type quit to exit. Type help for a command list.");
226
227 while (Running)
228 {
229 PrintPrompt();
230 string input = Console.ReadLine();
231 DoCommandAll(input, null, null);
232 }
233
234 foreach (SecondLife client in Clients.Values)
235 {
236 if (client.Network.Connected)
237 client.Network.Logout();
238 }
239 }
240
241 private void PrintPrompt()
242 {
243 int online = 0;
244
245 foreach (SecondLife client in Clients.Values)
246 {
247 if (client.Network.Connected) online++;
248 }
249
250 Console.Write(online + " avatars online> ");
251 }
252
253 /// <summary>
254 ///
255 /// </summary>
256 /// <param name="cmd"></param>
257 /// <param name="fromAgentID"></param>
258 /// <param name="imSessionID"></param>
259 public void DoCommandAll(string cmd, LLUUID fromAgentID, LLUUID imSessionID)
260 {
261 string[] tokens = cmd.Trim().Split(new char[] { ' ', '\t' });
262 string firstToken = tokens[0].ToLower();
263
264 if (tokens.Length == 0)
265 return;
266
267 if (firstToken == "login")
268 {
269 // Special login case: Only call it once, and allow it with
270 // no logged in avatars
271 string[] args = new string[tokens.Length - 1];
272 Array.Copy(tokens, 1, args, 0, args.Length);
273 Login(args);
274 }
275 else if (firstToken == "quit")
276 {
277 Quit();
278 Console.WriteLine("All clients logged out and program finished running.");
279 }
280 else
281 {
282 // make a copy of the clients list so that it can be iterated without fear of being changed during iteration
283 Dictionary<LLUUID, SecondLife> clientsCopy = new Dictionary<LLUUID, SecondLife>(Clients);
284
285 foreach (TestClient client in clientsCopy.Values)
286 client.DoCommand(cmd, fromAgentID, imSessionID);
287 }
288 }
289
290 /// <summary>
291 ///
292 /// </summary>
293 /// <param name="client"></param>
294 public void Logout(TestClient client)
295 {
296 Clients.Remove(client.Network.AgentID);
297 client.Network.Logout();
298 }
299
300 /// <summary>
301 ///
302 /// </summary>
303 public void LogoutAll()
304 {
305 // make a copy of the clients list so that it can be iterated without fear of being changed during iteration
306 Dictionary<LLUUID, SecondLife> clientsCopy = new Dictionary<LLUUID, SecondLife>(Clients);
307
308 foreach (TestClient client in clientsCopy.Values)
309 Logout(client);
310 }
311
312 /// <summary>
313 ///
314 /// </summary>
315 public void Quit()
316 {
317 LogoutAll();
318 Running = false;
319 // TODO: It would be really nice if we could figure out a way to abort the ReadLine here in so that Run() will exit.
320 }
321 }
322}