public PlayerChallenge GetChallenge(int challengeId) { DbConnection connection = new DbConnection(); PlayerChallenge challenge; //using (SqlConnection conn = connection.GetDbConnection()) SqlConnection conn = connection.GetDbConnection(); conn.Open(); using (SqlCommand command = new SqlCommand("GetChallenge", conn) { CommandType = System.Data.CommandType.StoredProcedure }) { SqlDataReader dataReader; command.Parameters.Add("@ChallengeId", SqlDbType.Int).Value = challengeId; dataReader = command.ExecuteReader(); if (dataReader.HasRows) { dataReader.Read(); challenge = new PlayerChallenge { ChallengingPlayerId = (int)dataReader.GetValue(0), OpponentPlayerId = (int)dataReader.GetValue(1), ChallengeDate = (DateTime)dataReader.GetValue(2), ChallengeStatus = (int)dataReader.GetValue(3) }; } else { challenge = new PlayerChallenge(); } dataReader.Close(); } conn.Close(); conn.Dispose(); return(challenge); }
/// <summary> /// Sends replay and result data to the server /// </summary> /// <typeparam name="T"> Replay DataType (class,dictionary, json/xml data etc)</typeparam> /// <typeparam name="U"> Result DataType (int, float etc)</typeparam> /// <param name="endturn"> Does this result end a turn</param> /// <param name="playerid"> Current player's ID</param> /// <param name="pc"> Current PlayerChallenge</param> /// <param name="replay"> Replay Data</param> /// <param name="result"> Result Data</param> /// <param name="callback"> Callback</param> public void SendReplay <T, U>(bool endturn, string playerid, PlayerChallenge pc, T replay, U result, Action <bool> callback) { var postdata = new Dictionary <string, object> { { "playerid", playerid }, { "challengeid", pc.challengeid }, { "result", result }, { "replay", replay }, { "eventid", pc.eventid }, { "levelname", pc.events[pc.eventid].levelname }, { "sceneindex", pc.events[pc.eventid].sceneindex }, { "endturn", endturn } }; Playtomic.API.StartCoroutine(sendReplay(postdata, callback)); }
/// <summary> /// Updates the servers copy of the PlayerChallenge /// </summary> /// <param name="challenge"> The updated challenge</param> /// <param name="callback"> Callback function</param> public void Update(PlayerChallenge challenge, Action <bool, PResponse> callback) { Update <PlayerChallenge>(challenge, callback); }
/// <summary> /// Saves a challenge /// </summary> /// <param name="challenge"> The challenge to save</param> /// <param name="callback"> Callback function</param> public void Save(PlayerChallenge challenge, Action <PlayerChallenge, PResponse> callback) { Save <PlayerChallenge>(challenge, callback); }