static void Main(string[] args)
        {
            //List<Chatbag> doclist;
            //doclist = ConfigParser.Parse("chatbag.xml", "chatbag.xsd");
            //Console.Out.WriteLine("Config parsing successful");

            ChatHandler.Instance.RegisterCommand(
                new ChatHandler.ChatCommand(0, "hello|hi|what's up_world",
                delegate(ChatHandler.MatchContainer match) { })
            );
            ChatHandler.Instance.RegisterField("curse", "(?:frickin[g]?|f****n[g]?)");
            ChatHandler.Instance.RegisterCommand(
                new ChatHandler.ChatCommand(0, "{curse}",
                delegate(ChatHandler.MatchContainer match) { })
            );

            string[] phrases = {"What's up frickin world, what's up?", "Hello f*****g world?"};
            foreach( string phrase in phrases ){
                OSChatMessage msg = new OSChatMessage();
                msg.Message = phrase;
                msg.Channel = 0;
                List<ChatHandler.MatchContainer> matches = ChatHandler.Instance.DetectCommand2(msg);
                foreach( ChatHandler.MatchContainer match in matches ){
                    Console.Out.WriteLine(string.Format(
                        "Command '{0}' found in '{1}' ({2})",
                        match.Command.Phrase, match.MatchedMessage.Message, String.Join<string>("_", match.MatchedWording) ));
                }
            }

            Console.Out.WriteLine("Match list complete");

            Console.Out.WriteLine("Tests completed successfully.");
            Console.Read();
        }
        private void OnChatFromWorld(object sender, OSChatMessage oscm)
        {
//            Console.WriteLine("Got chat [{0}]", oscm.Message);

//            m_osChatMessageReceived = oscm;
            m_chatEvent.Set();
        }
        protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
                               UUID fromID, bool fromAgent, bool broadcast)
        {
            OSChatMessage args = new OSChatMessage();

            args.Message = Utils.BytesToString(message);
            args.Channel = channel;
            args.Type = type;
            args.Position = fromPos;
            args.SenderUUID = fromID;
            args.Scene = this;

            if (fromAgent)
            {
                ScenePresence user = GetScenePresence(fromID);
                if (user != null)
                    args.Sender = user.ControllingClient;
            }
            else
            {
                SceneObjectPart obj = GetSceneObjectPart(fromID);
                args.SenderObject = obj;
            }

            args.From = fromName;
            //args.

            if (broadcast)
                EventManager.TriggerOnChatBroadcast(this, args);
            else
                EventManager.TriggerOnChatFromWorld(this, args);
        }
 private void BuildAndSendResult(float result, Scene scene, Vector3 position)
 {
     OSChatMessage message = new OSChatMessage();
     message.From = "Server";
     message.Message = "Result: " + result;
     message.Channel = 0;
     message.Type = ChatTypeEnum.Region;
     message.Position = position;
     message.Sender = null;
     message.SenderUUID = UUID.Zero;
     message.Scene = scene;
     scene.EventManager.TriggerOnChatBroadcast(null, message);
 }
 public bool OnNewChatMessageFromWorld(OSChatMessage c, out OSChatMessage newc)
 {
     Scene scene = (Scene)c.Scene;
     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, 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, 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, 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, scene, c.Position);
         }
     }
     newc = c;
     //Block the message from going to everyone, only the server needed to hear
     return true;
 }
