Webserver: renaming
This commit is contained in:
1 parent
013fc1e846
commit
3344f05b58
9 files changed
+357
-365
No files matched your search
@@ -1,11 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.ServiceModel.Description;
|
|
||||||
using System.ServiceModel.Web;
|
using System.ServiceModel.Web;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
@@ -13,91 +8,91 @@ namespace ServerLib
|
|||||||
{
|
{
|
||||||
public class CServer
|
public class CServer
|
||||||
{
|
{
|
||||||
private ServiceHost host;
|
private ServiceHost _Host;
|
||||||
private Uri baseAddress;
|
private Uri _BaseAddress;
|
||||||
private bool encrypted = false;
|
private bool _Encrypted = false;
|
||||||
|
|
||||||
private static SendKeyEventDelegate sendKeyEvent;
|
private static SendKeyEventDelegate _SendKeyEvent;
|
||||||
public static SendKeyEventDelegate SendKeyEvent
|
public static SendKeyEventDelegate SendKeyEvent
|
||||||
{
|
{
|
||||||
internal get { return CServer.sendKeyEvent; }
|
internal get { return CServer._SendKeyEvent; }
|
||||||
set { CServer.sendKeyEvent = value; }
|
set { CServer._SendKeyEvent = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#region profile
|
#region profile
|
||||||
|
|
||||||
private static GetProfileDataDelegate getProfileData;
|
private static GetProfileDataDelegate _GetProfileData;
|
||||||
public static GetProfileDataDelegate GetProfileData
|
public static GetProfileDataDelegate GetProfileData
|
||||||
{
|
{
|
||||||
internal get { return CServer.getProfileData; }
|
internal get { return CServer._GetProfileData; }
|
||||||
set { CServer.getProfileData = value; }
|
set { CServer._GetProfileData = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SendProfileDataDelegate sendProfileData;
|
private static SendProfileDataDelegate _SendProfileData;
|
||||||
public static SendProfileDataDelegate SendProfileData
|
public static SendProfileDataDelegate SendProfileData
|
||||||
{
|
{
|
||||||
internal get { return CServer.sendProfileData; }
|
internal get { return CServer._SendProfileData; }
|
||||||
set { CServer.sendProfileData = value; }
|
set { CServer._SendProfileData = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetProfileListDelegate getProfileList;
|
private static GetProfileListDelegate _GetProfileList;
|
||||||
public static GetProfileListDelegate GetProfileList
|
public static GetProfileListDelegate GetProfileList
|
||||||
{
|
{
|
||||||
internal get { return CServer.getProfileList; }
|
internal get { return CServer._GetProfileList; }
|
||||||
set { CServer.getProfileList = value; }
|
set { CServer._GetProfileList = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region photo
|
#region photo
|
||||||
private static SendPhotoDelegate sendPhoto;
|
private static SendPhotoDelegate _SendPhoto;
|
||||||
public static SendPhotoDelegate SendPhoto
|
public static SendPhotoDelegate SendPhoto
|
||||||
{
|
{
|
||||||
get { return CServer.sendPhoto; }
|
get { return CServer._SendPhoto; }
|
||||||
set { CServer.sendPhoto = value; }
|
set { CServer._SendPhoto = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region website
|
#region website
|
||||||
|
|
||||||
private static GetSiteFileDelegate getSiteFile;
|
private static GetSiteFileDelegate _GetSiteFile;
|
||||||
public static GetSiteFileDelegate GetSiteFile
|
public static GetSiteFileDelegate GetSiteFile
|
||||||
{
|
{
|
||||||
internal get { return CServer.getSiteFile; }
|
internal get { return CServer._GetSiteFile; }
|
||||||
set { CServer.getSiteFile = value; }
|
set { CServer._GetSiteFile = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetDelayedImageDelegate getDelayedImage;
|
private static GetDelayedImageDelegate _GetDelayedImage;
|
||||||
public static GetDelayedImageDelegate GetDelayedImage
|
public static GetDelayedImageDelegate GetDelayedImage
|
||||||
{
|
{
|
||||||
internal get { return CServer.getDelayedImage; }
|
internal get { return CServer._GetDelayedImage; }
|
||||||
set { CServer.getDelayedImage = value; }
|
set { CServer._GetDelayedImage = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region songs
|
#region songs
|
||||||
|
|
||||||
private static GetSongDelegate getSong;
|
private static GetSongDelegate _GetSong;
|
||||||
public static GetSongDelegate GetSong
|
public static GetSongDelegate GetSong
|
||||||
{
|
{
|
||||||
internal get { return CServer.getSong; }
|
internal get { return CServer._GetSong; }
|
||||||
set { CServer.getSong = value; }
|
set { CServer._GetSong = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetAllSongsDelegate getAllSongs;
|
private static GetAllSongsDelegate _GetAllSongs;
|
||||||
public static GetAllSongsDelegate GetAllSongs
|
public static GetAllSongsDelegate GetAllSongs
|
||||||
{
|
{
|
||||||
get { return CServer.getAllSongs; }
|
get { return CServer._GetAllSongs; }
|
||||||
set { CServer.getAllSongs = value; }
|
set { CServer._GetAllSongs = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetCurrentSongIdDelegate getCurrentSongId;
|
private static GetCurrentSongIdDelegate _GetCurrentSongId;
|
||||||
public static GetCurrentSongIdDelegate GetCurrentSongId
|
public static GetCurrentSongIdDelegate GetCurrentSongId
|
||||||
{
|
{
|
||||||
get { return CServer.getCurrentSongId; }
|
get { return CServer._GetCurrentSongId; }
|
||||||
set { CServer.getCurrentSongId = value; }
|
set { CServer._GetCurrentSongId = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -105,77 +100,77 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region user management
|
#region user management
|
||||||
|
|
||||||
private static SetPasswordDelegate setPassword;
|
private static SetPasswordDelegate _SetPassword;
|
||||||
public static SetPasswordDelegate SetPassword
|
public static SetPasswordDelegate SetPassword
|
||||||
{
|
{
|
||||||
internal get { return CServer.setPassword; }
|
internal get { return CServer._SetPassword; }
|
||||||
set { CServer.setPassword = value; }
|
set { CServer._SetPassword = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ValidatePasswordDelegate validatePassword;
|
private static ValidatePasswordDelegate _ValidatePassword;
|
||||||
public static ValidatePasswordDelegate ValidatePassword
|
public static ValidatePasswordDelegate ValidatePassword
|
||||||
{
|
{
|
||||||
internal get { return CServer.validatePassword; }
|
internal get { return CServer._ValidatePassword; }
|
||||||
set { CServer.validatePassword = value; }
|
set { CServer._ValidatePassword = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetUserRoleDelegate getUserRole;
|
private static GetUserRoleDelegate _GetUserRole;
|
||||||
public static GetUserRoleDelegate GetUserRole
|
public static GetUserRoleDelegate GetUserRole
|
||||||
{
|
{
|
||||||
internal get { return CServer.getUserRole; }
|
internal get { return CServer._GetUserRole; }
|
||||||
set { CServer.getUserRole = value; }
|
set { CServer._GetUserRole = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SetUserRoleDelegate setUserRole;
|
private static SetUserRoleDelegate _SetUserRole;
|
||||||
public static SetUserRoleDelegate SetUserRole
|
public static SetUserRoleDelegate SetUserRole
|
||||||
{
|
{
|
||||||
internal get { return CServer.setUserRole; }
|
internal get { return CServer._SetUserRole; }
|
||||||
set { CServer.setUserRole = value; }
|
set { CServer._SetUserRole = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetUserIdFromUsernameDelegate getUserIdFromUsername;
|
private static GetUserIdFromUsernameDelegate _GetUserIdFromUsername;
|
||||||
public static GetUserIdFromUsernameDelegate GetUserIdFromUsername
|
public static GetUserIdFromUsernameDelegate GetUserIdFromUsername
|
||||||
{
|
{
|
||||||
internal get { return CServer.getUserIdFromUsername; }
|
internal get { return CServer._GetUserIdFromUsername; }
|
||||||
set { CServer.getUserIdFromUsername = value; }
|
set { CServer._GetUserIdFromUsername = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public CServer(int port, bool encrypted)
|
public CServer(int port, bool encrypted)
|
||||||
{
|
{
|
||||||
init(port, encrypted);
|
_Init(port, encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region server control
|
#region server control
|
||||||
|
|
||||||
private void init(int port, bool encrypted)
|
private void _Init(int port, bool encrypted)
|
||||||
{
|
{
|
||||||
string hostname = Dns.GetHostName();
|
string hostname = Dns.GetHostName();
|
||||||
if (encrypted)
|
if (encrypted)
|
||||||
{
|
{
|
||||||
baseAddress = new Uri("https://" + hostname + ":" + port + "/");
|
_BaseAddress = new Uri("https://" + hostname + ":" + port + "/");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
baseAddress = new Uri("http://" + hostname + ":" + port + "/");
|
_BaseAddress = new Uri("http://" + hostname + ":" + port + "/");
|
||||||
}
|
}
|
||||||
this.encrypted = encrypted;
|
this._Encrypted = encrypted;
|
||||||
host = new WebServiceHost(typeof(CWebservice), baseAddress);
|
_Host = new WebServiceHost(typeof(CWebservice), _BaseAddress);
|
||||||
|
|
||||||
WebHttpBinding wb = new WebHttpBinding();
|
WebHttpBinding wb = new WebHttpBinding
|
||||||
wb.MaxReceivedMessageSize = 10485760;
|
{
|
||||||
wb.MaxBufferSize = 10485760;
|
MaxReceivedMessageSize = 10485760,
|
||||||
wb.MaxBufferPoolSize = 10485760;
|
MaxBufferSize = 10485760,
|
||||||
wb.ReaderQuotas.MaxStringContentLength = 10485760;
|
MaxBufferPoolSize = 10485760,
|
||||||
wb.ReaderQuotas.MaxArrayLength = 10485760;
|
ReaderQuotas = {MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760}
|
||||||
wb.ReaderQuotas.MaxBytesPerRead = 10485760;
|
};
|
||||||
if (encrypted)
|
if (encrypted)
|
||||||
{
|
{
|
||||||
wb.Security.Mode = WebHttpSecurityMode.Transport;
|
wb.Security.Mode = WebHttpSecurityMode.Transport;
|
||||||
wb.Security.Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.None };
|
wb.Security.Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.None };
|
||||||
}
|
}
|
||||||
host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
|
_Host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
@@ -187,27 +182,27 @@ namespace ServerLib
|
|||||||
smb.HttpGetEnabled = true;
|
smb.HttpGetEnabled = true;
|
||||||
host.Description.Behaviors.Add(smb);*/
|
host.Description.Behaviors.Add(smb);*/
|
||||||
|
|
||||||
host.Open();
|
_Host.Open();
|
||||||
}
|
}
|
||||||
catch (CommunicationException e)
|
catch (CommunicationException e)
|
||||||
{
|
{
|
||||||
if (e is AddressAccessDeniedException || e is AddressAlreadyInUseException)
|
if (e is AddressAccessDeniedException || e is AddressAlreadyInUseException)
|
||||||
{
|
{
|
||||||
registerUrlAndCert(baseAddress.Port);
|
_RegisterUrlAndCert(_BaseAddress.Port);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
host.Abort();
|
_Host.Abort();
|
||||||
init(baseAddress.Port, encrypted);
|
_Init(_BaseAddress.Port, _Encrypted);
|
||||||
host.Open();
|
_Host.Open();
|
||||||
}
|
}
|
||||||
catch (CommunicationException e2)
|
catch (CommunicationException e2)
|
||||||
{
|
{
|
||||||
host.Abort();
|
_Host.Abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
host.Abort();
|
_Host.Abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,25 +211,27 @@ namespace ServerLib
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
host.Close();
|
_Host.Close();
|
||||||
}
|
}
|
||||||
catch (CommunicationException e)
|
catch (CommunicationException e)
|
||||||
{
|
{
|
||||||
host.Abort();
|
_Host.Abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerUrlAndCert(int port)
|
private void _RegisterUrlAndCert(int port)
|
||||||
{
|
{
|
||||||
#if WIN
|
#if WIN
|
||||||
|
|
||||||
ProcessStartInfo info = new ProcessStartInfo();
|
ProcessStartInfo info = new ProcessStartInfo
|
||||||
info.FileName = "WebserverInitalConfig.exe";
|
{
|
||||||
info.Arguments = port.ToString() + " " + encrypted.ToString();
|
FileName = "WebserverInitalConfig.exe",
|
||||||
info.UseShellExecute = true;
|
Arguments = port.ToString() + " " + _Encrypted.ToString(),
|
||||||
info.CreateNoWindow = true;
|
UseShellExecute = true,
|
||||||
info.WindowStyle = ProcessWindowStyle.Hidden;
|
CreateNoWindow = true,
|
||||||
info.Verb = "runas";
|
WindowStyle = ProcessWindowStyle.Hidden,
|
||||||
|
Verb = "runas"
|
||||||
|
};
|
||||||
Process p = Process.Start(info);
|
Process p = Process.Start(info);
|
||||||
if (p != null)
|
if (p != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.Text;
|
|
||||||
using System.ServiceModel.Web;
|
using System.ServiceModel.Web;
|
||||||
using System.Web.Services;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.ServiceModel.Channels;
|
using System.ServiceModel.Channels;
|
||||||
|
|
||||||
@@ -17,7 +13,7 @@ namespace ServerLib
|
|||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/sendKeyEvent?key={key}")]
|
UriTemplate = "/sendKeyEvent?key={key}")]
|
||||||
void sendKeyEvent(string key);
|
void SendKeyEvent(string key);
|
||||||
|
|
||||||
#region profile
|
#region profile
|
||||||
|
|
||||||
@@ -25,25 +21,25 @@ namespace ServerLib
|
|||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/getOwnProfileId")]
|
UriTemplate = "/getOwnProfileId")]
|
||||||
int getOwnProfileId();
|
int GetOwnProfileId();
|
||||||
|
|
||||||
[OperationContract]
|
[OperationContract]
|
||||||
[WebInvoke(Method = "POST",
|
[WebInvoke(Method = "POST",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/sendProfile")]
|
UriTemplate = "/sendProfile")]
|
||||||
void sendProfile(ProfileData profile);
|
void SendProfile(SProfileData profile);
|
||||||
|
|
||||||
[OperationContract]
|
[OperationContract]
|
||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/getProfile?profileId={profileId}")]
|
UriTemplate = "/getProfile?profileId={profileId}")]
|
||||||
ProfileData getProfile(int profileId);
|
SProfileData GetProfile(int profileId);
|
||||||
|
|
||||||
[OperationContract]
|
[OperationContract]
|
||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/getProfileList")]
|
UriTemplate = "/getProfileList")]
|
||||||
ProfileData[] getProfileList();
|
SProfileData[] GetProfileList();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -54,7 +50,7 @@ namespace ServerLib
|
|||||||
RequestFormat = WebMessageFormat.Json,
|
RequestFormat = WebMessageFormat.Json,
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/sendPhoto")]
|
UriTemplate = "/sendPhoto")]
|
||||||
void sendPhoto(PhotoData photo);
|
void SendPhoto(SPhotoData photo);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -64,7 +60,7 @@ namespace ServerLib
|
|||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/login?username={username}&password={password}")]
|
UriTemplate = "/login?username={username}&password={password}")]
|
||||||
Guid login(string username, string password);
|
Guid Login(string username, string password);
|
||||||
|
|
||||||
[OperationContract]
|
[OperationContract]
|
||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
@@ -100,7 +96,7 @@ namespace ServerLib
|
|||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/delayedImage?id={id}")]
|
UriTemplate = "/delayedImage?id={id}")]
|
||||||
Base64Image GetDelayedImage(String id);
|
CBase64Image GetDelayedImage(String id);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -110,19 +106,19 @@ namespace ServerLib
|
|||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/getSong?songId={songId}")]
|
UriTemplate = "/getSong?songId={songId}")]
|
||||||
SongInfo getSong(int songId);
|
SOngInfo GetSong(int songId);
|
||||||
|
|
||||||
[OperationContract]
|
[OperationContract]
|
||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/getCurrentSongId")]
|
UriTemplate = "/getCurrentSongId")]
|
||||||
int getCurrentSongId();
|
int GetCurrentSongId();
|
||||||
|
|
||||||
[OperationContract]
|
[OperationContract]
|
||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/getAllSongs")]
|
UriTemplate = "/getAllSongs")]
|
||||||
SongInfo[] getAllSongs();
|
SOngInfo[] GetAllSongs();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -132,29 +128,25 @@ namespace ServerLib
|
|||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/getUserRole?profileId={profileId}")]
|
UriTemplate = "/getUserRole?profileId={profileId}")]
|
||||||
int getUserRole(int profileId);
|
int GetUserRole(int profileId);
|
||||||
|
|
||||||
[OperationContract]
|
[OperationContract]
|
||||||
[WebInvoke(Method = "GET",
|
[WebInvoke(Method = "GET",
|
||||||
ResponseFormat = WebMessageFormat.Json,
|
ResponseFormat = WebMessageFormat.Json,
|
||||||
UriTemplate = "/setUserRole?profileId={profileId}&userRole={userRole}")]
|
UriTemplate = "/setUserRole?profileId={profileId}&userRole={userRole}")]
|
||||||
void setUserRole(int profileId, int userRole);
|
void SetUserRole(int profileId, int userRole);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
class CWebservice : ICWebservice
|
class CWebservice : ICWebservice
|
||||||
{
|
{
|
||||||
public CWebservice()
|
private static Guid _GetSession()
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Guid getSession()
|
|
||||||
{
|
{
|
||||||
Guid sessionKey = Guid.Empty;
|
Guid sessionKey = Guid.Empty;
|
||||||
string sessionHeader =
|
string sessionHeader =
|
||||||
((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"];
|
((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"];
|
||||||
if (sessionHeader == null || sessionHeader == "")
|
if (string.IsNullOrEmpty(sessionHeader))
|
||||||
{
|
{
|
||||||
return sessionKey;
|
return sessionKey;
|
||||||
}
|
}
|
||||||
@@ -168,25 +160,33 @@ namespace ServerLib
|
|||||||
return sessionKey;
|
return sessionKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendKeyEvent(string key)
|
public void SendKeyEvent(string key)
|
||||||
{
|
{
|
||||||
Guid sessionKey = getSession();
|
Guid sessionKey = _GetSession();
|
||||||
|
|
||||||
if (sessionKey == Guid.Empty )
|
if (sessionKey == Guid.Empty)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!SessionControl.requestRight(sessionKey, UserRights.UseKeyboard))
|
else if (!CSessionControl.RequestRight(sessionKey, EUserRights.UseKeyboard))
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (CServer.SendKeyEvent == null)
|
else if (CServer.SendKeyEvent == null)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -196,51 +196,66 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region profile
|
#region profile
|
||||||
|
|
||||||
public int getOwnProfileId()
|
public int GetOwnProfileId()
|
||||||
{
|
{
|
||||||
Guid sessionKey = getSession();
|
Guid sessionKey = _GetSession();
|
||||||
if (sessionKey == Guid.Empty)
|
if (sessionKey == Guid.Empty)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int profileId = SessionControl.getUserIdFromSession(sessionKey);
|
int profileId = CSessionControl.GetUserIdFromSession(sessionKey);
|
||||||
if (profileId < 0)
|
if (profileId < 0)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return profileId;
|
return profileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendProfile(ProfileData profile)
|
public void SendProfile(SProfileData profile)
|
||||||
{
|
{
|
||||||
Guid sessionKey = getSession();
|
Guid sessionKey = _GetSession();
|
||||||
|
|
||||||
if (profile.ProfileId != -1) //-1 is the id for a new profile
|
if (profile.ProfileId != -1) //-1 is the id for a new profile
|
||||||
{
|
{
|
||||||
if (sessionKey == Guid.Empty)
|
if (sessionKey == Guid.Empty)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
|
if (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
|
||||||
SessionControl.getUserIdFromSession(sessionKey) != profile.ProfileId)
|
CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CServer.SendProfileData == null)
|
if (CServer.SendProfileData == null)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,41 +273,47 @@ namespace ServerLib
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileData getProfile(int profileId)
|
public SProfileData GetProfile(int profileId)
|
||||||
{
|
{
|
||||||
Guid sessionKey = getSession();
|
Guid sessionKey = _GetSession();
|
||||||
|
|
||||||
if (sessionKey == Guid.Empty)
|
if (sessionKey == Guid.Empty)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
{
|
||||||
return new ProfileData();
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||||
|
}
|
||||||
|
return new SProfileData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SessionControl.requestRight(sessionKey, UserRights.ViewOtherProfiles) &&
|
if (!CSessionControl.RequestRight(sessionKey, EUserRights.ViewOtherProfiles) &&
|
||||||
SessionControl.getUserIdFromSession(sessionKey) != profileId)
|
CSessionControl.GetUserIdFromSession(sessionKey) != profileId)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
{
|
||||||
return new ProfileData();
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
||||||
|
}
|
||||||
|
return new SProfileData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CServer.GetProfileData == null)
|
if (CServer.GetProfileData == null)
|
||||||
{
|
{
|
||||||
return new ProfileData();
|
return new SProfileData();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isReadonly = (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
|
bool isReadonly = (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
|
||||||
SessionControl.getUserIdFromSession(sessionKey) != profileId);
|
CSessionControl.GetUserIdFromSession(sessionKey) != profileId);
|
||||||
|
|
||||||
return CServer.GetProfileData(profileId, isReadonly);
|
return CServer.GetProfileData(profileId, isReadonly);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileData[] getProfileList()
|
public SProfileData[] GetProfileList()
|
||||||
{
|
{
|
||||||
if (CServer.GetProfileList == null)
|
if (CServer.GetProfileList == null)
|
||||||
{
|
{
|
||||||
return new ProfileData[] { };
|
return new SProfileData[] { };
|
||||||
}
|
}
|
||||||
return CServer.GetProfileList();
|
return CServer.GetProfileList();
|
||||||
}
|
}
|
||||||
@@ -301,20 +322,26 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region photo
|
#region photo
|
||||||
|
|
||||||
public void sendPhoto(PhotoData photo)
|
public void SendPhoto(SPhotoData photo)
|
||||||
{
|
{
|
||||||
Guid sessionKey = getSession();
|
Guid sessionKey = _GetSession();
|
||||||
if (sessionKey == Guid.Empty)
|
if (sessionKey == Guid.Empty)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SessionControl.requestRight(sessionKey, UserRights.UploadPhotos))
|
if (!CSessionControl.RequestRight(sessionKey, EUserRights.UploadPhotos))
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,13 +352,16 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region website
|
#region website
|
||||||
|
|
||||||
public Guid login(string username, string password)
|
public Guid Login(string username, string password)
|
||||||
{
|
{
|
||||||
Guid sessionId = SessionControl.openSession(username, password);
|
Guid sessionId = CSessionControl.OpenSession(username, password);
|
||||||
if (sessionId == Guid.Empty)
|
if (sessionId == Guid.Empty)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null)
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Wrong username or password";
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Wrong username or password";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
@@ -359,11 +389,12 @@ namespace ServerLib
|
|||||||
{
|
{
|
||||||
return new MemoryStream(data);
|
return new MemoryStream(data);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (WebOperationContext.Current != null)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream GetCssFile(string filename)
|
public Stream GetCssFile(string filename)
|
||||||
@@ -379,13 +410,11 @@ namespace ServerLib
|
|||||||
{
|
{
|
||||||
return new MemoryStream(data);
|
return new MemoryStream(data);
|
||||||
}
|
}
|
||||||
else
|
if (WebOperationContext.Current != null)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream GetCssImageFile(string filename)
|
public Stream GetCssImageFile(string filename)
|
||||||
@@ -401,11 +430,11 @@ namespace ServerLib
|
|||||||
{
|
{
|
||||||
return new MemoryStream(data);
|
return new MemoryStream(data);
|
||||||
}
|
}
|
||||||
else
|
if (WebOperationContext.Current != null)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream GetImgFile(string filename)
|
public Stream GetImgFile(string filename)
|
||||||
@@ -421,14 +450,14 @@ namespace ServerLib
|
|||||||
{
|
{
|
||||||
return new MemoryStream(data);
|
return new MemoryStream(data);
|
||||||
}
|
}
|
||||||
else
|
if (WebOperationContext.Current != null)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Base64Image GetDelayedImage(string id)
|
public CBase64Image GetDelayedImage(string id)
|
||||||
{
|
{
|
||||||
return CServer.GetDelayedImage(id);
|
return CServer.GetDelayedImage(id);
|
||||||
}
|
}
|
||||||
@@ -437,17 +466,17 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region songs
|
#region songs
|
||||||
|
|
||||||
public SongInfo getSong(int songId)
|
public SOngInfo GetSong(int songId)
|
||||||
{
|
{
|
||||||
return CServer.GetSong(songId);
|
return CServer.GetSong(songId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentSongId()
|
public int GetCurrentSongId()
|
||||||
{
|
{
|
||||||
return CServer.GetCurrentSongId();
|
return CServer.GetCurrentSongId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SongInfo[] getAllSongs()
|
public SOngInfo[] GetAllSongs()
|
||||||
{
|
{
|
||||||
return CServer.GetAllSongs();
|
return CServer.GetAllSongs();
|
||||||
}
|
}
|
||||||
@@ -456,24 +485,28 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region user management
|
#region user management
|
||||||
|
|
||||||
public int getUserRole(int profileId)
|
public int GetUserRole(int profileId)
|
||||||
{
|
{
|
||||||
return CServer.GetUserRole(profileId);
|
return CServer.GetUserRole(profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserRole(int profileId, int userRole)
|
public void SetUserRole(int profileId, int userRole)
|
||||||
{
|
{
|
||||||
Guid sessionKey = getSession();
|
Guid sessionKey = _GetSession();
|
||||||
if (sessionKey == Guid.Empty)
|
if (sessionKey == Guid.Empty)
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null) {
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles))
|
if (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles))
|
||||||
{
|
{
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
if (WebOperationContext.Current != null) {
|
||||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CServer.SetUserRole(profileId, userRole);
|
CServer.SetUserRole(profileId, userRole);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -15,15 +13,15 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region profile
|
#region profile
|
||||||
|
|
||||||
public delegate ProfileData GetProfileDataDelegate(int profileId, bool isReadonly);
|
public delegate SProfileData GetProfileDataDelegate(int profileId, bool isReadonly);
|
||||||
public delegate bool SendProfileDataDelegate(ProfileData profile);
|
public delegate bool SendProfileDataDelegate(SProfileData profile);
|
||||||
public delegate ProfileData[] GetProfileListDelegate();
|
public delegate SProfileData[] GetProfileListDelegate();
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public struct ProfileData
|
public struct SProfileData
|
||||||
{
|
{
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public Base64Image Avatar;
|
public CBase64Image Avatar;
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string PlayerName;
|
public string PlayerName;
|
||||||
[DataMember]
|
[DataMember]
|
||||||
@@ -42,13 +40,13 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region photo
|
#region photo
|
||||||
|
|
||||||
public delegate bool SendPhotoDelegate(PhotoData photo);
|
public delegate bool SendPhotoDelegate(SPhotoData photo);
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public struct PhotoData
|
public struct SPhotoData
|
||||||
{
|
{
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public Base64Image Photo;
|
public CBase64Image Photo;
|
||||||
//Add infomation about the user who took this image??
|
//Add infomation about the user who took this image??
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,12 +56,12 @@ namespace ServerLib
|
|||||||
|
|
||||||
public delegate byte[] GetSiteFileDelegate(string filename);
|
public delegate byte[] GetSiteFileDelegate(string filename);
|
||||||
|
|
||||||
public delegate Base64Image GetDelayedImageDelegate(string hashedFilename);
|
public delegate CBase64Image GetDelayedImageDelegate(string hashedFilename);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class Base64Image
|
public class CBase64Image
|
||||||
{
|
{
|
||||||
[DataMember]
|
[DataMember]
|
||||||
private string base64Data = "";
|
private string base64Data = "";
|
||||||
@@ -71,7 +69,7 @@ namespace ServerLib
|
|||||||
[DataMember]
|
[DataMember]
|
||||||
private string imageId = "";
|
private string imageId = "";
|
||||||
|
|
||||||
public Base64Image(Image img, ImageFormat format)
|
public CBase64Image(Image img, ImageFormat format)
|
||||||
{
|
{
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
img.Save(ms, format);
|
img.Save(ms, format);
|
||||||
@@ -79,12 +77,12 @@ namespace ServerLib
|
|||||||
base64Data = "data:image/" + formatString + ";base64," + Convert.ToBase64String(ms.ToArray());
|
base64Data = "data:image/" + formatString + ";base64," + Convert.ToBase64String(ms.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Base64Image(string imageId)
|
public CBase64Image(string imageId)
|
||||||
{
|
{
|
||||||
this.imageId = imageId;
|
this.imageId = imageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image getImage()
|
public Image GetImage()
|
||||||
{
|
{
|
||||||
string onlyBase64Data = base64Data.Substring(base64Data.IndexOf(";base64,") + (";base64,").Length);
|
string onlyBase64Data = base64Data.Substring(base64Data.IndexOf(";base64,") + (";base64,").Length);
|
||||||
byte[] imageData = Convert.FromBase64String(onlyBase64Data);
|
byte[] imageData = Convert.FromBase64String(onlyBase64Data);
|
||||||
@@ -94,7 +92,7 @@ namespace ServerLib
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getImageType()
|
public string GetImageType()
|
||||||
{
|
{
|
||||||
Match match = Regex.Match(base64Data, "(?<=data:image/)[a-zA-Z]+(?=;base64)");
|
Match match = Regex.Match(base64Data, "(?<=data:image/)[a-zA-Z]+(?=;base64)");
|
||||||
return match.Success ? match.Groups[0].Value : "";
|
return match.Success ? match.Groups[0].Value : "";
|
||||||
@@ -105,21 +103,21 @@ namespace ServerLib
|
|||||||
|
|
||||||
#region songs
|
#region songs
|
||||||
|
|
||||||
public delegate SongInfo GetSongDelegate(int songId);
|
public delegate SOngInfo GetSongDelegate(int songId);
|
||||||
|
|
||||||
public delegate SongInfo[] GetAllSongsDelegate();
|
public delegate SOngInfo[] GetAllSongsDelegate();
|
||||||
|
|
||||||
public delegate int GetCurrentSongIdDelegate();
|
public delegate int GetCurrentSongIdDelegate();
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public struct SongInfo
|
public struct SOngInfo
|
||||||
{
|
{
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Title;
|
public string Title;
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Artist;
|
public string Artist;
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public Base64Image Cover;
|
public CBase64Image Cover;
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Genre { get; set; }
|
public string Genre { get; set; }
|
||||||
[DataMember]
|
[DataMember]
|
||||||
|
|||||||
@@ -1,35 +1,32 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ServerLib
|
namespace ServerLib
|
||||||
{
|
{
|
||||||
internal class Session
|
internal class CSession
|
||||||
{
|
{
|
||||||
Guid id;
|
readonly Guid _ID;
|
||||||
public Guid Id
|
public Guid Id
|
||||||
{
|
{
|
||||||
get { return id; }
|
get { return _ID; }
|
||||||
}
|
}
|
||||||
|
|
||||||
int profileId;
|
readonly int _ProfileId;
|
||||||
public int ProfileId
|
public int ProfileId
|
||||||
{
|
{
|
||||||
get { return profileId; }
|
get { return _ProfileId; }
|
||||||
}
|
}
|
||||||
|
|
||||||
UserRoles roles;
|
readonly EUserRoles _Roles;
|
||||||
internal UserRoles Roles
|
internal EUserRoles Roles
|
||||||
{
|
{
|
||||||
get { return roles; }
|
get { return _Roles; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Session(Guid id, int profileId, UserRoles roles)
|
public CSession(Guid id, int profileId, EUserRoles roles)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this._ID = id;
|
||||||
this.profileId = profileId;
|
this._ProfileId = profileId;
|
||||||
this.roles = roles;
|
this._Roles = roles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,69 +1,68 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ServerLib
|
namespace ServerLib
|
||||||
{
|
{
|
||||||
internal static class SessionControl
|
internal static class CSessionControl
|
||||||
{
|
{
|
||||||
private static Dictionary<Guid, Session> activeSessions = new Dictionary<Guid, Session>();
|
private static readonly Dictionary<Guid, CSession> _ActiveSessions = new Dictionary<Guid, CSession>();
|
||||||
|
|
||||||
public static Guid openSession(string userName, string password)
|
public static Guid OpenSession(string userName, string password)
|
||||||
{
|
{
|
||||||
if (!validateUserAndPassword(userName, password))
|
if (!_ValidateUserAndPassword(userName, password))
|
||||||
{
|
{
|
||||||
return Guid.Empty;
|
return Guid.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
Guid newId = Guid.NewGuid();
|
Guid newId = Guid.NewGuid();
|
||||||
int id = getProfileIdFormUsername(userName);
|
int id = _GetProfileIdFormUsername(userName);
|
||||||
UserRoles roles = getUserRoles(id);
|
EUserRoles roles = _GetUserRoles(id);
|
||||||
Session session = new Session(newId, id, roles);
|
CSession session = new CSession(newId, id, roles);
|
||||||
invalidateSessions(id);
|
InvalidateSessions(id);
|
||||||
activeSessions.Add(newId, session);
|
_ActiveSessions.Add(newId, session);
|
||||||
|
|
||||||
return newId;
|
return newId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool validateUserAndPassword(string userName, string password)
|
private static bool _ValidateUserAndPassword(string userName, string password)
|
||||||
{
|
{
|
||||||
return CServer.ValidatePassword(getProfileIdFormUsername(userName), password);
|
return CServer.ValidatePassword(_GetProfileIdFormUsername(userName), password);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getProfileIdFormUsername(string username)
|
private static int _GetProfileIdFormUsername(string username)
|
||||||
{
|
{
|
||||||
return CServer.GetUserIdFromUsername(username);
|
return CServer.GetUserIdFromUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UserRoles getUserRoles(int profileId)
|
private static EUserRoles _GetUserRoles(int profileId)
|
||||||
{
|
{
|
||||||
return (UserRoles)CServer.GetUserRole(profileId);
|
return (EUserRoles)CServer.GetUserRole(profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void invalidateSessions(int profileId)
|
internal static void InvalidateSessions(int profileId)
|
||||||
{
|
{
|
||||||
foreach (var s in (from kv in activeSessions
|
foreach (var s in (from kv in _ActiveSessions
|
||||||
where kv.Value.ProfileId == profileId
|
where kv.Value.ProfileId == profileId
|
||||||
select kv).ToList())
|
select kv).ToList())
|
||||||
{
|
{
|
||||||
activeSessions.Remove(s.Key);
|
_ActiveSessions.Remove(s.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool requestRight(Guid sessionId, UserRights requestedRight)
|
internal static bool RequestRight(Guid sessionId, EUserRights requestedRight)
|
||||||
{
|
{
|
||||||
return ((UserRoleControl.getUserRightsFromUserRole(activeSessions[sessionId].Roles) & requestedRight) != 0);
|
return ((CUserRoleControl.GetUserRightsFromUserRole(_ActiveSessions[sessionId].Roles) & requestedRight) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static int getUserIdFromSession(Guid sessionId)
|
internal static int GetUserIdFromSession(Guid sessionId)
|
||||||
{
|
{
|
||||||
if (!activeSessions.ContainsKey(sessionId))
|
if (!_ActiveSessions.ContainsKey(sessionId))
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return activeSessions[sessionId].ProfileId;
|
return _ActiveSessions[sessionId].ProfileId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ServerLib
|
namespace ServerLib
|
||||||
{
|
{
|
||||||
[Flags]
|
[Flags]
|
||||||
internal enum UserRights
|
internal enum EUserRights
|
||||||
{
|
{
|
||||||
None = 0x00,
|
None = 0x00,
|
||||||
EditAllProfiles = 0x01,
|
EditAllProfiles = 0x01,
|
||||||
|
|||||||
@@ -1,35 +1,28 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ServerLib
|
namespace ServerLib
|
||||||
{
|
{
|
||||||
internal static class UserRoleControl
|
internal static class CUserRoleControl
|
||||||
{
|
{
|
||||||
private static Dictionary<UserRoles, UserRights> roleRightsMapping = new Dictionary<UserRoles, UserRights> {
|
private static readonly Dictionary<EUserRoles, EUserRights> _RoleRightsMapping = new Dictionary<EUserRoles, EUserRights> {
|
||||||
{UserRoles.Administrator,
|
{EUserRoles.Administrator,
|
||||||
(UserRights.EditAllProfiles|
|
(EUserRights.EditAllProfiles|
|
||||||
UserRights.UploadPhotos|
|
EUserRights.UploadPhotos|
|
||||||
UserRights.ViewOtherProfiles)|
|
EUserRights.ViewOtherProfiles)|
|
||||||
UserRights.UseKeyboard},
|
EUserRights.UseKeyboard},
|
||||||
{UserRoles.AuthenticatedUser,
|
{EUserRoles.AuthenticatedUser,
|
||||||
(UserRights.UploadPhotos|
|
(EUserRights.UploadPhotos|
|
||||||
UserRights.ViewOtherProfiles|
|
EUserRights.ViewOtherProfiles|
|
||||||
UserRights.UseKeyboard)}
|
EUserRights.UseKeyboard)}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
internal static UserRights getUserRightsFromUserRole(UserRoles userRole)
|
internal static EUserRights GetUserRightsFromUserRole(EUserRoles userRole)
|
||||||
{
|
{
|
||||||
UserRights resultRights = UserRights.None;
|
return _RoleRightsMapping.Where(role => userRole.HasFlag(role.Key))
|
||||||
|
.Select(role => role.Value)
|
||||||
foreach (UserRights r in roleRightsMapping.Where(role => userRole.HasFlag(role.Key)).Select(role => role.Value))
|
.Aggregate(EUserRights.None, (current, r) => current | r);
|
||||||
{
|
|
||||||
resultRights |= r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultRights;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace ServerLib
|
namespace ServerLib
|
||||||
{
|
{
|
||||||
[Flags]
|
[Flags]
|
||||||
internal enum UserRoles
|
internal enum EUserRoles
|
||||||
{
|
{
|
||||||
AuthenticatedUser = 0x00,
|
AuthenticatedUser = 0x00,
|
||||||
Administrator = 0x01
|
Administrator = 0x01
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -48,21 +46,21 @@ namespace Vocaluxe.Base.Server
|
|||||||
_Server = new CServer(CConfig.ServerPort, CConfig.ServerEncryption == EOffOn.TR_CONFIG_ON);
|
_Server = new CServer(CConfig.ServerPort, CConfig.ServerEncryption == EOffOn.TR_CONFIG_ON);
|
||||||
//TODO: remove CConfig.ServerPassword
|
//TODO: remove CConfig.ServerPassword
|
||||||
|
|
||||||
CServer.SendKeyEvent = sendKeyEvent;
|
CServer.SendKeyEvent = _SendKeyEvent;
|
||||||
CServer.GetProfileData = getProfileData;
|
CServer.GetProfileData = _GetProfileData;
|
||||||
CServer.SendProfileData = sendProfileData;
|
CServer.SendProfileData = _SendProfileData;
|
||||||
CServer.GetProfileList = getProfileList;
|
CServer.GetProfileList = _GetProfileList;
|
||||||
CServer.SendPhoto = sendPhoto;
|
CServer.SendPhoto = _SendPhoto;
|
||||||
CServer.GetSiteFile = getSiteFile;
|
CServer.GetSiteFile = _GetSiteFile;
|
||||||
CServer.GetSong = getSong;
|
CServer.GetSong = _GetSong;
|
||||||
CServer.GetAllSongs = getAllSongs;
|
CServer.GetAllSongs = _GetAllSongs;
|
||||||
CServer.GetCurrentSongId = getCurrentSongId;
|
CServer.GetCurrentSongId = _GetCurrentSongId;
|
||||||
CServer.SetPassword = setPassword;
|
CServer.SetPassword = _SetPassword;
|
||||||
CServer.ValidatePassword = validatePassword;
|
CServer.ValidatePassword = _ValidatePassword;
|
||||||
CServer.GetUserRole = getUserRole;
|
CServer.GetUserRole = _GetUserRole;
|
||||||
CServer.SetUserRole = setUserRole;
|
CServer.SetUserRole = _SetUserRole;
|
||||||
CServer.GetUserIdFromUsername = getUserIdFromUsername;
|
CServer.GetUserIdFromUsername = _GetUserIdFromUsername;
|
||||||
CServer.GetDelayedImage = getDelayedImage;
|
CServer.GetDelayedImage = _GetDelayedImage;
|
||||||
|
|
||||||
_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword);
|
_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword);
|
||||||
Controller.Init();
|
Controller.Init();
|
||||||
@@ -84,7 +82,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
_Clients = new Dictionary<int, CClientHandler>();
|
_Clients = new Dictionary<int, CClientHandler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool sendKeyEvent(string key)
|
private static bool _SendKeyEvent(string key)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (key != null && key != "")
|
if (key != null && key != "")
|
||||||
@@ -155,17 +153,17 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
#region profile
|
#region profile
|
||||||
|
|
||||||
private static ProfileData getProfileData(int profileId, bool isReadonly)
|
private static SProfileData _GetProfileData(int profileId, bool isReadonly)
|
||||||
{
|
{
|
||||||
CProfile profile = CProfiles.GetProfile(profileId);
|
CProfile profile = CProfiles.GetProfile(profileId);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
{
|
{
|
||||||
return new ProfileData();
|
return new SProfileData();
|
||||||
}
|
}
|
||||||
return CreateProfileData(profile, isReadonly); ;
|
return _CreateProfileData(profile, isReadonly);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool sendProfileData(ProfileData profile)
|
private static bool _SendProfileData(SProfileData profile)
|
||||||
{
|
{
|
||||||
CProfile newProfile;
|
CProfile newProfile;
|
||||||
CProfile existingProfile = CProfiles.GetProfile(profile.ProfileId);
|
CProfile existingProfile = CProfiles.GetProfile(profile.ProfileId);
|
||||||
@@ -206,11 +204,11 @@ namespace Vocaluxe.Base.Server
|
|||||||
newProfile.Avatar = avatar;*/
|
newProfile.Avatar = avatar;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile.PlayerName != null && profile.PlayerName != "")
|
if (!string.IsNullOrEmpty(profile.PlayerName))
|
||||||
{
|
{
|
||||||
newProfile.PlayerName = profile.PlayerName;
|
newProfile.PlayerName = profile.PlayerName;
|
||||||
}
|
}
|
||||||
else if (newProfile.PlayerName != null && newProfile.PlayerName != "")
|
else if (!string.IsNullOrEmpty(newProfile.PlayerName))
|
||||||
{
|
{
|
||||||
newProfile.PlayerName = "DummyName";
|
newProfile.PlayerName = "DummyName";
|
||||||
}
|
}
|
||||||
@@ -237,41 +235,39 @@ namespace Vocaluxe.Base.Server
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProfileData[] getProfileList()
|
private static SProfileData[] _GetProfileList()
|
||||||
{
|
{
|
||||||
List<ProfileData> result = new List<ProfileData>(CProfiles.NumProfiles);
|
List<SProfileData> result = new List<SProfileData>(CProfiles.NumProfiles);
|
||||||
|
|
||||||
foreach (CProfile profile in CProfiles.GetProfiles())
|
result.AddRange(CProfiles.GetProfiles().Select(profile => _CreateProfileData(profile, true)));
|
||||||
{
|
|
||||||
result.Add(CreateProfileData(profile, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProfileData CreateProfileData(CProfile profile, bool isReadonly)
|
private static SProfileData _CreateProfileData(CProfile profile, bool isReadonly)
|
||||||
{
|
{
|
||||||
ProfileData profileData = new ProfileData();
|
SProfileData profileData = new SProfileData
|
||||||
|
{
|
||||||
|
IsEditable = !isReadonly,
|
||||||
|
ProfileId = profile.ID,
|
||||||
|
PlayerName = profile.PlayerName,
|
||||||
|
Type = (int)profile.GuestProfile,
|
||||||
|
Difficulty = (int)profile.Difficulty
|
||||||
|
};
|
||||||
|
|
||||||
profileData.IsEditable = !isReadonly;
|
|
||||||
profileData.ProfileId = profile.ID;
|
|
||||||
profileData.PlayerName = profile.PlayerName;
|
|
||||||
profileData.Type = (int)profile.GuestProfile;
|
|
||||||
profileData.Difficulty = (int)profile.Difficulty;
|
|
||||||
CAvatar avatar = profile.Avatar;
|
CAvatar avatar = profile.Avatar;
|
||||||
if (avatar != null)
|
if (avatar != null)
|
||||||
{
|
{
|
||||||
if (File.Exists(avatar.FileName))
|
if (File.Exists(avatar.FileName))
|
||||||
{
|
{
|
||||||
profileData.Avatar = new Base64Image(createDelayedImage(avatar.FileName));
|
profileData.Avatar = new CBase64Image(_CreateDelayedImage(avatar.FileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return profileData;
|
return profileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CAvatar _AddAvatar(Base64Image avatarData)
|
private static CAvatar _AddAvatar(CBase64Image avatarData)
|
||||||
{
|
{
|
||||||
string result = String.Empty;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string filename = _SaveImage(avatarData, "snapshot", CSettings.FolderProfiles);
|
string filename = _SaveImage(avatarData, "snapshot", CSettings.FolderProfiles);
|
||||||
@@ -282,10 +278,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
CProfiles.AddAvatar(avatar);
|
CProfiles.AddAvatar(avatar);
|
||||||
return avatar;
|
return avatar;
|
||||||
}
|
}
|
||||||
else
|
return null;
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -297,7 +290,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
#region photo
|
#region photo
|
||||||
|
|
||||||
private static bool sendPhoto(PhotoData photoData)
|
private static bool _SendPhoto(SPhotoData photoData)
|
||||||
{
|
{
|
||||||
if (photoData.Photo == null)
|
if (photoData.Photo == null)
|
||||||
{
|
{
|
||||||
@@ -307,16 +300,16 @@ namespace Vocaluxe.Base.Server
|
|||||||
string name = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
|
string name = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
|
||||||
string filePath = _SaveImage(photoData.Photo, name, CSettings.FolderPhotos);
|
string filePath = _SaveImage(photoData.Photo, name, CSettings.FolderPhotos);
|
||||||
|
|
||||||
return (filePath != null && filePath != "");
|
return !string.IsNullOrEmpty(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region website
|
#region website
|
||||||
|
|
||||||
private static Dictionary<string, string> delayedImagePath = new Dictionary<string, string>();
|
private static readonly Dictionary<string, string> _DelayedImagePath = new Dictionary<string, string>();
|
||||||
|
|
||||||
private static byte[] getSiteFile(string filename)
|
private static byte[] _GetSiteFile(string filename)
|
||||||
{
|
{
|
||||||
string path = "Website/" + filename;
|
string path = "Website/" + filename;
|
||||||
path = path.Replace("..", "");
|
path = path.Replace("..", "");
|
||||||
@@ -336,7 +329,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
return File.ReadAllBytes(path);
|
return File.ReadAllBytes(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string createDelayedImage(string filename)
|
private static string _CreateDelayedImage(string filename)
|
||||||
{
|
{
|
||||||
byte[] by = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(filename));
|
byte[] by = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(filename));
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
@@ -347,52 +340,48 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
string hashedFilename = sb.ToString();
|
string hashedFilename = sb.ToString();
|
||||||
|
|
||||||
if (!delayedImagePath.ContainsKey(hashedFilename))
|
if (!_DelayedImagePath.ContainsKey(hashedFilename))
|
||||||
{
|
{
|
||||||
delayedImagePath.Add(hashedFilename, filename);
|
_DelayedImagePath.Add(hashedFilename, filename);
|
||||||
}
|
}
|
||||||
return hashedFilename;
|
return hashedFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Base64Image getDelayedImage(string hashedFilename)
|
private static CBase64Image _GetDelayedImage(string hashedFilename)
|
||||||
{
|
{
|
||||||
if (!delayedImagePath.ContainsKey(hashedFilename))
|
if (!_DelayedImagePath.ContainsKey(hashedFilename))
|
||||||
{
|
{
|
||||||
throw new FileNotFoundException("Image not found");
|
throw new FileNotFoundException("Image not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
string fileName = delayedImagePath[hashedFilename];
|
string fileName = _DelayedImagePath[hashedFilename];
|
||||||
|
|
||||||
if (File.Exists(fileName))
|
if (File.Exists(fileName))
|
||||||
{
|
{
|
||||||
Image image = Image.FromFile(fileName);
|
Image image = Image.FromFile(fileName);
|
||||||
return new Base64Image(image, image.RawFormat);
|
return new CBase64Image(image, image.RawFormat);
|
||||||
}
|
}
|
||||||
else
|
throw new FileNotFoundException("Image not found");
|
||||||
{
|
|
||||||
throw new FileNotFoundException("Image not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region songs
|
#region songs
|
||||||
|
|
||||||
private static SongInfo getSong(int songId)
|
private static SOngInfo _GetSong(int songId)
|
||||||
{
|
{
|
||||||
CSong song = CSongs.GetSong(songId);
|
CSong song = CSongs.GetSong(songId);
|
||||||
return getSongInfo(song, true);
|
return _GetSongInfo(song, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SongInfo[] getAllSongs()
|
private static SOngInfo[] _GetAllSongs()
|
||||||
{
|
{
|
||||||
var songs = CSongs.Songs;
|
var songs = CSongs.Songs;
|
||||||
return (from s in songs
|
return (from s in songs
|
||||||
select getSongInfo(s, false)).ToArray<SongInfo>();
|
select _GetSongInfo(s, false)).ToArray<SOngInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getCurrentSongId()
|
private static int _GetCurrentSongId()
|
||||||
{
|
{
|
||||||
CSong song = CGame.GetSong();
|
CSong song = CGame.GetSong();
|
||||||
if (song == null)
|
if (song == null)
|
||||||
@@ -402,9 +391,9 @@ namespace Vocaluxe.Base.Server
|
|||||||
return song.ID;
|
return song.ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SongInfo getSongInfo(CSong song, bool includeCover)
|
private static SOngInfo _GetSongInfo(CSong song, bool includeCover)
|
||||||
{
|
{
|
||||||
SongInfo result = new SongInfo();
|
SOngInfo result = new SOngInfo();
|
||||||
if (song != null)
|
if (song != null)
|
||||||
{
|
{
|
||||||
result.Title = song.Title;
|
result.Title = song.Title;
|
||||||
@@ -416,7 +405,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
result.SongId = song.ID;
|
result.SongId = song.ID;
|
||||||
if (includeCover)
|
if (includeCover)
|
||||||
{
|
{
|
||||||
result.Cover = new Base64Image(createDelayedImage(song.Folder + "\\" + song.CoverFileName));
|
result.Cover = new CBase64Image(_CreateDelayedImage(song.Folder + "\\" + song.CoverFileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -426,7 +415,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
#region user management
|
#region user management
|
||||||
|
|
||||||
private static void setPassword(int profileId, string newPassword)
|
private static void _SetPassword(int profileId, string newPassword)
|
||||||
{
|
{
|
||||||
CProfile profile = CProfiles.GetProfile(profileId);
|
CProfile profile = CProfiles.GetProfile(profileId);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
@@ -438,13 +427,13 @@ namespace Vocaluxe.Base.Server
|
|||||||
byte[] buffer = new byte[128];
|
byte[] buffer = new byte[128];
|
||||||
rng.GetNonZeroBytes(buffer);
|
rng.GetNonZeroBytes(buffer);
|
||||||
byte[] salt = buffer;
|
byte[] salt = buffer;
|
||||||
byte[] hashedPassword = hash((new System.Text.UTF8Encoding()).GetBytes(newPassword), salt);
|
byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(newPassword), salt);
|
||||||
|
|
||||||
profile.PasswordSalt = salt;
|
profile.PasswordSalt = salt;
|
||||||
profile.PasswordHash = hashedPassword;
|
profile.PasswordHash = hashedPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool validatePassword(int profileId, string password)
|
private static bool _ValidatePassword(int profileId, string password)
|
||||||
{
|
{
|
||||||
CProfile profile = CProfiles.GetProfile(profileId);
|
CProfile profile = CProfiles.GetProfile(profileId);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
@@ -454,21 +443,18 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
if (profile.PasswordHash == null)
|
if (profile.PasswordHash == null)
|
||||||
{
|
{
|
||||||
if (password == "" || password == null)
|
if (string.IsNullOrEmpty(password))
|
||||||
{
|
{
|
||||||
return true; //Allow emty passwords
|
return true; //Allow emty passwords
|
||||||
}
|
}
|
||||||
else
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] salt = profile.PasswordSalt;
|
byte[] salt = profile.PasswordSalt;
|
||||||
return hash((new System.Text.UTF8Encoding()).GetBytes(password), salt).SequenceEqual(profile.PasswordHash);
|
return _Hash((new UTF8Encoding()).GetBytes(password), salt).SequenceEqual(profile.PasswordHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool validatePassword(int profileId, byte[] hashedPassword)
|
private static bool _ValidatePassword(int profileId, byte[] hashedPassword)
|
||||||
{
|
{
|
||||||
CProfile profile = CProfiles.GetProfile(profileId);
|
CProfile profile = CProfiles.GetProfile(profileId);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
@@ -482,17 +468,14 @@ namespace Vocaluxe.Base.Server
|
|||||||
{
|
{
|
||||||
return true; //Allow emty passwords
|
return true; //Allow emty passwords
|
||||||
}
|
}
|
||||||
else
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] salt = profile.PasswordSalt;
|
byte[] salt = profile.PasswordSalt;
|
||||||
return hashedPassword.SequenceEqual(profile.PasswordHash);
|
return hashedPassword.SequenceEqual(profile.PasswordHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] getPassowordSalt(int profileId)
|
private static byte[] _GetPassowordSalt(int profileId)
|
||||||
{
|
{
|
||||||
CProfile profile = CProfiles.GetProfile(profileId);
|
CProfile profile = CProfiles.GetProfile(profileId);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
@@ -508,7 +491,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
return profile.PasswordSalt;
|
return profile.PasswordSalt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getUserRole(int profileId)
|
private static int _GetUserRole(int profileId)
|
||||||
{
|
{
|
||||||
CProfile profile = CProfiles.GetProfile(profileId);
|
CProfile profile = CProfiles.GetProfile(profileId);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
@@ -519,7 +502,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
return profile.UserRoles;
|
return profile.UserRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setUserRole(int profileId, int userRole)
|
private static void _SetUserRole(int profileId, int userRole)
|
||||||
{
|
{
|
||||||
CProfile profile = CProfiles.GetProfile(profileId);
|
CProfile profile = CProfiles.GetProfile(profileId);
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
@@ -530,12 +513,12 @@ namespace Vocaluxe.Base.Server
|
|||||||
profile.UserRoles = userRole;
|
profile.UserRoles = userRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getUserIdFromUsername(string username)
|
private static int _GetUserIdFromUsername(string username)
|
||||||
{
|
{
|
||||||
var playerIds = (from p in CProfiles.GetProfiles()
|
var playerIds = (from p in CProfiles.GetProfiles()
|
||||||
where String.Equals(p.PlayerName, username, StringComparison.OrdinalIgnoreCase)
|
where String.Equals(p.PlayerName, username, StringComparison.OrdinalIgnoreCase)
|
||||||
select p.ID);
|
select p.ID);
|
||||||
if (playerIds.Count() == 0)
|
if (!playerIds.Any())
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Invalid playername");
|
throw new ArgumentException("Invalid playername");
|
||||||
}
|
}
|
||||||
@@ -543,7 +526,7 @@ namespace Vocaluxe.Base.Server
|
|||||||
return playerIds.First();
|
return playerIds.First();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] hash(byte[] password, byte[] salt)
|
private static byte[] _Hash(byte[] password, byte[] salt)
|
||||||
{
|
{
|
||||||
HashAlgorithm hashAlgo = new SHA256Managed();
|
HashAlgorithm hashAlgo = new SHA256Managed();
|
||||||
|
|
||||||
@@ -557,12 +540,10 @@ namespace Vocaluxe.Base.Server
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private static string _SaveImage(CBase64Image imageDate, string name, string folder)
|
||||||
|
|
||||||
private static string _SaveImage(Base64Image imageDate, string name, string folder)
|
|
||||||
{
|
{
|
||||||
Image avatarImage = imageDate.getImage();
|
Image avatarImage = imageDate.GetImage();
|
||||||
string extension = imageDate.getImageType();
|
string extension = imageDate.GetImageType();
|
||||||
|
|
||||||
string filename = Path.Combine(folder, name);
|
string filename = Path.Combine(folder, name);
|
||||||
if (File.Exists(filename + "." + extension))
|
if (File.Exists(filename + "." + extension))
|
||||||
|
|||||||
Reference in new issue
Block a user