Example #1
0
        //public const string DeleteRosterQuery = @"<query xmlns=""jabber:iq:roster""><item jid=""##JID##"" subscription=""remove"" /></query>";

        public void DeleteFromRoster(JID jid)
        {
            //<iq from='[email protected]/balcony'
            //      id='hm4hs97y'
            //      type='set'>
            //    <query xmlns='jabber:iq:roster'>
            //      <item jid='*****@*****.**'
            //            subscription='remove'/>
            //    </query>
            //  </iq>

            //string strDeleteQuery = DeleteRosterQuery.Replace("##JID##", jid.BareJID);

            RosterIQ DeleteRosterIQ = new RosterIQ();

            //DeleteRosterIQ.InnerXML = strDeleteQuery;
            DeleteRosterIQ.Type = IQType.set.ToString();
            DeleteRosterIQ.To   = null;
            DeleteRosterIQ.From = XMPPClient.JID;
            //DeleteRosterIQ.xmlns = "jabber:client";

            rosteritem deleteitem = new rosteritem();

            deleteitem.JID          = jid;
            deleteitem.Subscription = subscription.remove.ToString();

            DeleteRosterIQ.Query.RosterItems = new rosteritem[] { deleteitem };


            IQ IQResponse = XMPPClient.SendRecieveIQ(DeleteRosterIQ, 10000);

            if (IQResponse != null)
            {
            }
        }
Example #2
0
        /// <summary>
        /// Commits the assignement of two players to the Matchmaker
        /// </summary>
        /// <param name="Manager">The xmpp manager</param>
        /// <param name="partner">The Jabber-ID of the partner</param>
        /// <param name="mid">The Match-ID of the upcoming match</param>
        public static void Assigned(XMPPManager Manager, JID partner, String mid)
        {
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("mid", mid);
            dict.Add("jid", partner);

            QueuingMessage message = new QueuingMessage(Enum.QueueingAction.assigned, dict);
            Manager.Client.SendRawXML(message.ToSendXML(Manager.OwnID, MatchmakerJID));
        }
Example #3
0
 public FileTransfer(byte [] bData, string strFileName, JID remotejid)
 {
     BytesTotal = bData.Length;
     FileName = strFileName;
     Bytes = bData;
     RemoteJID = remotejid;
     this.FileTransferDirection = System.Net.XMPP.FileTransferDirection.Send;
     this.FileTransferState = System.Net.XMPP.FileTransferState.WaitingOnUserAccept;
 }
Example #4
0
 public FileTransfer(string strFileName, int nBytesToBeReceived, JID remotejid)
 {
     BytesTotal = nBytesToBeReceived;
     BytesRemaining = nBytesToBeReceived;
     FileName = strFileName;
     RemoteJID = remotejid;
     this.FileTransferDirection = System.Net.XMPP.FileTransferDirection.Receive;
     this.FileTransferState = System.Net.XMPP.FileTransferState.WaitingOnUserAccept;
 }
Example #5
0
 public FileTransfer(byte [] bData, string strFileName, JID remotejid)
 {
     BytesTotal = bData.Length;
     FileName   = strFileName;
     Bytes      = bData;
     RemoteJID  = remotejid;
     this.FileTransferDirection = System.Net.XMPP.FileTransferDirection.Send;
     this.FileTransferState     = System.Net.XMPP.FileTransferState.WaitingOnUserAccept;
 }
Example #6
0
 public FileTransfer(string strFileName, int nBytesToBeReceived, JID remotejid)
 {
     BytesTotal                 = nBytesToBeReceived;
     BytesRemaining             = nBytesToBeReceived;
     FileName                   = strFileName;
     RemoteJID                  = remotejid;
     this.FileTransferDirection = System.Net.XMPP.FileTransferDirection.Receive;
     this.FileTransferState     = System.Net.XMPP.FileTransferState.WaitingOnUserAccept;
 }
Example #7
0
        /// <summary>
        /// Sends a chat message to a user
        /// </summary>
        /// <param name="msg"></param>
        public void SendChatMessage(string strMessage, JID jidto)
        {
            TextMessage txtmsg = new TextMessage();

            txtmsg.Received = DateTime.Now;
            txtmsg.From     = JID;
            txtmsg.To       = jidto;
            txtmsg.Message  = strMessage;
            GenericMessageLogic.SendChatMessage(txtmsg);
        }