Beispiel #6
0
 public OSChatMessage Copy()
 {
     OSChatMessage message = new OSChatMessage();
     message.Channel = Channel;
     message.From = From;
     message.Message = Message;
     message.Position = Position;
     message.Range = Range;
     message.Scene = Scene;
     message.Sender = Sender;
     message.SenderObject = SenderObject;
     message.SenderUUID = SenderUUID;
     message.Type = Type;
     message.ToAgentID = ToAgentID;
     return message;
 }
        public void Init()
        {
            m_osChatMessageReceived = null;
            m_chatMessagesReceived = 0;
            m_chatMessagesThreshold = 0;
            m_chatEvent = new AutoResetEvent(false);
            m_stoppedEvent = new AutoResetEvent(false);

            //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin");
//            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
            m_xEngine = new OpenSim.Region.ScriptEngine.XEngine.XEngine();
            m_xEngine.DebugLevel = 1;

            IniConfigSource configSource = new IniConfigSource();
            
            IConfig startupConfig = configSource.AddConfig("Startup");
            startupConfig.Set("DefaultScriptEngine", "XEngine");

            IConfig xEngineConfig = configSource.AddConfig("XEngine");
            xEngineConfig.Set("Enabled", "true");
            xEngineConfig.Set("StartDelay", "0");

            // These tests will not run with AppDomainLoading = true, at least on mono.  For unknown reasons, the call
            // to AssemblyResolver.OnAssemblyResolve fails.
            xEngineConfig.Set("AppDomainLoading", "false");

            xEngineConfig.Set("ScriptStopStrategy", "co-op");

            // Make sure loops aren't actually being terminated by a script delay wait.
            xEngineConfig.Set("ScriptDelayFactor", 0);

            // This is really just set for debugging the test.
            xEngineConfig.Set("WriteScriptSourceToDebugFile", true);

            // Set to false if we need to debug test so the old scripts don't get wiped before each separate test
//            xEngineConfig.Set("DeleteScriptsOnStartup", false);

            // This is not currently used at all for co-op termination.  Bumping up to demonstrate that co-op termination
            // has an effect - without it tests will fail due to a 120 second wait for the event to finish.
            xEngineConfig.Set("WaitForEventCompletionOnScriptStop", 120000);

            m_scene = new SceneHelpers().SetupScene("My Test", TestHelpers.ParseTail(0x9999), 1000, 1000, configSource);
            SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine);
            m_scene.StartScripts();
        }
        /// <summary>
        /// Send chat to listeners.
        /// </summary>
        /// <param name='message'></param>
        /// <param name='type'>/param>
        /// <param name='channel'></param>
        /// <param name='fromPos'></param>
        /// <param name='fromName'></param>
        /// <param name='fromID'></param>
        /// <param name='targetID'></param>
        /// <param name='fromAgent'></param>
        /// <param name='broadcast'></param>
        public void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
                               UUID fromID, UUID targetID, bool fromAgent, bool broadcast)
        {
            OSChatMessage args = new OSChatMessage();

            args.Message = Utils.BytesToString(message);
            args.Channel = channel;
            args.Type = type;
            args.Position = fromPos;
            args.SenderUUID = fromID;
            args.Scene = this;
            args.Destination = targetID;

            if (fromAgent)
            {
                ScenePresence user = GetScenePresence(fromID);
                if (user != null)
                    args.Sender = user.ControllingClient;
            }
            else
            {
                SceneObjectPart obj = GetSceneObjectPart(fromID);
                args.SenderObject = obj;
            }

            args.From = fromName;
            //args.

//            m_log.DebugFormat(
//                "[SCENE]: Sending message {0} on channel {1}, type {2} from {3}, broadcast {4}",
//                args.Message.Replace("\n", "\\n"), args.Channel, args.Type, fromName, broadcast);

            if (broadcast)
                EventManager.TriggerOnChatBroadcast(this, args);
            else
                EventManager.TriggerOnChatFromWorld(this, args);
        }
        public bool SendChatMessageToNeighbors(OSChatMessage message, ChatSourceType type, RegionInfo region)
        {
            bool RetVal = false;

            if (!m_KnownNeighbors.ContainsKey(region.RegionID))
                return RetVal;

            foreach (GridRegion neighbor in m_KnownNeighbors[region.RegionID])
            {
                if (neighbor.RegionID == region.RegionID)
                    continue;
                Scene scene = FindSceneByUUID(region.RegionID);
                if (scene != null)
                {
                    IChatModule chatModule = scene.RequestModuleInterface<IChatModule>();
                    if (chatModule != null && !RetVal)
                    {
                        chatModule.DeliverChatToAvatars(type, message);
                        RetVal = true;
                    }
                }
            }
            return RetVal;
        }
        protected void ProcessCustomerReply(OSChatMessage chat)
        {
            bool accepted = false;

            if (YES_OPTION == chat.Message)
            {
                if (m_targetPlayer.Money >= m_salePrice)
                    accepted = true;
                else
                    SendAlert(m_targetPlayer.Uuid, "You don't have enough money to accept that offer!");
            }

            if (accepted)
            {
                m_controller.State.SellWater(m_player, m_targetPlayer, m_waterToSell, m_salePrice);

                SendAlert(
                    m_player,
                    string.Format(
                        "You successfully leased {0} units of water to {1} for {2}{3}",
                        m_waterToSell, m_targetPlayer.Name, WaterWarsConstants.MONEY_UNIT, m_salePrice));

                SendAlert(
                    m_targetPlayer,
                    string.Format(
                        "You successfully leased {0} units of water from {1} for {2}{3}",
                        m_waterToSell, m_player.Name, WaterWarsConstants.MONEY_UNIT, m_salePrice));
            }
            else
            {
                m_controller.EventManager.TriggerWaterSold(
                    m_targetPlayer, m_player, m_waterToSell, m_salePrice, false);

                SendAlert(
                    m_player,
                    string.Format(
                        "{0} declined your offer to lease them {1} units of water for {2}{3}",
                        m_targetPlayer.Name, m_waterToSell, WaterWarsConstants.MONEY_UNIT, m_salePrice));
            }
        }
