/// <summary> /// Send the specified score. /// </summary> /// <param name="score">Score.</param> /// <param name="callback">Callback.</param> public void Score(float score, Action <bool, string> callback) { if (_finished) { if (callback != null) { callback(false, "This Match is already finished"); } return; } long myId = CombuManager.localUser.idLong; MatchAccount matchAccount = _users.Find(u => u.idAccount.Equals(myId)); MatchRound round = null; if (matchAccount != null) { round = matchAccount.rounds.Find(r => !r.hasScore); } if (round == null) { if (callback != null) { callback(false, "Cannot send score to this Match or it has been already sent"); } return; } var form = CombuManager.instance.CreateForm(); form.AddField("action", "match_score"); form.AddField("Id", round.id.ToString()); form.AddField("Score", score.ToString()); form.AddField("CustomData", customData.toJson()); CombuManager.instance.CallWebservice(CombuManager.instance.GetUrl("match.php"), form, (string text, string error) => { bool success = false; if (string.IsNullOrEmpty(error)) { Hashtable result = text.hashtableFromJson(); if (result != null) { bool.TryParse(result["success"].ToString(), out success); if (success) { matchAccount.FromJson(result["message"].ToString()); FillRounds(); } else { error = result["message"].ToString(); } } } if (callback != null) { callback(success, error); } }); }
/// <summary> /// Adds the user to this match. /// </summary> /// <param name="user">User.</param> public virtual void AddUser(Profile user) { MatchAccount matchAccount = new MatchAccount(); matchAccount.idMatch = id; matchAccount.user = user; matchAccount.idAccount = matchAccount.user.idLong; _users.Add(matchAccount); }
/// <summary> /// Initialize the object from a hashtable. /// </summary> /// <param name="hash">Hash.</param> public virtual void FromHashtable(Hashtable hash) { if (hash == null) { return; } if (hash.ContainsKey("Id") && hash["Id"] != null) { long.TryParse(hash["Id"].ToString(), out id); } if (hash.ContainsKey("IdTournament") && hash["IdTournament"] != null) { long.TryParse(hash["IdTournament"].ToString(), out idTournament); } if (hash.ContainsKey("Title") && hash["Title"] != null) { title = hash["Title"].ToString(); } if (hash.ContainsKey("Rounds") && hash["Rounds"] != null) { int.TryParse(hash["Rounds"].ToString(), out roundsCount); } if (hash.ContainsKey("DateCreation") && hash["DateCreation"] != null && !string.IsNullOrEmpty(hash["DateCreation"].ToString())) { dateCreation = hash ["DateCreation"].ToString().ToDatetimeOrDefault(); } if (hash.ContainsKey("DateExpire") && hash["DateExpire"] != null && !string.IsNullOrEmpty(hash["DateExpire"].ToString())) { dateExpire = hash ["DateExpire"].ToString().ToDatetimeOrDefault(); } if (hash.ContainsKey("Finished") && hash["Finished"] != null) { int f = 0; if (int.TryParse(hash["Finished"].ToString(), out f)) { _finished = f.Equals(1); } } if (hash.ContainsKey("CustomData") && hash["CustomData"] != null && hash["CustomData"] is Hashtable) { customData = (Hashtable)hash["CustomData"]; } if (hash.ContainsKey("Users") && hash["Users"] != null) { _users.Clear(); _deletedUsers.Clear(); ArrayList listUsers = (ArrayList)hash["Users"]; foreach (Hashtable userData in listUsers) { MatchAccount user = new MatchAccount(userData); _users.Add(user); } FillRounds(); } }