Example #8
0
        /// <summary>
        /// Constructor with login credentials
        /// </summary>
        /// <param name="jabberID">The JID-Object of the JabberID</param>
        /// <param name="password">The password to login to this account</param>
        /// <param name="mainPage">The MainPage-Control. I think you can give me 'this'</param>
        public XMPPManager(JID jabberID, String password, MainPage mainPage)
        {
            this.client = new XMPPClient();
            this.client.JID = jabberID;
            this.client.Password = password;
            this.client.Resource = "battleshipme";
            this.mainPage = mainPage;

            InitializeClient();
        }
Example #9
0
        public void RequestVCARD(JID jidfor)
        {
            IQ iq = new IQ();

            iq.From     = XMPPClient.JID;
            iq.To       = jidfor.BareJID;
            iq.Type     = IQType.get.ToString();
            iq.InnerXML = "<vCard xmlns='vcard-temp' />";

            XMPPClient.SendXMPP(iq);
        }
Example #10
0
        public void DownloadDataNode(JID jidto, string strNodeName, string strItem)
        {
            PubSubIQ iq = new PubSubIQ();
             iq.Type = IQType.set.ToString();
             iq.To = null; /// null for personal eventing pub sub
             iq.From = XMPPClient.JID;
             iq.PubSub.Publish = new Publish() { Node = strNodeName, Item = new PubSubItem() { Id = strNodeName } };

             ListSentIQs.Add(iq.ID);
             XMPPClient.SendObject(iq);
        }
Example #11
0
        public void UnsubscribeToPresence(JID jidto)
        {
            PresenceMessage pres = new PresenceMessage(null);

            pres.To     = jidto;
            pres.From   = null;
            pres.Type   = "unsubscribe";
            pres.Show   = null;
            pres.Status = null;
            pres.PresenceStatus.PresenceType = PresenceType.unsubscribe;
            XMPPClient.SendObject(pres);
        }
Example #12
0
        public void DownloadAvatarJabberIQMethod(JID jidfor)
        {
            IQ iq = new IQ();

            iq.From     = XMPPClient.JID;
            iq.To       = jidfor;
            iq.Type     = IQType.get.ToString();
            iq.InnerXML = "<query xmlns='jabber:iq:avatar' />";
            //iq.InnerXML = "<query xmlns='storage:client:avatar' />";

            XMPPClient.SendXMPP(iq);
        }
Example #13
0
 /// <summary>
 /// Creates a new match instance
 /// </summary>
 /// <param name="mid">The ID of the match</param>
 /// <param name="own">The own Jabber-ID</param>
 /// <param name="partner">The Jabber-ID of the game partner</param>
 public Match(String mid, JID own, JID partner)
 {
     this.MatchState = Enum.MatchState.ShipPlacement;
     this.PartnerDice = -1;
     this.OwnDice = -1;
     this.PartnersPreDice = -1;
     this.SendedShot = null;
     this.GamestateSended = false;
     this.MatchID = mid;
     this.OwnJID = own;
     this.PartnerJID = partner;
     this.Started = DateTime.Now;
     this.rnd = new Random(DateTime.Now.Millisecond);
     this.MatchWinner = null;
 }
