/// <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); } } } }
/// <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); } } } }
/// <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"); int port = -1; if (int.TryParse(msg.Body, out port) && port != -1) { Log.Info("gameready port " + port); if (this.OnDataReceived != null) { Log.Info("Firing gameready data on port " + port); this.OnDataReceived.Invoke(this, DataRecType.HostedGameReady, port); } Log.InfoFormat("CurrentHostedGamePort={0}", CurrentHostedGamePort); this.CurrentHostedGamePort = port; } else { Log.Info("Couldn't parse gameready port " + msg.Body ?? "null"); } } else if (msg.Subject == "gamelist") { 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; var g = games.FirstOrDefault(x => x.Id == WaitingGame); if (g != null) { if (this.OnDataReceived != null) { this.OnDataReceived.Invoke(this,DataRecType.HostedGameReady,g.Port); } } 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); } } } }