Beispiel #11
0
 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)
             {
                 m_log.ErrorFormat (
                     "[EVENT MANAGER]: Delegate for TriggerOnChatFromClient failed - continuing.  {0} {1}",
                     e.ToString (), e.StackTrace);
             }
         }
     }
 }
Beispiel #12
0
        public void BroadcastSim(string sender, string format, params string[] args)
        {
            try
            {
                OSChatMessage c = new OSChatMessage();
                c.From = sender;
                c.Message = String.Format(format, args);
                c.Type = ChatTypeEnum.Region; // ChatTypeEnum.Say;
                c.Position = CenterOfRegion;
                c.Sender = null;
                c.SenderUUID = UUID.Zero;

                ChannelState.OSChat(this, c, true);

            }
            catch (Exception ex) // IRC gate should not crash Sim
            {
                m_log.ErrorFormat("[IRC-Connector-{0}]: BroadcastSim Exception Trap: {1}\n{2}", idn, ex.Message, ex.StackTrace);
            }
        }
        private void OnChatFromClient(object sender, OSChatMessage msg)
        {
            if (msg.Sender == null)
                return;

            //m_log.DebugFormat("chan {0} msg {1}", msg.Channel, msg.Message);

            IClientAPI client = msg.Sender;

            if (!m_floaters.ContainsKey(client.AgentId))
                return;

            string[] parts = msg.Message.Split(new char[] {':'});
            if (parts.Length == 0)
                return;

            ScenePresence sp = m_scene.GetScenePresence(client.AgentId);
            if (sp == null || sp.IsChildAgent)
                return;

            Dictionary<int, FloaterData> d = m_floaters[client.AgentId];

            // Work around a viewer bug - VALUE from any
            // dialog can appear on this channel and needs to
            // be dispatched to ALL open dialogs for the user
            if (msg.Channel == 427169570)
            {
                if (parts[0] == "VALUE")
                {
                    foreach (FloaterData dd in d.Values)
                    {
                        if(dd.Handler(client, dd, parts))
                        {
                            m_floaters[client.AgentId].Remove(dd.Channel);
                            SendToClient(sp, String.Format("># floater {0} destroy", dd.FloaterName));
                            break;
                        }
                    }
                }
                return;
            }

            if (!d.ContainsKey(msg.Channel))
                return;

            FloaterData data = d[msg.Channel];

            if (parts[0] == "NOTIFY")
            {
                if (parts[1] == "cancel" || parts[1] == data.FloaterName)
                {
                    m_floaters[client.AgentId].Remove(data.Channel);
                    SendToClient(sp, String.Format("># floater {0} destroy", data.FloaterName));
                }
            }

            if (data.Handler != null && data.Handler(client, data, parts))
            {
                m_floaters[client.AgentId].Remove(data.Channel);
                SendToClient(sp, String.Format("># floater {0} destroy", data.FloaterName));
            }
        }