Example #14
0
        //public const string AddRosterQuery = @"<query xmlns=""jabber:iq:roster""><item jid=""##JID##"" name=""##NAME##""><group>##GROUP##</group></item></query>";

        public void AddToRoster(JID jid, string strName, string strGroup)
        {
            //<iq from='[email protected]/balcony'
            //      id='ph1xaz53'
            //      type='set'>
            //    <query xmlns='jabber:iq:roster'>
            //      <item jid='*****@*****.**'
            //            name='Nurse'>
            //        <group>Servants</group>
            //      </item>
            //    </query>
            //  </iq>

            //string strAddQuery = AddRosterQuery.Replace("##JID##", jid.BareJID);
            //strAddQuery = strAddQuery.Replace("##NAME##", strName);
            //strAddQuery = strAddQuery.Replace("##GROUP##", strGroup);

            RosterIQ AddRosterIQ = new RosterIQ();

            AddRosterIQ.Type = IQType.set.ToString();
            AddRosterIQ.To   = null;
            AddRosterIQ.From = XMPPClient.JID;
            rosteritem newitem = new rosteritem();

            newitem.Name = strName;

            JID newjid = jid;

            if (newjid.User.Length <= 0)
            {
                newjid.User   = newjid.Domain;
                newjid.Domain = XMPPClient.JID.Domain;
            }

            newitem.JID          = newjid;
            newitem.Subscription = subscription.none.ToString();
            newitem.Groups       = new string[] { strGroup };

            AddRosterIQ.Query.RosterItems = new rosteritem[] { newitem };



            IQ IQResponse = XMPPClient.SendRecieveIQ(AddRosterIQ, 10000);

            if (IQResponse != null)
            {
            }
        }
Example #15
0
        public string SendFile(string strFullFileName, byte[] bData, JID jidto)
        {
            string       strFileName = FileTransfer.GetFileNameFromFullString(strFullFileName);
            FileTransfer trans       = new FileTransfer(bData, strFileName, jidto)
            {
                FileTransferDirection = FileTransferDirection.Send
            };

            lock (m_objFileTransferLock)
            {
                FileTransfers.Add(trans);
            }

            XMPPClient.StreamInitiationAndTransferLogic.RequestStartFileTransfer(trans);
            return(trans.sid);
        }
Example #16
0
        /// <summary>
        /// Creates a new instance of a ship, which is not placed on the playground
        /// </summary>
        /// <param name="owner">The Jabber-ID of the owner</param>
        /// <param name="type">The type</param>                
        public Ship(JID owner, ShipType type, Boolean alternate)
        {
            this.Owner = owner;
            this.IsPlaced = false;
            this.ShipType = type;
            this.HitPoints = new Dictionary<int, bool>();
            this.OverlayColor = Color.White;
            this.IsDestroyed = false;

            switch (type)
            {
                case ShipType.DESTROYER:
                case ShipType.SUBMARINE:
                    this.Orientation = System.Windows.Controls.Orientation.Vertical;
                    break;
                case ShipType.BATTLESHIP:
                case ShipType.AIRCRAFT_CARRIER:
                    this.Orientation = System.Windows.Controls.Orientation.Horizontal;
                    break;
            }
            LoadTexture();

            // Ship is not placed. We place it manually
            switch (type)
            {
                case ShipType.DESTROYER:
                    this.Position = new Vector2(20, DeviceCache.BelowGrid + 20);
                    break;
                case ShipType.SUBMARINE:
                    if (alternate)
                        this.Position = new Vector2(20 + (1 * (this.shipTexture.Width * scaleRate)) + 20, DeviceCache.BelowGrid + 20);
                    else
                        this.Position = new Vector2(20 + (5 * (this.shipTexture.Width * scaleRate)) + 20, DeviceCache.BelowGrid + 20);
                    break;
                case ShipType.BATTLESHIP:
                    this.Position = new Vector2(20 + (2 * (this.shipTexture.Height * scaleRate)) + 20, DeviceCache.BelowGrid + 20);
                    break;
                case ShipType.AIRCRAFT_CARRIER:
                    this.Position = new Vector2(20 + (2 * (this.shipTexture.Height * scaleRate)) + 20, DeviceCache.BelowGrid + (this.shipTexture.Height * scaleRate) + 30);
                    break;
            }

            for (int i = 0; i < this.Size; i++)
            {
                this.HitPoints.Add(i, false);
            }
        }
Example #17
0
        public void DownloadDataNode(JID jidto, string strNodeName, string strItem)
        {
            PubSubIQ iq = new PubSubIQ();

            iq.Type           = IQType.set.ToString();
            iq.To             = null; /// null for personal eventing pub sub
            iq.From           = XMPPClient.JID;
            iq.PubSub.Publish = new Publish()
            {
                Node = strNodeName, Item = new PubSubItem()
                {
                    Id = strNodeName
                }
            };

            ListSentIQs.Add(iq.ID);
            XMPPClient.SendObject(iq);
        }
