Пример #1
0
        public void SendGameInvite(User user, Guid sessionId, string gamePassword)
        {
            Log.InfoFormat("Sending game request to {0}", user.UserName);
            var req = new InviteToGameRequest(sessionId, gamePassword);
            var m   = new Message(user.JidUser, this.Me.JidUser, MessageType.normal, "", "invitetogamerequest");

            m.GenerateId();
            m.AddChild(req);
            this.xmpp.Send(m);
        }
Пример #2
0
        /// <summary>
        /// The xmpp on on message.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="msg">
        /// The msg.
        /// </param>
        private void XmppOnOnMessage(object sender, Message msg)
        {
            if (msg.Type == MessageType.normal)
            {
                if (msg.Subject == "gameready")
                {
                    Log.Info("Got gameready message");

                    var game = msg.ChildNodes.OfType <HostedGameData>().FirstOrDefault();
                    if (game == null)
                    {
                        Log.Warn("Game message wasn't in the correct format.");
                        return;
                    }

                    this.CurrentHostedGamePort = game.Port;

                    if (this.OnDataReceived != null)
                    {
                        this.OnDataReceived.Invoke(this, DataRecType.HostedGameReady, game);
                    }
                }
                else if (msg.Subject == "gamelist")
                {
                    Log.Info("Got gamelist msg, this doesn't do anything anymore");
                    //var list = new List<HostedGameData>();
                    //foreach (object a in msg.ChildNodes)
                    //{
                    //    var gi = a as HostedGameData;
                    //    if (gi != null)
                    //    {
                    //        list.Add(gi);
                    //    }
                    //}

                    //this.games = list;
                    //if (this.OnDataReceived != null)
                    //{
                    //    this.OnDataReceived.Invoke(this, DataRecType.GameList, list);
                    //}
                }
                else if (msg.Subject == "refresh")
                {
                    Log.Info("Server wants a refresh of game list");
                    if (this.OnDataReceived != null)
                    {
                        Log.Info("Firing server wants a refresh of game list");
                        this.OnDataReceived.Invoke(this, DataRecType.GamesNeedRefresh, null);
                    }
                }
                else if (msg.Subject == "invitetogamerequest")
                {
                    Log.InfoFormat("Received game invite from user {0}", msg.From.User);
                    InviteToGameRequest req = msg.ChildNodes.OfType <InviteToGameRequest>().FirstOrDefault();
                    if (req == null)
                    {
                        Log.WarnFormat("Tried to read invitetogamerequest packet but it was broken...");
                        return;
                    }
                    if (this.OnDataReceived != null)
                    {
                        var sreq = new InviteToGame();
                        sreq.From      = new User(msg.From);
                        sreq.SessionId = req.SessionId;
                        sreq.Password  = req.Password;
                        this.OnDataReceived.Invoke(this, DataRecType.GameInvite, sreq);
                    }
                }
                else if (msg.From.Bare.ToLower() == this.xmpp.MyJID.Server.ToLower())
                {
                    if (msg.Subject == null)
                    {
                        msg.Subject = string.Empty;
                    }

                    if (msg.Body == null)
                    {
                        msg.Body = string.Empty;
                    }

                    var d = new Dictionary <string, string>();
                    d["Message"] = msg.Body;
                    d["Subject"] = msg.Subject;
                    if (this.OnDataReceived != null)
                    {
                        this.OnDataReceived.Invoke(this, DataRecType.Announcement, d);
                    }
                }
            }
        }
Пример #3
0
 public void SendGameInvite(User user, Guid sessionId, string gamePassword)
 {
     Log.InfoFormat("Sending game request to {0}", user.UserName);
     var req = new InviteToGameRequest(sessionId, gamePassword);
     var m = new Message(user.JidUser, this.Me.JidUser, MessageType.normal, "", "invitetogamerequest");
     m.GenerateId();
     m.AddChild(req);
     this.xmpp.Send(m);
 }