2 // Radegast Metaverse Client
\r
3 // Copyright (c) 2009, Radegast Development Team
\r
4 // All rights reserved.
\r
6 // Redistribution and use in source and binary forms, with or without
\r
7 // modification, are permitted provided that the following conditions are met:
\r
9 // * Redistributions of source code must retain the above copyright notice,
\r
10 // this list of conditions and the following disclaimer.
\r
11 // * Redistributions in binary form must reproduce the above copyright
\r
12 // notice, this list of conditions and the following disclaimer in the
\r
13 // documentation and/or other materials provided with the distribution.
\r
14 // * Neither the name of the application "Radegast", nor the names of its
\r
15 // contributors may be used to endorse or promote products derived from
\r
16 // this software without specific prior written permission.
\r
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 using System.Collections.Generic;
\r
35 using System.Windows.Forms;
\r
37 using OpenMetaverse;
\r
41 public class RadegastInstance
\r
43 private GridClient client;
\r
44 private RadegastNetcom netcom;
\r
46 private ImageCache imageCache;
\r
47 private StateManager state;
\r
48 private ConfigManager config;
\r
50 private frmMain mainForm;
\r
51 private TabsConsole tabsConsole;
\r
52 public readonly string userDir;
\r
53 public readonly string animCacheDir;
\r
55 public Dictionary<UUID, Group> groups;
\r
56 public Dictionary<UUID, string> nameCache = new Dictionary<UUID,string>();
\r
58 public delegate void OnAvatarNameCallBack(UUID agentID, string agentName);
\r
59 public event OnAvatarNameCallBack OnAvatarName;
\r
61 public readonly bool advancedDebugging = false;
\r
62 public readonly bool MonoRuntime;
\r
64 public RadegastInstance()
\r
68 userDir = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), Properties.Resources.ProgramName);
\r
69 if (!Directory.Exists(userDir))
\r
71 Directory.CreateDirectory(userDir);
\r
76 userDir = System.Environment.CurrentDirectory;
\r
78 animCacheDir = Path.Combine(userDir, @"anim_cache");
\r
80 // Are we running mono?
\r
81 if (null == Type.GetType("Mono.Runtime"))
\r
83 MonoRuntime = false;
\r
90 Settings.PIPELINE_REFRESH_INTERVAL = 2000.0f;
\r
92 client = new GridClient();
\r
93 client.Settings.ALWAYS_REQUEST_OBJECTS = true;
\r
94 client.Settings.ALWAYS_DECODE_OBJECTS = true;
\r
95 client.Settings.OBJECT_TRACKING = true;
\r
96 client.Settings.ENABLE_SIMSTATS = true;
\r
97 client.Settings.FETCH_MISSING_INVENTORY = true;
\r
98 client.Settings.MULTIPLE_SIMS = true;
\r
99 client.Settings.SEND_AGENT_THROTTLE = true;
\r
100 client.Settings.SEND_AGENT_UPDATES = true;
\r
102 client.Settings.USE_TEXTURE_CACHE = true;
\r
103 client.Settings.TEXTURE_CACHE_DIR = Path.Combine(userDir, "cache");
\r
104 client.Assets.Cache.AutoPruneEnabled = false;
\r
106 client.Throttle.Texture = 2446000.0f;
\r
107 client.Throttle.Asset = 2446000.0f;
\r
108 client.Settings.THROTTLE_OUTGOING_PACKETS = true;
\r
109 client.Settings.LOGIN_TIMEOUT = 120 * 1000;
\r
110 client.Settings.SIMULATOR_TIMEOUT = 120 * 1000;
\r
112 netcom = new RadegastNetcom(client);
\r
114 imageCache = new ImageCache();
\r
115 state = new StateManager(this);
\r
116 InitializeConfig();
\r
118 mainForm = new frmMain(this);
\r
119 mainForm.InitializeControls();
\r
120 tabsConsole = mainForm.TabConsole;
\r
122 Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
\r
123 groups = new Dictionary<UUID, Group>();
\r
125 client.Groups.OnCurrentGroups += new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
\r
126 client.Groups.OnGroupLeft += new GroupManager.GroupLeftCallback(Groups_OnGroupLeft);
\r
127 client.Groups.OnGroupDropped += new GroupManager.GroupDroppedCallback(Groups_OnGroupDropped);
\r
128 client.Groups.OnGroupJoined += new GroupManager.GroupJoinedCallback(Groups_OnGroupJoined);
\r
129 client.Groups.OnGroupProfile += new GroupManager.GroupProfileCallback(Groups_OnGroupProfile);
\r
130 client.Avatars.OnAvatarNames += new AvatarManager.AvatarNamesCallback(Avatars_OnAvatarNames);
\r
133 public void CleanUp()
\r
135 if (client != null)
\r
137 client.Groups.OnCurrentGroups -= new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
\r
138 client.Groups.OnGroupLeft -= new GroupManager.GroupLeftCallback(Groups_OnGroupLeft);
\r
139 client.Groups.OnGroupDropped -= new GroupManager.GroupDroppedCallback(Groups_OnGroupDropped);
\r
140 client.Groups.OnGroupJoined -= new GroupManager.GroupJoinedCallback(Groups_OnGroupJoined);
\r
141 client.Groups.OnGroupProfile -= new GroupManager.GroupProfileCallback(Groups_OnGroupProfile);
\r
142 client.Avatars.OnAvatarNames -= new AvatarManager.AvatarNamesCallback(Avatars_OnAvatarNames);
\r
147 Environment.Exit(0);
\r
152 void Avatars_OnAvatarNames(Dictionary<UUID, string> names)
\r
156 foreach (KeyValuePair<UUID, string> av in names)
\r
158 if (OnAvatarName != null) try { OnAvatarName(av.Key, av.Value); }
\r
159 catch (Exception) { };
\r
161 if (!nameCache.ContainsKey(av.Key))
\r
163 nameCache.Add(av.Key, av.Value);
\r
169 public string getAvatarName(UUID key)
\r
171 if (nameCache.ContainsKey(key))
\r
173 return nameCache[key];
\r
177 client.Avatars.RequestAvatarName(key);
\r
178 return "Loading...";
\r
182 void Groups_OnGroupProfile(Group group)
\r
184 if (groups.ContainsKey(group.ID))
\r
186 groups[group.ID] = group;
\r
190 void Groups_OnGroupJoined(UUID groupID, bool success)
\r
192 if (success && !groups.ContainsKey(groupID))
\r
194 groups.Add(groupID, new Group());
\r
195 client.Groups.RequestGroupProfile(groupID);
\r
199 void Groups_OnGroupLeft(UUID groupID, bool success)
\r
201 if (groups.ContainsKey(groupID))
\r
203 groups.Remove(groupID);
\r
207 void Groups_OnGroupDropped(UUID groupID)
\r
209 if (groups.ContainsKey(groupID))
\r
211 groups.Remove(groupID);
\r
215 void Groups_OnCurrentGroups(Dictionary<UUID, Group> gr)
\r
220 private void Application_ApplicationExit(object sender, EventArgs e)
\r
222 config.SaveCurrentConfig();
\r
225 private void InitializeConfig()
\r
227 config = new ConfigManager(this);
\r
228 config.ApplyDefault();
\r
230 netcom.LoginOptions.FirstName = config.CurrentConfig.FirstName;
\r
231 netcom.LoginOptions.LastName = config.CurrentConfig.LastName;
\r
232 netcom.LoginOptions.Password = config.CurrentConfig.PasswordMD5;
\r
233 netcom.LoginOptions.IsPasswordMD5 = true;
\r
236 public GridClient Client
\r
238 get { return client; }
\r
241 public RadegastNetcom Netcom
\r
243 get { return netcom; }
\r
246 public ImageCache ImageCache
\r
248 get { return imageCache; }
\r
251 public StateManager State
\r
253 get { return state; }
\r
256 public ConfigManager Config
\r
258 get { return config; }
\r
261 public frmMain MainForm
\r
263 get { return mainForm; }
\r
266 public TabsConsole TabConsole
\r
268 get { return tabsConsole; }
\r