Example #18
0
        public ServiceDiscoveryIQ QueryServiceDiscovery(JID jidto, string strNode)
        {
            ServiceDiscoveryIQ iqrequest = new ServiceDiscoveryIQ();

            iqrequest.From = this.JID;
            iqrequest.To   = jidto;
            iqrequest.Type = IQType.get.ToString();
            iqrequest.ServiceDiscoveryItemQuery      = new ServiceDiscoveryItemQuery();
            iqrequest.ServiceDiscoveryItemQuery.Node = strNode;

            IQ iqresponse = SendRecieveIQ(iqrequest, 10000);

            if (iqresponse is ServiceDiscoveryIQ)
            {
                return(iqresponse as ServiceDiscoveryIQ);
            }

            return(null);
        }
 /// <summary>
 /// Generates the XML for sending over XMPP
 /// </summary>
 /// <param name="from">The Jabber-ID of the sender</param>
 /// <param name="to">The Jabber-ID of the receiver</param>
 /// <returns>An XML string</returns>
 public String ToSendXML(JID from, JID to)
 {
     String s = "<message from=\"" + from.FullJID + "\" id=\"" + Guid.NewGuid() + "\" to=\"" + to.FullJID + "\" type=\"normal\">\n<battleship xmlns=\"http://battleship.me/xmlns/\">";
     switch (Action) {
         case QueueingAction.request:
             s += "<queueing action=\"request\" />";
                 break;
         case QueueingAction.ping:
                 s += "<queueing action=\"ping\" id=\"" + this.ID + "\" />";
                 break;
         case QueueingAction.assigned:
                 s += "<queueing action=\"assigned\" jid=\"" + this.JID + "\" mid=\"" + this.MatchID + "\" />";
                 break;
         default:
             throw new Exception("This Queuing Message Type is not for sending!");
     }
     s += "</battleship>\n</message>";
     return s;
 }
Example #20
0
        /// <summary>
        /// Creates a new instance of a ship
        /// </summary>
        /// <param name="owner">The Jabber-ID of the owner</param>
        /// <param name="type">The type</param>
        /// <param name="or">The orientation</param>
        /// <param name="targetField">The target field, where the ship is placed</param>
        public Ship(JID owner, ShipType type, System.Windows.Controls.Orientation or, Field targetField)
        {
            this.Owner = owner;
            this.ShipType = type;
            this.IsPlaced = false;
            this.HitPoints = new Dictionary<int, bool>();
            this.Orientation = or;
            this.Position = targetField.Position;
            this.IsDestroyed = false;
            this.OverlayColor = Color.White;
            targetField.ReferencedShip = this;
            StartField = targetField;
            LoadTexture();

            for (int i = 0; i < this.Size; i++)
            {
                this.HitPoints.Add(i, false);
            }
        }
 /// <summary>
 /// Creates a new entity of a QueuingMessage
 /// </summary>
 /// <param name="action">The current action</param>
 /// <param name="dict">The dictionary with parameters</param>
 public QueuingMessage(QueueingAction action, Dictionary<string, object> dict)
     : base(Schiffchen.Logic.Enum.Type.Queueing)
 {
     this.Action = action;
     switch (action)
     {
         case QueueingAction.success:
         case QueueingAction.ping:
             if (dict.ContainsKey("id"))
             {
                 this.ID = (Int32)dict["id"];
             }
             break;
         case QueueingAction.assign:
         case QueueingAction.assigned:
             this.JID = (JID)dict["jid"];
             this.MatchID = (String)dict["mid"];
             break;
     }
 }
Example #22
0
        public string SendFile(string strFullFileName, JID jidto)
        {
            string strFileName = FileTransfer.GetFileNameFromFullString(strFullFileName);

            System.IO.FileStream stream = new FileStream(strFullFileName, FileMode.Open, FileAccess.Read);
            byte [] bData = new byte[stream.Length];
            stream.Read(bData, 0, bData.Length);
            stream.Close();

            FileTransfer trans = new FileTransfer(bData, strFileName, jidto)
            {
                FileTransferDirection = FileTransferDirection.Send
            };

            lock (m_objFileTransferLock)
            {
                FileTransfers.Add(trans);
            }

            XMPPClient.StreamInitiationAndTransferLogic.RequestStartFileTransfer(trans);
            return(trans.sid);
        }
