コード例 #1
0
ファイル: XamlMessageBuilder.cs プロジェクト: Irdis/VSTalk
        public Message Create(FlowDocument document)
        {
            var xdoc = new XmlDocument();
            xdoc.LoadXml(XamlWriter.Save(document));

            var newAttr = xdoc.CreateAttribute("xml:space");
            newAttr.Value = "preserve";

            xdoc.DocumentElement.Attributes.Append(newAttr);
            var sb = new StringBuilder(xdoc.OuterXml);
            //see: http://stackoverflow.com/questions/2624068/wpf-richtextbox-xamlwriter-behaviour
            var xamlPart = sb.Replace("{}{", "{").ToString();

            var txtPart = new TextRange(document.ContentStart, document.ContentEnd)
                    .Text
                    .TrimEnd();
            var xaml = new XamlBody();
            xaml.Content = xamlPart;
            var msg = new Message
            {
                    Body = txtPart,
            };
            msg.AddChild(xaml);
            return msg;
        }
コード例 #2
0
ファイル: Message.cs プロジェクト: phiree/dzdocs
        private void Message1()
        {
            // transient message (will not be stored offline if the server support AMP)

            /*
            <message to='*****@*****.**'
                     from='[email protected]/elsinore'
                     type='chat'
                     id='chatty1'>
              <body>Who&apos;s there?</body>
              <amp xmlns='http://jabber.org/protocol/amp'>
                <rule action='drop' condition='deliver' value='stored'/>
              </amp>
            </message>
            */

            agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
            msg.To = new Jid("*****@*****.**");
            msg.From = new Jid("[email protected]/elsinore");
            msg.Type = MessageType.chat;
            msg.Id = "chatty1";

            msg.Body = "Who&apos;s there?";

            Amp amp = new Amp();
            Rule rule = new Rule(Condition.Deliver, "stored", agsXMPP.protocol.extensions.amp.Action.drop);
            amp.AddRule(rule);

            msg.AddChild(amp);

            Program.Print(msg);
        }
コード例 #3
0
ファイル: MatchmakingBot.cs プロジェクト: traemyn/OCTGN
        public Guid BeginHostGame(Guid gameid, Version gameVersion, string gamename,
                                  string gameIconUrl, string password, string actualgamename, Version sasVersion, bool specators)
        {
            var hgr = new HostGameRequest(gameid, gameVersion, gamename, actualgamename, gameIconUrl, password ?? "", sasVersion, specators);

            Log.InfoFormat("BeginHostGame {0}", hgr);
            var m = new Message(new Jid(AppConfig.Instance.GameServUsername, AppConfig.Instance.ServerPath, null), this.Xmpp.MyJID, MessageType.normal, "", "hostgame");

            m.GenerateId();
            m.AddChild(hgr);
            this.Xmpp.Send(m);
            return(hgr.RequestId);
        }
コード例 #4
0
ファイル: frmMain.cs プロジェクト: Br3nda/sfdocsamples
        private void btnSendCommand_Click(object sender, EventArgs e)
        {
            RosterNode roster = Util.XmppServices.RosterControl.SelectedItem();

            if (roster == null)
            {
                return;
            }
            if (roster.RosterItem != null)
            {
                //IQ iq = new IQ(IqType.get, XmppCon.MyJID, roster.RosterItem.Jid);

                agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
                msg.To = roster.RosterItem.Jid;

                agsXMPP.Client.Comand cmd = new agsXMPP.Client.Comand();

                cmd.Type  = "tipo 01";
                cmd.Value = Convert.ToInt32(txtCmdValue.Text);

                msg.AddChild(cmd);
                Util.XmppServices.XmppCon.Send(msg);
            }
        }
コード例 #5
0
ファイル: MatchmakingBot.cs プロジェクト: rexperalta/OCTGN
 public Guid BeginHostGame(Guid gameid, Version gameVersion, string gamename,
     string gameIconUrl, string password, string actualgamename, Version sasVersion, bool specators)
 {
     var hgr = new HostGameRequest(gameid, gameVersion, gamename, actualgamename, gameIconUrl, password ?? "", sasVersion, specators);
     Log.InfoFormat("BeginHostGame {0}", hgr);
     var m = new Message(new Jid(AppConfig.Instance.GameServUsername, AppConfig.Instance.ServerPath, null), this.Xmpp.MyJID, MessageType.normal, "", "hostgame");
     m.GenerateId();
     m.AddChild(hgr);
     this.Xmpp.Send(m);
     return hgr.RequestId;
 }
