Skip to content

Commit

Permalink
Работа с сервером. Попытка с RSA
Browse files Browse the repository at this point in the history
  • Loading branch information
MilkRen committed May 14, 2024
1 parent 35521b3 commit 30eceae
Show file tree
Hide file tree
Showing 29 changed files with 900 additions and 305 deletions.
12 changes: 12 additions & 0 deletions LauncherDM/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="LauncherDM.Properties.SettingsApp" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="LauncherDM.Source.Settings.SettingsApp" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<LauncherDM.Properties.SettingsApp>
<setting name="Ip" serializeAs="String">
<value>127.0.0.1</value>
</setting>
<setting name="Port" serializeAs="String">
<value>25590</value>
</setting>
<setting name="Token" serializeAs="String">
<value />
</setting>
</LauncherDM.Properties.SettingsApp>
<LauncherDM.Source.Settings.SettingsApp>
<setting name="AccessToken" serializeAs="String">
<value />
Expand Down
11 changes: 10 additions & 1 deletion LauncherDM/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions LauncherDM/Properties/Resources.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@
<data name="ForgotPassword" xml:space="preserve">
<value>Forgot password</value>
</data>
<data name="Email" xml:space="preserve">
<value>Email</value>
</data>
</root>
3 changes: 3 additions & 0 deletions LauncherDM/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,7 @@
<data name="ForgotPassword" xml:space="preserve">
<value>Забыли пароль</value>
</data>
<data name="Email" xml:space="preserve">
<value>Почта</value>
</data>
</root>
36 changes: 36 additions & 0 deletions LauncherDM/Properties/SettingsApp.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions LauncherDM/Properties/SettingsApp.settings
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="LauncherDM.Properties" GeneratedClassName="SettingsApp">
<Profiles />
<Settings>
<Setting Name="Ip" Type="System.String" Scope="User">
<Value Profile="(Default)">127.0.0.1</Value>
</Setting>
<Setting Name="Port" Type="System.String" Scope="User">
<Value Profile="(Default)">25590</Value>
</Setting>
<Setting Name="Token" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
28 changes: 28 additions & 0 deletions LauncherDM/Services/AuthorizationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using LauncherDM.Services.Interfaces;
using ServerTCP;
using ServerTCP.Сryptographies;