Example #23
0
 /// <summary>
 /// Sets the Jabber-ID of the Matchmaker
 /// </summary>
 static Matchmaker()
 {
     MatchmakerJID = new JID("*****@*****.**");
 }
Example #24
0
 /// <summary>
 /// Generates the XML for sending over XMPP
 /// </summary>
 /// <param name="from">The Jabber-ID of the sender</param>
 /// <param name="to">The Jabber-ID of the receiver</param>
 /// <returns>An XML string</returns>
 public String ToSendXML(JID from, JID to)
 {
     String s = "<message from=\"" + from.FullJID + "\" id=\"" + Guid.NewGuid() + "\" to=\"" + to.FullJID + "\" type=\"normal\">\n<battleship xmlns=\"http://battleship.me/xmlns/\">";
     switch (Action)
     {
         case MatchAction.Diceroll:
             s += "<diceroll dice=\"" + this.Dice + "\" />";
             break;
         case MatchAction.Shot:
             s += "<shoot x=\"" + this.X + "\" y=\"" + this.Y + "\" />";
             break;
         case MatchAction.Shotresult:
             s += "<shoot x=\"" + this.X + "\" y=\"" + this.Y + "\" result=\"" + this.Result + "\" />";
             if (this.ShipInfo != null)
             {
                 s += "<ship x=\"" + this.ShipInfo.X + "\" y=\"" + this.ShipInfo.Y + "\" size=\"" + this.ShipInfo.Size + "\" orientation=\"" + this.ShipInfo.Orientation.ToString().ToLower() + "\" destroyed=\"" + this.ShipInfo.Destroyed.ToString().ToLower() + "\" />";
             }
             break;
         case MatchAction.Ping:
             s += "<ping />";
             break;
         case MatchAction.Gamestate:
             s += "<gamestate state=\"" + this.State + "\" looser=\"" + this.Looser + "\" />";
             break;
         default:
             throw new Exception("This Match Message Type is not for sending!");
     }
     s += "</battleship>\n</message>";
     return s;
 }
Example #25
0
 public Conversation(JID jid)
 {
     JID = jid;
 }
Example #26
0
 public void UnsubscribeToPresence(JID jidto)
 {
     PresenceMessage pres = new PresenceMessage(null);
     pres.To = jidto;
     pres.From = null;
     pres.Type = "unsubscribe";
     pres.Show = null;
     pres.Status = null;
     pres.PresenceStatus.PresenceType = PresenceType.unsubscribe;
     XMPPClient.SendObject(pres);
 }
Example #27
0
        public void RequestVCARD(JID jidfor)
        {
            IQ iq = new IQ();
            iq.From = XMPPClient.JID;
            iq.To = jidfor.BareJID;
            iq.Type = IQType.get.ToString();
            iq.InnerXML = "<vCard xmlns='vcard-temp' />";

            XMPPClient.SendXMPP(iq);
        }
Example #28
0
        public void DownloadAvatarJabberIQMethod(JID jidfor)
        {
            IQ iq = new IQ();
            iq.From = XMPPClient.JID;
            iq.To = jidfor;
            iq.Type = IQType.get.ToString();
            iq.InnerXML = "<query xmlns='jabber:iq:avatar' />";
            //iq.InnerXML = "<query xmlns='storage:client:avatar' />";

            XMPPClient.SendXMPP(iq);
        }
Example #29
0
 public Conversation(JID jid)
 {
     JID = jid;
 }