コード例 #6
0
ファイル: GameBot.cs プロジェクト: Gondulf/OCTGN
 private static void XmppOnOnMessage(object sender , Message msg)
 {
     switch(msg.Type)
     {
         case MessageType.normal:
             if(msg.Subject == "hostgame")
             {
                 var data = msg.Body.Split(new string[1]{",:,"},StringSplitOptions.RemoveEmptyEntries);
                 if (data.Length != 3) return;
                 var guid = Guid.Empty;
                 Version ver = null;
                 if (String.IsNullOrWhiteSpace(data[2])) return;
                 var gameName = data[2];
                 if(Guid.TryParse(data[0] , out guid) && Version.TryParse(data[1] , out ver))
                 {
                     var port = Gaming.HostGame(guid , ver , gameName , "" , new NewUser(msg.From));
                     if (port == -1) return;
                     var m = new Message(msg.From , msg.To , MessageType.normal , port.ToString() , "gameready");
                     m.GenerateId();
                     Xmpp.Send(m);
                     var gameMessage = String.Format(" {0} is hosting a game called '{1}'" ,msg.From.User,gameName);
                     m = new Message(new Jid("lobby@conference." + ServerPath), msg.To, MessageType.groupchat, gameMessage);
                     //Xmpp.Send(m);
                     //RefreshLists();
                 }
             }
             else if(msg.Subject == "gamelist")
             {
                 //Trace.WriteLine("[Bot]Request GameList: " + msg.From.User);
                 var list = Gaming.GetLobbyList().Where(x=>x.GameStatus == EHostedGame.StartedHosting);
                 var m = new Message(msg.From , MessageType.normal , "" , "gamelist");
                 m.GenerateId();
                 foreach (var a in list)
                 {
                     m.AddChild(a);
                 }
                 Xmpp.Send(m);
             }
             else if(msg.Subject == "gamestarted")
             {
                 int port = -1;
                 if(Int32.TryParse(msg.Body,out port))
                     Gaming.StartGame(port);
                 //RefreshLists();
             }
             break;
         case MessageType.error:
             break;
         case MessageType.chat:
             break;
         case MessageType.groupchat:
             break;
         case MessageType.headline:
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
コード例 #7
0
ファイル: GameBot.cs プロジェクト: rerbes/OCTGN
        private void XmppOnOnMessage(object sender , Message msg)
        {
            try
            {
                switch (msg.Type)
                {
                    case MessageType.normal:
                        if (msg.Subject == "hostgame")
                        {

                            if (msg.HasChildElements == false)
                            {
                                // F it, someone screwed up this year.
                                return;
                            }

                            if (msg.ChildNodes.OfType<HostGameRequest>().Any() == false)
                            {
                                // Again, what the fuuuuu
                                return;
                            }

                            var req = msg.ChildNodes.OfType<HostGameRequest>().First();

                            Log.InfoFormat("Host game from {0}", msg.From);
                            while (SasUpdater.Instance.IsUpdating)
                            {
                                Thread.Sleep(100);
                            }
                            var id = GameManager.Instance.HostGame(req, new User(msg.From));

                            if(id != Guid.Empty)
                                userRequests.Add("hostrequest_" + id, id, DateTimeOffset.UtcNow.AddSeconds(30));
                        }
                        else if (msg.Subject == "gamelist")
                        {
                            // If someone tried to refresh their game list too soon, f them
                            if (userRequests.Contains("refreshrequest_" + msg.From.User.ToLower()))
                                return;
                            // Mark the user as already requested a list for the next 15 seconds
                            userRequests.Add("refreshrequest_" + msg.From.User.ToLower(), 1, DateTimeOffset.UtcNow.AddSeconds(15));
                            var list = GameManager.Instance.Games;
                            var m = new Message(msg.From, MessageType.normal, "", "gamelist");
                            m.GenerateId();
                            foreach (var a in list)
                            {
                                m.AddChild(a);
                            }
                            Xmpp.Send(m);
                        }
                        else if (msg.Subject == "killgame")
                        {
                            var items = msg.Body.Split(new[]{"#:999:#"}, StringSplitOptions.RemoveEmptyEntries);
                            if (items.Length != 2) return;
                            var client = new ApiClient();
                            var res = client.Login(msg.From.User, items[1]);
                            if (res == LoginResult.Ok)
                            {
                                var id = Guid.Parse(items[0]);
                                GameManager.Instance.KillGame(id);
                            }
                            throw new Exception("Error verifying user " + res);
                        }
                        break;
                    case MessageType.error:
                        break;
                    case MessageType.chat:
                        if (!msg.From.User.Equals("d0c", StringComparison.InvariantCultureIgnoreCase)) return;
                        // Keep this around in case we want to add commands at some point, we'll have an idea on how to write the code
                        //if (msg.Body.Equals("pause"))
                        //{
                        //    _isPaused = true;
                        //    Log.Warn(":::::: PAUSED ::::::");
                        //    var m = new Message(msg.From, MessageType.chat, "Paused");
                        //    m.GenerateId();
                        //    Xmpp.Send(m);
                        //}
                        break;
                }

            }
            catch (Exception e)
            {
                Log.Error("[Bot]XmppOnOnMessage Error",e);
            }
        }
コード例 #8
0
ファイル: GameBot.cs プロジェクト: rerbes/OCTGN
 public void SendGameReady(HostedGameData game)
 {
     var m = new Message(game.Username + "@of.octgn.net", MessageType.normal, "", "gameready");
     m.GenerateId();
     m.AddChild(game);
     Xmpp.Send(m);
 }
コード例 #9
0
ファイル: MucManager.cs プロジェクト: jptoto/argsxmpp
        /// <summary>
        /// Invite multiple contacts to a chatroom
        /// </summary>
        /// <param name="jids"></param>
        /// <param name="room"></param>
        /// <param name="reason"></param>
        public void Invite(Jid[] jids, Jid room, string reason)
        {
            Message msg = new Message();
            msg.To = room;

            User user = new User();
            foreach (Jid jid in jids)
            {
                if (reason != null)
                    user.AddChild(new Invite(jid, reason));
                else
                    user.AddChild(new Invite(jid));
            }

            msg.AddChild(user);

            m_connection.Send(msg);
        }
コード例 #10
0
ファイル: MucManager.cs プロジェクト: jptoto/argsxmpp
        /// <summary>
        /// Decline a groupchat invitation
        /// </summary>
        /// <param name="to">the jid which invited us</param>
        /// <param name="room">to room to which we send the decline (this is normally the same room we were invited to)</param>
        /// <param name="reason">reason why we decline the invitation</param>
        public void Decline(Jid to, Jid room, string reason)
        {
            Message msg = new Message();
            msg.To = room;

            User user = new User();
            if (reason != null)
                user.Decline = new Decline(to, reason);
            else
                user.Decline = new Decline(to);

            msg.AddChild(user);

            m_connection.Send(msg);
        }
コード例 #11
0
ファイル: Message.cs プロジェクト: phiree/dzdocs
        private void Message2()
        {
            // transient message (will not be stored offline if the server support AMP)

            /*
            <message to='*****@*****.**'
                     from='[email protected]/elsinore'
                     type='chat'
                     id='chatty1'>
              <body>Who&apos;s there?</body>
              <amp xmlns='http://jabber.org/protocol/amp'>
                <rule action='drop' condition='deliver' value='stored'/>
              </amp>
            </message>
            */

            agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
            msg.To = new Jid("*****@*****.**");
            msg.From = new Jid("[email protected]/elsinore");
            msg.Type = MessageType.chat;
            msg.Id = "chatty1";

            msg.Body = "Who&apos;s there?";

            Element amp = new Element();
            amp.TagName     = "amp";
            amp.Namespace   = "http://jabber.org/protocol/amp";

            Element rule = new Element();
            rule.TagName    = "rule";
            rule.Namespace  = "http://jabber.org/protocol/amp";
            rule.SetAttribute("action", "drop");
            rule.SetAttribute("condition", "deliver");
            rule.SetAttribute("value", "stored");

            amp.AddChild(rule);
            msg.AddChild(amp);

            Program.Print(msg);
        }
コード例 #12
0
ファイル: frmMain.cs プロジェクト: spzenk/sfdocsamples
        private void btnSendCommand_Click(object sender, EventArgs e)
        {
            RosterNode roster = Util.XmppServices.RosterControl.SelectedItem();
            if (roster == null) return;
            if (roster.RosterItem != null)
            {
                //IQ iq = new IQ(IqType.get, XmppCon.MyJID, roster.RosterItem.Jid);

                agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
                msg.To = roster.RosterItem.Jid;

                agsXMPP.Client.Comand cmd = new agsXMPP.Client.Comand();

                cmd.Type = "tipo 01";
                cmd.Value = Convert.ToInt32(txtCmdValue.Text);

                msg.AddChild(cmd);
                Util.XmppServices.XmppCon.Send(msg);
            }

        }
コード例 #13
0
ファイル: GameBot.cs プロジェクト: Kamalisk/OCTGN
 private static void XmppOnOnMessage(object sender , Message msg)
 {
     switch(msg.Type)
     {
         case MessageType.normal:
             if(msg.Subject == "hostgame")
             {
                 if (isPaused)
                 {
                     messageQueue.Enqueue(msg);
                     return;
                 }
                 var data = msg.Body.Split(new string[1]{",:,"},StringSplitOptions.None);
                 if (data.Length != 4) return;
                 var guid = Guid.Empty;
                 Version ver = null;
                 if (String.IsNullOrWhiteSpace(data[2])) return;
                 var gameName = data[2];
                 var password = data[3];
                 if(Guid.TryParse(data[0] , out guid) && Version.TryParse(data[1] , out ver))
                 {
                     var port = Gaming.HostGame(guid , ver , gameName , password , new Lobby.User(msg.From));
                     if (port == -1) return;
                     var m = new Message(msg.From , msg.To , MessageType.normal , port.ToString() , "gameready");
                     m.GenerateId();
                     Xmpp.Send(m);
                 }
             }
             else if(msg.Subject == "gamelist")
             {
                 if (isPaused)
                 {
                     messageQueue.Enqueue(msg);
                     return;
                 }
                 var list = Gaming.GetLobbyList().Where(x=>x.GameStatus == EHostedGame.StartedHosting);
                 var m = new Message(msg.From , MessageType.normal , "" , "gamelist");
                 m.GenerateId();
                 foreach (var a in list)
                 {
                     m.AddChild(a);
                 }
                 Xmpp.Send(m);
             }
             else if (msg.Subject == "gamestarted")
             {
                 if (isPaused)
                 {
                     messageQueue.Enqueue(msg);
                     return;
                 }
                 int port = -1;
                 if (Int32.TryParse(msg.Body, out port)) Gaming.StartGame(port);
             }
             break;
         case MessageType.error:
             break;
         case MessageType.chat:
                 if (!msg.From.User.Equals("d0c", StringComparison.InvariantCultureIgnoreCase)) return;
                 if (msg.Body.Equals("pause"))
                 {
                     isPaused = true;
                     Console.WriteLine(":::::: PAUSED ::::::");
                     var m = new Message(msg.From, MessageType.chat, "Paused");
                     m.GenerateId();
                     Xmpp.Send(m);
                 }
                 else if (msg.Body.Equals("unpause"))
                 {
                     isPaused = false;
                     Console.WriteLine("Unpausing...");
                     var m = new Message(msg.From, MessageType.chat, "Unpausing");
                     m.GenerateId();
                     Xmpp.Send(m);
                     while (messageQueue.Count > 0)
                     {
                         XmppOnOnMessage(null,messageQueue.Dequeue());
                     }
                     Console.WriteLine(":::::: UNPAUSED ::::::");
                     var m2 = new Message(msg.From, MessageType.chat, "UnPaused");
                     m2.GenerateId();
                     Xmpp.Send(m2);
                 }
             break;
         case MessageType.groupchat:
             break;
         case MessageType.headline:
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
コード例 #14
0
ファイル: Wire.cs プロジェクト: StackableRegiments/metl2011
 public void stanza(string target, Element stanza)
 {
     var message = new agsXMPP.protocol.client.Message();
     string modifiedTarget =
         stanza.GetTag(MeTLStanzas.privacyTag) == "private" ?
         string.Format("{0}{1}", target, stanza.GetTag("author")) : target;
     message.To = new Jid(string.Format("{0}@{1}", modifiedTarget, Constants.JabberWire.MUC));
     message.From = jid;
     message.Type = MessageType.groupchat;
     message.AddChild(stanza);
     send(message);
 }