push changes i have

This commit is contained in:
SilicaAndPina 2021-03-16 23:42:47 +13:00
parent 6256c38414
commit 7686680c09
7 changed files with 244 additions and 5 deletions

View file

@ -5025,6 +5025,26 @@ namespace HISP.Server
}
}
public static void AddNewWinner(int playerId, string gameTitle, int wins, int looses)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO Leaderboards VALUES(@playerId,@gameTitle,@wins,@loose,1,0,@type)";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Parameters.AddWithValue("@gameTitle", gameTitle);
sqlCommand.Parameters.AddWithValue("@wins", wins);
sqlCommand.Parameters.AddWithValue("@loose", looses);
sqlCommand.Parameters.AddWithValue("@type", "WINLOSS");
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
return;
}
}
public static void AddNewHighscore(int playerId, string gameTitle, int score, string type)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -5076,6 +5096,38 @@ namespace HISP.Server
}
}
public static Highscore.HighscoreTableEntry[] GetTopWinners(string gameTitle, int limit)
{
List<Highscore.HighscoreTableEntry> entires = new List<Highscore.HighscoreTableEntry>();
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT * FROM Leaderboards WHERE minigame=@gameTitle ORDER BY wins DESC LIMIT @limit";
sqlCommand.Parameters.AddWithValue("@gameTitle", gameTitle);
sqlCommand.Parameters.AddWithValue("@limit", limit);
sqlCommand.Prepare();
MySqlDataReader reader = sqlCommand.ExecuteReader();
while (reader.Read())
{
Highscore.HighscoreTableEntry highscoreEntry = new Highscore.HighscoreTableEntry();
highscoreEntry.UserId = reader.GetInt32(0);
highscoreEntry.GameName = gameTitle;
highscoreEntry.Wins = reader.GetInt32(2);
highscoreEntry.Looses = reader.GetInt32(3);
highscoreEntry.TimesPlayed = reader.GetInt32(4);
highscoreEntry.Score = reader.GetInt32(5);
highscoreEntry.Type = reader.GetString(6);
entires.Add(highscoreEntry);
}
sqlCommand.Dispose();
return entires.ToArray();
}
}
public static Highscore.HighscoreTableEntry[] GetTopScores(string gameTitle, int limit)
{
List<Highscore.HighscoreTableEntry> entires = new List<Highscore.HighscoreTableEntry>();
@ -5131,6 +5183,40 @@ namespace HISP.Server
return i;
}
}
public static void UpdateHighscoreWinGame(int playerId, string gameTitle)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE Leaderboards SET wins=wins+1, timesplayed=timesplayed+1 WHERE playerId=@playerId AND minigame=@gameTitle";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Parameters.AddWithValue("@gameTitle", gameTitle);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
return;
}
}
public static void UpdateHighscoreLooseGame(int playerId, string gameTitle)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE Leaderboards SET looses=looses+1, timesplayed=timesplayed+1 WHERE playerId=@playerId AND minigame=@gameTitle";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Parameters.AddWithValue("@gameTitle", gameTitle);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
return;
}
}
public static void UpdateHighscore(int playerId, string gameTitle, int score)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))