Merge remote-tracking branch 'remotes/flokuep/release-0.3' into develop

Conflicts:
	Vocaluxe/Base/CDataBase.cs
This commit is contained in:
Flamefire committed 2013-08-22 00:43:53 +02:00
commit cd826bdafd
20 files changed
+267 -126

No files matched your search

+10 -12
View File
@@ -62,7 +62,7 @@ namespace Vocaluxe.Base
{ {
get get
{ {
List<string> coverThemes = new List<string>(); var coverThemes = new List<string>();
for (int i = 0; i < _CoverThemes.Count; i++) for (int i = 0; i < _CoverThemes.Count; i++)
coverThemes.Add(_CoverThemes[i].Name); coverThemes.Add(_CoverThemes[i].Name);
@@ -154,7 +154,7 @@ namespace Vocaluxe.Base
if (xmlReader != null) if (xmlReader != null)
{ {
SCoverTheme coverTheme = new SCoverTheme(); var coverTheme = new SCoverTheme();
xmlReader.GetValue("//root/Info/Name", out coverTheme.Name, String.Empty); xmlReader.GetValue("//root/Info/Name", out coverTheme.Name, String.Empty);
xmlReader.GetValue("//root/Info/Folder", out coverTheme.Folder, String.Empty); xmlReader.GetValue("//root/Info/Folder", out coverTheme.Folder, String.Empty);
@@ -179,7 +179,7 @@ namespace Vocaluxe.Base
if (String.IsNullOrEmpty(coverTheme.Name)) if (String.IsNullOrEmpty(coverTheme.Name))
return; return;
List<string> ignoreList = new List<string>(); var ignoreList = new List<string>();
CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File)); CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderCover, coverTheme.File));
if (xmlReader != null) if (xmlReader != null)
{ {
@@ -206,7 +206,7 @@ namespace Vocaluxe.Base
} }
} }
List<string> files = new List<string>(); var files = new List<string>();
string coverPath = Path.Combine(CSettings.FolderCover, coverTheme.Folder); string coverPath = Path.Combine(CSettings.FolderCover, coverTheme.Folder);
files.AddRange(CHelper.ListFiles(coverPath, "*.png", true, true)); files.AddRange(CHelper.ListFiles(coverPath, "*.png", true, true));
@@ -222,19 +222,17 @@ namespace Vocaluxe.Base
} }
} }
private static void _AddCover(string Name, string File) private static void _AddCover(string name, string file)
{ {
CTexture texture = CDraw.AddTexture(File); CTexture texture = CDraw.AddTexture(file);
if (!_CoverExists(Name)) if (!_CoverExists(name))
{ _Cover.Add(name, texture);
_Cover.Add(Name, texture);
}
else else
{ {
CTexture tex = _Cover[Name]; CTexture tex = _Cover[name];
CDraw.RemoveTexture(ref tex); CDraw.RemoveTexture(ref tex);
_Cover[Name] = texture; _Cover[name] = texture;
} }
} }
} }
+119 -7
View File
@@ -71,6 +71,76 @@ namespace Vocaluxe.Base
} }
#region Highscores #region Highscores
public static bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out string dateAdded, out int highscoreID)
{
string sArtist = string.Empty;
string sTitle = string.Empty;
int songID = -1;
using (SQLiteConnection connection = new SQLiteConnection())
{
connection.ConnectionString = "Data Source=" + _HighscoreFilePath;
try
{
connection.Open();
}
catch (Exception)
{
}
using (SQLiteCommand command = new SQLiteCommand(connection))
{
songID = _GetDataBaseSongID(artist, title, 0, command);
highscoreID = songID;
}
}
return _GetDataBaseSongInfos(songID, out sArtist, out sTitle, out numPlayed, out dateAdded, _HighscoreFilePath);
}
public static void IncreaseSongCounter(SPlayer player)
{
using (SQLiteConnection connection = new SQLiteConnection())
{
connection.ConnectionString = "Data Source=" + _HighscoreFilePath;
try
{
connection.Open();
}
catch (Exception)
{
}
using (SQLiteCommand command = new SQLiteCommand(connection))
{
int dataBaseSongID = _GetDataBaseSongID(player, command);
_IncreaseSongCounter(dataBaseSongID, command);
}
}
}
public static void IncreaseSongCounter(int dataBaseSongID)
{
using (SQLiteConnection connection = new SQLiteConnection())
{
connection.ConnectionString = "Data Source=" + _HighscoreFilePath;
try
{
connection.Open();
}
catch (Exception)
{
}
using (SQLiteCommand command = new SQLiteCommand(connection))
{
_IncreaseSongCounter(dataBaseSongID, command);
}
}
}
public static int AddScore(string playerName, int score, int lineNr, long date, int medley, int duet, int shortSong, int difficulty, public static int AddScore(string playerName, int score, int lineNr, long date, int medley, int duet, int shortSong, int difficulty,
string artist, string title, int numPlayed, string filePath) string artist, string title, int numPlayed, string filePath)
{ {
@@ -113,7 +183,7 @@ namespace Vocaluxe.Base
using (SQLiteCommand command = new SQLiteCommand(connection)) using (SQLiteCommand command = new SQLiteCommand(connection))
{ {
int dataBaseSongID = _GetDataBaseSongID(player, command); int dataBaseSongID = CSongs.GetSong(player.SongID).DataBaseSongID;
return _AddScore(CProfiles.GetPlayerName(player.ProfileID), (int)Math.Round(player.Points), player.VoiceNr, player.DateTicks, player.Medley ? 1 : 0, return _AddScore(CProfiles.GetPlayerName(player.ProfileID), (int)Math.Round(player.Points), player.VoiceNr, player.DateTicks, player.Medley ? 1 : 0,
player.Duet ? 1 : 0, player.ShortSong ? 1 : 0, (int)CProfiles.GetDifficulty(player.ProfileID), dataBaseSongID, command); player.Duet ? 1 : 0, player.ShortSong ? 1 : 0, (int)CProfiles.GetDifficulty(player.ProfileID), dataBaseSongID, command);
} }
@@ -250,6 +320,13 @@ namespace Vocaluxe.Base
} }
} }
private static void _IncreaseSongCounter(int dataBaseSongID, SQLiteCommand command)
{
command.CommandText = "UPDATE Songs SET NumPlayed = NumPlayed + 1 WHERE [id] = @id";
command.Parameters.Add("@id", DbType.Int32, 0).Value = dataBaseSongID;
command.ExecuteNonQuery();
}
private static int _GetDataBaseSongID(SPlayer player, SQLiteCommand command) private static int _GetDataBaseSongID(SPlayer player, SQLiteCommand command)
{ {
CSong song = CSongs.GetSong(player.SongID); CSong song = CSongs.GetSong(player.SongID);
@@ -275,14 +352,16 @@ namespace Vocaluxe.Base
reader.Dispose(); reader.Dispose();
return id; return id;
} }
if (reader != null) if (reader != null)
reader.Close(); reader.Close();
command.CommandText = "INSERT INTO Songs (Title, Artist, NumPlayed) " + command.CommandText = "INSERT INTO Songs (Title, Artist, NumPlayed, DateAdded) " +
"VALUES (@title, @artist, @numplayed)"; "VALUES (@title, @artist, @numplayed, @dateadded)";
command.Parameters.Add("@title", DbType.String, 0).Value = title; command.Parameters.Add("@title", DbType.String, 0).Value = title;
command.Parameters.Add("@artist", DbType.String, 0).Value = artist; command.Parameters.Add("@artist", DbType.String, 0).Value = artist;
command.Parameters.Add("@numplayed", DbType.Int32, 0).Value = defNumPlayed; command.Parameters.Add("@numplayed", DbType.Int32, 0).Value = defNumPlayed;
command.Parameters.Add("@dateadded", System.Data.DbType.Int64, 0).Value = DateTime.Now.Ticks;
command.ExecuteNonQuery(); command.ExecuteNonQuery();
command.CommandText = "SELECT id FROM Songs WHERE [Title] = @title AND [Artist] = @artist"; command.CommandText = "SELECT id FROM Songs WHERE [Title] = @title AND [Artist] = @artist";
@@ -302,11 +381,12 @@ namespace Vocaluxe.Base
return -1; return -1;
} }
private static bool _GetDataBaseSongInfos(int songID, out string artist, out string title, out int numPlayed, string filePath) private static bool _GetDataBaseSongInfos(int songID, out string artist, out string title, out int numPlayed, out string dateAdded, string filePath)
{ {
artist = String.Empty; artist = String.Empty;
title = String.Empty; title = String.Empty;
numPlayed = 0; numPlayed = 0;
dateAdded = String.Empty;
using (SQLiteConnection connection = new SQLiteConnection()) using (SQLiteConnection connection = new SQLiteConnection())
{ {
@@ -323,7 +403,7 @@ namespace Vocaluxe.Base
using (SQLiteCommand command = new SQLiteCommand(connection)) using (SQLiteCommand command = new SQLiteCommand(connection))
{ {
command.CommandText = "SELECT Artist, Title, NumPlayed FROM Songs WHERE [id] = @id"; command.CommandText = "SELECT Artist, Title, NumPlayed, DateAdded FROM Songs WHERE [id] = @id";
command.Parameters.Add("@id", DbType.String, 0).Value = songID; command.Parameters.Add("@id", DbType.String, 0).Value = songID;
SQLiteDataReader reader; SQLiteDataReader reader;
@@ -342,6 +422,7 @@ namespace Vocaluxe.Base
artist = reader.GetString(0); artist = reader.GetString(0);
title = reader.GetString(1); title = reader.GetString(1);
numPlayed = reader.GetInt32(2); numPlayed = reader.GetInt32(2);
dateAdded = reader.GetInt64(3).ToString("dd/MM/yyyy");
reader.Dispose(); reader.Dispose();
return true; return true;
} }
@@ -504,6 +585,7 @@ namespace Vocaluxe.Base
_CreateHighscoreDBV1(filePath); _CreateHighscoreDBV1(filePath);
_ConvertFrom110(filePath); _ConvertFrom110(filePath);
_UpdateDatabase(1, connection); _UpdateDatabase(1, connection);
_UpdateDatabase(2, connection);
} }
else if (version == 0 && scoresTableExists) else if (version == 0 && scoresTableExists)
{ {
@@ -511,6 +593,7 @@ namespace Vocaluxe.Base
_CreateHighscoreDBV1(filePath); _CreateHighscoreDBV1(filePath);
_ConvertFrom101(filePath); _ConvertFrom101(filePath);
_UpdateDatabase(1, connection); _UpdateDatabase(1, connection);
_UpdateDatabase(2, connection);
} }
else else
_CreateHighscoreDB(filePath); _CreateHighscoreDB(filePath);
@@ -524,6 +607,7 @@ namespace Vocaluxe.Base
_CreateHighscoreDBV1(filePath); _CreateHighscoreDBV1(filePath);
_ConvertFrom110(filePath); _ConvertFrom110(filePath);
_UpdateDatabase(1, connection); _UpdateDatabase(1, connection);
_UpdateDatabase(2, connection);
} }
else if (version == 0 && scoresTableExists) else if (version == 0 && scoresTableExists)
{ {
@@ -531,6 +615,7 @@ namespace Vocaluxe.Base
_CreateHighscoreDBV1(filePath); _CreateHighscoreDBV1(filePath);
_ConvertFrom101(filePath); _ConvertFrom101(filePath);
_UpdateDatabase(1, connection); _UpdateDatabase(1, connection);
_UpdateDatabase(2, connection);
} }
else else
_CreateHighscoreDB(filePath); _CreateHighscoreDB(filePath);
@@ -831,8 +916,16 @@ namespace Vocaluxe.Base
private static bool _UpdateDatabase(int currentVersion, SQLiteConnection connection) private static bool _UpdateDatabase(int currentVersion, SQLiteConnection connection)
{ {
bool updated = true; bool updated = true;
if (currentVersion < 2) if (currentVersion < 2)
{
updated &= _ConvertV1toV2(connection); updated &= _ConvertV1toV2(connection);
}
if (currentVersion < 3)
{
updated &= _ConvertV2toV3(connection);
}
return updated; return updated;
} }
@@ -853,6 +946,25 @@ namespace Vocaluxe.Base
return true; return true;
} }
private static bool _ConvertV2toV3(SQLiteConnection connection)
{
SQLiteCommand command;
command = new SQLiteCommand(connection);
command.CommandText = "ALTER TABLE Songs ADD DateAdded BIGINT";
command.ExecuteNonQuery();
command.CommandText = "UPDATE Songs SET [DateAdded] = @DateAdded";
command.Parameters.Add("@DateAdded",System.Data.DbType.Int64, 0).Value = DateTime.Now.Ticks;
command.ExecuteNonQuery();
command.CommandText = "UPDATE Version SET [Value] = @version";
command.Parameters.Add("@version", System.Data.DbType.Int32, 0).Value = 3;
command.ExecuteNonQuery();
command.Dispose();
return true;
}
private static bool _ImportData(string sourceDBPath) private static bool _ImportData(string sourceDBPath)
{ {
#region open db #region open db
@@ -897,9 +1009,9 @@ namespace Vocaluxe.Base
int shortsong = source.GetInt32(7); int shortsong = source.GetInt32(7);
int diff = source.GetInt32(8); int diff = source.GetInt32(8);
string artist, title; string artist, title, dateadded;
int numplayed; int numplayed;
if (_GetDataBaseSongInfos(songid, out artist, out title, out numplayed, sourceDBPath)) if (_GetDataBaseSongInfos(songid, out artist, out title, out numplayed, out dateadded, sourceDBPath))
AddScore(player, score, linenr, date, medley, duet, shortsong, diff, artist, title, numplayed, _HighscoreFilePath); AddScore(player, score, linenr, date, medley, duet, shortsong, diff, artist, title, numplayed, _HighscoreFilePath);
} }
#endregion import table scores #endregion import table scores
+5
View File
@@ -782,6 +782,11 @@ namespace Vocaluxe.Base
{ {
return CDataBase.GetCover(fileName, ref texture, coverSize); return CDataBase.GetCover(fileName, ref texture, coverSize);
} }
public bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out string dateAdded, out int highscoreID)
{
return CDataBase.GetDataBaseSongInfos(artist, title, out numPlayed, out dateAdded, out highscoreID);
}
} }
class CBcontrollers : IControllers class CBcontrollers : IControllers
+7 -7
View File
@@ -52,14 +52,14 @@ namespace Vocaluxe.Base
public static void Init() public static void Init()
{ {
LoadPlaylists(); LoadPlaylists();
ConvertUSDXPlaylists(); _ConvertUSDXPlaylists();
_SortPlaylistsByName(); _SortPlaylistsByName();
} }
public static void ConvertUSDXPlaylists() private static void _ConvertUSDXPlaylists()
{ {
List<string> files = new List<string>(); var files = new List<string>();
files.AddRange(CHelper.ListFiles(CSettings.FolderPlaylists, "*.upl", true, true)); files.AddRange(CHelper.ListFiles(CSettings.FolderPlaylists, "*.upl", true, true));
foreach (string file in files) foreach (string file in files)
@@ -73,12 +73,12 @@ namespace Vocaluxe.Base
public static void LoadPlaylists() public static void LoadPlaylists()
{ {
_Playlists = new List<CPlaylistFile>(); _Playlists = new List<CPlaylistFile>();
List<string> files = new List<string>(); var files = new List<string>();
files.AddRange(CHelper.ListFiles(CSettings.FolderPlaylists, "*.xml", true, true)); files.AddRange(CHelper.ListFiles(CSettings.FolderPlaylists, "*.xml", true, true));
foreach (string file in files) foreach (string file in files)
{ {
CPlaylistFile playlist = new CPlaylistFile(file); var playlist = new CPlaylistFile(file);
_Playlists.Add(playlist); _Playlists.Add(playlist);
} }
} }
@@ -126,7 +126,7 @@ namespace Vocaluxe.Base
public static int NewPlaylist() public static int NewPlaylist()
{ {
CPlaylistFile pl = new CPlaylistFile {PlaylistName = "New Playlist"}; var pl = new CPlaylistFile {PlaylistName = "New Playlist"};
_Playlists.Add(pl); _Playlists.Add(pl);
return _Playlists.Count - 1; return _Playlists.Count - 1;
} }
@@ -219,7 +219,7 @@ namespace Vocaluxe.Base
private static CPlaylistFile _ConvertUSDXPlaylist(string file) private static CPlaylistFile _ConvertUSDXPlaylist(string file)
{ {
CPlaylistFile pl = new CPlaylistFile(); var pl = new CPlaylistFile();
ReadOnlyCollection<CSong> allSongs = CSongs.AllSongs; ReadOnlyCollection<CSong> allSongs = CSongs.AllSongs;
if (!File.Exists(file)) if (!File.Exists(file))
+2 -2
View File
@@ -55,7 +55,7 @@ namespace Vocaluxe.Base
public const ERevision VersionRevision = ERevision.Beta; public const ERevision VersionRevision = ERevision.Beta;
public const int DatabaseHighscoreVersion = 2; public const int DatabaseHighscoreVersion = 3;
public const int DatabaseCoverVersion = 1; public const int DatabaseCoverVersion = 1;
public const int DatabaseCreditsRessourcesVersion = 1; public const int DatabaseCreditsRessourcesVersion = 1;
@@ -224,4 +224,4 @@ namespace Vocaluxe.Base
Directory.CreateDirectory(path); Directory.CreateDirectory(path);
} }
} }
} }
+6 -2
View File
@@ -31,12 +31,16 @@ namespace Vocaluxe.Base
private static float _Fps; private static float _Fps;
private static readonly double _NanosecPerTick = (1000.0 * 1000.0 * 1000.0) / Stopwatch.Frequency; private static readonly double _NanosecPerTick = (1000.0 * 1000.0 * 1000.0) / Stopwatch.Frequency;
// ReSharper disable MemberCanBePrivate.Global
public static void Reset() public static void Reset()
// ReSharper restore MemberCanBePrivate.Global
{ {
_Stopwatch.Reset(); _Stopwatch.Reset();
} }
// ReSharper disable MemberCanBePrivate.Global
public static void Start() public static void Start()
// ReSharper restore MemberCanBePrivate.Global
{ {
_Stopwatch.Start(); _Stopwatch.Start();
} }
@@ -117,7 +121,7 @@ namespace Vocaluxe.Base
if (!_Timer.IsRunning || (_Timer.ElapsedMilliseconds > 75) || !keyRepeat) if (!_Timer.IsRunning || (_Timer.ElapsedMilliseconds > 75) || !keyRepeat)
{ {
SKeyEvent pool = new SKeyEvent(ESender.Keyboard, alt, shift, ctrl, pressed && (unicode != Char.MinValue), unicode, key); var pool = new SKeyEvent(ESender.Keyboard, alt, shift, ctrl, pressed && (unicode != Char.MinValue), unicode, key);
lock (_CopyLock) lock (_CopyLock)
{ {
@@ -226,7 +230,7 @@ namespace Vocaluxe.Base
x = (int)(x * (float)CSettings.RenderW / CDraw.GetScreenWidth()); x = (int)(x * (float)CSettings.RenderW / CDraw.GetScreenWidth());
y = (int)(y * (float)CSettings.RenderH / CDraw.GetScreenHeight()); y = (int)(y * (float)CSettings.RenderH / CDraw.GetScreenHeight());
SMouseEvent pool = new SMouseEvent(ESender.Mouse, _Mod, x, y, lb, ld, rb, -wheel / 120, lbh, rbh, mb, mbh); var pool = new SMouseEvent(ESender.Mouse, _Mod, x, y, lb, ld, rb, -wheel / 120, lbh, rbh, mb, mbh);
lock (_CopyLock) lock (_CopyLock)
{ {
+7 -5
View File
@@ -80,7 +80,7 @@ namespace Vocaluxe.Base.Fonts
bmpSize = new Size(1, 1); bmpSize = new Size(1, 1);
} }
} }
using (Bitmap bmp = new Bitmap(bmpSize.Width, bmpSize.Height, PixelFormat.Format32bppArgb)) using (var bmp = new Bitmap(bmpSize.Width, bmpSize.Height, PixelFormat.Format32bppArgb))
using (Graphics g = Graphics.FromImage(bmp)) using (Graphics g = Graphics.FromImage(bmp))
{ {
g.Clear(Color.Transparent); g.Clear(Color.Transparent);
@@ -96,15 +96,15 @@ namespace Vocaluxe.Base.Fonts
g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
PointF point = new PointF(outlineSize / 2, outlineSize / 4); var point = new PointF(outlineSize / 2, outlineSize / 4);
using (GraphicsPath path = new GraphicsPath()) using (var path = new GraphicsPath())
{ {
//Have to use size in em not pixels! //Have to use size in em not pixels!
float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style); float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style);
path.AddString(chrString, fo.FontFamily, (int)fo.Style, emSize, point, new StringFormat()); path.AddString(chrString, fo.FontFamily, (int)fo.Style, emSize, point, new StringFormat());
using (Pen pen = new Pen(CFonts.OutlineColor.AsColor(), outlineSize)) using (var pen = new Pen(CFonts.OutlineColor.AsColor(), outlineSize))
{ {
pen.LineJoin = LineJoin.Round; pen.LineJoin = LineJoin.Round;
g.DrawPath(pen, path); g.DrawPath(pen, path);
@@ -123,6 +123,7 @@ namespace Vocaluxe.Base.Fonts
_DrawBounding.Height = _Texture.Height;*/ _DrawBounding.Height = _Texture.Height;*/
#pragma warning disable 162 #pragma warning disable 162
// ReSharper disable HeuristicUnreachableCode // ReSharper disable HeuristicUnreachableCode
// ReSharper disable ConditionIsAlwaysTrueOrFalse
if (false && Char.IsLetterOrDigit(chr)) if (false && Char.IsLetterOrDigit(chr))
{ {
if (outline > 0) if (outline > 0)
@@ -130,6 +131,7 @@ namespace Vocaluxe.Base.Fonts
else else
bmpCropped.Save("font_" + chr + CFonts.Style + "2.png", ImageFormat.Png); bmpCropped.Save("font_" + chr + CFonts.Style + "2.png", ImageFormat.Png);
} }
// ReSharper restore ConditionIsAlwaysTrueOrFalse
// ReSharper restore HeuristicUnreachableCode // ReSharper restore HeuristicUnreachableCode
#pragma warning restore 162 #pragma warning restore 162
} }
@@ -164,7 +166,7 @@ namespace Vocaluxe.Base.Fonts
int minX = 0, maxX = bmp.Width - 1, minY = 0; int minX = 0, maxX = bmp.Width - 1, minY = 0;
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
int values = bmpData.Width * bmp.Height; int values = bmpData.Width * bmp.Height;
Int32[] rgbValues = new Int32[values]; var rgbValues = new Int32[values];
Marshal.Copy(bmpData.Scan0, rgbValues, 0, values); Marshal.Copy(bmpData.Scan0, rgbValues, 0, values);
int index = 0; int index = 0;
bool found = false; bool found = false;
+2 -2
View File
@@ -21,12 +21,12 @@ namespace Vocaluxe.Base.Server
{ {
class CClientHandler class CClientHandler
{ {
public int ConnectionID; private int _ConnectionID;
public bool LoggedIn; public bool LoggedIn;
public CClientHandler(int connectionID) public CClientHandler(int connectionID)
{ {
ConnectionID = connectionID; _ConnectionID = connectionID;
LoggedIn = false; LoggedIn = false;
} }
} }
+46 -58
View File
@@ -8,12 +8,13 @@ namespace Vocaluxe.Base.Server
{ {
public static class CCommands public static class CCommands
{ {
private static UTF8Encoding encoder = new UTF8Encoding(); private static readonly UTF8Encoding _Encoder = new UTF8Encoding();
public static SHA256Managed SHA256 = new SHA256Managed(); private static readonly SHA256Managed _Sha256 = new SHA256Managed();
public const string BroadcastKeyword = "I am a Vocaluxe Server"; public const string BroadcastKeyword = "I am a Vocaluxe Server";
#region Commands #region Commands
// ReSharper disable UnusedMember.Global
public const int ResponseOK = 1; public const int ResponseOK = 1;
public const int ResponseNOK = 2; public const int ResponseNOK = 2;
@@ -41,27 +42,27 @@ namespace Vocaluxe.Base.Server
public const int CommandSendAvatarPictureJpg = 501; public const int CommandSendAvatarPictureJpg = 501;
public const int CommandSendProfile = 510; public const int CommandSendProfile = 510;
// ReSharper restore UnusedMember.Global
#endregion Commands #endregion Commands
#region General #region General
public static byte[] CreateCommandWithoutParams(int Command) public static byte[] CreateCommandWithoutParams(int command)
{ {
return BitConverter.GetBytes(Command); return BitConverter.GetBytes(command);
} }
#endregion General #endregion General
#region Login #region Login
public static byte[] CreateCommandLogin(string Password) public static byte[] CreateCommandLogin(string password)
{ {
var data = new SLoginData(); var data = new SLoginData {Sha256 = _Sha256.ComputeHash(Encoding.UTF8.GetBytes(password))};
data.SHA256 = SHA256.ComputeHash(Encoding.UTF8.GetBytes(Password));
return Serialize<SLoginData>(CommandLogin, data); return _Serialize(CommandLogin, data);
} }
public static bool DecodeCommandLogin(byte[] Message, out SLoginData LoginData) public static bool DecodeCommandLogin(byte[] message, out SLoginData loginData)
{ {
return TryDeserialize<SLoginData>(Message, out LoginData); return _TryDeserialize(message, out loginData);
} }
#endregion Login #endregion Login
@@ -69,74 +70,64 @@ namespace Vocaluxe.Base.Server
#endregion Keyboard #endregion Keyboard
#region Profiles #region Profiles
public static byte[] CreateCommandSendAvatarPicture(int Width, int Height, byte[] data) public static byte[] CreateCommandSendAvatarPicture(int width, int height, byte[] data)
{ {
var ap = new SAvatarPicture(); var ap = new SAvatarPicture {Height = height, Width = width, Data = new byte[data.Length]};
ap.Height = Height; Array.Copy(data, ap.Data, data.Length);
ap.Width = Width;
ap.data = new byte[data.Length];
Array.Copy(data, ap.data, data.Length);
return Serialize<SAvatarPicture>(CommandSendAvatarPicture, ap); return _Serialize(CommandSendAvatarPicture, ap);
} }
public static bool DecodeCommandSendAvatarPicture(byte[] Message, out SAvatarPicture AvatarPicture) public static bool DecodeCommandSendAvatarPicture(byte[] message, out SAvatarPicture avatarPicture)
{ {
return TryDeserialize<SAvatarPicture>(Message, out AvatarPicture); return _TryDeserialize(message, out avatarPicture);
} }
public static byte[] CreateCommandSendAvatarPictureJpg(byte[] AvatarJpgData) public static byte[] CreateCommandSendAvatarPictureJpg(byte[] avatarJpgData)
{ {
var ap = new SAvatarPicture(); var ap = new SAvatarPicture {Height = 0, Width = 0, Data = new byte[avatarJpgData.Length]};
ap.Height = 0; Array.Copy(avatarJpgData, ap.Data, avatarJpgData.Length);
ap.Width = 0;
ap.data = new byte[AvatarJpgData.Length];
Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length);
return Serialize<SAvatarPicture>(CommandSendAvatarPictureJpg, ap); return _Serialize(CommandSendAvatarPictureJpg, ap);
} }
public static byte[] CreateCommandSendProfile(byte[] AvatarJpgData, string PlayerName, int Difficulty) public static byte[] CreateCommandSendProfile(byte[] avatarJpgData, string playerName, int difficulty)
{ {
var ap = new SAvatarPicture(); var ap = new SAvatarPicture {Height = 0, Width = 0, Data = new byte[avatarJpgData.Length]};
ap.Height = 0; Array.Copy(avatarJpgData, ap.Data, avatarJpgData.Length);
ap.Width = 0;
ap.data = new byte[AvatarJpgData.Length];
Array.Copy(AvatarJpgData, ap.data, AvatarJpgData.Length);
var profile = new SProfile(); var profile = new SProfile {Avatar = ap, PlayerName = playerName, Difficulty = difficulty};
profile.Avatar = ap;
profile.PlayerName = PlayerName;
profile.Difficulty = Difficulty;
return Serialize<SProfile>(CommandSendProfile, profile); return _Serialize(CommandSendProfile, profile);
} }
public static bool DecodeCommandSendProfile(byte[] Message, out SProfile Profile) public static bool DecodeCommandSendProfile(byte[] message, out SProfile profile)
{ {
return TryDeserialize<SProfile>(Message, out Profile); return _TryDeserialize(message, out profile);
} }
#endregion Profiles #endregion Profiles
#region Serializing #region Serializing
private static byte[] Serialize<T>(int Command, T obj) private static byte[] _Serialize<T>(T obj)
{ {
byte[] command = BitConverter.GetBytes(Command); return _Serialize(0, obj);
}
private static byte[] _Serialize<T>(int command, T obj)
{
byte[] cmd = BitConverter.GetBytes(command);
var stream = new MemoryStream(); var stream = new MemoryStream();
stream.Write(command, 0, command.Length); stream.Write(cmd, 0, cmd.Length);
byte[] data; byte[] data;
using (var ms = new MemoryStream()) string json = JsonConvert.SerializeObject(obj);
{ data = _Encoder.GetBytes(json);
string json = JsonConvert.SerializeObject(obj);
data = encoder.GetBytes(json);
}
stream.Write(data, 0, data.Length); stream.Write(data, 0, data.Length);
return stream.ToArray(); return stream.ToArray();
} }
private static bool TryDeserialize<T>(byte[] message, out T obj) private static bool _TryDeserialize<T>(byte[] message, out T obj)
{ {
obj = default(T); obj = default(T);
@@ -148,17 +139,14 @@ namespace Vocaluxe.Base.Server
var data = new byte[message.Length - 4]; var data = new byte[message.Length - 4];
Array.Copy(message, 4, data, 0, data.Length); Array.Copy(message, 4, data, 0, data.Length);
using (var ms = new MemoryStream(data)) try
{ {
try obj = JsonConvert.DeserializeObject<T>(_Encoder.GetString(data));
{ return true;
obj = JsonConvert.DeserializeObject<T>(encoder.GetString(data)); }
return true; catch
} {
catch return false;
{
return false;
}
} }
} }
#endregion Serializing #endregion Serializing
+8 -7
View File
@@ -42,10 +42,8 @@ namespace Vocaluxe.Base.Server
public static void Init() public static void Init()
{ {
_Clients = new Dictionary<int, CClientHandler>(); _Clients = new Dictionary<int, CClientHandler>();
if (CConfig.ServerEncryption == EOffOn.TR_CONFIG_ON) String pw = (CConfig.ServerEncryption == EOffOn.TR_CONFIG_ON) ? CConfig.ServerPassword : String.Empty;
_Server = new CServer(RequestHandler, CConfig.ServerPort, CConfig.ServerPassword); _Server = new CServer(RequestHandler, CConfig.ServerPort, pw);
else
_Server = new CServer(RequestHandler, CConfig.ServerPort, String.Empty);
_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword); _Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword);
Controller.Init(); Controller.Init();
@@ -89,6 +87,9 @@ namespace Vocaluxe.Base.Server
loggedIn = _Clients[connectionID].LoggedIn; loggedIn = _Clients[connectionID].LoggedIn;
} }
if (!loggedIn)
return CCommands.CreateCommandWithoutParams(CCommands.ResponseNOK);
int command = BitConverter.ToInt32(message, 0); int command = BitConverter.ToInt32(message, 0);
switch (command) switch (command)
@@ -121,7 +122,7 @@ namespace Vocaluxe.Base.Server
using (var bmp = new Bitmap(avatarPicture.Width, avatarPicture.Height)) using (var bmp = new Bitmap(avatarPicture.Width, avatarPicture.Height))
{ {
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
Marshal.Copy(avatarPicture.data, 0, bmpData.Scan0, avatarPicture.data.Length); Marshal.Copy(avatarPicture.Data, 0, bmpData.Scan0, avatarPicture.Data.Length);
bmp.UnlockBits(bmpData); bmp.UnlockBits(bmpData);
const string filename = "snapshot"; const string filename = "snapshot";
@@ -140,7 +141,7 @@ namespace Vocaluxe.Base.Server
SAvatarPicture avatarPictureJpg; SAvatarPicture avatarPictureJpg;
if (CCommands.DecodeCommandSendAvatarPicture(message, out avatarPictureJpg)) if (CCommands.DecodeCommandSendAvatarPicture(message, out avatarPictureJpg))
{ {
if (_AddAvatar(avatarPictureJpg.data) != String.Empty) if (_AddAvatar(avatarPictureJpg.Data) != String.Empty)
answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK); answer = CCommands.CreateCommandWithoutParams(CCommands.ResponseOK);
} }
break; break;
@@ -151,7 +152,7 @@ namespace Vocaluxe.Base.Server
{ {
try try
{ {
string avatarFilename = _AddAvatar(profile.Avatar.data); string avatarFilename = _AddAvatar(profile.Avatar.Data);
if (avatarFilename != String.Empty) if (avatarFilename != String.Empty)
{ {
var p = new CProfile var p = new CProfile
+2 -2
View File
@@ -2,14 +2,14 @@
{ {
public struct SLoginData public struct SLoginData
{ {
public byte[] SHA256; public byte[] Sha256;
} }
public struct SAvatarPicture public struct SAvatarPicture
{ {
public int Width; public int Width;
public int Height; public int Height;
public byte[] data; public byte[] Data;
} }
public struct SProfile public struct SProfile
+9 -6
View File
@@ -446,13 +446,16 @@ namespace Vocaluxe.Screens
int selectedAvatarID = _SelectSlides[_SelectSlideAvatars].ValueIndex; int selectedAvatarID = _SelectSlides[_SelectSlideAvatars].ValueIndex;
_SelectSlides[_SelectSlideAvatars].Clear(); _SelectSlides[_SelectSlideAvatars].Clear();
IEnumerable<CAvatar> avatars = CProfiles.GetAvatars(); IEnumerable<CAvatar> avatars = CProfiles.GetAvatars();
foreach (CAvatar avatar in avatars) if (avatars != null)
{ {
_SelectSlides[_SelectSlideAvatars].AddValue( foreach (CAvatar avatar in avatars)
Path.GetFileName(avatar.FileName), {
null, _SelectSlides[_SelectSlideAvatars].AddValue(
avatar.ID, Path.GetFileName(avatar.FileName),
-1); null,
avatar.ID,
-1);
}
} }
if (keep) if (keep)
+21
View File
@@ -123,6 +123,8 @@ namespace Vocaluxe.Screens
_Round = CGame.NumRounds > 1 ? 0 : 1; _Round = CGame.NumRounds > 1 ? 0 : 1;
_Points = CGame.GetPoints(); _Points = CGame.GetPoints();
_SavePlayedSongs();
_SetVisibility(); _SetVisibility();
_UpdateRatings(); _UpdateRatings();
} }
@@ -389,6 +391,25 @@ namespace Vocaluxe.Screens
} }
} }
private void _SavePlayedSongs()
{
for (int round = 0; round < _Points.NumRounds; round++)
{
SPlayer[] players = _Points.GetPlayer(round, CGame.NumPlayer);
for (int p = 0; p < players.Length; p++)
{
if (players[p].Points > CSettings.MinScoreForDB && players[p].SongFinished)
{
CSong song = CSongs.GetSong(players[p].SongID);
CDataBase.IncreaseSongCounter(song.DataBaseSongID);
song.NumPlayed++;
break;
}
}
}
}
private void _LeaveScreen() private void _LeaveScreen()
{ {
CParty.LeavingScore(); CParty.LeavingScore();
+4 -2
View File
@@ -546,12 +546,14 @@ namespace Vocaluxe.Screens
public override void ApplyVolume() public override void ApplyVolume()
{ {
CSound.SetStreamVolumeMax(_CurrentStream, CConfig.GameMusicVolume); if(_CurrentStream > -1)
CSound.SetStreamVolumeMax(_CurrentStream, CConfig.GameMusicVolume);
} }
private void _CloseSong() private void _CloseSong()
{ {
CSound.FadeAndStop(_CurrentStream, 0f, 0.5f); if(_CurrentStream > -1)
CSound.FadeAndStop(_CurrentStream, 0f, 0.5f);
CSound.RecordStop(); CSound.RecordStop();
if (_CurrentVideo != -1) if (_CurrentVideo != -1)
{ {
+1
View File
@@ -262,6 +262,7 @@ namespace VocaluxeLib
public interface IDataBase public interface IDataBase
{ {
bool GetCover(string fileName, ref CTexture texture, int coverSize); bool GetCover(string fileName, ref CTexture texture, int coverSize);
bool GetDataBaseSongInfos(string artist, string title, out int numPlayed, out string dateAdded, out int highscoreID);
} }
public interface IControllers public interface IControllers
+1 -1
View File
@@ -25,7 +25,7 @@ namespace VocaluxeLib.PartyModes
{ {
public abstract class CPartyMode : IPartyMode public abstract class CPartyMode : IPartyMode
{ {
protected string _Folder; private string _Folder;
protected SScreenSongOptions _ScreenSongOptions; protected SScreenSongOptions _ScreenSongOptions;
protected readonly Dictionary<string, CMenuParty> _Screens; protected readonly Dictionary<string, CMenuParty> _Screens;
+12
View File
@@ -147,6 +147,10 @@ namespace VocaluxeLib.Songs
public readonly List<string> Language = new List<string>(); public readonly List<string> Language = new List<string>();
public int DataBaseSongID = -1;
public string DateAdded = "";
public int NumPlayed = 0;
// Notes // Notes
public readonly CNotes Notes = new CNotes(); public readonly CNotes Notes = new CNotes();
@@ -240,6 +244,10 @@ namespace VocaluxeLib.Songs
foreach (string value in song.Language) foreach (string value in song.Language)
Language.Add(value); Language.Add(value);
DataBaseSongID = song.DataBaseSongID;
DateAdded = song.DateAdded;
NumPlayed = song.NumPlayed;
Notes = new CNotes(song.Notes); Notes = new CNotes(song.Notes);
} }
@@ -353,10 +361,12 @@ namespace VocaluxeLib.Songs
if (value != "") if (value != "")
ArtistSorting = value; ArtistSorting = value;
break; break;
case "DUETSINGERP1":
case "P1": case "P1":
if (value != "") if (value != "")
DuetPart1 = value; DuetPart1 = value;
break; break;
case "DUETSINGERP2":
case "P2": case "P2":
if (value != "") if (value != "")
DuetPart2 = value; DuetPart2 = value;
@@ -528,6 +538,8 @@ namespace VocaluxeLib.Songs
sr.Dispose(); sr.Dispose();
_CheckFiles(); _CheckFiles();
CBase.DataBase.GetDataBaseSongInfos(Artist, Title, out NumPlayed, out DateAdded, out DataBaseSongID);
//Before saving this tags to .txt: Check, if ArtistSorting and Artist are equal, then don't save this tag. //Before saving this tags to .txt: Check, if ArtistSorting and Artist are equal, then don't save this tag.
if (ArtistSorting == "") if (ArtistSorting == "")
ArtistSorting = Artist; ArtistSorting = Artist;
+2 -7
View File
@@ -12,16 +12,11 @@
Text = note.Text; Text = note.Text;
} }
public CSongNote(int startBeat, int duration, int tone, string text) : base(startBeat, duration, tone)
{
NoteType = ENoteType.Normal;
Text = text;
}
public CSongNote(int startBeat, int duration, int tone, string text, ENoteType noteType) public CSongNote(int startBeat, int duration, int tone, string text, ENoteType noteType)
: this(startBeat, duration, tone, text) : base(startBeat, duration, tone)
{ {
NoteType = noteType; NoteType = noteType;
Text = text;
} }
#endregion Constructors #endregion Constructors
+1 -1
View File
@@ -35,7 +35,7 @@
{ {
get { return HitNote != null; } get { return HitNote != null; }
} }
public CSongNote HitNote { get; set; } public CSongNote HitNote { get; private set; }
// for drawing perfect note effect // for drawing perfect note effect
public bool Perfect { get; set; } public bool Perfect { get; set; }
#endregion #endregion
+2 -5
View File
@@ -34,10 +34,7 @@ namespace VocaluxeLib.Songs
if (_Lines.Count == 0) if (_Lines.Count == 0)
return 0; return 0;
int startbeat = _Lines.Max(line => line.FirstNoteBeat); int result = _Lines[_Lines.Count - 1].EndBeat - _Lines[0].StartBeat;
int endbeat = _Lines.Min(line => line.LastNoteBeat);
int result = endbeat - startbeat;
return result > 0 ? result : 0; return result > 0 ? result : 0;
} }
} }
@@ -111,7 +108,7 @@ namespace VocaluxeLib.Songs
if (lineIndex < 0) if (lineIndex < 0)
{ {
//Note is before ALL lines //Note is before ALL lines
CSongLine line = new CSongLine {StartBeat = note.StartBeat}; var line = new CSongLine {StartBeat = note.StartBeat};
line.AddNote(note); line.AddNote(note);
_Lines.Insert(0, line); _Lines.Insert(0, line);
} }