diff --git a/ClientServerLib/ClientServerLib/UserRoleControl.cs b/ClientServerLib/ClientServerLib/UserRoleControl.cs index 5af1a6ba..8bff242a 100644 --- a/ClientServerLib/ClientServerLib/UserRoleControl.cs +++ b/ClientServerLib/ClientServerLib/UserRoleControl.cs @@ -6,7 +6,7 @@ namespace ServerLib internal static class CUserRoleControl { private static readonly Dictionary _RoleRightsMapping = new Dictionary { - {EUserRoles.Administrator, + {EUserRoles.TR_USERROLE_ADMIN, (EUserRights.EditAllProfiles| EUserRights.UploadPhotos| EUserRights.ViewOtherProfiles| @@ -16,10 +16,23 @@ namespace ServerLib EUserRights.CreatePlaylists| EUserRights.DeletePlaylists| EUserRights.RemoveSongsFromPlaylists)}, - {EUserRoles.AuthenticatedUser, + {EUserRoles.TR_USERROLE_GUEST, + EUserRights.None}, + {EUserRoles.TR_USERROLE_NORMAL, (EUserRights.UploadPhotos| - EUserRights.ViewOtherProfiles| - EUserRights.UseKeyboard)} + EUserRights.ViewOtherProfiles)}, + {EUserRoles.TR_USERROLE_KEYBOARDUSER, + EUserRights.UseKeyboard}, + {EUserRoles.TR_USERROLE_ADDSONGSUSER, + EUserRights.AddSongToPlaylist}, + {EUserRoles.TR_USERROLE_PLAYLISTEDITOR, + (EUserRights.AddSongToPlaylist| + EUserRights.ReorderPlaylists| + EUserRights.CreatePlaylists| + EUserRights.DeletePlaylists| + EUserRights.RemoveSongsFromPlaylists)}, + {EUserRoles.TR_USERROLE_PROFILEEDITOR, + EUserRights.EditAllProfiles} }; diff --git a/ClientServerLib/ClientServerLib/UserRoles.cs b/ClientServerLib/ClientServerLib/UserRoles.cs index 31bdfa95..bcdb0988 100644 --- a/ClientServerLib/ClientServerLib/UserRoles.cs +++ b/ClientServerLib/ClientServerLib/UserRoles.cs @@ -5,8 +5,12 @@ namespace ServerLib [Flags] internal enum EUserRoles { - GuestUser = 0, - AuthenticatedUser = 1, - Administrator = 2 + TR_USERROLE_GUEST = 0, + TR_USERROLE_NORMAL = 1, + TR_USERROLE_ADMIN = 2, + TR_USERROLE_KEYBOARDUSER = 4, + TR_USERROLE_ADDSONGSUSER = 8, + TR_USERROLE_PLAYLISTEDITOR = 16, + TR_USERROLE_PROFILEEDITOR = 32 } } diff --git a/Vocaluxe/Base/CProfiles.cs b/Vocaluxe/Base/CProfiles.cs index dd683f3c..d77331ca 100644 --- a/Vocaluxe/Base/CProfiles.cs +++ b/Vocaluxe/Base/CProfiles.cs @@ -212,7 +212,7 @@ namespace Vocaluxe.Base public static void LoadProfiles() { - var change = new SChange {Action = EAction.LoadProfiles}; + var change = new SChange { Action = EAction.LoadProfiles }; lock (_QueueMutex) { @@ -222,7 +222,7 @@ namespace Vocaluxe.Base public static void LoadAvatars() { - var change = new SChange {Action = EAction.LoadAvatars}; + var change = new SChange { Action = EAction.LoadAvatars }; lock (_QueueMutex) { @@ -235,7 +235,7 @@ namespace Vocaluxe.Base if (newProfile == null) return; - var change = new SChange {Action = EAction.AddProfile, Profile = newProfile}; + var change = new SChange { Action = EAction.AddProfile, Profile = newProfile }; lock (_QueueMutex) { @@ -248,7 +248,7 @@ namespace Vocaluxe.Base if (editProfile == null) return; - var change = new SChange {Action = EAction.EditProfile, Profile = editProfile}; + var change = new SChange { Action = EAction.EditProfile, Profile = editProfile }; lock (_QueueMutex) { @@ -261,7 +261,7 @@ namespace Vocaluxe.Base if (!IsProfileIDValid(profileID)) return; - var change = new SChange {Action = EAction.DeleteProfile, ProfileID = profileID}; + var change = new SChange { Action = EAction.DeleteProfile, ProfileID = profileID }; lock (_QueueMutex) { @@ -274,7 +274,7 @@ namespace Vocaluxe.Base if (newAvatar == null) return; - var change = new SChange {Action = EAction.AddAvatar, Avatar = newAvatar}; + var change = new SChange { Action = EAction.AddAvatar, Avatar = newAvatar }; lock (_QueueMutex) { @@ -287,7 +287,7 @@ namespace Vocaluxe.Base if (editAvatar == null) return; - var change = new SChange {Action = EAction.EditAvatar, Avatar = editAvatar}; + var change = new SChange { Action = EAction.EditAvatar, Avatar = editAvatar }; lock (_QueueMutex) { @@ -310,9 +310,9 @@ namespace Vocaluxe.Base if (!IsProfileIDValid(profileID)) { return null; - } + } - return _Profiles[profileID]; + return _Profiles[profileID]; } public static IEnumerable GetAvatars() @@ -442,8 +442,10 @@ namespace Vocaluxe.Base { if (!IsProfileIDValid(profileID)) return; - - _Profiles[profileID].UserRole = option; + //Only allow the change of TR_USERROLE_GUEST, TR_USERROLE_NORMAL and TR_USERROLE_ADMIN + const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL | EUserRole.TR_USERROLE_ADMIN); + option &= mask; + _Profiles[profileID].UserRole = (_Profiles[profileID].UserRole & ~mask) | option; } public static EOffOn GetActive(int profileID) @@ -464,7 +466,7 @@ namespace Vocaluxe.Base if (!IsProfileIDValid(profileID)) return true; // this will prevent from saving dummy profiles to highscore db - return _Profiles[profileID].UserRole == EUserRole.TR_USERROLE_GUEST; + return _Profiles[profileID].UserRole.HasFlag(EUserRole.TR_USERROLE_GUEST); } public static bool IsActive(int profileID) diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index f4470328..9358b954 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -228,7 +228,10 @@ namespace Vocaluxe.Base.Server if (profile.Type >= 0 && profile.Type <= 1) { - newProfile.UserRole = (EUserRole)profile.Type; + var option = profile.Type == 0 ? EUserRole.TR_USERROLE_GUEST : EUserRole.TR_USERROLE_NORMAL; + //Only allow the change of TR_USERROLE_GUEST and TR_USERROLE_NORMAL + const EUserRole mask = EUserRole.TR_USERROLE_NORMAL; + newProfile.UserRole = (newProfile.UserRole & mask) | option; } if (!string.IsNullOrEmpty(profile.Password)) @@ -281,10 +284,11 @@ namespace Vocaluxe.Base.Server IsEditable = !isReadonly, ProfileId = profile.ID, PlayerName = profile.PlayerName, - Type = (int)profile.UserRole, + //Is TR_USERROLE_GUEST or TR_USERROLE_NORMAL? + Type = (profile.UserRole.HasFlag(EUserRole.TR_USERROLE_NORMAL)?1:0), Difficulty = (int)profile.Difficulty }; - + CAvatar avatar = profile.Avatar; if (avatar != null) { @@ -502,7 +506,7 @@ namespace Vocaluxe.Base.Server { throw new ArgumentException("invalid songId"); } - if (position < 0 || CPlaylists.Playlists[playlistId].Songs.Count <= position + if (position < 0 || CPlaylists.Playlists[playlistId].Songs.Count <= position || CPlaylists.Playlists[playlistId].Songs[position].SongID != songId) { throw new ArgumentException("invalid position"); @@ -521,7 +525,7 @@ namespace Vocaluxe.Base.Server { throw new ArgumentException("invalid songId"); } - + if (CPlaylists.Playlists[playlistId].Songs.Count < newPosition) { throw new ArgumentException("invalid newPosition"); @@ -673,7 +677,10 @@ namespace Vocaluxe.Base.Server throw new ArgumentException("Invalid profileId"); } - return (int)profile.UserRole; + //Hide TR_USERROLE_GUEST and TR_USERROLE_NORMAL + const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL); + + return (int)(profile.UserRole & ~mask); } private static void _SetUserRole(int profileId, int userRole) @@ -683,8 +690,14 @@ namespace Vocaluxe.Base.Server { throw new ArgumentException("Invalid profileId"); } - - profile.UserRole = (EUserRole)userRole; + + var option = (EUserRole)userRole; + + //Only allow the change of all options exept TR_USERROLE_GUEST and TR_USERROLE_NORMAL + const EUserRole mask = (EUserRole.TR_USERROLE_GUEST | EUserRole.TR_USERROLE_NORMAL); + option &= ~mask; + + profile.UserRole = (profile.UserRole & mask) | option; CProfiles.EditProfile(profile); CProfiles.Update(); diff --git a/Vocaluxe/Website/index.html b/Vocaluxe/Website/index.html index 256db6f1..987d8c49 100644 --- a/Vocaluxe/Website/index.html +++ b/Vocaluxe/Website/index.html @@ -329,10 +329,16 @@
- - - - + + + + + + + + + +
diff --git a/Vocaluxe/Website/js/main.js b/Vocaluxe/Website/js/main.js index bfc14a85..5334e726 100644 --- a/Vocaluxe/Website/js/main.js +++ b/Vocaluxe/Website/js/main.js @@ -7,34 +7,24 @@ var playlistRequestName = ""; var customSelectPlaylistSongCallback = null; var sessionId = ""; var serverBaseAddress = ""; -var tranlationLoaded; if (document.location.protocol == "file:") { if (typeof (window.deviceAndJqmLoaded) == "undefined") { window.deviceAndJqmLoaded = $.Deferred(); } window.deviceAndJqmLoaded.done(function () { - preStart(); + start(); }); } else { $(document).ready(function () { - preStart(); - }); -} - -function preStart() { - tranlationLoaded = $.Deferred(); - - initTranslation(); - - tranlationLoaded.done(function () { - translate(); start(); }); } + function start() { replaceTransitionHandler(); + initTranslation(); initPageLoadHandler(); initKeyboardPageHandler(); initMainPageHandler(); @@ -410,13 +400,28 @@ function initPageLoadHandler() { var promise = request({ url: "getUserRole?profileId=" + profileIdRequest }).done(function (result) { - $('#roleAdministrator').prop("checked", ((result & 0x01) != 0)).checkboxradio("refresh"); + var userRoles = { + TR_USERROLE_ADMIN: 2, + TR_USERROLE_KEYBOARDUSER: 4, + TR_USERROLE_ADDSONGSUSER: 8, + TR_USERROLE_PLAYLISTEDITOR: 16, + TR_USERROLE_PROFILEEDITOR: 32 + }; + + for (var roleName in userRoles) { + $('#' + roleName).prop("checked", ((result & userRoles[roleName]) != 0)).checkboxradio("refresh"); + } + $('#btnRoleSave').unbind('click').click(function () { var role = 0; - if ($('#roleAdministrator').prop("checked")) { - role = (role | 0x01); + + for (var roleName2 in userRoles) { + if ($('#' + roleName2).prop("checked")) { + role = (role | userRoles[roleName2]); + } } + request({ url: "setUserRole?profileId=" + profileIdRequest + "&userRole=" + role, headers: { "session": sessionId } @@ -1239,24 +1244,185 @@ function showWikipedia(artist) { } function initTranslation() { - $.i18n.init({ - resGetPath: 'locales/__lng__.json', - supportedLngs: ['en', 'de'], - fallbackLng: 'en', - keyseparator: '::', - nsseparator: ':::' - }).done(function () { - tranlationLoaded.resolve(); - }); -} + var translations = { + "en": { + translation: { + 'loginName': 'User:', + 'loginPassword': 'Password:', + 'loginButton': 'Login', + 'registerButton': 'Create Profile', + 'discoverReadQrButton': 'Scan QRCode', + 'mainPageYourProfileLink': 'Your Profile', + 'mainPageYourProfileLinkDesc': 'Edit your profile', + 'mainPageCurrentSongLink': 'Current Song', + 'mainPageCurrentSongLinkDesc': 'Display informations about the current song', + 'mainPageSelectSong': 'All songs', + 'mainPageSelectSongDesc': 'Lists all available songs', + 'mainPageSelectPlaylist': 'All playlists', + 'mainPageSelectPlaylistDesc': 'Lists all playlists', + 'mainPageSelectProfile': 'Profiles', + 'mainPageSelectProfileDesc': 'Shows all profiles', + 'mainPageTakePhotoLink': 'Take Photo', + 'mainPageTakePhotoLinkDesc': 'Takes a photo and displays it at the end of the current round', + 'mainPageKeyboard': 'Keyboard', + 'mainPageKeyboardDesc': 'Send keys', + 'mainPageSelectUserAdmin': 'Administration', + 'mainPageSelectUserAdminDesc': 'Configure user rights', + 'mainPageLogoutLink': 'Logout', + 'mainPageLogoutLinkDesc': 'Closes the session', + 'selectProfileHeader': 'All profiles', + 'displayProfileHeader': 'Profile', + 'displayProfileName': 'Name:', + 'displayProfilePlayerType': 'Player Type:', + 'displayProfilePlayerTypeNormal': 'Normal', + 'displayProfilePlayerTypeGuest': 'Guest', + 'displayProfilePlayerDifficulty': 'Difficulty:', + 'displayProfilePlayerDifficultyEasy': 'Easy', + 'displayProfilePlayerDifficultyNormal': 'Normal', + 'displayProfilePlayerDifficultyHard': 'Hard', + 'displayProfilePlayerPassword': 'New Password:', + 'displayProfilePlayerSaveButton': 'Save and upload', + 'displaySongHeader': 'No current song', + 'displaySongArtist': 'Artist:', + 'displaySongGenre': 'Genre:', + 'displaySongYear': 'Year:', + 'displaySongLanguage': 'Language:', + 'displaySongIsDuet': 'Duet:', + 'popupVideoClose': 'Close', + 'selectSongHeader': 'All songs', + 'keyboardHeader': 'Keyboard', + 'keyboardButtonUp': 'up', + 'keyboardButtonLeft': 'left', + 'keyboardButtonRight': 'right', + 'keyboardButtonDown': 'down', + 'keyboardButtonEscape': 'escape', + 'keyboardButtonTab': 'tab', + 'keyboardButtonReturn': 'return', + 'keyboardButtonKeys': 'To send other keys type here:', + 'selectUserAdminHeader': 'All profiles', + 'displayUserAdminHeader': 'Profile', + 'displayUserAdminContentSaveButton': 'Save', + 'selectPlaylistHeader': 'Select a playlist', + 'displayPlaylistHeader': 'Playlist', + 'displayPlaylistSaveButton': 'Save', + 'selectPlaylistAddPlaylistButton': 'Add', + 'Loading (external)...': 'Loading (external)...', + 'Loading...': 'Loading...', + 'Error...': 'Error...', + 'No connection': 'No connection', + 'No session': 'No session', + 'Uploading photo...': 'Uploading photo...', + 'Getting current song...': 'Getting current song...', + 'Login...': 'Login...', + 'Creating profile...': 'Creating profile...', + 'This is not a valid name.': 'This is not a valid name.', + 'Uploading profile...': 'Uploading profile...', + 'songs': 'songs', + 'YourName': 'YourName', + 'discoverConnectHeader': 'Connect to server', + 'discoverConnectServerAddress': 'Serveraddress:', + 'discoverConnectButton': 'Connect', + 'Checking...': 'Checking...', + 'timeout': 'Timeout' + } + }, + "de": { + translation: { + 'loginName': 'Benutzer:', + 'loginPassword': 'Passwort:', + 'loginButton': 'Einloggen', + 'registerButton': 'Erstelle Profil', + 'discoverReadQrButton': 'Fotografiere QRCode', + 'mainPageYourProfileLink': 'Dein Profil', + 'mainPageYourProfileLinkDesc': 'Bearbeite dein Profil', + 'mainPageCurrentSongLink': 'Aktuelles Lied', + 'mainPageCurrentSongLinkDesc': 'Zeigt Informationen über das aktuelle Lied an', + 'mainPageSelectSong': 'Alle Lieder', + 'mainPageSelectSongDesc': 'Listet alle verfügbaren Lieder auf', + 'mainPageSelectPlaylist': 'Alle Playlisten', + 'mainPageSelectPlaylistDesc': 'Listet alle verfügbaren Playlisten auf', + 'mainPageSelectProfile': 'Profile', + 'mainPageSelectProfileDesc': 'Listet alle Profile auf', + 'mainPageTakePhotoLink': 'Nehme Foto auf', + 'mainPageTakePhotoLinkDesc': 'Nimmt ein Foto auf und zeigt es am ende der Runde an', + 'mainPageKeyboard': 'Tastatur', + 'mainPageKeyboardDesc': 'Sende Tastatureingaben', + 'mainPageSelectUserAdmin': 'Administration', + 'mainPageSelectUserAdminDesc': 'Konfiguriere die Benutzerrechte', + 'mainPageLogoutLink': 'Abmelden', + 'mainPageLogoutLinkDesc': 'Beendet diese Sitzung', + 'selectProfileHeader': 'Alle Profile', + 'displayProfileHeader': 'Profile', + 'displayProfileName': 'Name:', + 'displayProfilePlayerType': 'Player Typ:', + 'displayProfilePlayerTypeNormal': 'Normal', + 'displayProfilePlayerTypeGuest': 'Gast', + 'displayProfilePlayerDifficulty': 'Schwierigkeit:', + 'displayProfilePlayerDifficultyEasy': 'Einfach', + 'displayProfilePlayerDifficultyNormal': 'Normal', + 'displayProfilePlayerDifficultyHard': 'Schwer', + 'displayProfilePlayerPassword': 'Neues Passwort:', + 'displayProfilePlayerSaveButton': 'Speichern und hochladen', + 'displaySongHeader': 'Kein aktuelles Lied', + 'displaySongArtist': 'Künstler:', + 'displaySongGenre': 'Genre:', + 'displaySongYear': 'Jahr:', + 'displaySongLanguage': 'Sprache:', + 'displaySongIsDuet': 'Duet:', + 'popupVideoClose': 'Schließen', + 'selectSongHeader': 'Alle Lieder', + 'keyboardHeader': 'Tastatur', + 'keyboardButtonUp': 'hoch', + 'keyboardButtonLeft': 'links', + 'keyboardButtonRight': 'rechts', + 'keyboardButtonDown': 'runter', + 'keyboardButtonEscape': 'Escape', + 'keyboardButtonTab': 'Tab', + 'keyboardButtonReturn': 'Enter', + 'keyboardButtonKeys': 'Um andere Zeichen zu senden, hier tippen:', + 'selectUserAdminHeader': 'Alle Profile', + 'displayUserAdminHeader': 'Profile', + 'displayUserAdminContentSaveButton': 'Speichern', + 'selectPlaylistHeader': 'Wähle eine Playlist', + 'displayPlaylistHeader': 'Playlist', + 'displayPlaylistSaveButton': 'Speichern', + 'selectPlaylistAddPlaylistButton': 'Hinzufügen', + 'Loading (external)...': 'Laden (extern)...', + 'Loading...': 'Laden...', + 'Error...': 'Fehler...', + 'No connection': 'Keine Verbindung', + 'No session': 'Keine Sitzung', + 'Uploading photo...': 'Foto hochladen...', + 'Getting current song...': 'Lade aktuelles Lied...', + 'Login...': 'Einloggen...', + 'Creating profile...': 'Erstelle Profil...', + 'This is not a valid name.': 'Dies ist kein gültiger Name.', + 'Uploading profile...': 'Profil hochladen...', + 'songs': 'Lieder', + 'YourName': 'DeinName', + 'discoverConnectHeader': 'Verbinde zum Server', + 'discoverConnectServerAddress': 'Serveradresse:', + 'discoverConnectButton': 'Verbinden', + 'Checking...': 'Prüfen...', + 'timeout': 'Zeitüberschreitung' + } + } + }; -function translate() { //repair broken buttons on the first page (get broken while translating) var repairButtons = function () { $($('#discoverConnect')[0].childNodes).wrap(' '); $($('#discoverReadQr')[0].childNodes).wrap(' '); }; - - $('body').i18n(); - repairButtons(); + + $.i18n.init({ + resStore: translations, + supportedLngs: ['en', 'de'], + fallbackLng: 'en', + keyseparator: '::', + nsseparator: ':::' + }).done(function () { + $('body').i18n(); + repairButtons(); + }); } \ No newline at end of file diff --git a/VocaluxeLib/Enums.cs b/VocaluxeLib/Enums.cs index cabbe88e..b3f78439 100644 --- a/VocaluxeLib/Enums.cs +++ b/VocaluxeLib/Enums.cs @@ -350,10 +350,15 @@ namespace VocaluxeLib NoPopup = -1 } + [Flags] public enum EUserRole { TR_USERROLE_GUEST = 0, TR_USERROLE_NORMAL = 1, - TR_USERROLE_ADMIN = 2 + TR_USERROLE_ADMIN = 2, + TR_USERROLE_KEYBOARDUSER = 4, + TR_USERROLE_ADDSONGSUSER = 8, + TR_USERROLE_PLAYLISTEDITOR = 16, + TR_USERROLE_PROFILEEDITOR = 32 } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/CNameSelection.cs b/VocaluxeLib/Menu/CNameSelection.cs index c3e2501f..bb1df5b2 100644 --- a/VocaluxeLib/Menu/CNameSelection.cs +++ b/VocaluxeLib/Menu/CNameSelection.cs @@ -370,7 +370,7 @@ namespace VocaluxeLib.Menu _Player = player; _PlayerSelector.Color = CBase.Theme.GetPlayerColor(player); } - //Normal activation + //Normal activation else if (active) { Selection = 0; @@ -379,7 +379,7 @@ namespace VocaluxeLib.Menu _PlayerSelector.Color = CBase.Theme.GetPlayerColor(player); _PlayerSelector.Visible = true; } - //Deactivate + //Deactivate else { Selection = -1; @@ -456,7 +456,7 @@ namespace VocaluxeLib.Menu return new CStatic(_PartyModeID); } - public void UnloadTextures() {} + public void UnloadTextures() { } public void LoadTextures() { @@ -486,7 +486,7 @@ namespace VocaluxeLib.Menu for (int j = 0; j < _NumW; j++) { var rect = new SRectF(Rect.X + j * (_TileW + _SpaceW), Rect.Y + i * (_TileH + _SpaceH), _TileW, _TileH, Rect.Z); - var tileStatic = new CStatic(_PartyModeID, _TextureEmptyTile, ColorEmptyTile, rect) {Aspect = EAspect.Crop}; + var tileStatic = new CStatic(_PartyModeID, _TextureEmptyTile, ColorEmptyTile, rect) { Aspect = EAspect.Crop }; var tileText = new CText(rect.X + rect.W / 2, rect.Y + rect.H + _Theme.NameSpace, rect.Z, _Theme.NameHeight, rect.W, EAlignment.Center, _Theme.NameStyle, _Theme.NameFont, _Theme.NameColor, ""); _Tiles.Add(new CTile(tileStatic, tileText, -1)); @@ -508,7 +508,8 @@ namespace VocaluxeLib.Menu for (int p = 0; p < CBase.Game.GetNumPlayer(); p++) { //Don't show profile if is selected, but if selected and guest - if (CBase.Game.GetPlayers()[p].ProfileID == profile.ID && profile.UserRole == EUserRole.TR_USERROLE_GUEST) + if (CBase.Game.GetPlayers()[p].ProfileID == profile.ID + && profile.UserRole.HasFlag(EUserRole.TR_USERROLE_GUEST)) visible = false; } }