public static MatchChallenge FromBuffer(byte[] buffer, int start, int end) { MatchChallenge mc = new MatchChallenge(); string me; string opprating; mc.opp = ParserUtils.GetNextToken(buffer, ref start, end); Console.WriteLine("OPP: " + mc.opp); opprating = ParserUtils.GetNextToken(buffer, ref start, end); try { mc.opprating = Int32.Parse(opprating.Substring(1, opprating.Length - 2)); } catch { mc.opprating = 0; } me = ParserUtils.GetNextToken(buffer, ref start, end); Console.WriteLine("ME: " + me); if(me[0] == '[') { mc.color = me.Substring(1, me.Length - 2); me = ParserUtils.GetNextToken(buffer, ref start, end); } Console.WriteLine("MY RATING: " + ParserUtils.GetNextToken(buffer, ref start, end)); mc.rated = ParserUtils.GetNextToken(buffer, ref start, end).Equals("rated"); Console.WriteLine(mc.rated); mc.category = ParserUtils.GetNextToken(buffer, ref start, end); mc.time = Int32.Parse(ParserUtils.GetNextToken(buffer, ref start, end)); mc.increment = Int32.Parse(ParserUtils.GetNextToken(buffer, '.', ref start, end)); return mc; }
private void ShowChallengeDialog(MatchChallenge mc) { StringBuilder buf = new StringBuilder (); string rating; if (mc.OpponentsRating != 0) rating = mc.OpponentsRating. ToString (); else rating = "----"; buf.Append (String. Format ("<big><b>{0} ({1}) wants to play a {2} game</b></big>\n", mc.Opponent, rating, mc.Category)); buf.Append (String. Format ("<b><u>Time:</u> {0} </b><i>mins</i>, <b><u>Increment:</u></b> {1}\n", mc.Time, mc.Increment)); if (mc.Color != null) buf.Append (String. Format ("\n<b><u>Color:</u></b> {0}\n", mc.Color)); buf.Append ("\n\n<b>Do you want to play?</b>"); MessageDialog dlg = new MessageDialog (null, DialogFlags. Modal, MessageType. Question, ButtonsType. YesNo, true, buf. ToString ()); dlg.Modal = false; dlg.GrabFocus (); int ret = dlg.Run (); if (ret == (int) ResponseType.Yes) client.CommandSender. SendCommand ("accept"); else if (ret == (int) ResponseType.No) client.CommandSender. SendCommand ("decline"); dlg.Hide (); dlg.Dispose (); }
private void OnChallengeEvent(object o, MatchChallenge mc) { Console.WriteLine (mc); ShowChallengeDialog (mc); }