Fix merge error
Formatting
This commit is contained in:
1 parent
d4dc4f7c20
commit
2458e1834a
2 files changed
+18
-87
No files matched your search
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Web;
|
||||
using System.Diagnostics;
|
||||
@@ -97,7 +96,7 @@ namespace ServerLib
|
||||
#region server control
|
||||
private void _Init(int port, bool encrypted)
|
||||
{
|
||||
string hostname = GetLocalAddress();
|
||||
string hostname = Dns.GetHostName();
|
||||
string protocol = (encrypted) ? "https" : "http";
|
||||
_BaseAddress = new Uri(protocol + "://" + hostname + ":" + port + "/");
|
||||
_Encrypted = encrypted;
|
||||
|
||||
@@ -15,42 +15,33 @@ namespace ServerLib
|
||||
string sessionHeader =
|
||||
((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"];
|
||||
if (string.IsNullOrEmpty(sessionHeader))
|
||||
{
|
||||
return sessionKey;
|
||||
}
|
||||
try
|
||||
{
|
||||
sessionKey = Guid.Parse(sessionHeader);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
catch (Exception) {}
|
||||
return sessionKey;
|
||||
}
|
||||
|
||||
public void SendKeyEvent(string key)
|
||||
{
|
||||
if (!_CheckRight(EUserRights.UseKeyboard))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (CServer.SendKeyEvent == null)
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CServer.SendKeyEvent(key);
|
||||
}
|
||||
}
|
||||
|
||||
#region profile
|
||||
|
||||
public int GetOwnProfileId()
|
||||
{
|
||||
Guid sessionKey = _GetSession();
|
||||
@@ -58,7 +49,7 @@ namespace ServerLib
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||
}
|
||||
return -1;
|
||||
@@ -68,7 +59,7 @@ namespace ServerLib
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||
}
|
||||
return -1;
|
||||
@@ -82,18 +73,16 @@ namespace ServerLib
|
||||
|
||||
if (profile.ProfileId != -1) //-1 is the id for a new profile
|
||||
{
|
||||
if (CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId
|
||||
&& !(_CheckRight(EUserRights.EditAllProfiles) ))
|
||||
{
|
||||
if (CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId
|
||||
&& !(_CheckRight(EUserRights.EditAllProfiles)))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (CServer.SendProfileData == null)
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
|
||||
}
|
||||
return;
|
||||
@@ -108,9 +97,7 @@ namespace ServerLib
|
||||
if (_CheckRight(EUserRights.ViewOtherProfiles) || CSessionControl.GetUserIdFromSession(sessionKey) == profileId)
|
||||
{
|
||||
if (CServer.GetProfileData == null)
|
||||
{
|
||||
return new SProfileData();
|
||||
}
|
||||
|
||||
bool isReadonly = (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
|
||||
CSessionControl.GetUserIdFromSession(sessionKey) != profileId);
|
||||
@@ -118,36 +105,26 @@ namespace ServerLib
|
||||
return CServer.GetProfileData(profileId, isReadonly);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new SProfileData();
|
||||
}
|
||||
}
|
||||
|
||||
public SProfileData[] GetProfileList()
|
||||
{
|
||||
if (CServer.GetProfileList == null)
|
||||
{
|
||||
return new SProfileData[] { };
|
||||
}
|
||||
return new SProfileData[] {};
|
||||
return CServer.GetProfileList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region photo
|
||||
|
||||
public void SendPhoto(SPhotoData photo)
|
||||
{
|
||||
if (_CheckRight(EUserRights.UploadPhotos))
|
||||
{
|
||||
CServer.SendPhoto(photo);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region website
|
||||
|
||||
public Guid Login(string username, string password)
|
||||
{
|
||||
Guid sessionId = CSessionControl.OpenSession(username, password);
|
||||
@@ -155,7 +132,7 @@ namespace ServerLib
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Wrong username or password";
|
||||
}
|
||||
}
|
||||
@@ -165,9 +142,7 @@ namespace ServerLib
|
||||
public Stream Index()
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
|
||||
}
|
||||
|
||||
return new MemoryStream(CServer.GetSiteFile("index.html"));
|
||||
}
|
||||
@@ -186,14 +161,10 @@ namespace ServerLib
|
||||
byte[] data = CServer.GetSiteFile("js/" + filename);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
return new MemoryStream(data);
|
||||
}
|
||||
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||
}
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -211,13 +182,9 @@ namespace ServerLib
|
||||
byte[] data = CServer.GetSiteFile("css/" + filename);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
return new MemoryStream(data);
|
||||
}
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||
}
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -235,13 +202,9 @@ namespace ServerLib
|
||||
byte[] data = CServer.GetSiteFile("css\\images\\" + filename);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
return new MemoryStream(data);
|
||||
}
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||
}
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -259,13 +222,9 @@ namespace ServerLib
|
||||
byte[] data = CServer.GetSiteFile("img/" + filename);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
return new MemoryStream(data);
|
||||
}
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||
}
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -283,14 +242,10 @@ namespace ServerLib
|
||||
byte[] data = CServer.GetSiteFile("locales/" + filename);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
return new MemoryStream(data);
|
||||
}
|
||||
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -303,11 +258,9 @@ namespace ServerLib
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region songs
|
||||
|
||||
public SSongInfo GetSong(int songId)
|
||||
{
|
||||
return CServer.GetSong(songId);
|
||||
@@ -325,7 +278,6 @@ namespace ServerLib
|
||||
#endregion
|
||||
|
||||
#region playlist
|
||||
|
||||
public SPlaylistInfo[] GetPlaylists()
|
||||
{
|
||||
return CServer.GetPlaylists();
|
||||
@@ -339,25 +291,19 @@ namespace ServerLib
|
||||
public void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
|
||||
{
|
||||
if (_CheckRight(EUserRights.AddSongToPlaylist))
|
||||
{
|
||||
CServer.AddSongToPlaylist(songId, playlistId, allowDuplicates);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveSongFromPlaylist(int position, int playlistId, int songId)
|
||||
{
|
||||
if (_CheckRight(EUserRights.RemoveSongsFromPlaylists))
|
||||
{
|
||||
CServer.RemoveSongFromPlaylist(position, playlistId, songId);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveSongInPlaylist(int newPosition, int playlistId, int songId)
|
||||
{
|
||||
if (_CheckRight(EUserRights.ReorderPlaylists))
|
||||
{
|
||||
CServer.MoveSongInPlaylist(newPosition, playlistId, songId);
|
||||
}
|
||||
}
|
||||
|
||||
public bool PlaylistContainsSong(int songId, int playlistId)
|
||||
@@ -373,24 +319,18 @@ namespace ServerLib
|
||||
public void RemovePlaylist(int playlistId)
|
||||
{
|
||||
if (_CheckRight(EUserRights.DeletePlaylists))
|
||||
{
|
||||
CServer.RemovePlaylist(playlistId);
|
||||
}
|
||||
}
|
||||
|
||||
public int AddPlaylist(string playlistName)
|
||||
{
|
||||
if (_CheckRight(EUserRights.CreatePlaylists))
|
||||
{
|
||||
return CServer.AddPlaylist(playlistName);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region user management
|
||||
|
||||
public int GetUserRole(int profileId)
|
||||
{
|
||||
return CServer.GetUserRole(profileId);
|
||||
@@ -399,11 +339,9 @@ namespace ServerLib
|
||||
public void SetUserRole(int profileId, int userRole)
|
||||
{
|
||||
if (_CheckRight(EUserRights.EditAllProfiles))
|
||||
{
|
||||
CServer.SetUserRole(profileId, userRole);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool HasUserRight(int right)
|
||||
{
|
||||
return _CheckRightWithNoErrorMessage((EUserRights)right);
|
||||
@@ -417,7 +355,7 @@ namespace ServerLib
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||
}
|
||||
return false;
|
||||
@@ -427,7 +365,7 @@ namespace ServerLib
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
||||
}
|
||||
return false;
|
||||
@@ -440,19 +378,13 @@ namespace ServerLib
|
||||
Guid sessionKey = _GetSession();
|
||||
|
||||
if (sessionKey == Guid.Empty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CSessionControl.RequestRight(sessionKey, requestedRight))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user