Example #30
0
        //public const string AddRosterQuery = @"<query xmlns=""jabber:iq:roster""><item jid=""##JID##"" name=""##NAME##""><group>##GROUP##</group></item></query>";
        public void AddToRoster(JID jid, string strName, string strGroup)
        {
            //<iq from='[email protected]/balcony'
             //      id='ph1xaz53'
             //      type='set'>
             //    <query xmlns='jabber:iq:roster'>
             //      <item jid='*****@*****.**'
             //            name='Nurse'>
             //        <group>Servants</group>
             //      </item>
             //    </query>
             //  </iq>

            //string strAddQuery = AddRosterQuery.Replace("##JID##", jid.BareJID);
            //strAddQuery = strAddQuery.Replace("##NAME##", strName);
            //strAddQuery = strAddQuery.Replace("##GROUP##", strGroup);

            RosterIQ AddRosterIQ = new RosterIQ();
            AddRosterIQ.Type = IQType.set.ToString();
            AddRosterIQ.To = null;
            AddRosterIQ.From = XMPPClient.JID;
            rosteritem newitem = new rosteritem();
            newitem.Name = strName;

            JID newjid = jid;
            if (newjid.User.Length <= 0)
            {
                newjid.User = newjid.Domain;
                newjid.Domain = XMPPClient.JID.Domain;
            }

            newitem.JID = newjid;
            newitem.Subscription = subscription.none.ToString();
            newitem.Groups = new string[] { strGroup };

            AddRosterIQ.Query.RosterItems = new rosteritem[] { newitem };

            IQ IQResponse = XMPPClient.SendRecieveIQ(AddRosterIQ, 10000);
            if (IQResponse != null)
            {
            }
        }
Example #31
0
        //public const string DeleteRosterQuery = @"<query xmlns=""jabber:iq:roster""><item jid=""##JID##"" subscription=""remove"" /></query>";
        public void DeleteFromRoster(JID jid)
        {
            //<iq from='[email protected]/balcony'
             //      id='hm4hs97y'
             //      type='set'>
             //    <query xmlns='jabber:iq:roster'>
             //      <item jid='*****@*****.**'
             //            subscription='remove'/>
             //    </query>
             //  </iq>

            //string strDeleteQuery = DeleteRosterQuery.Replace("##JID##", jid.BareJID);

            RosterIQ DeleteRosterIQ = new RosterIQ();
            //DeleteRosterIQ.InnerXML = strDeleteQuery;
            DeleteRosterIQ.Type = IQType.set.ToString();
            DeleteRosterIQ.To = null;
            DeleteRosterIQ.From = XMPPClient.JID;
            //DeleteRosterIQ.xmlns = "jabber:client";

            rosteritem deleteitem = new rosteritem();
            deleteitem.JID = jid;
            deleteitem.Subscription = subscription.remove.ToString();

            DeleteRosterIQ.Query.RosterItems = new rosteritem[] { deleteitem };

            IQ IQResponse = XMPPClient.SendRecieveIQ(DeleteRosterIQ, 10000);
            if (IQResponse != null)
            {
            }
        }
Example #32
0
 /// <summary>
 /// Is called on receiving a message with the gamestate
 /// </summary>
 /// <param name="sender">The sender</param>
 /// <param name="e">The message event arguments</param>
 void XmppManager_IncomingGamestate(object sender, MessageEventArgs e)
 {
     if (!this.GamestateSended)
     {
         JID looser = getLooser();
         if (looser != null)
         {
             Partner.SendGamestate(looser.BareJID);
             this.GamestateSended = true;
             this.MatchState = Enum.MatchState.Finished;
             if (looser == OwnJID)
             {
                 this.MatchWinner = PartnerJID;
             }
             else
             {
                 this.MatchWinner = OwnJID;
             }
         }
     }
     else
     {
         JID looser = getLooser();
         if (looser != null)
         {
             this.MatchState = Enum.MatchState.Finished;
             if (looser == OwnJID)
             {
                 this.MatchWinner = PartnerJID;
             }
             else
             {
                 this.MatchWinner = OwnJID;
             }
         }
     }
 }
Example #33
0
 public void AddToRoster(JID jid, string strName, string strGroup)
 {
     RosterLogic.AddToRoster(jid, strName, strGroup);
     PresenceLogic.SubscribeToPresence(jid);
 }
Example #34
0
 public RosterItem FindRosterItem(JID jid)
 {
     return(RosterItems.FindRosterItem(jid));
 }