corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.IO; |
||
4 | using CommandLine.Utility; |
||
5 | |||
6 | namespace OpenMetaverse.TestClient |
||
7 | { |
||
8 | public class CommandLineArgumentsException : Exception |
||
9 | { |
||
10 | } |
||
11 | |||
12 | public class Program |
||
13 | { |
||
14 | public static string LoginURI; |
||
15 | |||
16 | private static void Usage() |
||
17 | { |
||
18 | Console.WriteLine("Usage: " + Environment.NewLine + |
||
19 | "TestClient.exe [--first firstname --last lastname --pass password] [--file userlist.txt] [--loginuri=\"uri\"] [--startpos \"sim/x/y/z\"] [--master \"master name\"] [--masterkey \"master uuid\"] [--gettextures] [--scriptfile \"filename\"]"); |
||
20 | } |
||
21 | |||
22 | static void Main(string[] args) |
||
23 | { |
||
24 | Arguments arguments = new Arguments(args); |
||
25 | |||
26 | List<LoginDetails> accounts = new List<LoginDetails>(); |
||
27 | LoginDetails account; |
||
28 | bool groupCommands = false; |
||
29 | string masterName = String.Empty; |
||
30 | UUID masterKey = UUID.Zero; |
||
31 | string file = String.Empty; |
||
32 | bool getTextures = false; |
||
33 | bool noGUI = false; // true if to not prompt for input |
||
34 | string scriptFile = String.Empty; |
||
35 | |||
36 | if (arguments["groupcommands"] != null) |
||
37 | groupCommands = true; |
||
38 | |||
39 | if (arguments["masterkey"] != null) |
||
40 | masterKey = UUID.Parse(arguments["masterkey"]); |
||
41 | |||
42 | if (arguments["master"] != null) |
||
43 | masterName = arguments["master"]; |
||
44 | |||
45 | if (arguments["loginuri"] != null) |
||
46 | LoginURI = arguments["loginuri"]; |
||
47 | if (String.IsNullOrEmpty(LoginURI)) |
||
48 | LoginURI = Settings.AGNI_LOGIN_SERVER; |
||
49 | Logger.Log("Using login URI " + LoginURI, Helpers.LogLevel.Info); |
||
50 | |||
51 | if (arguments["gettextures"] != null) |
||
52 | getTextures = true; |
||
53 | |||
54 | if (arguments["nogui"] != null) |
||
55 | noGUI = true; |
||
56 | |||
57 | if (arguments["scriptfile"] != null) |
||
58 | { |
||
59 | scriptFile = arguments["scriptfile"]; |
||
60 | if (!File.Exists(scriptFile)) |
||
61 | { |
||
62 | Logger.Log(String.Format("File {0} Does not exist", scriptFile), Helpers.LogLevel.Error); |
||
63 | return; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | if (arguments["file"] != null) |
||
68 | { |
||
69 | file = arguments["file"]; |
||
70 | |||
71 | if (!File.Exists(file)) |
||
72 | { |
||
73 | Logger.Log(String.Format("File {0} Does not exist", file), Helpers.LogLevel.Error); |
||
74 | return; |
||
75 | } |
||
76 | |||
77 | // Loading names from a file |
||
78 | try |
||
79 | { |
||
80 | using (StreamReader reader = new StreamReader(file)) |
||
81 | { |
||
82 | string line; |
||
83 | int lineNumber = 0; |
||
84 | |||
85 | while ((line = reader.ReadLine()) != null) |
||
86 | { |
||
87 | lineNumber++; |
||
88 | string[] tokens = line.Trim().Split(new char[] { ' ', ',' }); |
||
89 | |||
90 | if (tokens.Length >= 3) |
||
91 | { |
||
92 | account = new LoginDetails(); |
||
93 | account.FirstName = tokens[0]; |
||
94 | account.LastName = tokens[1]; |
||
95 | account.Password = tokens[2]; |
||
96 | |||
97 | if (tokens.Length >= 4) // Optional starting position |
||
98 | { |
||
99 | char sep = '/'; |
||
100 | string[] startbits = tokens[3].Split(sep); |
||
101 | account.StartLocation = NetworkManager.StartLocation(startbits[0], Int32.Parse(startbits[1]), |
||
102 | Int32.Parse(startbits[2]), Int32.Parse(startbits[3])); |
||
103 | } |
||
104 | |||
105 | accounts.Add(account); |
||
106 | } |
||
107 | else |
||
108 | { |
||
109 | Logger.Log("Invalid data on line " + lineNumber + |
||
110 | ", must be in the format of: FirstName LastName Password [Sim/StartX/StartY/StartZ]", |
||
111 | Helpers.LogLevel.Warning); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | catch (Exception ex) |
||
117 | { |
||
118 | Logger.Log("Error reading from " + args[1], Helpers.LogLevel.Error, ex); |
||
119 | return; |
||
120 | } |
||
121 | } |
||
122 | else if (arguments["first"] != null && arguments["last"] != null && arguments["pass"] != null) |
||
123 | { |
||
124 | // Taking a single login off the command-line |
||
125 | account = new LoginDetails(); |
||
126 | account.FirstName = arguments["first"]; |
||
127 | account.LastName = arguments["last"]; |
||
128 | account.Password = arguments["pass"]; |
||
129 | |||
130 | accounts.Add(account); |
||
131 | } |
||
132 | else if (arguments["help"] != null) |
||
133 | { |
||
134 | Usage(); |
||
135 | return; |
||
136 | } |
||
137 | |||
138 | foreach (LoginDetails a in accounts) |
||
139 | { |
||
140 | a.GroupCommands = groupCommands; |
||
141 | a.MasterName = masterName; |
||
142 | a.MasterKey = masterKey; |
||
143 | a.URI = LoginURI; |
||
144 | |||
145 | if (arguments["startpos"] != null) |
||
146 | { |
||
147 | char sep = '/'; |
||
148 | string[] startbits = arguments["startpos"].Split(sep); |
||
149 | a.StartLocation = NetworkManager.StartLocation(startbits[0], Int32.Parse(startbits[1]), |
||
150 | Int32.Parse(startbits[2]), Int32.Parse(startbits[3])); |
||
151 | } |
||
152 | } |
||
153 | |||
154 | // Login the accounts and run the input loop |
||
155 | ClientManager.Instance.Start(accounts, getTextures); |
||
156 | |||
157 | if (!String.IsNullOrEmpty(scriptFile)) |
||
158 | ClientManager.Instance.DoCommandAll("script " + scriptFile, UUID.Zero); |
||
159 | |||
160 | // Then Run the ClientManager normally |
||
161 | ClientManager.Instance.Run(noGUI); |
||
162 | } |
||
163 | } |
||
164 | } |