2006-10-21 02:52:28 +00:00
|
|
|
/*
|
2008-07-21 21:12:59 +00:00
|
|
|
* Copyright (c) 2006-2008, openmetaverse.org
|
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.
|
2008-07-21 21:12:59 +00:00
|
|
|
* - Neither the name of the openmetaverse.org 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-10-21 05:53:58 +00:00
|
|
|
using System.Collections.Generic;
|
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
|
|
|
{
|
2008-07-23 15:35:39 +00:00
|
|
|
class PacketDump
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
2007-04-15 04:59:44 +00:00
|
|
|
static bool LoginSuccess = false;
|
|
|
|
|
static AutoResetEvent LoginEvent = new AutoResetEvent(false);
|
|
|
|
|
|
2006-10-21 02:52:28 +00:00
|
|
|
// Default packet handler, registered for all packet types
|
|
|
|
|
public static void DefaultHandler(Packet packet, Simulator simulator)
|
|
|
|
|
{
|
2006-11-14 16:03:06 +00:00
|
|
|
Console.WriteLine(packet.ToString());
|
2006-10-21 02:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
2006-11-09 10:18:03 +00:00
|
|
|
public static void DisconnectHandler(NetworkManager.DisconnectType type, string message)
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
2006-11-09 10:18:03 +00:00
|
|
|
if (type == NetworkManager.DisconnectType.NetworkTimeout)
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
|
|
|
|
Console.WriteLine("Network connection timed out, disconnected");
|
|
|
|
|
}
|
2006-11-09 10:18:03 +00:00
|
|
|
else if (type == NetworkManager.DisconnectType.ServerInitiated)
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
|
|
|
|
Console.WriteLine("Server disconnected us: " + message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2008-07-21 21:12:59 +00:00
|
|
|
GridClient client;
|
2006-10-21 02:52:28 +00:00
|
|
|
|
2006-11-21 15:24:17 +00:00
|
|
|
if (args.Length == 0 || (args.Length < 4 && args[0] != "--printmap"))
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
2008-07-23 15:35:39 +00:00
|
|
|
Console.WriteLine("Usage: PacketDump [--printmap] [--decrypt] [inputfile] [outputfile] "
|
2006-11-21 15:24:17 +00:00
|
|
|
+ "[--protocol] [firstname] [lastname] [password] [seconds (0 for infinite)]");
|
2006-10-21 02:52:28 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (args[0] == "--decrypt")
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ProtocolManager.DecodeMapFile(args[1], args[2]);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
client = new GridClient();
|
2007-04-15 04:59:44 +00:00
|
|
|
// Turn off some unnecessary things
|
2008-05-08 16:58:09 +00:00
|
|
|
Settings.LOG_LEVEL = Helpers.LogLevel.None;
|
2007-04-15 04:59:44 +00:00
|
|
|
client.Settings.MULTIPLE_SIMS = false;
|
|
|
|
|
// Throttle packets that we don't want all the way down
|
|
|
|
|
client.Throttle.Land = 0;
|
|
|
|
|
client.Throttle.Wind = 0;
|
|
|
|
|
client.Throttle.Cloud = 0;
|
2006-10-21 02:52:28 +00:00
|
|
|
|
|
|
|
|
if (args[0] == "--printmap")
|
|
|
|
|
{
|
|
|
|
|
ProtocolManager protocol;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2006-10-29 20:22:54 +00:00
|
|
|
protocol = new ProtocolManager("message_template.msg", client);
|
2006-10-21 02:52:28 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
// Error initializing the client, probably missing file(s)
|
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protocol.PrintMap();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Setup the packet callback and disconnect event handler
|
2006-11-09 10:18:03 +00:00
|
|
|
client.Network.RegisterCallback(PacketType.Default, new NetworkManager.PacketCallback(DefaultHandler));
|
2007-02-22 18:13:42 +00:00
|
|
|
client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(DisconnectHandler);
|
2006-10-21 02:52:28 +00:00
|
|
|
|
2007-04-15 04:59:44 +00:00
|
|
|
client.Network.OnLogin += new NetworkManager.LoginCallback(Network_OnLogin);
|
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
|
|
|
|
|
|
|
|
LoginEvent.WaitOne();
|
|
|
|
|
|
|
|
|
|
if (!LoginSuccess)
|
|
|
|
|
{
|
2007-05-14 07:33:57 +00:00
|
|
|
Console.WriteLine("Login failed: {0}", client.Network.LoginMessage);
|
2007-04-15 04:59:44 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2006-10-21 02:52:28 +00:00
|
|
|
|
2007-05-14 07:33:57 +00:00
|
|
|
Console.WriteLine("Message of the day: " + client.Network.LoginMessage);
|
2006-11-21 15:24:17 +00:00
|
|
|
|
2006-11-07 23:30:09 +00:00
|
|
|
int start = Environment.TickCount;
|
2006-11-21 15:24:17 +00:00
|
|
|
int milliseconds = Int32.Parse(args[3]) * 1000;
|
|
|
|
|
bool forever = (milliseconds > 0) ? false : true;
|
2006-11-07 23:30:09 +00:00
|
|
|
|
2006-11-14 16:03:06 +00:00
|
|
|
while (true)
|
2006-10-21 02:52:28 +00:00
|
|
|
{
|
2006-11-07 23:30:09 +00:00
|
|
|
System.Threading.Thread.Sleep(100);
|
2006-11-21 15:24:17 +00:00
|
|
|
|
|
|
|
|
if (!forever && Environment.TickCount - start > milliseconds)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-10-21 02:52:28 +00:00
|
|
|
}
|
2006-11-07 23:30:09 +00:00
|
|
|
|
|
|
|
|
client.Network.Logout();
|
2006-10-21 02:52:28 +00:00
|
|
|
}
|
2007-04-15 04:59:44 +00:00
|
|
|
|
2007-12-21 02:25:36 +00:00
|
|
|
static void Network_OnLogin(LoginStatus login, string message)
|
2007-04-15 04:59:44 +00:00
|
|
|
{
|
2007-04-27 01:00:09 +00:00
|
|
|
Console.WriteLine("Login: " + login.ToString() + " (" + message + ")");
|
2007-04-15 04:59:44 +00:00
|
|
|
|
|
|
|
|
switch (login)
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-21 02:52:28 +00:00
|
|
|
}
|
|
|
|
|
}
|