//
// Radegast Metaverse Client
-// Copyright (c) 2009, Radegast Development Team
+// Copyright (c) 2009-2010, Radegast Development Team
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
if (RadegastFormCreated != null) RadegastFormCreated(radForm);
}
#endregion
+
private GridClient client;
private RadegastNetcom netcom;
}
}
+ /// <summary>
+ /// When was Radegast started (UTC)
+ /// </summary>
+ public readonly DateTime StartupTimeUTC;
+
+ /// <summary>
+ /// Time zone of the current world (currently hard coded to US Pacific time)
+ /// </summary>
+ public TimeZoneInfo WordTimeZone;
+
private string userDir;
/// <summary>
/// System (not grid!) user's dir
/// </summary>
public RLVManager RLV { get { return rlv; } }
+ private GridManager gridManager;
+ /// <summary>Manages default params for different grids</summary>
+ public GridManager GridManger { get { return gridManager; } }
+
#region Events
#region ClientChanged event
client = client0;
+ // Initialize current time zone, and mark when we started
+ GetWorldTimeZone();
+ StartupTimeUTC = DateTime.UtcNow;
+
// Are we running mono?
monoRuntime = Type.GetType("Mono.Runtime") != null;
InitializeClient(client);
rlv = new RLVManager(this);
+ gridManager = new GridManager(this);
+ gridManager.LoadGrids();
mainForm = new frmMain(this);
mainForm.InitializeControls();
client.Assets.Cache.AutoPruneEnabled = false;
client.Throttle.Total = 5000000f;
- client.Settings.THROTTLE_OUTGOING_PACKETS = true;
+ client.Settings.THROTTLE_OUTGOING_PACKETS = false;
client.Settings.LOGIN_TIMEOUT = 120 * 1000;
client.Settings.SIMULATOR_TIMEOUT = 120 * 1000;
client.Settings.MAX_CONCURRENT_TEXTURE_DOWNLOADS = 20;
client.Groups.GroupDropped += new EventHandler<GroupDroppedEventArgs>(Groups_GroupsChanged);
client.Groups.GroupJoinedReply += new EventHandler<GroupOperationEventArgs>(Groups_GroupsChanged);
client.Avatars.UUIDNameReply += new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
- netcom.ClientConnected += new EventHandler<EventArgs>(netcom_ClientConnected);
+ if (netcom != null)
+ netcom.ClientConnected += new EventHandler<EventArgs>(netcom_ClientConnected);
}
private void UnregisterClientEvents(GridClient client)
client.Groups.GroupDropped -= new EventHandler<GroupDroppedEventArgs>(Groups_GroupsChanged);
client.Groups.GroupJoinedReply -= new EventHandler<GroupOperationEventArgs>(Groups_GroupsChanged);
client.Avatars.UUIDNameReply -= new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
- netcom.ClientConnected -= new EventHandler<EventArgs>(netcom_ClientConnected);
+ if (netcom != null)
+ netcom.ClientConnected -= new EventHandler<EventArgs>(netcom_ClientConnected);
+ }
+
+ private void GetWorldTimeZone()
+ {
+ try
+ {
+ foreach (TimeZoneInfo tz in TimeZoneInfo.GetSystemTimeZones())
+ {
+ if (tz.Id == "Pacific Standard Time" || tz.Id == "America/Los_Angeles")
+ {
+ WordTimeZone = tz;
+ break;
+ }
+ }
+ }
+ catch (Exception) { }
}
+ public DateTime GetWorldTime()
+ {
+ DateTime now;
+
+ try
+ {
+ if (WordTimeZone != null)
+ now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, WordTimeZone);
+ else
+ now = DateTime.UtcNow.AddHours(-7);
+ }
+ catch (Exception)
+ {
+ now = DateTime.UtcNow.AddHours(-7);
+ }
+
+ return now;
+ }
+
+
public void Reconnect()
{
TabConsole.DisplayNotificationInChat("Attempting to reconnect...", ChatBufferTextStyle.StatusDarkBlue);
public void CleanUp()
{
+ if (gridManager != null)
+ {
+ gridManager.Dispose();
+ gridManager = null;
+ }
+
if (rlv != null)
{
rlv.Dispose();
}
}
+ /// <summary>
+ /// Fetches avatar name
+ /// </summary>
+ /// <param name="key">Avatar UUID</param>
+ /// <param name="blocking">Should we wait until the name is retrieved</param>
+ /// <returns>Avatar name</returns>
+ public string getAvatarName(UUID key, bool blocking)
+ {
+ if (!blocking)
+ return getAvatarName(key);
+
+ string name = null;
+
+ using (ManualResetEvent gotName = new ManualResetEvent(false))
+ {
+
+ EventHandler<UUIDNameReplyEventArgs> handler = (object sender, UUIDNameReplyEventArgs e) =>
+ {
+ if (e.Names.ContainsKey(key))
+ {
+ name = e.Names[key];
+ gotName.Set();
+ }
+ };
+
+ client.Avatars.UUIDNameReply += handler;
+ name = getAvatarName(key);
+
+ if (name == INCOMPLETE_NAME)
+ {
+ gotName.WaitOne(10 * 1000, false);
+ }
+
+ client.Avatars.UUIDNameReply -= handler;
+ }
+ return name;
+
+ }
+
+ /// <summary>
+ /// Fetches avatar name from cache, if not in cache will requst name from the server
+ /// </summary>
+ /// <param name="key">Avatar UUID</param>
+ /// <returns>Avatar name</returns>
public string getAvatarName(UUID key)
{
lock (nameCache)