Beispiel #14
0
        // This method gives the region an opportunity to interfere with 
        // message delivery. For now we just enforce the enable/disable
        // flag.

        internal void OSChat(Object irc, OSChatMessage msg)
        {
            if (enabled)
            {
                // m_log.DebugFormat("[IRC-OSCHAT] Region {0} being sent message", region.Region);
                msg.Scene = scene;
                scene.EventManager.TriggerOnChatBroadcast(irc, msg);
            }
        }
Beispiel #15
0
        // This handler detects chat events int he virtual world.

        public void OnSimChat(Object sender, OSChatMessage msg)
        {

            // early return if this comes from the IRC forwarder

            if (cs.irc.Equals(sender)) return;

            // early return if nothing to forward

            if (msg.Message.Length == 0) return;

            // check for commands coming from avatars or in-world
            // object (if commands are enabled)

            if (cs.CommandsEnabled && msg.Channel == cs.CommandChannel)
            {

                m_log.DebugFormat("[IRC-Region {0}] command on channel {1}: {2}", Region, msg.Channel, msg.Message);

                string[] messages = msg.Message.Split(' ');
                string command = messages[0].ToLower();

                try
                {
                    switch (command)
                    {

                        // These commands potentially require a change in the
                        // underlying ChannelState.

                        case "server":
                            cs.Close(this);
                            cs = cs.UpdateServer(this, messages[1]);
                            cs.Open(this);
                            break;
                        case "port":
                            cs.Close(this);
                            cs = cs.UpdatePort(this, messages[1]);
                            cs.Open(this);
                            break;
                        case "channel":
                            cs.Close(this);
                            cs = cs.UpdateChannel(this, messages[1]);
                            cs.Open(this);
                            break;
                        case "nick":
                            cs.Close(this);
                            cs = cs.UpdateNickname(this, messages[1]);
                            cs.Open(this);
                            break;

                        // These may also (but are less likely) to require a
                        // change in ChannelState.

                        case "client-reporting":
                            cs = cs.UpdateClientReporting(this, messages[1]);
                            break;
                        case "in-channel":
                            cs = cs.UpdateRelayIn(this, messages[1]);
                            break;
                        case "out-channel":
                            cs = cs.UpdateRelayOut(this, messages[1]);
                            break;

                        // These are all taken to be temporary changes in state
                        // so the underlying connector remains intact. But note
                        // that with regions sharing a connector, there could
                        // be interference.

                        case "close":
                            enabled = false;
                            cs.Close(this);
                            break;

                        case "connect":
                            enabled = true;
                            cs.Open(this);
                            break;

                        case "reconnect":
                            enabled = true;
                            cs.Close(this);
                            cs.Open(this);
                            break;

                        // This one is harmless as far as we can judge from here.
                        // If it is not, then the complaints will eventually make
                        // that evident.

                        default:
                            m_log.DebugFormat("[IRC-Region {0}] Forwarding unrecognized command to IRC : {1}", 
                                            Region, msg.Message);
                            cs.irc.Send(msg.Message);
                            break;
                    }
                }
                catch (Exception ex)
                { 
                    m_log.WarnFormat("[IRC-Region {0}] error processing in-world command channel input: {1}",
                                    Region, ex.Message);
                    m_log.Debug(ex);
                }

                return;

            }

            // The command channel remains enabled, even if we have otherwise disabled the IRC
            // interface.

            if (!enabled)
                return;

            // drop messages unless they are on a valid in-world
            // channel as configured in the ChannelState

            if (!cs.ValidInWorldChannels.Contains(msg.Channel))
            {
                m_log.DebugFormat("[IRC-Region {0}] dropping message {1} on channel {2}", Region, msg, msg.Channel);
                return;
            }

            ScenePresence avatar = null;
            string fromName = msg.From;

            if (msg.Sender != null)
            {
                avatar = scene.GetScenePresence(msg.Sender.AgentId);
                if (avatar != null) fromName = avatar.Name;
            }

            if (!cs.irc.Connected)
            {
                m_log.WarnFormat("[IRC-Region {0}] IRCConnector not connected: dropping message from {1}", Region, fromName);
                return;
            }

            m_log.DebugFormat("[IRC-Region {0}] heard on channel {1} : {2}", Region, msg.Channel, msg.Message);

            if (null != avatar && cs.RelayChat && (msg.Channel == 0 || msg.Channel == DEBUG_CHANNEL)) 
            {
                string txt = msg.Message;
                if (txt.StartsWith("/me "))
                    txt = String.Format("{0} {1}", fromName, msg.Message.Substring(4));

                cs.irc.PrivMsg(cs.PrivateMessageFormat, fromName, Region, txt);
                return;
            }

            if (null == avatar && cs.RelayPrivateChannels && null != cs.AccessPassword && 
                msg.Channel == cs.RelayChannelOut)
            {
                Match m = cs.AccessPasswordRegex.Match(msg.Message);
                if (null != m)
                {
                    m_log.DebugFormat("[IRC] relaying message from {0}: {1}", m.Groups["avatar"].ToString(), 
                                      m.Groups["message"].ToString());
                    cs.irc.PrivMsg(cs.PrivateMessageFormat, m.Groups["avatar"].ToString(),
                                   scene.RegionInfo.RegionName, m.Groups["message"].ToString());
                }
            }
        }
        /// <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 != "")
            {
#if (!ISWIN)
                foreach (string pluginMain in ChatPlugins.Keys)
                {
                    if (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;
                    }
                }
#else
                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;
                }
