diff options
Diffstat (limited to 'OpenSim/Tools/pCampBot/BotManager.cs')
-rw-r--r-- | OpenSim/Tools/pCampBot/BotManager.cs | 107 |
1 files changed, 50 insertions, 57 deletions
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index c9d1446..0aaa226 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs | |||
@@ -53,7 +53,7 @@ namespace pCampBot | |||
53 | protected bool m_verbose = true; | 53 | protected bool m_verbose = true; |
54 | protected Random somthing = new Random(Environment.TickCount); | 54 | protected Random somthing = new Random(Environment.TickCount); |
55 | protected int numbots = 0; | 55 | protected int numbots = 0; |
56 | protected IConfig Previous_config; | 56 | private IConfig Config; |
57 | 57 | ||
58 | /// <summary> | 58 | /// <summary> |
59 | /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data | 59 | /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data |
@@ -102,72 +102,65 @@ namespace pCampBot | |||
102 | /// <param name="cs">The configuration for the bots to use</param> | 102 | /// <param name="cs">The configuration for the bots to use</param> |
103 | public void dobotStartup(int botcount, IConfig cs) | 103 | public void dobotStartup(int botcount, IConfig cs) |
104 | { | 104 | { |
105 | Previous_config = cs; | 105 | Config = cs; |
106 | m_td = new Thread[botcount]; | 106 | m_td = new Thread[botcount]; |
107 | |||
108 | string firstName = cs.GetString("firstname"); | ||
109 | string lastNameStem = cs.GetString("lastname"); | ||
110 | string password = cs.GetString("password"); | ||
111 | string loginUri = cs.GetString("loginuri"); | ||
112 | |||
107 | for (int i = 0; i < botcount; i++) | 113 | for (int i = 0; i < botcount; i++) |
108 | { | 114 | { |
109 | startupBot(i, cs); | 115 | string lastName = string.Format("{0}_{1}", lastNameStem, i); |
116 | startupBot(i, cs, firstName, lastName, password, loginUri); | ||
110 | } | 117 | } |
111 | } | 118 | } |
112 | 119 | ||
113 | /// <summary> | 120 | // /// <summary> |
114 | /// Add additional bots (and threads) to our bot pool | 121 | // /// Add additional bots (and threads) to our bot pool |
115 | /// </summary> | 122 | // /// </summary> |
116 | /// <param name="botcount">How Many of them to add</param> | 123 | // /// <param name="botcount">How Many of them to add</param> |
117 | public void addbots(int botcount) | 124 | // public void addbots(int botcount) |
118 | { | 125 | // { |
119 | int len = m_td.Length; | 126 | // int len = m_td.Length; |
120 | Thread[] m_td2 = new Thread[len + botcount]; | 127 | // Thread[] m_td2 = new Thread[len + botcount]; |
121 | for (int i = 0; i < len; i++) | 128 | // for (int i = 0; i < len; i++) |
122 | { | 129 | // { |
123 | m_td2[i] = m_td[i]; | 130 | // m_td2[i] = m_td[i]; |
124 | } | 131 | // } |
125 | m_td = m_td2; | 132 | // m_td = m_td2; |
126 | int newlen = len + botcount; | 133 | // int newlen = len + botcount; |
127 | for (int i = len; i < newlen; i++) | 134 | // for (int i = len; i < newlen; i++) |
128 | { | 135 | // { |
129 | startupBot(i, Previous_config); | 136 | // startupBot(i, Config); |
130 | } | 137 | // } |
131 | } | 138 | // } |
132 | 139 | ||
133 | /// <summary> | 140 | /// <summary> |
134 | /// This starts up the bot and stores the thread for the bot in the thread array | 141 | /// This starts up the bot and stores the thread for the bot in the thread array |
135 | /// </summary> | 142 | /// </summary> |
136 | /// <param name="pos">The position in the thread array to stick the bot's thread</param> | 143 | /// <param name="pos">The position in the thread array to stick the bot's thread</param> |
137 | /// <param name="cs">Configuration of the bot</param> | 144 | /// <param name="cs">Configuration of the bot</param> |
138 | public void startupBot(int pos, IConfig cs) | 145 | /// <param name="firstName">First name</param> |
146 | /// <param name="lastName">Last name</param> | ||
147 | /// <param name="password">Password</param> | ||
148 | /// <param name="loginUri">Login URI</param> | ||
149 | public void startupBot(int pos, IConfig cs, string firstName, string lastName, string password, string loginUri) | ||
139 | { | 150 | { |
140 | PhysicsBot pb = new PhysicsBot(cs); | 151 | PhysicsBot pb = new PhysicsBot(cs, firstName, lastName, password, loginUri); |
141 | 152 | ||
142 | pb.OnConnected += handlebotEvent; | 153 | pb.OnConnected += handlebotEvent; |
143 | pb.OnDisconnected += handlebotEvent; | 154 | pb.OnDisconnected += handlebotEvent; |
144 | if (cs.GetString("firstname", "random") == "random") pb.firstname = CreateRandomName(); | ||
145 | if (cs.GetString("lastname", "random") == "random") pb.lastname = CreateRandomName(); | ||
146 | 155 | ||
147 | m_td[pos] = new Thread(pb.startup); | 156 | m_td[pos] = new Thread(pb.startup); |
148 | m_td[pos].Name = "CampBot_" + pos; | 157 | m_td[pos].Name = pb.Name; |
149 | m_td[pos].IsBackground = true; | 158 | m_td[pos].IsBackground = true; |
150 | m_td[pos].Start(); | 159 | m_td[pos].Start(); |
151 | m_lBot.Add(pb); | 160 | m_lBot.Add(pb); |
152 | } | 161 | } |
153 | 162 | ||
154 | /// <summary> | 163 | /// <summary> |
155 | /// Creates a random name for the bot | ||
156 | /// </summary> | ||
157 | /// <returns></returns> | ||
158 | private string CreateRandomName() | ||
159 | { | ||
160 | string returnstring = ""; | ||
161 | string chars = "abcdefghijklmnopqrstuvwxyz0123456789"; | ||
162 | |||
163 | for (int i = 0; i < 7; i++) | ||
164 | { | ||
165 | returnstring += chars.Substring(somthing.Next(chars.Length),1); | ||
166 | } | ||
167 | return returnstring; | ||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// High level connnected/disconnected events so we can keep track of our threads by proxy | 164 | /// High level connnected/disconnected events so we can keep track of our threads by proxy |
172 | /// </summary> | 165 | /// </summary> |
173 | /// <param name="callbot"></param> | 166 | /// <param name="callbot"></param> |
@@ -177,11 +170,11 @@ namespace pCampBot | |||
177 | switch (eventt) | 170 | switch (eventt) |
178 | { | 171 | { |
179 | case EventType.CONNECTED: | 172 | case EventType.CONNECTED: |
180 | m_log.Info("[" + callbot.firstname + " " + callbot.lastname + "]: Connected"); | 173 | m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected"); |
181 | numbots++; | 174 | numbots++; |
182 | break; | 175 | break; |
183 | case EventType.DISCONNECTED: | 176 | case EventType.DISCONNECTED: |
184 | m_log.Info("[" + callbot.firstname + " " + callbot.lastname + "]: Disconnected"); | 177 | m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected"); |
185 | m_td[m_lBot.IndexOf(callbot)].Abort(); | 178 | m_td[m_lBot.IndexOf(callbot)].Abort(); |
186 | numbots--; | 179 | numbots--; |
187 | if (numbots <= 0) | 180 | if (numbots <= 0) |
@@ -223,17 +216,17 @@ namespace pCampBot | |||
223 | Environment.Exit(0); | 216 | Environment.Exit(0); |
224 | } | 217 | } |
225 | */ | 218 | */ |
226 | 219 | // | |
227 | private void HandleAddBots(string module, string[] cmd) | 220 | // private void HandleAddBots(string module, string[] cmd) |
228 | { | 221 | // { |
229 | int newbots = 0; | 222 | // int newbots = 0; |
230 | 223 | // | |
231 | if (cmd.Length > 2) | 224 | // if (cmd.Length > 2) |
232 | { | 225 | // { |
233 | Int32.TryParse(cmd[2], out newbots); | 226 | // Int32.TryParse(cmd[2], out newbots); |
234 | } | 227 | // } |
235 | if (newbots > 0) | 228 | // if (newbots > 0) |
236 | addbots(newbots); | 229 | // addbots(newbots); |
237 | } | 230 | // } |
238 | } | 231 | } |
239 | } | 232 | } |