Annotation of /trunk/ModularRex/RexParts/ModrexAppearance.cs
Parent Directory
|
Revision Log
Revision 4 - (view) (download)
| 1 : | afrisby | 3 | using System; |
| 2 : | using System.Collections.Generic; | ||
| 3 : | afrisby | 2 | using System.Reflection; |
| 4 : | using log4net; | ||
| 5 : | using ModularRex.RexNetwork; | ||
| 6 : | using Nini.Config; | ||
| 7 : | using OpenMetaverse; | ||
| 8 : | using OpenSim.Framework; | ||
| 9 : | using OpenSim.Region.Environment.Interfaces; | ||
| 10 : | using OpenSim.Region.Environment.Scenes; | ||
| 11 : | |||
| 12 : | namespace ModularRex.RexParts | ||
| 13 : | { | ||
| 14 : | afrisby | 4 | public class ModrexAppearance : IRegionModule |
| 15 : | afrisby | 2 | { |
| 16 : | private static readonly ILog m_log = | ||
| 17 : | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
| 18 : | |||
| 19 : | afrisby | 4 | private readonly List<Scene> m_scenes = new List<Scene>(); |
| 20 : | afrisby | 2 | |
| 21 : | afrisby | 4 | public void SendAppearanceToAllUsers(UUID user, string avatarServerURL) |
| 22 : | afrisby | 2 | { |
| 23 : | afrisby | 4 | m_log.Info("[REXAPR] Sending user " + user + " appearance to all users. [" + avatarServerURL + "]"); |
| 24 : | // Ignore empty avatars | ||
| 25 : | if (String.IsNullOrEmpty(avatarServerURL)) | ||
| 26 : | { | ||
| 27 : | m_log.Info("[REXAPR] Skipping blank URL on user..."); | ||
| 28 : | return; | ||
| 29 : | } | ||
| 30 : | afrisby | 2 | |
| 31 : | afrisby | 4 | // Send to every agent in every scene |
| 32 : | // We may want to target this more cleanly | ||
| 33 : | // in future. | ||
| 34 : | foreach (Scene scene in m_scenes) | ||
| 35 : | { | ||
| 36 : | scene.ForEachScenePresence( | ||
| 37 : | delegate(ScenePresence avatar) | ||
| 38 : | { | ||
| 39 : | if (avatar.ControllingClient is RexClientView) | ||
| 40 : | { | ||
| 41 : | ((RexClientView) avatar.ControllingClient).SendRexAppearance( | ||
| 42 : | user, avatarServerURL); | ||
| 43 : | } | ||
| 44 : | }); | ||
| 45 : | } | ||
| 46 : | } | ||
| 47 : | afrisby | 3 | |
| 48 : | afrisby | 4 | public void SendAllAppearancesToUser(RexClientView target) |
| 49 : | { | ||
| 50 : | m_log.Info("[REXAPR] Sending all appearances to user " + target.AgentId + "."); | ||
| 51 : | List<UUID> sent = new List<UUID>(); | ||
| 52 : | afrisby | 3 | |
| 53 : | afrisby | 4 | foreach (Scene scene in m_scenes) |
| 54 : | afrisby | 3 | { |
| 55 : | afrisby | 4 | scene.ForEachScenePresence( |
| 56 : | delegate(ScenePresence avatar) | ||
| 57 : | { | ||
| 58 : | if (avatar.ControllingClient is RexClientView && | ||
| 59 : | !sent.Contains(avatar.ControllingClient.AgentId) && | ||
| 60 : | avatar.ControllingClient != target && | ||
| 61 : | !string.IsNullOrEmpty( | ||
| 62 : | ((RexClientView) avatar.ControllingClient) | ||
| 63 : | .RexAvatarURL)) | ||
| 64 : | { | ||
| 65 : | target.SendRexAppearance(avatar.ControllingClient.AgentId, | ||
| 66 : | ((RexClientView) avatar.ControllingClient) | ||
| 67 : | .RexAvatarURL); | ||
| 68 : | sent.Add(avatar.ControllingClient.AgentId); | ||
| 69 : | } | ||
| 70 : | }); | ||
| 71 : | } | ||
| 72 : | afrisby | 2 | } |
| 73 : | |||
| 74 : | afrisby | 4 | public void SendAllAppearancesToAllUsers() |
| 75 : | afrisby | 2 | { |
| 76 : | afrisby | 4 | m_log.Info("[REXAPR] Sending all appearances to all users."); |
| 77 : | List<UUID> sent = new List<UUID>(); | ||
| 78 : | |||
| 79 : | afrisby | 3 | foreach (Scene scene in m_scenes) |
| 80 : | afrisby | 2 | { |
| 81 : | afrisby | 3 | scene.ForEachScenePresence( |
| 82 : | delegate(ScenePresence avatar) | ||
| 83 : | { | ||
| 84 : | afrisby | 4 | if (avatar.ControllingClient is RexClientView && |
| 85 : | !sent.Contains(avatar.ControllingClient.AgentId)) | ||
| 86 : | afrisby | 3 | { |
| 87 : | afrisby | 4 | sent.Add(avatar.ControllingClient.AgentId); |
| 88 : | SendAllAppearancesToUser((RexClientView) avatar.ControllingClient); | ||
| 89 : | afrisby | 3 | } |
| 90 : | }); | ||
| 91 : | afrisby | 2 | } |
| 92 : | } | ||
| 93 : | |||
| 94 : | afrisby | 3 | |
| 95 : | afrisby | 2 | public void Initialise(Scene scene, IConfigSource source) |
| 96 : | { | ||
| 97 : | afrisby | 3 | try |
| 98 : | { | ||
| 99 : | if(!source.Configs["realXtend"].GetBoolean("enabled",false)) | ||
| 100 : | { | ||
| 101 : | return; | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | m_log.Info("RexAppearance Module Being Used"); | ||
| 105 : | } | ||
| 106 : | catch (Exception) | ||
| 107 : | { | ||
| 108 : | m_log.Info("Rex Config Error, Disabled"); | ||
| 109 : | return; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | afrisby | 4 | m_log.Info("[REXAPPEAR] Added Scene"); |
| 113 : | afrisby | 3 | m_scenes.Add(scene); |
| 114 : | |||
| 115 : | afrisby | 2 | scene.EventManager.OnNewClient += EventManager_OnNewClient; |
| 116 : | } | ||
| 117 : | |||
| 118 : | void EventManager_OnNewClient(IClientAPI client) | ||
| 119 : | { | ||
| 120 : | // Check if the client was insubstantiated as a RexClientView. | ||
| 121 : | if(client is RexClientView) | ||
| 122 : | { | ||
| 123 : | RexClientView mcv = (RexClientView) client; | ||
| 124 : | |||
| 125 : | mcv.OnRexAppearance += mcv_OnRexAppearance; | ||
| 126 : | afrisby | 4 | |
| 127 : | // Send initial appearance to others | ||
| 128 : | SendAppearanceToAllUsers(mcv.AgentId, mcv.RexAvatarURL); | ||
| 129 : | // Send others appearance to us | ||
| 130 : | SendAllAppearancesToUser((RexClientView) client); | ||
| 131 : | afrisby | 2 | } |
| 132 : | } | ||
| 133 : | |||
| 134 : | /// <summary> | ||
| 135 : | /// Fired when a "Neighbours: Update your appearance" packet is sent by the viewer | ||
| 136 : | /// </summary> | ||
| 137 : | /// <param name="sender">IClientApi of the sender</param> | ||
| 138 : | void mcv_OnRexAppearance(RexClientView sender) | ||
| 139 : | { | ||
| 140 : | afrisby | 4 | SendAppearanceToAllUsers(sender.AgentId, sender.RexAvatarURL); |
| 141 : | afrisby | 2 | } |
| 142 : | |||
| 143 : | public void PostInitialise() | ||
| 144 : | { | ||
| 145 : | afrisby | 4 | m_log.Info("[REXAPPEAR] PostInit called"); |
| 146 : | afrisby | 2 | } |
| 147 : | |||
| 148 : | public void Close() | ||
| 149 : | { | ||
| 150 : | |||
| 151 : | } | ||
| 152 : | |||
| 153 : | public string Name | ||
| 154 : | { | ||
| 155 : | afrisby | 4 | get { return "RexAppearance"; } |
| 156 : | afrisby | 2 | } |
| 157 : | |||
| 158 : | public bool IsSharedModule | ||
| 159 : | { | ||
| 160 : | get { return true; } | ||
| 161 : | } | ||
| 162 : | } | ||
| 163 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

