diff --git a/libsecondlife-cs/NetworkManager.cs b/libsecondlife-cs/NetworkManager.cs index 40549da0..5fbcf415 100644 --- a/libsecondlife-cs/NetworkManager.cs +++ b/libsecondlife-cs/NetworkManager.cs @@ -739,7 +739,7 @@ namespace libsecondlife public static string StartLocation(string sim, int x, int y, int z) { //uri:sim&x&y&z - return "uri:" + sim + "&" + x + "&" + y + "&" + z; + return "uri:" + sim.ToLower() + "&" + x + "&" + y + "&" + z; } /// @@ -755,8 +755,9 @@ namespace libsecondlife string firstName, string lastName, string password, string userAgent, string author) { return DefaultLoginValues(firstName, lastName, password, "00:00:00:00:00:00", "last", - 1, 50, 50, 50, "Win", "0", userAgent, author); + 1, 50, 50, 50, "Win", "0", userAgent, author, false); } + /// /// /// @@ -767,17 +768,32 @@ namespace libsecondlife /// /// public static Dictionary DefaultLoginValues( - string firstName, string lastName, string password, string startLocation, string userAgent, string author) + string firstName, string lastName, string password, string startLocation, string userAgent, string author, + bool md5pass) { return DefaultLoginValues(firstName, lastName, password, "00:00:00:00:00:00", startLocation, - 1, 50, 50, 50, "Win", "0", userAgent, author); + 1, 50, 50, 50, "Win", "0", userAgent, author, md5pass); } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// public static Dictionary DefaultLoginValues(string firstName, string lastName, string password, string mac, string startLocation, string platform, string viewerDigest, string userAgent, string author) { return DefaultLoginValues(firstName, lastName, password, mac, startLocation, - 1, 50, 50, 50, platform, viewerDigest, userAgent, author); + 1, 50, 50, 50, platform, viewerDigest, userAgent, author, false); } /// @@ -799,13 +815,13 @@ namespace libsecondlife /// public static Dictionary DefaultLoginValues(string firstName, string lastName, string password, string mac, string startLocation, int major, int minor, - int patch, int build, string platform, string viewerDigest, string userAgent, string author) + int patch, int build, string platform, string viewerDigest, string userAgent, string author, bool md5pass) { Dictionary values = new Dictionary(); values["first"] = firstName; values["last"] = lastName; - values["passwd"] = Helpers.MD5(password); + values["passwd"] = md5pass ? password : Helpers.MD5(password); values["start"] = startLocation; values["major"] = major; values["minor"] = minor; @@ -814,6 +830,7 @@ namespace libsecondlife values["platform"] = platform; values["mac"] = mac; values["agree_to_tos"] = "true"; + values["read_critical"] = "true"; values["viewer_digest"] = viewerDigest; values["user-agent"] = userAgent + " (" + Helpers.VERSION + ")"; values["author"] = author; @@ -851,11 +868,28 @@ namespace libsecondlife /// /// Uses the ConnectedCallback delegate. public event ConnectedCallback OnConnected; - + + /// + /// + /// + /// + /// + /// + /// + /// + /// public bool Login(string firstName, string lastName, string password, string userAgent, string author) { Dictionary loginParams = NetworkManager.DefaultLoginValues(firstName, lastName, - password, userAgent, author); + password, "last", userAgent, author, false); + return Login(loginParams); + } + + public bool Login(string firstName, string lastName, string password, string userAgent, string start, + string author, bool md5pass) + { + Dictionary loginParams = NetworkManager.DefaultLoginValues(firstName, lastName, + password, userAgent, start, author, md5pass); return Login(loginParams); } @@ -889,7 +923,7 @@ namespace libsecondlife } catch (Exception e) { - LoginError = e.Message; + LoginError = "XML-RPC Error: " + e.Message; LoginValues = null; return false; } @@ -897,7 +931,7 @@ namespace libsecondlife if (result.IsFault) { Client.Log("Fault " + result.FaultCode + ": " + result.FaultString, Helpers.LogLevel.Error); - LoginError = "Fault " + result.FaultCode + ": " + result.FaultString; + LoginError = "XML-RPC Fault: " + result.FaultCode + ": " + result.FaultString; LoginValues = null; return false; } diff --git a/libsecondlife-cs/examples/AnimationSample/AnimationSample.cs b/libsecondlife-cs/examples/AnimationSample/AnimationSample.cs index 1d13d835..e512cf00 100644 --- a/libsecondlife-cs/examples/AnimationSample/AnimationSample.cs +++ b/libsecondlife-cs/examples/AnimationSample/AnimationSample.cs @@ -50,13 +50,8 @@ namespace AnimationSample private void btnLogin_Click(object sender, EventArgs e) { - //Login information - Dictionary loginParams = NetworkManager.DefaultLoginValues(txtFirst.Text, txtLast.Text, txtPassword.Text, "00:00:00:00:00:00", - "last", 1, 12, 12, 12, "Win", "0", "animationsample", "jessemalthus@gmail.com"); - Hashtable loginReply = new Hashtable(); - // Login - if (!client.Network.Login(loginParams)) + if (!client.Network.Login(txtFirst.Text, txtLast.Text, txtPassword.Text, "animationsample", "jessemalthus@gmail.com")) { // Login failed MessageBox.Show("We're sorry, but login failed. Error: \n " + client.Network.LoginError); diff --git a/libsecondlife-cs/tests/DebugServer.cs b/libsecondlife-cs/tests/DebugServer.cs deleted file mode 100644 index f2986168..00000000 --- a/libsecondlife-cs/tests/DebugServer.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Text.RegularExpressions; -using System.Xml; -using System.Threading; -using Nwc.XmlRpc; -using libsecondlife; -using libsecondlife.Packets; - -namespace libsecondlife.Tests -{ - public class DebugServer - { - public bool Initialized = false; - - private SecondLife libsl; - private bool done = false; - private Socket Listener; - private IPEndPoint Endpoint; - EndPoint RemoteEndpoint = new IPEndPoint(IPAddress.Loopback, 0); - private ushort Sequence = 0; - - public DebugServer(string keywordFile, string mapFile, int port) - { - libsl = new SecondLife(); - - BindSocket(port); - } - - private void BindSocket(int port) - { - Endpoint = new IPEndPoint(IPAddress.Loopback, port); - Listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); - - Console.WriteLine("[SERVER] Binding a UDP socket to " + Endpoint.ToString()); - - try - { - Listener.Bind(Endpoint); - } - catch (SocketException) - { - Console.WriteLine("[SERVER] Failed to bind to " + Endpoint.ToString()); - return; - } - - // Start listening for incoming data - Thread thread = new Thread(new ThreadStart(Listen)); - thread.Start(); - - Initialized = true; - } - - private void Listen() - { - Packet packet; - int length; - byte[] bytes = new byte[4096]; - - Console.WriteLine("[SERVER] Listening for incoming data on " + Endpoint.ToString()); - - while (!done) - { - packet = null; - - // Grab the next packet - length = Listener.ReceiveFrom(bytes, ref RemoteEndpoint); - - Console.WriteLine("[SERVER] Received a packet from {0}", RemoteEndpoint.ToString()); - - if (Helpers.FieldToString(bytes).StartsWith("stopserver")) - { - Console.WriteLine("[SERVER] Received a shutdown request, stopping the server"); - done = true; - break; - } - - int packetEnd = length - 1; - packet = Packet.BuildPacket(bytes, ref packetEnd); - - if (packet.Header.AppendedAcks) - { - Console.WriteLine("[SERVER] Found " + packet.Header.AckList.Length + " appended acks"); - } - - if (packet.Header.Reliable) - { - SendACK((uint)packet.Header.Sequence); - } - - Console.WriteLine(packet.ToString()); - } - - Console.WriteLine("[SERVER] Shutting down the socket on " + Endpoint.ToString()); - Listener.Close(); - } - - private void SendACK(uint id) - { - try - { - PacketAckPacket ack = new PacketAckPacket(); - ack.Packets = new PacketAckPacket.PacketsBlock[1]; - ack.Packets[0].ID = id; - - ack.Header.Reliable = false; - - // Set the sequence number - ack.Header.Sequence = ++Sequence; - - Listener.SendTo(ack.ToBytes(), RemoteEndpoint); - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - } - } - } -} diff --git a/libsecondlife-cs/tests/Tests.cs b/libsecondlife-cs/tests/Tests.cs index d502df64..7c90641c 100644 --- a/libsecondlife-cs/tests/Tests.cs +++ b/libsecondlife-cs/tests/Tests.cs @@ -8,88 +8,68 @@ using NUnit.Framework; namespace libsecondlife.Tests { [TestFixture] - public class EndianTests : Assert + public class UnitTests : Assert { - SecondLife Client = null; - DebugServer Server = null; - Packet CurrentPacket = null; - bool NetworkFinished = false; + SecondLife Client; + ulong CurrentRegionHandle = 0; + ulong AhernRegionHandle = 1096213093149184; [SetUp] public void Init() { Client = new SecondLife(); - Client.Network.AgentID = LLUUID.GenerateUUID(); - Client.Network.SessionID = LLUUID.GenerateUUID(); - Server = new DebugServer("keywords.txt", "message_template.msg", 8338); - Assert.IsTrue(Server.Initialized, "Failed to initialize the server, couldn't bind to port 8338?"); + //string startLoc = NetworkManager.StartLocation("ahern", 128, 128, 32); - Simulator debugSim = Client.Network.Connect(IPAddress.Loopback, 8338, 1, true); - Assert.IsNotNull(debugSim, "Failed to connect to the debugging simulator"); + // Register callbacks + Client.Network.RegisterCallback(PacketType.ObjectUpdate, new PacketCallback(ObjectUpdateHandler)); - Client.Network.RegisterCallback(PacketType.SimulatorAssign, new PacketCallback(SimulatorAssignHandler)); - } + bool result = Client.Network.Login("Testing", "Anvil", "testinganvil", "Unit Test Framework", + "contact@libsecondlife.org"); - [Test] - public void U8Receive() - { - CurrentPacket = null; - NetworkFinished = false; - - // 2. Instruct the server to send a SimulatorAssign to the client with some fixed values + Assert.IsTrue(result, "Login failed for Testing Anvil: " + Client.Network.LoginError); int start = Environment.TickCount; - - while (!NetworkFinished && Environment.TickCount - start < 5000) + while (Client.Network.CurrentSim.Region.Name == "") { - System.Threading.Thread.Sleep(0); + if (Environment.TickCount - start > 5000) + { + Assert.Fail("Timeout waiting for a RegionHandshake packet"); + } } - // 5. Parse the Packet and run our assertion(s) - Assert.IsNotNull(CurrentPacket, "Never received the packet"); - Assert.IsTrue(true); + Assert.AreEqual(Client.Network.CurrentSim.Region.Name.ToLower(), "ahern", "Logged in to sim " + + Client.Network.CurrentSim.Region.Name + " instead of Ahern"); } [Test] - public void S8Receive() + public void U64Receive() { - ; + int start = Environment.TickCount; + while (CurrentRegionHandle == 0) + { + if (Environment.TickCount - start > 5000) + { + Assert.Fail("Timeout waiting for an ObjectUpdate packet"); + } + } + + Assert.IsTrue(CurrentRegionHandle == AhernRegionHandle, "Current region is " + + CurrentRegionHandle + " when we were expecting " + AhernRegionHandle + ", possible endian issue"); } - [Test] - public void U16Receive() + private void ObjectUpdateHandler(Packet packet, Simulator sim) { - ; - } + ObjectUpdatePacket update = (ObjectUpdatePacket)packet; - [Test] - public void S16Receive() - { - ; - } - - private void SimulatorAssignHandler(Packet packet, Simulator sim) - { - CurrentPacket = packet; - NetworkFinished = true; + CurrentRegionHandle = update.RegionData.RegionHandle; } [TearDown] public void Shutdown() { - try - { - Client.Network.SendPacket(System.Text.Encoding.UTF8.GetBytes("stopserver")); - Client.Network.Logout(); - } - catch (NotConnectedException) - { - Assert.IsTrue(false, "Logout failed, not connected"); - } - + Client.Network.Logout(); Client = null; - Server = null; } } } diff --git a/libsecondlife-cs/tests/libsecondlife.Tests.csproj b/libsecondlife-cs/tests/libsecondlife.Tests.csproj index 9875a633..f57f00f5 100644 --- a/libsecondlife-cs/tests/libsecondlife.Tests.csproj +++ b/libsecondlife-cs/tests/libsecondlife.Tests.csproj @@ -37,7 +37,6 @@ - diff --git a/libsecondlife.nunit b/libsecondlife.nunit new file mode 100644 index 00000000..4e585128 --- /dev/null +++ b/libsecondlife.nunit @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file