#endif

            }
            string Name2 = "";
            if (sender is IClientAPI)
            {
                Name2 = (sender).Name;
            }
            c.From = Name2;

            DeliverChatToAvatars(ChatSourceType.Agent, c);
        }
        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;

                        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);
                    });
        }
Beispiel #18
0
        // This supports any local message traffic that might be needed in 
        // support of command processing. At present there is none.

        internal void LocalChat(string msg)
        {
            if (enabled)
            {
                OSChatMessage osm = new OSChatMessage();
                osm.From = "IRC Agent";
                osm.Message = msg;
                osm.Type = ChatTypeEnum.Region;
                osm.Position = CenterOfRegion;
                osm.Sender = null;
                osm.SenderUUID = OpenMetaverse.UUID.Zero; // Hmph! Still?
                osm.Channel = 0;
                OSChat(this, osm);
            }
        }
Beispiel #19
0
        public void ListenerRun()
        {

            string inputLine;
            int resetk = m_resetk;

            try
            {
                while (m_enabled && m_connected)
                {

                    if ((inputLine = m_reader.ReadLine()) == null)
                        throw new Exception("Listener input socket closed");

                    // m_log.Info("[IRCConnector]: " + inputLine);

                    if (inputLine.Contains("PRIVMSG"))
                    {

                        Dictionary<string, string> data = ExtractMsg(inputLine);

                        // Any chat ???
                        if (data != null)
                        {

                            OSChatMessage c = new OSChatMessage();
                            c.Message = data["msg"];
                            c.Type = ChatTypeEnum.Region;
                            c.Position = CenterOfRegion;
                            c.From = data["nick"];
                            c.Sender = null;
                            c.SenderUUID = UUID.Zero;

                            // Is message "\001ACTION foo bar\001"? 
                            // Then change to: "/me foo bar"

                            if ((1 == c.Message[0]) && c.Message.Substring(1).StartsWith("ACTION"))
                                c.Message = String.Format("/me {0}", c.Message.Substring(8, c.Message.Length - 9));

                            ChannelState.OSChat(this, c, false);

                        }

                    }
                    else
                    {
                        ProcessIRCCommand(inputLine);
                    }
                }
            }
            catch (Exception /*e*/)
            {
                // m_log.ErrorFormat("[IRC-Connector-{0}]: ListenerRun exception trap: {1}", idn, e.Message);
                // m_log.Debug(e);
            }

            // This is potentially circular, but harmless if so.
            // The connection is marked as not connected the first time
            // through reconnect.

            if (m_enabled && (m_resetk == resetk))
                Reconnect();
        }
