public bool OnNewChatMessageFromWorld (OSChatMessage c, out OSChatMessage newc) { string [] operators = c.Message.Split (' '); if (operators [0] == "calc.Add") { if (operators.Length == 3) { float Num1 = float.Parse (operators [1]); float Num2 = float.Parse (operators [2]); float RetVal = Num1 + Num2; BuildAndSendResult (RetVal, c.Scene, c.Position); } } if (operators [0] == "calc.Subtract") { if (operators.Length == 3) { float Num1 = float.Parse (operators [1]); float Num2 = float.Parse (operators [2]); float RetVal = Num1 - Num2; BuildAndSendResult (RetVal, c.Scene, c.Position); } } if (operators [0] == "calc.Multiply") { if (operators.Length == 3) { float Num1 = float.Parse (operators [1]); float Num2 = float.Parse (operators [2]); float RetVal = Num1 * Num2; BuildAndSendResult (RetVal, c.Scene, c.Position); } } if (operators [0] == "calc.Divide") { if (operators.Length == 3) { float Num1 = float.Parse (operators [1]); float Num2 = float.Parse (operators [2]); float RetVal = Num1 / Num2; BuildAndSendResult (RetVal, c.Scene, c.Position); } } newc = c; //Block the message from going to everyone, only the server needed to hear return true; }
void HandleChatPacket(OSChatMessage chat) { if (string.IsNullOrEmpty(chat.Message)) return; // Object? if (chat.Sender == null && chat.SenderObject != null) { ChatEventArgs e = new ChatEventArgs { Sender = new SOPObject(m_internalScene, chat.SenderObject.LocalId, m_security), Text = chat.Message, Channel = chat.Channel }; _OnChat(this, e); return; } // Avatar? if (chat.Sender != null && chat.SenderObject == null) { ChatEventArgs e = new ChatEventArgs { Sender = new SPAvatar(m_internalScene, chat.SenderUUID, m_security), Text = chat.Message, Channel = chat.Channel }; _OnChat(this, e); return; } // Skip if other }
void DeliverClientMessage (object sender, OSChatMessage e) { if (null != e.Sender) DeliverMessage (e.Type, e.Channel, e.Sender.Name, e.Sender.AgentId, e.Message, e.Position, -1, UUID.Zero); else DeliverMessage (e.Type, e.Channel, e.From, UUID.Zero, e.Message, e.Position, -1, UUID.Zero); }
public virtual void DeliverChatToAvatars (ChatSourceType sourceType, OSChatMessage c) { string fromName = c.From; UUID fromID = UUID.Zero; string message = c.Message; IScene scene = c.Scene; Vector3 fromPos = c.Position; if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; IScenePresence avatar = (scene != null && c.Sender != null) ? scene.GetScenePresence (c.Sender.AgentId) : null; switch (sourceType) { case ChatSourceType.Agent: if (scene != null) { if (avatar != null && message == "") { fromPos = avatar.AbsolutePosition; fromName = avatar.Name; fromID = c.Sender.AgentId; //Always send this so it fires on typing start and end IAttachmentsModule attMod = scene.RequestModuleInterface<IAttachmentsModule> (); if (attMod != null) attMod.SendScriptEventToAttachments (avatar.UUID, "changed", new object [] { Changed.STATE }); } else fromID = c.SenderUUID; } else fromID = c.SenderUUID; break; case ChatSourceType.Object: fromID = c.SenderUUID; break; } if (message.Length >= 1000) // libomv limit message = message.Substring (0, 1000); // determine who should receive the message var presences = m_Scene.GetScenePresences (); var fromRegionPos = fromPos; foreach (IScenePresence presence in presences) { if (presence.IsChildAgent) continue; // check presence distances var toRegionPos = presence.AbsolutePosition; var dis = (int)Util.GetDistanceTo (toRegionPos, fromRegionPos); if (c.Type == ChatTypeEnum.Custom && dis > c.Range) // further than the defined custom range continue; if (c.Type == ChatTypeEnum.Shout && dis > m_shoutdistance) // too far for shouting continue; if (c.Type == ChatTypeEnum.Say && dis > m_saydistance) // too far for normal chat continue; if (c.Type == ChatTypeEnum.Whisper && dis > m_whisperdistance) // too far out for whisper continue; if (sourceType == ChatSourceType.Agent) { if (avatar != null) { if (avatar.CurrentParcel != null) { if (avatar.CurrentParcelUUID != presence.CurrentParcelUUID) // not in the same parcel continue; // If both are not in the same private parcel, don't send the chat message // if (!(avatar.CurrentParcel.LandData.Private && presence.CurrentParcel.LandData.Private)) if (avatar.CurrentParcel.LandData.Private && !presence.CurrentParcel.LandData.Private) continue; } } } // this one is good to go.... TrySendChatMessage (presence, fromPos, fromID, fromName, c.Type, message, sourceType, c.Range); } /* previous for reference - remove when verified - greythane - foreach (IScenePresence presence in from presence in m_Scene.GetScenePresences() where !presence.IsChildAgent let fromRegionPos = fromPos let toRegionPos = presence.AbsolutePosition let dis = (int) Util.GetDistanceTo(toRegionPos, fromRegionPos) where (c.Type != ChatTypeEnum.Whisper || dis <= m_whisperdistance) && (c.Type != ChatTypeEnum.Say || dis <= m_saydistance) && (c.Type != ChatTypeEnum.Shout || dis <= m_shoutdistance) && (c.Type != ChatTypeEnum.Custom || dis <= c.Range) where sourceType != ChatSourceType.Agent || avatar == null || avatar.CurrentParcel == null || (avatar.CurrentParcelUUID == presence.CurrentParcelUUID || (!avatar.CurrentParcel.LandData.Private && !presence.CurrentParcel.LandData.Private)) select presence) { //If one of them is in a private parcel, and the other isn't in the same parcel, don't send the chat message TrySendChatMessage (presence, fromPos, fromID, fromName, c.Type, message, sourceType, c.Range); } */ }
/// <summary> /// Set the correct position for the chat message /// </summary> /// <param name="c"></param> /// <returns></returns> protected OSChatMessage FixPositionOfChatMessage(OSChatMessage c) { IScenePresence avatar; if ((avatar = c.Scene.GetScenePresence(c.Sender.AgentId)) != null) c.Position = avatar.AbsolutePosition; return c; }
/// <summary> /// New chat message from the client /// </summary> /// <param name="sender"></param> /// <param name="c"></param> protected virtual void OnChatFromClient(IClientAPI sender, OSChatMessage c) { c = FixPositionOfChatMessage(c); // redistribute to interested subscribers if (c.Message != "") c.Scene.EventManager.TriggerOnChatFromClient(sender, c); // early return if not on public or debug channel if (c.Channel != DEFAULT_CHANNEL && c.Channel != DEBUG_CHANNEL) return; // sanity check: if (c.Sender == null) { MainConsole.Instance.ErrorFormat("[CHAT] OnChatFromClient from {0} has empty Sender field!", sender); return; } //If the message is not blank, tell the plugins about it if (c.Message != "") { foreach ( string pluginMain in ChatPlugins.Keys.Where( pluginMain => pluginMain == "all" || c.Message.StartsWith(pluginMain + "."))) { IChatPlugin plugin; ChatPlugins.TryGetValue(pluginMain, out plugin); //If it returns false, stop the message from being sent if (!plugin.OnNewChatMessageFromWorld(c, out c)) return; } } string Name2 = ""; if (sender is IClientAPI) { Name2 = (sender).Name; } c.From = Name2; DeliverChatToAvatars(ChatSourceType.Agent, c); }
public OSChatMessage Copy() { OSChatMessage message = new OSChatMessage { Channel = Channel, From = From, Message = Message, Position = Position, Range = Range, Scene = Scene, Sender = Sender, SenderObject = SenderObject, SenderUUID = SenderUUID, Type = Type, ToAgentID = ToAgentID }; return message; }
/// <summary> /// Send the message from the prim to the avatars in the regions /// </summary> /// <param name="sender"></param> /// <param name="c"></param> public virtual void OnChatFromWorld(Object sender, OSChatMessage c) { // early return if not on public or debug channel if (c.Channel != DEFAULT_CHANNEL && c.Channel != DEBUG_CHANNEL) return; if (c.Range > m_maxChatDistance) //Check for max distance c.Range = m_maxChatDistance; DeliverChatToAvatars(ChatSourceType.Object, c); }
protected override void OnChatBroadcast(Object sender, OSChatMessage c) { if (m_replacingChatModule) { // distribute chat message to each and every avatar in // the region base.OnChatBroadcast(sender, c); } // capture chat if required if (m_logFile != null) { m_logFile.WriteLine(c.From +": "+c.Message); m_logFile.Flush(); } return; }
protected override void OnChatFromClient(IClientAPI sender, OSChatMessage c) { if (m_replacingChatModule) { // replacing ChatModule: need to redistribute // ChatFromClient to interested subscribers c = FixPositionOfChatMessage(c); IScene scene = c.Scene; scene.EventManager.TriggerOnChatFromClient(sender, c); if (m_conciergedScenes.Contains(c.Scene)) { // when we are replacing ChatModule, we treat // OnChatFromClient like OnChatBroadcast for // concierged regions, effectively extending the // range of chat to cover the whole // region. however, we don't do this for whisper // (got to have some privacy) if (c.Type != ChatTypeEnum.Whisper) { base.OnChatBroadcast(sender, c); return; } } // redistribution will be done by base class base.OnChatFromClient(sender, c); } // capture chat if required if (m_logFile != null) { m_logFile.WriteLine(c.From +": "+c.Message); m_logFile.Flush(); } return; }
// protected void AnnounceToAgentsRegion(Scene scene, string msg) // { // ScenePresence agent = null; // if ((client.Scene is Scene) && (client.Scene as Scene).TryGetScenePresence(client.AgentId, out agent)) // AnnounceToAgentsRegion(agent, msg); // else // m_log.DebugFormat("[Concierge]: could not find an agent for client {0}", client.Name); // } protected void AnnounceToAgentsRegion(IScene scene, string msg) { OSChatMessage c = new OSChatMessage(); c.Message = msg; c.Type = ChatTypeEnum.Say; c.Channel = 0; c.Position = PosOfGod; c.From = m_whoami; c.Sender = null; c.SenderUUID = UUID.Zero; c.Scene = scene; scene.EventManager.TriggerOnChatBroadcast(this, c); }
protected void AnnounceToAgent(IScenePresence agent, string msg) { OSChatMessage c = new OSChatMessage(); c.Message = msg; c.Type = ChatTypeEnum.Say; c.Channel = 0; c.Position = PosOfGod; c.From = m_whoami; c.Sender = null; c.SenderUUID = UUID.Zero; c.Scene = agent.Scene; agent.ControllingClient.SendChatMessage(msg, (byte) ChatTypeEnum.Say, PosOfGod, m_whoami, UUID.Zero, (byte)ChatSourceType.Object, (byte)ChatAudibleLevel.Fully); }
public override void OnChatFromWorld(Object sender, OSChatMessage c) { if (m_replacingChatModule) { if (m_conciergedScenes.Contains(c.Scene)) { // when we are replacing ChatModule, we treat // OnChatFromClient like OnChatBroadcast for // concierged regions, effectively extending the // range of chat to cover the whole // region. however, we don't do this for whisper // (got to have some privacy) if (c.Type != ChatTypeEnum.Whisper) { base.OnChatBroadcast(sender, c); return; } } base.OnChatFromWorld(sender, c); } return; }
void EventManager_OnChatFromClient(object sender, OSChatMessage chat) { if (_OnChat != null) { HandleChatPacket(chat); return; } }
void EventManager_OnChatFromClient(IClientAPI sender, OSChatMessage chat) { if (chat.Message == "" || sender == null || chat.Channel != m_chatToIRCChannel) return; Client client; if(TryGetClient(sender.AgentId, out client)) { Util.FireAndForget(delegate(object o) { IScenePresence sp = sender.Scene.GetScenePresence(sender.AgentId); if (sp != null) { string channel; if (m_channel.TryGetValue(sp.CurrentParcel.LandData.GlobalID, out channel)) { client.SendChat("(grid: " + MainServer.Instance.ServerURI.Remove(0, 7) + ") - " + chat.Message, channel); } } }); } }
public virtual void DeliverChatToAvatars(ChatSourceType sourceType, OSChatMessage c) { string fromName = c.From; UUID fromID = UUID.Zero; string message = c.Message; IScene scene = c.Scene; Vector3 fromPos = c.Position; if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; IScenePresence avatar = (scene != null && c.Sender != null) ? scene.GetScenePresence(c.Sender.AgentId) : null; switch (sourceType) { case ChatSourceType.Agent: if (scene != null) { if (avatar != null && message == "") { fromPos = avatar.AbsolutePosition; fromName = avatar.Name; fromID = c.Sender.AgentId; //Always send this so it fires on typing start and end IAttachmentsModule attMod = scene.RequestModuleInterface<IAttachmentsModule>(); if (attMod != null) attMod.SendScriptEventToAttachments(avatar.UUID, "changed", new object[] {Changed.STATE}); } else fromID = c.SenderUUID; } else fromID = c.SenderUUID; break; case ChatSourceType.Object: fromID = c.SenderUUID; break; } if (message.Length >= 1000) // libomv limit message = message.Substring(0, 1000); foreach (IScenePresence presence in from presence in m_Scene.GetScenePresences() where !presence.IsChildAgent let fromRegionPos = fromPos let toRegionPos = presence.AbsolutePosition let dis = (int) Util.GetDistanceTo(toRegionPos, fromRegionPos) where (c.Type != ChatTypeEnum.Whisper || dis <= m_whisperdistance) && (c.Type != ChatTypeEnum.Say || dis <= m_saydistance) && (c.Type != ChatTypeEnum.Shout || dis <= m_shoutdistance) && (c.Type != ChatTypeEnum.Custom || dis <= c.Range) where sourceType != ChatSourceType.Agent || avatar == null || avatar.CurrentParcel == null || (avatar.CurrentParcelUUID == presence.CurrentParcelUUID || (!avatar.CurrentParcel.LandData.Private && !presence.CurrentParcel.LandData.Private)) select presence) { //If one of them is in a private parcel, and the other isn't in the same parcel, don't send the chat message TrySendChatMessage(presence, fromPos, fromID, fromName, c.Type, message, sourceType, c.Range); } }
void EventManager_OnChatFromClient(IClientAPI sender, OSChatMessage chat) { if(chat.Message == "" || sender == null || chat.Channel != m_chatToIRCChannel) return; Client client; if(TryGetClient(sender.AgentId, out client)) { Util.FireAndForget ((object o) => client.SendChat ("[" + gridname + "]: " + chat.Message, m_channel)); } }
public void SimChat(string message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName, UUID fromID, bool fromAgent, bool broadcast, float range, UUID ToAgentID, IScene scene) { OSChatMessage args = new OSChatMessage { Message = message, Channel = channel, Type = type, Position = fromPos, Range = range, SenderUUID = fromID, Scene = scene, ToAgentID = ToAgentID }; if (fromAgent) { IScenePresence user = scene.GetScenePresence(fromID); if (user != null) args.Sender = user.ControllingClient; } else { args.SenderObject = scene.GetSceneObjectPart(fromID); } args.From = fromName; //args. if (broadcast) { OnChatBroadcast(scene, args); scene.EventManager.TriggerOnChatBroadcast(scene, args); } else { OnChatFromWorld(scene, args); scene.EventManager.TriggerOnChatFromWorld(scene, args); } }
/// <summary> /// Tell the client what the result is /// </summary> /// <param name="result"></param> /// <param name="scene"></param> /// <param name="position"></param> static void BuildAndSendResult (float result, IScene scene, Vector3 position) { var message = new OSChatMessage { From = "Server", Message = "Result: " + result, Channel = 0, Type = ChatTypeEnum.Region, Position = position, Sender = null, SenderUUID = UUID.Zero, Scene = scene }; scene.EventManager.TriggerOnChatBroadcast (null, message); }
protected virtual void OnChatBroadcast(Object sender, OSChatMessage c) { // unless the chat to be broadcast is of type Region, we // drop it if its channel is neither 0 nor DEBUG_CHANNEL if (c.Channel != DEFAULT_CHANNEL && c.Channel != DEBUG_CHANNEL && c.Type != ChatTypeEnum.Region) return; ChatTypeEnum cType = c.Type; if (c.Channel == DEBUG_CHANNEL) cType = ChatTypeEnum.DebugChannel; if (c.Range > m_maxChatDistance) c.Range = m_maxChatDistance; if (cType == ChatTypeEnum.SayTo) //Change to something client can understand as SayTo doesn't exist except on the server cType = ChatTypeEnum.Owner; if (cType == ChatTypeEnum.Region) cType = ChatTypeEnum.Say; if (c.Message.Length > 1100) c.Message = c.Message.Substring(0, 1000); // broadcast chat works by redistributing every incoming chat // message to each avatar in the scene. string fromName = c.From; UUID fromID = UUID.Zero; ChatSourceType sourceType = ChatSourceType.Object; if (null != c.Sender) { IScenePresence avatar = c.Scene.GetScenePresence(c.Sender.AgentId); fromID = c.Sender.AgentId; fromName = avatar.Name; sourceType = ChatSourceType.Agent; } // MainConsole.Instance.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType); c.Scene.ForEachScenePresence( delegate(IScenePresence presence) { // ignore chat from child agents if (presence.IsChildAgent) return; IClientAPI client = presence.ControllingClient; // don't forward SayOwner chat from objects to // non-owner agents if ((c.Type == ChatTypeEnum.Owner) && (null != c.SenderObject) && (c.SenderObject.OwnerID != client.AgentId)) return; // don't forward SayTo chat from objects to // non-targeted agents if ((c.Type == ChatTypeEnum.SayTo) && (c.ToAgentID != client.AgentId)) return; bool cached = false; MuteList[] mutes = GetMutes(client.AgentId, out cached); foreach (MuteList m in mutes) if (m.MuteID == c.SenderUUID || (c.SenderObject != null && m.MuteID == c.SenderObject.ParentEntity.UUID)) return; client.SendChatMessage(c.Message, (byte) cType, new Vector3(client.Scene.RegionInfo.RegionSizeX*0.5f, client.Scene.RegionInfo.RegionSizeY*0.5f, 30), fromName, fromID, (byte) sourceType, (byte) ChatAudibleLevel.Fully); }); }
public bool OnNewChatMessageFromWorld (OSChatMessage c, out OSChatMessage newc) { bool isGod = false; IScenePresence sP = c.Scene.GetScenePresence (c.SenderUUID); if (sP != null) { if (!sP.IsChildAgent) { // Check if the sender is a 'god...' if (sP.GodLevel != 0) { isGod = true; // add to authorized users if (!m_authorizedSpeakers.Contains (c.SenderUUID)) m_authorizedSpeakers.Add (c.SenderUUID); if (!m_authList.Contains (c.SenderUUID)) m_authList.Add (c.SenderUUID); } //Check that the agent is allowed to speak in this region if (!m_authorizedSpeakers.Contains (c.SenderUUID)) { //They can't talk, so block it newc = c; return false; } } } if (c.Message.Contains ("Chat.")) { if (!m_useAuth || m_authList.Contains (c.SenderUUID)) { IScenePresence senderSP; c.Scene.TryGetScenePresence (c.SenderUUID, out senderSP); string [] message = c.Message.Split ('.'); if (message [1] == "SayDistance") { chatModule.SayDistance = Convert.ToInt32 (message [2]); chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, message [1] + " changed.", ChatSourceType.System, -1); } if (message [1] == "WhisperDistance") { chatModule.WhisperDistance = Convert.ToInt32 (message [2]); chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, message [1] + " changed.", ChatSourceType.System, -1); } if (message [1] == "ShoutDistance") { chatModule.ShoutDistance = Convert.ToInt32 (message [2]); chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, message [1] + " changed.", ChatSourceType.System, -1); } //Add the user to the list of allowed speakers and 'chat' admins if (message [1] == "AddToAuth") { IScenePresence NewSP; c.Scene.TryGetAvatarByName (message [2], out NewSP); m_authList.Add (NewSP.UUID); chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, message [2] + " added.", ChatSourceType.System, -1); } if (message [1] == "RemoveFromAuth") { IScenePresence NewSP; c.Scene.TryGetAvatarByName (message [2], out NewSP); m_authList.Remove (NewSP.UUID); chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, message [2] + " added.", ChatSourceType.System, -1); } //Block chat from those not in the auth list if (message [1] == "BlockChat") { m_blockChat = true; chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, "Chat blocked.", ChatSourceType.System, -1); } //Allow chat from all again if (message [1] == "AllowChat") { m_blockChat = false; chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, "Chat allowed.", ChatSourceType.System, -1); } //Remove speaking privileges from an individual if (message [1] == "RevokeSpeakingRights") { IScenePresence NewSP; c.Scene.TryGetAvatarByName (message [2], out NewSP); m_authorizedSpeakers.Remove (NewSP.UUID); chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, message [2] + " - revoked.", ChatSourceType.System, -1); } //Allow an individual to speak again if (message [1] == "GiveSpeakingRights") { IScenePresence NewSP; c.Scene.TryGetAvatarByName (message [2], out NewSP); m_authorizedSpeakers.Add (NewSP.UUID); chatModule.TrySendChatMessage (senderSP, c.Position, UUID.Zero, "WhiteCoreChat", ChatTypeEnum.Region, message [2] + " - revoked.", ChatSourceType.System, -1); } } newc = c; // Block commands from normal chat return false; } if (sP != null) { //Add the god prefix if (isGod && m_indicategod) c.Message = m_godPrefix + c.Message; } newc = c; return true; }
public void TriggerOnChatFromClient(IClientAPI sender, OSChatMessage chat) { ChatFromClientEvent handlerChatFromClient = OnChatFromClient; if (handlerChatFromClient != null) { foreach (ChatFromClientEvent d in handlerChatFromClient.GetInvocationList()) { try { d(sender, chat); } catch (Exception e) { MainConsole.Instance.ErrorFormat( "[EVENT MANAGER]: Delegate for TriggerOnChatFromClient failed - continuing. {0} {1}", e, e.StackTrace); } } } }
void EventManager_OnChatFromClient(IClientAPI sender, OSChatMessage chat) { if(chat.Message == "" || sender == null || chat.Channel != m_chatToIRCChannel) return; Client client; if(TryGetClient(sender.AgentId, out client)) { Util.FireAndForget(delegate(object o) { client.SendChat("(grid: " + MainServer.Instance.ServerURI.Remove(0, 7) + ") - " + chat.Message, m_channel); }); } }