2006-10-21 02:52:28 +00:00
|
|
|
/*
|
2015-11-06 19:40:28 +01:00
|
|
|
* Copyright (c) 2006-2016, openmetaverse.co
|
2025-01-02 16:43:28 -06:00
|
|
|
* Copyright (c) 2025, Sjofn LLC.
|
2006-10-21 02:52:28 +00:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* - 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.
|
2015-11-06 19:00:05 +01:00
|
|
|
* - Neither the name of the openmetaverse.co nor the names
|
2006-10-21 02:52:28 +00:00
|
|
|
* 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR 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;
|
2006-11-07 23:30:09 +00:00
|
|
|
using System.Threading;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
2006-10-21 02:52:28 +00:00
|
|
|
|
2008-07-23 15:35:39 +00:00
|
|
|
namespace PacketDump
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
2025-01-02 16:43:28 -06:00
|
|
|
internal class PacketDump
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
2025-01-02 16:43:28 -06:00
|
|
|
private static bool LoginSuccess = false;
|
|
|
|
|
private static AutoResetEvent LoginEvent = new AutoResetEvent(false);
|
2007-04-15 04:59:44 +00:00
|
|
|
|
2006-10-21 02:52:28 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
2025-01-02 16:43:28 -06:00
|
|
|
private static void Main(string[] args)
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
2024-06-30 18:10:23 -05:00
|
|
|
if (args.Length != 4)
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
2025-01-02 16:43:28 -06:00
|
|
|
Console.WriteLine("Usage: LMV.PacketDump [firstname] [lastname] [password] [seconds (0 for infinite)]");
|
2006-10-21 02:52:28 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-02 16:43:28 -06:00
|
|
|
var client = new GridClient
|
|
|
|
|
{
|
|
|
|
|
Settings = { MULTIPLE_SIMS = false },
|
|
|
|
|
Throttle =
|
|
|
|
|
{
|
|
|
|
|
// Throttle packets that we don't want all the way down
|
|
|
|
|
Land = 0,
|
|
|
|
|
Wind = 0,
|
|
|
|
|
Cloud = 0
|
|
|
|
|
}
|
|
|
|
|
};
|
2006-10-21 02:52:28 +00:00
|
|
|
|
2025-01-02 16:43:28 -06:00
|
|
|
// Setup a packet callback that is called for every packet (PacketType.Default)
|
2009-10-28 08:01:52 +00:00
|
|
|
client.Network.RegisterCallback(PacketType.Default, DefaultHandler);
|
2008-08-21 19:03:29 +00:00
|
|
|
|
|
|
|
|
// Register handlers for when we login, and when we are disconnected
|
2009-10-28 08:01:52 +00:00
|
|
|
client.Network.LoginProgress += LoginHandler;
|
|
|
|
|
client.Network.Disconnected += DisconnectHandler;
|
2006-10-21 02:52:28 +00:00
|
|
|
|
2008-08-21 19:03:29 +00:00
|
|
|
// Start the login process
|
2008-07-23 15:35:39 +00:00
|
|
|
client.Network.BeginLogin(client.Network.DefaultLoginParams(args[0], args[1], args[2], "PacketDump", "1.0.0"));
|
2007-04-15 04:59:44 +00:00
|
|
|
|
2008-08-21 19:03:29 +00:00
|
|
|
// Wait until LoginEvent is set in the LoginHandler callback, or we time out
|
2025-01-13 07:44:05 -06:00
|
|
|
if (LoginEvent.WaitOne(TimeSpan.FromSeconds(20), false))
|
2007-04-15 04:59:44 +00:00
|
|
|
{
|
2008-08-21 19:03:29 +00:00
|
|
|
if (LoginSuccess)
|
2006-11-21 15:24:17 +00:00
|
|
|
{
|
2008-08-21 19:03:29 +00:00
|
|
|
// Network.LoginMessage is set after a successful login
|
|
|
|
|
Logger.Log("Message of the day: " + client.Network.LoginMessage, Helpers.LogLevel.Info);
|
|
|
|
|
|
|
|
|
|
// Determine how long to run for
|
2025-01-02 16:43:28 -06:00
|
|
|
var start = Environment.TickCount;
|
|
|
|
|
var milliseconds = int.Parse(args[3]) * 1000;
|
|
|
|
|
var forever = (milliseconds <= 0);
|
2008-08-21 19:03:29 +00:00
|
|
|
|
|
|
|
|
// Packet handling is done with asynchronous callbacks. Run a sleeping loop in the main
|
|
|
|
|
// thread until we run out of time or the program is closed
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
System.Threading.Thread.Sleep(100);
|
|
|
|
|
|
|
|
|
|
if (!forever && Environment.TickCount - start > milliseconds)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finished running, log out
|
|
|
|
|
client.Network.Logout();
|
2006-11-21 15:24:17 +00:00
|
|
|
}
|
2008-08-21 19:03:29 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Log("Login failed: " + client.Network.LoginMessage, Helpers.LogLevel.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Log("Login timed out", Helpers.LogLevel.Error);
|
|
|
|
|
}
|
2006-10-21 02:52:28 +00:00
|
|
|
}
|
2007-04-15 04:59:44 +00:00
|
|
|
|
2025-01-02 16:43:28 -06:00
|
|
|
private static void LoginHandler(object sender, LoginProgressEventArgs e)
|
2007-04-15 04:59:44 +00:00
|
|
|
{
|
2024-06-30 16:48:27 -05:00
|
|
|
Logger.Log($"Login: {e.Status} ({e.Message})", Helpers.LogLevel.Info);
|
2007-04-15 04:59:44 +00:00
|
|
|
|
2009-10-28 08:01:52 +00:00
|
|
|
switch (e.Status)
|
2007-04-15 04:59:44 +00:00
|
|
|
{
|
2007-12-21 02:25:36 +00:00
|
|
|
case LoginStatus.Failed:
|
2007-04-15 04:59:44 +00:00
|
|
|
LoginEvent.Set();
|
|
|
|
|
break;
|
2007-12-21 02:25:36 +00:00
|
|
|
case LoginStatus.Success:
|
2007-04-15 04:59:44 +00:00
|
|
|
LoginSuccess = true;
|
|
|
|
|
LoginEvent.Set();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-08-21 19:03:29 +00:00
|
|
|
|
2009-10-28 08:01:52 +00:00
|
|
|
public static void DisconnectHandler(object sender, DisconnectedEventArgs e)
|
2008-08-21 19:03:29 +00:00
|
|
|
{
|
2009-10-28 08:01:52 +00:00
|
|
|
if (e.Reason == NetworkManager.DisconnectType.NetworkTimeout)
|
2008-08-21 19:03:29 +00:00
|
|
|
{
|
|
|
|
|
Console.WriteLine("Network connection timed out, disconnected");
|
|
|
|
|
}
|
2009-10-28 08:01:52 +00:00
|
|
|
else if (e.Reason == NetworkManager.DisconnectType.ServerInitiated)
|
2008-08-21 19:03:29 +00:00
|
|
|
{
|
2009-10-28 08:01:52 +00:00
|
|
|
Console.WriteLine("Server disconnected us: " + e.Message);
|
2008-08-21 19:03:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-28 08:01:52 +00:00
|
|
|
public static void DefaultHandler(object sender, PacketReceivedEventArgs e)
|
2008-08-21 19:03:29 +00:00
|
|
|
{
|
2009-10-28 08:01:52 +00:00
|
|
|
Logger.Log(e.Packet.ToString(), Helpers.LogLevel.Info);
|
2008-08-21 19:03:29 +00:00
|
|
|
}
|
2006-10-21 02:52:28 +00:00
|
|
|
}
|
|
|
|
|
}
|