Annotation of /trunk/IdealistViewer/Application/Protocol.cs
Parent Directory
|
Revision Log
Revision 33 - (view) (download)
| 1 : | teravus | 2 | using System; |
| 2 : | using System.Collections.Generic; | ||
| 3 : | teravus | 31 | using System.Reflection; |
| 4 : | teravus | 2 | using System.Text; |
| 5 : | using OpenMetaverse; | ||
| 6 : | using OpenMetaverse.Rendering; | ||
| 7 : | teravus | 31 | using log4net; |
| 8 : | teravus | 2 | |
| 9 : | teravus | 31 | |
| 10 : | teravus | 2 | namespace IdealistViewer |
| 11 : | { | ||
| 12 : | public class SLProtocol | ||
| 13 : | { | ||
| 14 : | teravus | 31 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 15 : | |||
| 16 : | teravus | 2 | public delegate void GridConnected(); |
| 17 : | public delegate void Chat(string message, ChatAudibleLevel audible, ChatType type, ChatSourceType sourcetype, | ||
| 18 : | string fromName, UUID id, UUID ownerid, Vector3 position); | ||
| 19 : | public delegate void LandPatch(Simulator sim, int x, int y, int width, float[] data); | ||
| 20 : | public delegate void NewAvatar(Simulator sim, Avatar avatar, ulong regionHandle, | ||
| 21 : | ushort timeDilation); | ||
| 22 : | public delegate void NewPrim(Simulator sim, Primitive prim, ulong regionHandle, | ||
| 23 : | ushort timeDilation); | ||
| 24 : | public delegate void Login(LoginStatus status, string message); | ||
| 25 : | public delegate void ObjectKilled(Simulator sim, uint objectID); | ||
| 26 : | public delegate void ObjectUpdated(Simulator simulator, ObjectUpdate update, ulong regionHandle, ushort timeDilation); | ||
| 27 : | public delegate void SimConnected(Simulator sim); | ||
| 28 : | teravus | 13 | public delegate void ImageReceived(AssetTexture tex); |
| 29 : | teravus | 2 | |
| 30 : | public event NewAvatar OnNewAvatar; | ||
| 31 : | public event Chat OnChat; | ||
| 32 : | public event GridConnected OnGridConnected; | ||
| 33 : | public event SimConnected OnSimConnected; | ||
| 34 : | public event LandPatch OnLandPatch; | ||
| 35 : | public event Login OnLogin; | ||
| 36 : | public event NewPrim OnNewPrim; | ||
| 37 : | public event ObjectKilled OnObjectKilled; | ||
| 38 : | public event ObjectUpdated OnObjectUpdated; | ||
| 39 : | teravus | 16 | public event ImageReceived OnImageReceived; |
| 40 : | teravus | 2 | |
| 41 : | GridClient m_user; | ||
| 42 : | public SLProtocol() | ||
| 43 : | { | ||
| 44 : | m_user = new GridClient(); | ||
| 45 : | //m_user.Settings.STORE_LAND_PATCHES = true; | ||
| 46 : | m_user.Settings.MULTIPLE_SIMS = true; | ||
| 47 : | teravus | 24 | //m_user.Settings.OBJECT_TRACKING = true; |
| 48 : | teravus | 17 | //m_user.Settings.AVATAR_TRACKING = true; |
| 49 : | teravus | 16 | m_user.Settings.USE_TEXTURE_CACHE = false; |
| 50 : | teravus | 13 | //m_user.Settings. |
| 51 : | teravus | 16 | m_user.Settings.ALWAYS_DECODE_OBJECTS = true; |
| 52 : | teravus | 24 | |
| 53 : | teravus | 2 | //m_user.Settings.SEND_AGENT_THROTTLE = true; |
| 54 : | //m_user.Settings.SEND_PINGS = true; | ||
| 55 : | |||
| 56 : | m_user.Network.OnConnected += gridConnectedCallback; | ||
| 57 : | m_user.Network.OnSimConnected += simConnectedCallback; | ||
| 58 : | m_user.Terrain.OnLandPatch += landPatchCallback; | ||
| 59 : | m_user.Self.OnChat += chatCallback; | ||
| 60 : | m_user.Objects.OnNewAvatar += newAvatarCallback; | ||
| 61 : | m_user.Objects.OnNewPrim += newPrim; | ||
| 62 : | m_user.Objects.OnObjectKilled += objectKilledCallback; | ||
| 63 : | m_user.Network.OnLogin += loginCallback; | ||
| 64 : | m_user.Objects.OnObjectUpdated += objectUpdatedCallback; | ||
| 65 : | teravus | 16 | m_user.Assets.OnImageReceived += imageReceivedCallback; |
| 66 : | teravus | 13 | //m_user.Assets.RequestImage( |
| 67 : | //m_user.Assets.Cache..RequestImage(UUID.Zero, ImageType.Normal); | ||
| 68 : | teravus | 2 | |
| 69 : | } | ||
| 70 : | teravus | 16 | private void imageReceivedCallback(ImageDownload image, AssetTexture asset) |
| 71 : | { | ||
| 72 : | if (OnImageReceived != null) | ||
| 73 : | { | ||
| 74 : | OnImageReceived(asset); | ||
| 75 : | } | ||
| 76 : | } | ||
| 77 : | teravus | 2 | private void objectKilledCallback(Simulator simulator, uint objectID) |
| 78 : | { | ||
| 79 : | if (OnObjectKilled != null) | ||
| 80 : | { | ||
| 81 : | OnObjectKilled(simulator, objectID); | ||
| 82 : | } | ||
| 83 : | } | ||
| 84 : | |||
| 85 : | teravus | 31 | public void BeginLogin(string loginURI, string username, string password, string startlocation) |
| 86 : | teravus | 2 | { |
| 87 : | teravus | 31 | LoginParams loginParams = getLoginParams(loginURI, username, password, startlocation); |
| 88 : | teravus | 2 | |
| 89 : | m_user.Network.BeginLogin(loginParams); | ||
| 90 : | } | ||
| 91 : | private void gridConnectedCallback(object sender) | ||
| 92 : | { | ||
| 93 : | |||
| 94 : | m_user.Appearance.SetPreviousAppearance(false); | ||
| 95 : | |||
| 96 : | |||
| 97 : | |||
| 98 : | if (OnGridConnected != null) | ||
| 99 : | { | ||
| 100 : | OnGridConnected(); | ||
| 101 : | } | ||
| 102 : | } | ||
| 103 : | private void simConnectedCallback(Simulator sender) | ||
| 104 : | { | ||
| 105 : | m_user.Throttle.Total = 500000; | ||
| 106 : | m_user.Throttle.Land = 80000; | ||
| 107 : | m_user.Throttle.Task = 200000; | ||
| 108 : | teravus | 16 | m_user.Throttle.Texture = 150000; |
| 109 : | teravus | 2 | m_user.Throttle.Wind = 10000; |
| 110 : | m_user.Throttle.Resend = 100000; | ||
| 111 : | m_user.Throttle.Asset = 100000; | ||
| 112 : | m_user.Throttle.Cloud = 10000; | ||
| 113 : | teravus | 24 | m_user.Self.Movement.Camera.Far = 56f; |
| 114 : | m_user.Self.Movement.Camera.Position = m_user.Self.RelativePosition; | ||
| 115 : | teravus | 2 | |
| 116 : | if (OnSimConnected != null) | ||
| 117 : | { | ||
| 118 : | OnSimConnected(sender); | ||
| 119 : | } | ||
| 120 : | } | ||
| 121 : | private void loginCallback(LoginStatus status, string message) | ||
| 122 : | { | ||
| 123 : | if (OnLogin != null) | ||
| 124 : | { | ||
| 125 : | OnLogin((LoginStatus)status, message); | ||
| 126 : | } | ||
| 127 : | } | ||
| 128 : | public void Logout() | ||
| 129 : | { | ||
| 130 : | if (m_user.Network.Connected) | ||
| 131 : | { | ||
| 132 : | m_user.Network.Logout(); | ||
| 133 : | } | ||
| 134 : | } | ||
| 135 : | public bool Connected | ||
| 136 : | { | ||
| 137 : | get { return m_user.Network.Connected; } | ||
| 138 : | } | ||
| 139 : | public void Whisper(string message) | ||
| 140 : | { | ||
| 141 : | m_user.Self.Chat(message, 0, ChatType.Whisper); | ||
| 142 : | } | ||
| 143 : | |||
| 144 : | public void Say(string message) | ||
| 145 : | { | ||
| 146 : | m_user.Self.Chat(message, 0, ChatType.Normal); | ||
| 147 : | } | ||
| 148 : | |||
| 149 : | public void Shout(string message) | ||
| 150 : | { | ||
| 151 : | m_user.Self.Chat(message, 0, ChatType.Shout); | ||
| 152 : | } | ||
| 153 : | |||
| 154 : | teravus | 31 | private LoginParams getLoginParams(string loginURI, string username, string password, string startlocation) |
| 155 : | teravus | 2 | { |
| 156 : | string firstname; | ||
| 157 : | string lastname; | ||
| 158 : | |||
| 159 : | Util.separateUsername(username, out firstname, out lastname); | ||
| 160 : | |||
| 161 : | LoginParams loginParams = m_user.Network.DefaultLoginParams( | ||
| 162 : | firstname, lastname, password, "IdealistViewer", "0.0.0.1");//Constants.Version); | ||
| 163 : | |||
| 164 : | |||
| 165 : | teravus | 31 | loginURI = Util.getSaneLoginURI(loginURI); |
| 166 : | |||
| 167 : | if (startlocation.Length == 0) | ||
| 168 : | { | ||
| 169 : | |||
| 170 : | if (!loginURI.EndsWith("/")) | ||
| 171 : | loginURI += "/"; | ||
| 172 : | |||
| 173 : | string[] locationparse = loginURI.Split('/'); | ||
| 174 : | try | ||
| 175 : | { | ||
| 176 : | startlocation = locationparse[locationparse.Length - 2]; | ||
| 177 : | if (startlocation == locationparse[2]) | ||
| 178 : | { | ||
| 179 : | startlocation = "last"; | ||
| 180 : | } | ||
| 181 : | else | ||
| 182 : | { | ||
| 183 : | loginURI = ""; | ||
| 184 : | for (int i = 0; i < locationparse.Length - 2; i++) | ||
| 185 : | { | ||
| 186 : | loginURI += locationparse[i] + "/"; | ||
| 187 : | } | ||
| 188 : | } | ||
| 189 : | |||
| 190 : | } | ||
| 191 : | catch (Exception) | ||
| 192 : | { | ||
| 193 : | startlocation = "last"; | ||
| 194 : | } | ||
| 195 : | |||
| 196 : | } | ||
| 197 : | else | ||
| 198 : | { | ||
| 199 : | |||
| 200 : | |||
| 201 : | teravus | 32 | //if (!loginURI.EndsWith("/")) |
| 202 : | // loginURI += "/"; | ||
| 203 : | teravus | 31 | |
| 204 : | teravus | 32 | // string[] locationparse = loginURI.Split('/'); |
| 205 : | // try | ||
| 206 : | // { | ||
| 207 : | // string end = locationparse[locationparse.Length - 2]; | ||
| 208 : | // if (end != locationparse[2]) | ||
| 209 : | // { | ||
| 210 : | // loginURI = ""; | ||
| 211 : | // for (int i = 0; i < 3; i++) | ||
| 212 : | // { | ||
| 213 : | // if (locationparse[i].Length != 0 || i==1) | ||
| 214 : | // loginURI += locationparse[i] + "/"; | ||
| 215 : | // } | ||
| 216 : | // } | ||
| 217 : | teravus | 31 | |
| 218 : | teravus | 32 | //} |
| 219 : | // catch (Exception) | ||
| 220 : | //{ | ||
| 221 : | teravus | 31 | //startlocation = "last"; |
| 222 : | teravus | 32 | // m_log.Warn("[URLPARSING]: Unable to parse URL provided!"); |
| 223 : | //} | ||
| 224 : | teravus | 31 | |
| 225 : | |||
| 226 : | } | ||
| 227 : | |||
| 228 : | loginParams.URI = loginURI; | ||
| 229 : | teravus | 32 | |
| 230 : | |||
| 231 : | if (startlocation != "last" && startlocation != "home") | ||
| 232 : | teravus | 33 | startlocation = "uri:" + startlocation + "&128&128&20"; |
| 233 : | teravus | 32 | |
| 234 : | teravus | 31 | loginParams.Start = startlocation; |
| 235 : | |||
| 236 : | teravus | 2 | return loginParams; |
| 237 : | } | ||
| 238 : | |||
| 239 : | private void chatCallback(string message, ChatAudibleLevel audible, ChatType type, ChatSourceType sourcetype, | ||
| 240 : | string fromName, UUID id, UUID ownerid, Vector3 position) | ||
| 241 : | { | ||
| 242 : | // This is weird -- we get start/stop typing chats from | ||
| 243 : | // other avatars, and we get messages back that we sent. | ||
| 244 : | // (Tested on OpenSim r3187) | ||
| 245 : | // So we explicitly check for those cases here. | ||
| 246 : | if (OnChat != null && (int)type < 4 && id != m_user.Self.AgentID) | ||
| 247 : | { | ||
| 248 : | OnChat(message, audible, type, sourcetype, | ||
| 249 : | fromName, id, ownerid, position); | ||
| 250 : | } | ||
| 251 : | } | ||
| 252 : | |||
| 253 : | |||
| 254 : | |||
| 255 : | private void newPrim(Simulator simulator, Primitive prim, ulong regionHandle, | ||
| 256 : | ushort timeDilation) | ||
| 257 : | { | ||
| 258 : | |||
| 259 : | if (OnNewPrim != null) | ||
| 260 : | { | ||
| 261 : | OnNewPrim(simulator,prim, regionHandle,timeDilation); | ||
| 262 : | } | ||
| 263 : | } | ||
| 264 : | |||
| 265 : | |||
| 266 : | private void landPatchCallback(Simulator simulator, int x, int y, int width, float[] data) | ||
| 267 : | { | ||
| 268 : | if (OnLandPatch != null) | ||
| 269 : | { | ||
| 270 : | OnLandPatch(simulator,x, y, width, data); | ||
| 271 : | } | ||
| 272 : | } | ||
| 273 : | private void newAvatarCallback(Simulator simulator, Avatar avatar, ulong regionHandle, | ||
| 274 : | ushort timeDilation) | ||
| 275 : | { | ||
| 276 : | if (OnNewAvatar != null) | ||
| 277 : | { | ||
| 278 : | //avatar.Velocity | ||
| 279 : | OnNewAvatar(simulator,avatar,regionHandle,timeDilation); | ||
| 280 : | } | ||
| 281 : | } | ||
| 282 : | private void objectUpdatedCallback(Simulator simulator, ObjectUpdate update, ulong regionHandle, | ||
| 283 : | ushort timeDilation) | ||
| 284 : | { | ||
| 285 : | if (OnObjectUpdated != null) | ||
| 286 : | { | ||
| 287 : | OnObjectUpdated(simulator, update, regionHandle, timeDilation); | ||
| 288 : | } | ||
| 289 : | } | ||
| 290 : | |||
| 291 : | teravus | 16 | public void RequestTexture(UUID assetID) |
| 292 : | { | ||
| 293 : | m_user.Assets.RequestImage(assetID, ImageType.Normal); | ||
| 294 : | } | ||
| 295 : | teravus | 24 | public void SetCameraPosition(Vector3 Position) |
| 296 : | { | ||
| 297 : | m_user.Self.Movement.Camera.Position = Position; | ||
| 298 : | } | ||
| 299 : | teravus | 2 | } |
| 300 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

