Develop #10
@@ -10,7 +10,7 @@ using Util;
|
|||||||
namespace ClientApp.Utils
|
namespace ClientApp.Utils
|
||||||
{
|
{
|
||||||
public delegate void EngineCallback();
|
public delegate void EngineCallback();
|
||||||
public class Client : IDataReceiver
|
public class Client : IDataReceiver, IDisposable
|
||||||
{
|
{
|
||||||
public EngineCallback engineConnectFailed;
|
public EngineCallback engineConnectFailed;
|
||||||
public EngineCallback engineConnectSuccess;
|
public EngineCallback engineConnectSuccess;
|
||||||
@@ -87,6 +87,10 @@ namespace ClientApp.Utils
|
|||||||
/// <param name="ar">the result of the async read</param>
|
/// <param name="ar">the result of the async read</param>
|
||||||
private void OnRead(IAsyncResult ar)
|
private void OnRead(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
|
if (ar == null || (!ar.IsCompleted))
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
int receivedBytes = this.stream.EndRead(ar);
|
int receivedBytes = this.stream.EndRead(ar);
|
||||||
|
|
||||||
if (totalBufferReceived + receivedBytes > 1024)
|
if (totalBufferReceived + receivedBytes > 1024)
|
||||||
@@ -122,7 +126,7 @@ namespace ClientApp.Utils
|
|||||||
this.LoginViewModel.setLoginStatus(true);
|
this.LoginViewModel.setLoginStatus(true);
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
initEngine();
|
initEngine();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -224,7 +228,7 @@ namespace ClientApp.Utils
|
|||||||
/// <param name="bytes">the message</param>
|
/// <param name="bytes">the message</param>
|
||||||
public void Bike(byte[] bytes)
|
public void Bike(byte[] bytes)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!sessionRunning)
|
if (!sessionRunning)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -266,7 +270,7 @@ namespace ClientApp.Utils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void tryLogin(string username, string password)
|
public void tryLogin(string username, string password)
|
||||||
{
|
{
|
||||||
|
|
||||||
string hashPassword = Util.Hasher.HashString(password);
|
string hashPassword = Util.Hasher.HashString(password);
|
||||||
|
|
||||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, hashPassword));
|
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, hashPassword));
|
||||||
@@ -288,5 +292,13 @@ namespace ClientApp.Utils
|
|||||||
{
|
{
|
||||||
this.LoginViewModel = loginViewModel;
|
this.LoginViewModel = loginViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Debug.WriteLine("client dispose called");
|
||||||
|
this.stream.Dispose();
|
||||||
|
this.client.Dispose();
|
||||||
|
this.handler.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,8 @@ namespace ClientApp.ViewModels
|
|||||||
this.MenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(this.mWindow, GetMousePosition()));
|
this.MenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(this.mWindow, GetMousePosition()));
|
||||||
|
|
||||||
var resizer = new WindowResizer(this.mWindow);
|
var resizer = new WindowResizer(this.mWindow);
|
||||||
|
|
||||||
|
this.mWindow.Closed += (sender, e) => this.client.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,4 +13,26 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Page Include="$(MSBuildThisFileDirectory)Styles\Buttons.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="$(MSBuildThisFileDirectory)Styles\Colors.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="$(MSBuildThisFileDirectory)Styles\Fonts.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="$(MSBuildThisFileDirectory)Styles\Texts.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
<Page Include="$(MSBuildThisFileDirectory)Styles\Windows.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -34,14 +34,16 @@ namespace Server
|
|||||||
|
|
||||||
private void OnRead(IAsyncResult ar)
|
private void OnRead(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
|
if (ar == null || (!ar.IsCompleted))
|
||||||
|
return;
|
||||||
|
|
||||||
int receivedBytes = this.stream.EndRead(ar);
|
int receivedBytes = this.stream.EndRead(ar);
|
||||||
|
|
||||||
if (totalBufferReceived + receivedBytes > 1024)
|
if (totalBufferReceived + receivedBytes > 1024)
|
||||||
if (totalBufferReceived + receivedBytes > 1024)
|
if (totalBufferReceived + receivedBytes > 1024)
|
||||||
{
|
{
|
||||||
throw new OutOfMemoryException("buffer too small");
|
throw new OutOfMemoryException("buffer too small");
|
||||||
}
|
}
|
||||||
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
|
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes);
|
||||||
totalBufferReceived += receivedBytes;
|
totalBufferReceived += receivedBytes;
|
||||||
|
|
||||||
@@ -209,7 +211,7 @@ namespace Server
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user