Annotation of /trunk/ModularRex/RexParts/ModrexAppearance.cs
Parent Directory
|
Revision Log
Revision 87 - (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 : | mikkopa | 63 | using OpenSim.Region.Framework.Interfaces; |
| 9 : | using OpenSim.Region.Framework.Scenes; | ||
| 10 : | tuco | 87 | using OpenSim.Framework; |
| 11 : | afrisby | 2 | |
| 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 : | afrisby | 8 | RexClientView rex; |
| 40 : | if (avatar.ClientView.TryGet(out rex)) | ||
| 41 : | afrisby | 4 | { |
| 42 : | afrisby | 8 | rex.SendRexAppearance(user, avatarServerURL); |
| 43 : | afrisby | 4 | } |
| 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 : | tuco | 87 | IClientAPI client; |
| 54 : | string avatarurl; | ||
| 55 : | |||
| 56 : | afrisby | 4 | foreach (Scene scene in m_scenes) |
| 57 : | afrisby | 3 | { |
| 58 : | afrisby | 4 | scene.ForEachScenePresence( |
| 59 : | delegate(ScenePresence avatar) | ||
| 60 : | { | ||
| 61 : | tuco | 87 | if (avatar.ControllingClient is IRexClientAPI) |
| 62 : | client = avatar.ControllingClient; | ||
| 63 : | else | ||
| 64 : | client = null; | ||
| 65 : | |||
| 66 : | if(client != null && !sent.Contains(client.AgentId) && target != client) | ||
| 67 : | afrisby | 4 | { |
| 68 : | tuco | 87 | avatarurl = ((IRexClientAPI)client).RexAvatarURLVisible; |
| 69 : | if (!string.IsNullOrEmpty(avatarurl)) | ||
| 70 : | afrisby | 8 | { |
| 71 : | tuco | 87 | target.SendRexAppearance(client.AgentId,avatarurl); |
| 72 : | sent.Add(client.AgentId); | ||
| 73 : | } | ||
| 74 : | afrisby | 4 | } |
| 75 : | }); | ||
| 76 : | } | ||
| 77 : | afrisby | 2 | } |
| 78 : | |||
| 79 : | afrisby | 4 | public void SendAllAppearancesToAllUsers() |
| 80 : | afrisby | 2 | { |
| 81 : | afrisby | 4 | m_log.Info("[REXAPR] Sending all appearances to all users."); |
| 82 : | List<UUID> sent = new List<UUID>(); | ||
| 83 : | |||
| 84 : | afrisby | 3 | foreach (Scene scene in m_scenes) |
| 85 : | afrisby | 2 | { |
| 86 : | afrisby | 3 | scene.ForEachScenePresence( |
| 87 : | delegate(ScenePresence avatar) | ||
| 88 : | { | ||
| 89 : | afrisby | 8 | RexClientView rex; |
| 90 : | if (avatar.ClientView.TryGet(out rex)) | ||
| 91 : | afrisby | 3 | { |
| 92 : | afrisby | 8 | if (!sent.Contains(avatar.ControllingClient.AgentId)) |
| 93 : | { | ||
| 94 : | sent.Add(rex.AgentId); | ||
| 95 : | SendAllAppearancesToUser(rex); | ||
| 96 : | } | ||
| 97 : | afrisby | 3 | } |
| 98 : | }); | ||
| 99 : | afrisby | 2 | } |
| 100 : | } | ||
| 101 : | |||
| 102 : | afrisby | 3 | |
| 103 : | afrisby | 2 | public void Initialise(Scene scene, IConfigSource source) |
| 104 : | { | ||
| 105 : | afrisby | 3 | try |
| 106 : | { | ||
| 107 : | if(!source.Configs["realXtend"].GetBoolean("enabled",false)) | ||
| 108 : | { | ||
| 109 : | return; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | m_log.Info("RexAppearance Module Being Used"); | ||
| 113 : | } | ||
| 114 : | catch (Exception) | ||
| 115 : | { | ||
| 116 : | m_log.Info("Rex Config Error, Disabled"); | ||
| 117 : | return; | ||
| 118 : | } | ||
| 119 : | |||
| 120 : | afrisby | 4 | m_log.Info("[REXAPPEAR] Added Scene"); |
| 121 : | afrisby | 3 | m_scenes.Add(scene); |
| 122 : | |||
| 123 : | afrisby | 8 | scene.EventManager.OnClientConnect += EventManager_OnClientConnect; |
| 124 : | afrisby | 2 | } |
| 125 : | |||
| 126 : | afrisby | 8 | void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) |
| 127 : | afrisby | 2 | { |
| 128 : | tuco | 87 | if(client is IRexClientAPI) |
| 129 : | afrisby | 2 | { |
| 130 : | tuco | 87 | IRexClientAPI rexclientapi = (IRexClientAPI)client; |
| 131 : | rexclientapi.OnRexAppearance += mcv_OnRexAppearance; | ||
| 132 : | SendAppearanceToAllUsers(rexclientapi.AgentId,rexclientapi.RexAvatarURLVisible); | ||
| 133 : | afrisby | 2 | } |
| 134 : | tuco | 87 | |
| 135 : | if(client is RexClientView) | ||
| 136 : | SendAllAppearancesToUser((RexClientView)client); | ||
| 137 : | afrisby | 2 | } |
| 138 : | |||
| 139 : | /// <summary> | ||
| 140 : | /// Fired when a "Neighbours: Update your appearance" packet is sent by the viewer | ||
| 141 : | /// </summary> | ||
| 142 : | /// <param name="sender">IClientApi of the sender</param> | ||
| 143 : | tuco | 87 | void mcv_OnRexAppearance(IClientAPI sender) |
| 144 : | afrisby | 2 | { |
| 145 : | tuco | 87 | if (sender is IRexClientAPI) |
| 146 : | SendAppearanceToAllUsers(sender.AgentId, ((IRexClientAPI)sender).RexAvatarURLVisible); | ||
| 147 : | afrisby | 2 | } |
| 148 : | |||
| 149 : | public void PostInitialise() | ||
| 150 : | { | ||
| 151 : | afrisby | 4 | m_log.Info("[REXAPPEAR] PostInit called"); |
| 152 : | afrisby | 2 | } |
| 153 : | |||
| 154 : | public void Close() | ||
| 155 : | { | ||
| 156 : | |||
| 157 : | } | ||
| 158 : | |||
| 159 : | public string Name | ||
| 160 : | { | ||
| 161 : | afrisby | 4 | get { return "RexAppearance"; } |
| 162 : | afrisby | 2 | } |
| 163 : | |||
| 164 : | public bool IsSharedModule | ||
| 165 : | { | ||
| 166 : | get { return true; } | ||
| 167 : | } | ||
| 168 : | } | ||
| 169 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

