From b0c6baaeb05c5f15c951d3128419fac82b399911 Mon Sep 17 00:00:00 2001
From: Teravus Ovares
Date: Sun, 3 Feb 2008 04:13:46 +0000
Subject: * Adding the PhysicsCamperBot load testing app to the SVN in it's own
folder. You'll have to build it separately to take advantage of it. *read
the Readme file*. The bots created by this application roam around
amusingly to simulate load. * Be smart, Don't use this on a public grid, lest
you get banned permanently.
---
pCampBot/BotManager.cs | 254 ++++++++++++++++++++++++++++++++++++
pCampBot/PhysicsBot.cs | 208 +++++++++++++++++++++++++++++
pCampBot/PhysicsCamperBotREADME.txt | 21 +++
pCampBot/pCampBot.cs | 80 ++++++++++++
pCampBot/pCampBot.csproj | 102 +++++++++++++++
pCampBot/prebuild.xml | 63 +++++++++
pCampBot/runprebuild.bat | 2 +
pCampBot/runprebuild.sh | 4 +
8 files changed, 734 insertions(+)
create mode 100644 pCampBot/BotManager.cs
create mode 100644 pCampBot/PhysicsBot.cs
create mode 100644 pCampBot/PhysicsCamperBotREADME.txt
create mode 100644 pCampBot/pCampBot.cs
create mode 100644 pCampBot/pCampBot.csproj
create mode 100644 pCampBot/prebuild.xml
create mode 100644 pCampBot/runprebuild.bat
create mode 100644 pCampBot/runprebuild.sh
(limited to 'pCampBot')
diff --git a/pCampBot/BotManager.cs b/pCampBot/BotManager.cs
new file mode 100644
index 0000000..a9cd643
--- /dev/null
+++ b/pCampBot/BotManager.cs
@@ -0,0 +1,254 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using libsecondlife;
+using libsecondlife.Packets;
+using Nini.Config;
+using System.Threading;
+using OpenSim.Framework;
+using OpenSim.Framework.Console;
+
+namespace pCampBot
+{
+ ///
+ /// Thread/Bot manager for the application
+ ///
+ public class BotManager : conscmd_callback
+ {
+ protected LogBase m_log;
+ protected List m_lBot;
+ protected Thread[] m_td;
+ protected string m_logFilename = "botlog.log";
+ protected bool m_verbose = true;
+ protected Random somthing = new Random(System.Environment.TickCount);
+ protected int numbots = 0;
+ protected IConfig Previous_config;
+
+ ///
+ /// Constructor Creates Mainlog.Instance to take commands and provide the place to write data
+ ///
+ public BotManager()
+ {
+
+ m_log = CreateLog();
+ MainLog.Instance = m_log;
+ m_lBot = new List();
+
+ }
+
+ ///
+ /// Startup number of bots specified in the starting arguments
+ ///
+ /// How many bots to start up
+ /// The configuration for the bots to use
+ public void dobotStartup(int botcount, IConfig cs)
+ {
+ Previous_config = cs;
+ m_td = new Thread[botcount];
+ for (int i = 0; i < botcount; i++)
+ {
+ startupBot(i, cs);
+
+
+ }
+
+ }
+ ///
+ /// Add additional bots (and threads) to our bot pool
+ ///
+ /// How Many of them to add
+ public void addbots(int botcount)
+ {
+ int len = m_td.Length;
+ Thread[] m_td2 = new Thread[len + botcount];
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ m_td2[i] = m_td[i];
+ }
+ m_td = m_td2;
+ int newlen = len + botcount;
+ for (i = i; i < newlen; i++)
+ {
+ startupBot(i, Previous_config);
+ }
+
+ }
+
+ ///
+ /// This starts up the bot and stores the thread for the bot in the thread array
+ ///
+ /// The position in the thread array to stick the bot's thread
+ /// Configuration of the bot
+ public void startupBot(int pos, IConfig cs)
+ {
+ PhysicsBot pb = new PhysicsBot(cs);
+
+ pb.OnConnected += handlebotEvent;
+ pb.OnDisconnected += handlebotEvent;
+ if (cs.GetString("firstname", "random") == "random") pb.firstname = CreateRandomName();
+ if (cs.GetString("lastname", "random") == "random") pb.lastname = CreateRandomName();
+
+ m_td[pos] = new Thread(pb.startup);
+ m_td[pos].Start();
+ m_lBot.Add(pb);
+
+ }
+
+ ///
+ /// Creates a random name for the bot
+ ///
+ ///
+ private string CreateRandomName()
+ {
+ string returnstring = "";
+ string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+
+ for (int i = 0; i < 7; i++)
+ {
+ returnstring += chars.Substring(somthing.Next(chars.Length),1);
+ }
+ return returnstring;
+
+ }
+
+ ///
+ /// High level connnected/disconnected events so we can keep track of our threads by proxy
+ ///
+ ///
+ ///
+ public void handlebotEvent(PhysicsBot callbot, EventType eventt)
+ {
+ switch (eventt)
+ {
+ case EventType.CONNECTED:
+ MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Connected");
+ numbots++;
+ break;
+ case EventType.DISCONNECTED:
+ MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Disconnected");
+ m_td[m_lBot.IndexOf(callbot)].Abort();
+ numbots--;
+ if (numbots >1)
+ Environment.Exit(0);
+ break;
+
+ }
+ }
+ ///
+ /// Shutting down all bots
+ ///
+ public void doBotShutdown()
+ {
+ foreach (PhysicsBot pb in m_lBot)
+ {
+ pb.shutdown();
+ }
+
+
+
+ }
+
+ ///
+ /// Standard Creatlog routine
+ ///
+ ///
+ protected LogBase CreateLog()
+ {
+ if (!Directory.Exists(Util.logDir()))
+ {
+ Directory.CreateDirectory(Util.logDir());
+ }
+
+ return new LogBase((Path.Combine(Util.logDir(), m_logFilename)), "Region", this, m_verbose);
+ }
+
+ ///
+ /// I don't think the bots use this..
+ ///
+ ///
+ ///
+ ///
+ private string CombineParams(string[] commandParams, int pos)
+ {
+ string result = String.Empty;
+ for (int i = pos; i < commandParams.Length; i++)
+ {
+ result += commandParams[i] + " ";
+ }
+ result = result.TrimEnd(' ');
+ return result;
+ }
+
+ ///
+ /// Command runnint tool.. Currently use it to add bots, shutdown and (dangerous)Forcequit
+ ///
+ ///
+ ///
+ public void RunCmd(string command, string[] cmdparams)
+ {
+ switch (command)
+ {
+ case "shutdown":
+ MainLog.Instance.Warn("BOTMANAGER", "Shutting down bots");
+ doBotShutdown();
+ break;
+ case "quit":
+ MainLog.Instance.Warn("DANGER", "This should only be used to quit the program if you've already used the shutdown command and the program hasn't quit");
+ Environment.Exit(0);
+ break;
+ case "addbots":
+ int newbots = 0;
+ Helpers.TryParse(cmdparams[0], out newbots);
+
+ if (newbots > 0)
+ addbots(newbots);
+ break;
+ case "help":
+ MainLog.Instance.Notice("HELP", "\nshutdown - graceful shutdown\naddbots - adds n bots to the test\nquit - forcequits, dangerous if you have not already run shutdown");
+ break;
+
+
+ }
+ }
+
+ ///
+ /// Required method to implement the conscmd_callback interface
+ ///
+ ///
+ public void Show(string ShowWhat)
+ {
+
+ }
+ }
+
+}
diff --git a/pCampBot/PhysicsBot.cs b/pCampBot/PhysicsBot.cs
new file mode 100644
index 0000000..53a774a
--- /dev/null
+++ b/pCampBot/PhysicsBot.cs
@@ -0,0 +1,208 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using libsecondlife;
+using libsecondlife.Packets;
+using Nini.Config;
+using System.Threading;
+using OpenSim.Framework;
+using OpenSim.Framework.Console;
+using Timer=System.Timers.Timer;
+
+
+
+namespace pCampBot
+{
+ public class PhysicsBot
+ {
+ public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events
+ public IConfig startupConfig; // bot config, passed from BotManager
+
+ public string firstname;
+ public string lastname;
+ public string password;
+ public string loginURI;
+
+ public event AnEvent OnConnected;
+ public event AnEvent OnDisconnected;
+
+ protected Timer m_action; // Action Timer
+
+ protected Random somthing = new Random(System.Environment.TickCount);// We do stuff randomly here
+
+ //New instance of a SecondLife client
+ public SecondLife client = new SecondLife();
+
+ protected string[] talkarray;
+ ///
+ ///
+ ///
+ /// nini config for the bot
+ public PhysicsBot(IConfig bsconfig)
+ {
+ startupConfig = bsconfig;
+ readconfig();
+ talkarray = readexcuses();
+ }
+
+ //We do our actions here. This is where one would
+ //add additional steps and/or things the bot should do
+
+ void m_action_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
+ {
+ //client.Throttle.Task = 500000f;
+ //client.Throttle.Set();
+
+ client.Self.Movement.AlwaysRun = true;
+ LLVector3 pos = client.Self.SimPosition;
+ LLVector3 newpos = new LLVector3(somthing.Next(255),somthing.Next(255),somthing.Next(255));
+
+
+ client.Self.Movement.TurnToward(newpos);
+ for (int i = 0; i < 2000; i++)
+ {
+ client.Self.Movement.AtPos = true;
+ }
+ client.Self.Jump();
+ string randomf = talkarray[somthing.Next(talkarray.Length)];
+ if (talkarray.Length > 1 && randomf.Length > 1)
+ client.Self.Chat("Can't do it, " + randomf, 0, ChatType.Normal);
+
+ Thread.Sleep(somthing.Next(1,20));
+
+ }
+
+ ///
+ /// Read the Nini config and initialize
+ ///
+ public void readconfig()
+ {
+ firstname = startupConfig.GetString("firstname", "random");
+ lastname = startupConfig.GetString("lastname", "random");
+ password = startupConfig.GetString("password", "12345");
+ loginURI = startupConfig.GetString("loginuri", "http://10.1.1.5:9000");
+
+
+
+ }
+
+ ///
+ /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes.
+ ///
+ public void shutdown()
+ {
+ client.Network.Logout();
+ }
+ ///
+ /// This is the bot startup loop.
+ ///
+ public void startup()
+ {
+
+ client.Settings.LOGIN_SERVER = loginURI;
+ client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected);
+ client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected);
+ client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(this.Network_OnDisconnected);
+ if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name"))
+ {
+
+ if (OnConnected != null)
+ {
+ m_action = new Timer(somthing.Next(1000, 10000));
+ m_action.Elapsed += new System.Timers.ElapsedEventHandler(m_action_Elapsed);
+ m_action.Start();
+ OnConnected(this, EventType.CONNECTED);
+ client.Self.Jump();
+
+ }
+ }
+ else
+ {
+
+ MainLog.Instance.Error(firstname + " " + lastname,"Can't Log in: " + client.Network.LoginMessage);
+ if (OnDisconnected != null)
+ {
+ OnDisconnected(this, EventType.DISCONNECTED);
+ }
+ }
+
+ }
+
+ public void Network_OnConnected(object sender)
+ {
+ if (OnConnected != null)
+ {
+ OnConnected(this, EventType.CONNECTED);
+ }
+
+ }
+ public void Simulator_Connected(object sender)
+ {
+
+
+ }
+
+ public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
+ {
+ if (OnDisconnected != null)
+ {
+ OnDisconnected(this,EventType.DISCONNECTED);
+ }
+
+
+ }
+ public string[] readexcuses()
+ {
+
+
+
+ string allexcuses = "";
+
+
+ string file = Path.Combine(Util.configDir(), "excuses");
+ if (File.Exists(file))
+ {
+ StreamReader csr = File.OpenText(file);
+ allexcuses = csr.ReadToEnd();
+ csr.Close();
+ }
+
+
+ return allexcuses.Split(Environment.NewLine.ToCharArray());
+
+ }
+
+
+ }
+
+
+}
diff --git a/pCampBot/PhysicsCamperBotREADME.txt b/pCampBot/PhysicsCamperBotREADME.txt
new file mode 100644
index 0000000..988f589
--- /dev/null
+++ b/pCampBot/PhysicsCamperBotREADME.txt
@@ -0,0 +1,21 @@
+This is the PhysicsCamperbot libslBot tester.
+
+This is designed to be run in standalone mode with authorize accounts turned off as a way to stress test the simulator.
+It creates clients that log in, randomly jump/walk around, and say excuses from the BOFH
+
+**Warning:** Using this bot on a public grid could get you banned perminantly, so just say No! to greifing!
+
+-----Setup -----
+Run the prebuilds for it IN THIS FOLDER and then open the created solution and compile it. It will end up in the regular opensim bin folder.
+
+-----Running the bot----
+
+windows: pCampBot.exe -botcount -loginuri
+*nix: mono pCampBot.exe -botcount -loginuri
+
+The names it produces are random by default, however, you can specify either a firstname or a lastname in the command line also.
+ex: pCampBot.exe -botcount -loginuri -lastname
+
+If you specify both a firstname *and* a lastname, you'll likely run into trouble unless you're only running a single bot. In that case, there's also a password option.
+
+pCampBot.exe -botcount 1 -loginuri http://somegrid.com:8002 -firstname SomeDude -lastname SomeDude -password GobbleDeGook
diff --git a/pCampBot/pCampBot.cs b/pCampBot/pCampBot.cs
new file mode 100644
index 0000000..983eaf0
--- /dev/null
+++ b/pCampBot/pCampBot.cs
@@ -0,0 +1,80 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using libsecondlife;
+using libsecondlife.Packets;
+using Nini.Config;
+using System.Threading;
+using OpenSim.Framework.Console;
+
+
+namespace pCampBot
+{
+ ///
+ /// Event Types from the BOT. Add new events here
+ ///
+ public enum EventType:int
+ {
+ NONE = 0,
+ CONNECTED = 1,
+ DISCONNECTED = 2
+ }
+ public class pCampBot
+ {
+
+
+ [STAThread]
+ public static void Main(string[] args)
+ {
+ //Set up our nifty config.. thanks to nini
+ ArgvConfigSource cs = new ArgvConfigSource(args);
+
+ cs.AddSwitch("Startup", "botcount");
+ cs.AddSwitch("Startup", "loginuri");
+ cs.AddSwitch("Startup", "firstname");
+ cs.AddSwitch("Startup", "lastname");
+ cs.AddSwitch("Startup", "password");
+
+
+ IConfig ol = cs.Configs["Startup"];
+ int botcount = ol.GetInt("botcount", 1);
+ BotManager bm = new BotManager();
+
+ //startup specified number of bots. 1 is the default
+ bm.dobotStartup(botcount, ol);
+ while (true)
+ {
+ MainLog.Instance.MainLogPrompt();
+ }
+
+ }
+ }
+}
diff --git a/pCampBot/pCampBot.csproj b/pCampBot/pCampBot.csproj
new file mode 100644
index 0000000..04b044c
--- /dev/null
+++ b/pCampBot/pCampBot.csproj
@@ -0,0 +1,102 @@
+
+
+ Local
+ 8.0.50727
+ 2.0
+ {7F3A2F5C-0000-0000-0000-000000000000}
+ Debug
+ AnyCPU
+
+
+
+ pCampBot
+ JScript
+ Grid
+ IE50
+ false
+ Exe
+
+ pCampBot
+
+
+
+
+
+ False
+ 285212672
+ False
+
+
+ TRACE;DEBUG
+
+ True
+ 4096
+ False
+ ..\bin\
+ False
+ False
+ False
+ 4
+
+
+
+ False
+ 285212672
+ False
+
+
+ TRACE
+
+ False
+ 4096
+ True
+ ..\bin\
+ False
+ False
+ False
+ 4
+
+
+
+
+ ..\bin\libsecondlife.dll
+ False
+
+
+ ..\bin\Nini.dll
+ False
+
+
+ ..\bin\OpenSim.Framework.Console.dll
+ False
+
+
+ ..\bin\OpenSim.Framework.dll
+ False
+
+
+ System.dll
+ False
+
+
+
+
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+
+
+
+
+
+
+
+
diff --git a/pCampBot/prebuild.xml b/pCampBot/prebuild.xml
new file mode 100644
index 0000000..25219fd
--- /dev/null
+++ b/pCampBot/prebuild.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+ TRACE;DEBUG
+ false
+ false
+ false
+ 4
+ false
+
+ ../bin
+ true
+ true
+ false
+
+
+
+
+ TRACE
+ true
+ false
+ false
+ 4
+ false
+
+ ../bin
+ false
+ true
+ false
+
+
+
+
+
+
+
+
+ ../bin/
+
+
+
+
+ ../bin/
+
+
+
+ ../bin/
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pCampBot/runprebuild.bat b/pCampBot/runprebuild.bat
new file mode 100644
index 0000000..05dfe16
--- /dev/null
+++ b/pCampBot/runprebuild.bat
@@ -0,0 +1,2 @@
+..\bin\Prebuild.exe /target nant
+..\bin\Prebuild.exe /target vs2005
\ No newline at end of file
diff --git a/pCampBot/runprebuild.sh b/pCampBot/runprebuild.sh
new file mode 100644
index 0000000..23fbfef
--- /dev/null
+++ b/pCampBot/runprebuild.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+mono ../bin/Prebuild.exe /target nant
+mono ../bin/Prebuild.exe /target vs2005
--
cgit v1.1