Skip to content

Commit

Permalink
Json sender fixed for modern networking.
Browse files Browse the repository at this point in the history
  • Loading branch information
crowbarmaster committed Sep 16, 2021
1 parent 9712278 commit 45cb1ea
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
44 changes: 34 additions & 10 deletions BedrockService/Client/BedrockService.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
Expand Down Expand Up @@ -52,11 +67,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Forms\editPermWhitelist.cs">
<Compile Include="Forms\PlayerManagerForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\editPermWhitelist.Designer.cs">
<DependentUpon>editPermWhitelist.cs</DependentUpon>
<Compile Include="Forms\PlayerManagerForm.Designer.cs">
<DependentUpon>PlayerManagerForm.cs</DependentUpon>
</Compile>
<Compile Include="Management\FormManager.cs" />
<Compile Include="Management\LogManager.cs" />
Expand All @@ -76,8 +91,8 @@
<Compile Include="Utilities\Utilities.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Networking\TCPClient.cs" />
<EmbeddedResource Include="Forms\editPermWhitelist.resx">
<DependentUpon>editPermWhitelist.cs</DependentUpon>
<EmbeddedResource Include="Forms\PlayerManagerForm.resx">
<DependentUpon>PlayerManagerForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\EditSrv.resx">
<DependentUpon>EditSrv.cs</DependentUpon>
Expand All @@ -95,9 +110,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<AdditionalFiles Include="Configs\Config.conf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
<AdditionalFiles Include="Configs\Config.conf" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand All @@ -112,12 +125,23 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Service\BedrockService.Service.csproj">
<Project>{13b2b5a8-71e9-49f4-9bfb-3c3b3c0a054c}</Project>
<Name>BedrockService.Service</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
20 changes: 5 additions & 15 deletions BedrockService/Client/Utilities/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
using BedrockService.Client.Management;
using BedrockService.Service.Networking;
using BedrockService.Utilities;
using System;
using System.Text;

namespace BedrockService.Client.Utilities
{
public static class JsonUtilities
{
public static bool SendString(string input)
{
return FormManager.GetTCPClient.SendData(Encoding.UTF8.GetBytes(input));
}

public static string GetJsonString<T>(object obj)
{
return JsonParser.Serialize(JsonParser.FromValue((T)obj));
}

public static bool SendJsonMsg<T>(object obj)
{
return FormManager.GetTCPClient.SendData(Encoding.UTF8.GetBytes(JsonParser.Serialize(JsonParser.FromValue((T)obj))));
}

public static JsonParser GetJsonMsg(byte[] bytes)
public static bool SendJsonMsg<T>(object obj, NetworkMessageDestination destination, NetworkMessageTypes type)
{
if (bytes != null)
return JsonParser.Deserialize(Encoding.UTF8.GetString(bytes));
else
return null;
byte[] bytes = Encoding.UTF8.GetBytes(JsonParser.Serialize(JsonParser.FromValue((T)obj)));
return FormManager.GetTCPClient.SendData(bytes, NetworkMessageSource.Client, destination, type);
}
}
}

0 comments on commit 45cb1ea

Please sign in to comment.