namespace LauncherDM.Services
{
internal class AuthorizationService : IAuthorizationService
{
private IServerRequestService _serverRequest;
public bool Authorization(string login, string password)
{
//var requestPublicKey = _serverRequest.SendMessageRequest(MessageHeader.MessageType.PublicKey);
//var publicKey = requestPublicKey.Message.ToString();

var data = string.Concat(login, ",", password);
//var cryptMessage = CryptoRsa.Encrypt(publicKey, data);
//var requestToken = _serverRequest.SendMessageRequest(cryptMessage, MessageHeader.MessageType.Login);

var requestToken = _serverRequest.SendMessageRequest(data, MessageHeader.MessageType.Login);
return false;
}

public AuthorizationService()
{
_serverRequest = new ServerRequestService();
}
}
}
2 changes: 1 addition & 1 deletion LauncherDM/Services/DialogWindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void OpenWindow(object viewModel)
authorization.Show();
return;
}
else if (viewModel is AuthorizationWindowViewModel)
else if (viewModel is AccountUserControlViewModel or AuthorizationWindowViewModel)
{
var regAndLogWindow = new RegAndLogWindow();
regAndLogWindow.DataContext = new RegAndLogWindowViewModel(new ToolbarToWindowViewModel(new WindowService(regAndLogWindow)),
Expand Down
7 changes: 7 additions & 0 deletions LauncherDM/Services/Interfaces/IAuthorizationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace LauncherDM.Services.Interfaces
{
internal interface IAuthorizationService
{
bool Authorization(string login, string password);
}
}
6 changes: 6 additions & 0 deletions LauncherDM/Services/Interfaces/IRegAndLogWindowService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LauncherDM.Services.Interfaces
{
interface IRegAndLogWindowService
{
}
}
10 changes: 3 additions & 7 deletions LauncherDM/Services/Interfaces/IServerRequestService.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using ServerTCP;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ServerTCP.MessageLanguages;

namespace LauncherDM.Services.Interfaces
{
interface IServerRequestService
{
public MessageHeader SendMessageRequest(string data, MessageHeader.MessageType messageType, int length);
public MessageHeader SendMessageRequest(object data, MessageHeader.MessageType messageType, bool loadToken = false);

public MessageHeader SendMessageRequest(MessageHeader.MessageType messageType);
public MessageHeader SendMessageRequest(MessageHeader.MessageType messageType, bool loadToken = false);
}
}
12 changes: 12 additions & 0 deletions LauncherDM/Services/Interfaces/IWindowAnimationsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LauncherDM.Services.Interfaces
{
interface IWindowAnimationsService
{
}
}
3 changes: 1 addition & 2 deletions LauncherDM/Services/LoadingWindowService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Reflection;
using System.Reflection;
using LauncherDM.Services.Interfaces;
using ServerTCP;

Expand Down
8 changes: 8 additions & 0 deletions LauncherDM/Services/RegAndLogWindowServiceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using LauncherDM.Services.Interfaces;

namespace LauncherDM.Services
{
class RegAndLogWindowServiceService : IRegAndLogWindowService
{
}
}
41 changes: 16 additions & 25 deletions LauncherDM/Services/ServerRequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Windows.Markup;
using ServerTCP;
using LauncherDM.Properties;
using static ServerTCP.MessageLanguages;

namespace LauncherDM.Services
{
Expand All @@ -14,19 +14,16 @@ namespace LauncherDM.Services
/// </summary>
class ServerRequestService : IServerRequestService
{
private static readonly string _ip = DataInfo.Ip;
private static readonly int _port = DataInfo.Port;

private IPAddress _ipAddress;
private IPEndPoint _endPoint;

public ServerRequestService()
{
_ipAddress = IPAddress.Parse(_ip);
_endPoint = new IPEndPoint(_ipAddress, _port);
_ipAddress = IPAddress.Parse(SettingsApp.Default.Ip);
_endPoint = new IPEndPoint(_ipAddress, int.Parse(SettingsApp.Default.Port));
}

public MessageHeader SendMessageRequest(string data, MessageHeader.MessageType messageType, int length)
public MessageHeader SendMessageRequest(object data, MessageHeader.MessageType messageType, bool loadToken = false)
{
TcpClient tcpClient = null;
try
Expand All @@ -36,31 +33,25 @@ public MessageHeader SendMessageRequest(string data, MessageHeader.MessageType m
tcpClient = new TcpClient();
tcpClient.Connect(_endPoint);

var messageHeader = new MessageHeader(data, messageType);
byte[] headerBytes = messageHeader.MessageToArray();

var messageHeader = new MessageHeader(data, messageType, MessageLanguages.Language);
byte[] headerBytes = messageHeader.MessageToArray(loadToken);
NetworkStream tcpStream = tcpClient.GetStream();
tcpStream.Write(headerBytes);

do
{
byte[] getBytes = new byte[tcpClient.ReceiveBufferSize];
tcpStream.Read(getBytes, 0, tcpClient.ReceiveBufferSize);
var defaultData = getBytes.Skip(1).Take(5);
var size = 0;
foreach (var sizeData in defaultData)
size += sizeData;
getBytes = getBytes.Take(size + MessageHeader.LengthAndDataType).ToArray();
return MessageHeader.FromArray(getBytes);
var getBytes = new byte[tcpClient.ReceiveBufferSize];
var lengthByte = tcpStream.Read(getBytes, 0, tcpClient.ReceiveBufferSize);
return MessageHeader.FromArray(getBytes.Take(lengthByte).ToArray());
} while (tcpStream.DataAvailable);
}

}
catch (Exception e)
{
//IResourcesHelperService resourcesHelper = new ResourcesHelperService();
IDialogMessageBoxService dialogMessageBox = new DialogMessageBoxService();
dialogMessageBox.DialogShow("Error Server Reques", "Error Server Reques");
////IResourcesHelperService resourcesHelper = new ResourcesHelperService();
//IDialogMessageBoxService dialogMessageBox = new DialogMessageBoxService();
//dialogMessageBox.DialogShow("Error Server Reques", "Error Server Reques");
return null;
}
finally
Expand All @@ -69,7 +60,7 @@ public MessageHeader SendMessageRequest(string data, MessageHeader.MessageType m
}
}

public MessageHeader SendMessageRequest(MessageHeader.MessageType messageType)
public MessageHeader SendMessageRequest(MessageHeader.MessageType messageType, bool loadToken = false)
{
TcpClient tcpClient = null;
try
Expand All @@ -79,8 +70,8 @@ public MessageHeader SendMessageRequest(MessageHeader.MessageType messageType)
tcpClient = new TcpClient();
tcpClient.Connect(_endPoint);

var messageHeader = new MessageHeader(messageType);
byte[] headerBytes = messageHeader.MessageToArray();
var messageHeader = new MessageHeader(messageType, MessageLanguages.Language);
byte[] headerBytes = messageHeader.MessageToArray(loadToken);
NetworkStream tcpStream = tcpClient.GetStream();
tcpStream.Write(headerBytes);

Expand Down
13 changes: 13 additions & 0 deletions LauncherDM/Services/WindowAnimationsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using LauncherDM.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LauncherDM.Services
{
class WindowAnimationsService : IWindowAnimationsService
{
}
}
Loading

0 comments on commit 30eceae

Please sign in to comment.