Beispiel #20
0
        /********************************************************************
         *
         * Listener Stuff
         *
         * *****************************************************************/

        private 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);
            }
            else
            {
                DeliverMessage(e.Type, e.Channel, e.From, UUID.Zero,
                        e.Message, e.Position);
            }
        }
Beispiel #21
0
        private void Update()
        {
            frame++;
            if (frame > 20)
            {
                frame = 0;
                if (OnAgentUpdate != null)
                {
                    AgentUpdateArgs pack = new AgentUpdateArgs();
                    pack.ControlFlags = movementFlag;
                    pack.BodyRotation = bodyDirection;

                    OnAgentUpdate(this, pack);
                }
                if (flyState == 0)
                {
                    movementFlag = (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY |
                                   (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG;
                    flyState = 1;
                }
                else if (flyState == 1)
                {
                    movementFlag = (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY |
                                   (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS;
                    flyState = 2;
                }
                else
                {
                    movementFlag = (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
                    flyState = 0;
                }

                if (count >= 10)
                {
                    if (OnChatFromClient != null)
                    {
                        OSChatMessage args = new OSChatMessage();
                        args.Message = "Hey You! Get out of my Home. This is my Region";
                        args.Channel = 0;
                        args.From = FirstName + " " + LastName;
                        args.Scene = m_scene;
                        args.Position = new Vector3(128, 128, 26);
                        args.Sender = this;
                        args.Type = ChatTypeEnum.Shout;

                        OnChatFromClient(this, args);
                    }
                    count = -1;
                }

                count++;
            }
        }
Beispiel #22
0
        private void SendOnChatFromClient(string message, ChatTypeEnum chatType)
        {
            OSChatMessage chatFromClient = new OSChatMessage();
            chatFromClient.Channel = 0;
            chatFromClient.From = Name;
            chatFromClient.Message = message;
            chatFromClient.Position = StartPos;
            chatFromClient.Scene = m_scene;
            chatFromClient.Sender = this;
            chatFromClient.SenderUUID = AgentId;
            chatFromClient.Type = chatType;

            OnChatFromClient(this, chatFromClient);
        }
Beispiel #23
0
 public void TriggerOnChatBroadcast(Object sender, OSChatMessage chat)
 {
     ChatBroadcastEvent handlerChatBroadcast = OnChatBroadcast;
     if (handlerChatBroadcast != null)
     {
         foreach (ChatBroadcastEvent d in handlerChatBroadcast.GetInvocationList())
         {
             try
             {
                 d(sender, chat);
             }
             catch (Exception e)
             {
                 m_log.ErrorFormat(
                     "[EVENT MANAGER]: Delegate for TriggerOnChatBroadcast failed - continuing.  {0} {1}", 
                     e.Message, e.StackTrace);
             }
         }
     }
 }
        /// <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);
        }
Beispiel #25
0
        void OnEmptyScriptCompileQueue(int numScriptsFailed, string message)
        {
            m_log.DebugFormat("[RegionReady]: Script compile queue empty!");

            if (m_firstEmptyCompileQueue || m_oarFileLoading) 
            {
                OSChatMessage c = new OSChatMessage();
                if (m_firstEmptyCompileQueue) 
                    c.Message = "server_startup,";
                else 
                    c.Message = "oar_file_load,";
                m_firstEmptyCompileQueue = false;
                m_oarFileLoading = false;

                m_scene.Backup(false);

                c.From = "RegionReady";
                if (m_lastOarLoadedOk) 
                    c.Message += "1,";
                else
                    c.Message += "0,";
                c.Channel = m_channelNotify;
                c.Message += numScriptsFailed.ToString() + "," + message;
                c.Type = ChatTypeEnum.Region;
                c.Position = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30);
                c.Sender = null;
                c.SenderUUID = UUID.Zero;
                c.Scene = m_scene;

                m_log.DebugFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}",
                                 m_scene.RegionInfo.RegionName, c.Message, m_channelNotify);

                m_scene.EventManager.TriggerOnChatBroadcast(this, c);

                TriggerRegionReady(m_scene);
            }
        }
        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);
            }
        }
        // This function is lifted from the IRCConnector because it 
        // contains information that is not differentiating from an
        // IRC point-of-view.

        public static void OSChat(IRCConnector p_irc, OSChatMessage c, bool cmsg)
        {

            // m_log.DebugFormat("[IRC-OSCHAT] from {0}:{1}", p_irc.Server, p_irc.IrcChannel);

            try
            {

                // Scan through the set of unique channel configuration for those
                // that belong to this connector. And then forward the message to 
                // all regions known to those channels.
                // Note that this code is responsible for completing some of the
                // settings for the inbound OSChatMessage

                lock (IRCBridgeModule.m_channels)
                {
                    foreach (ChannelState cs in IRCBridgeModule.m_channels)
                    {
                        if (p_irc == cs.irc)
                        {

                            // This non-IRC differentiator moved to here

                            if (cmsg && !cs.ClientReporting)
                                continue;

                            // This non-IRC differentiator moved to here

                            c.Channel = (cs.RelayPrivateChannels ? cs.RelayChannel : 0);

                            foreach (RegionState region in cs.clientregions)
                            {
                                region.OSChat(cs.irc, c);
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_log.ErrorFormat("[IRC-OSCHAT]: BroadcastSim Exception: {0}", ex.Message);
                m_log.Debug(ex);
            }
        }
        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;
            Vector3 regionPos = scene != null
                                    ? new Vector3(scene.RegionInfo.RegionLocX,
                                                  scene.RegionInfo.RegionLocY, 0)
                                    : Vector3.Zero;

            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);

            // MainConsole.Instance.DebugFormat("[CHAT]: DCTA: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, c.Type, sourceType);

            foreach (IScenePresence presence in from s in m_scenes
                                                select s.GetScenePresences() into ScenePresences
                                                from presence in ScenePresences
                                                where !presence.IsChildAgent
                                                let fromRegionPos = fromPos + regionPos
                                                let toRegionPos = presence.AbsolutePosition +
                                                                  new Vector3(presence.Scene.RegionInfo.RegionLocX,
                                                                              presence.Scene.RegionInfo.RegionLocY, 0)
                                                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, regionPos, fromID, fromName, c.Type, message, sourceType,
                                   c.Range);
            }
        }
        public List<GridRegion> SendChatMessageToNeighbors(OSChatMessage message, ChatSourceType type, RegionInfo region, out bool RetVal)
        {
            RetVal = false;
            List<GridRegion> regionsNotified = new List<GridRegion>();

            if (!m_KnownNeighbors.ContainsKey(region.RegionID))
                return regionsNotified;

            foreach (GridRegion neighbor in m_KnownNeighbors[region.RegionID])
            {
                if (neighbor.RegionID == region.RegionID)
                    continue;
                Scene scene = FindSceneByUUID(neighbor.RegionID);
                if (scene != null)
                {
                    Aurora.Framework.IChatModule chatModule = scene.RequestModuleInterface<Aurora.Framework.IChatModule>();
                    if (chatModule != null && !RetVal)
                    {
                        chatModule.DeliverChatToAvatars(type, message);
                        RetVal = true;
                    }
                    regionsNotified.Add(neighbor);
                }
            }
            return regionsNotified;
        }
        /// <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;
        }