Skip to content

Commit 78cf9e4

Browse files
authored
Merge feature/addUserSwap into develop (#22)
- Add UserSwap - Improve global code quality
1 parent f36835d commit 78cf9e4

21 files changed

Lines changed: 254 additions & 117 deletions

.editorconfig

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
root=true
2+
3+
[*]
4+
tab_width = 4
5+
indent_size = 4
6+
end_of_line = crlf
7+
8+
[*.cs]
9+
10+
# Default severity for all analyzer diagnostics
11+
dotnet_analyzer_diagnostic.severity = none
12+
csharp_prefer_simple_using_statement = true:suggestion
13+
csharp_prefer_braces = true:silent
14+
csharp_style_prefer_method_group_conversion = true:silent
15+
csharp_style_prefer_top_level_statements = true:silent
16+
csharp_style_prefer_primary_constructors = true:suggestion
17+
csharp_style_expression_bodied_methods = false:silent
18+
csharp_style_expression_bodied_constructors = false:silent
19+
csharp_style_expression_bodied_operators = false:silent
20+
csharp_style_expression_bodied_properties = true:silent
21+
csharp_style_expression_bodied_indexers = true:silent
22+
csharp_style_expression_bodied_accessors = true:silent
23+
csharp_style_expression_bodied_lambdas = true:silent
24+
csharp_style_expression_bodied_local_functions = false:silent
25+
csharp_indent_labels = one_less_than_current
26+
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
27+
28+
# Newline settings
29+
dotnet_diagnostic.IDE0055.severity = warning
30+
csharp_new_line_before_open_brace = all
31+
csharp_new_line_before_else = true
32+
csharp_new_line_before_catch = true
33+
csharp_new_line_before_finally = true
34+
csharp_new_line_before_members_in_object_initializers = true
35+
csharp_new_line_before_members_in_anonymous_types = true
36+
37+
# Namespace settings
38+
dotnet_diagnostic.IDE0160.severity = warning
39+
csharp_style_namespace_declarations = block_scoped
40+
41+
# unused usings
42+
dotnet_diagnostic.IDE0005.severity = warning
43+
44+
45+
[*.{cs,vb}]
46+
# using directives
47+
dotnet_diagnostic.IDE0055.severity = warning
48+
dotnet_diagnostic.IDE0065.severity = warning
49+
csharp_using_directive_placement = outside_namespace
50+
dotnet_sort_system_directives_first = true
51+
dotnet_separate_import_directive_groups = false
52+
53+
#### Naming styles ####
54+
55+
# Naming rules
56+
57+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
58+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
59+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
60+
61+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
62+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
63+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
64+
65+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
66+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
67+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
68+
69+
# Symbol specifications
70+
71+
dotnet_naming_symbols.interface.applicable_kinds = interface
72+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
73+
dotnet_naming_symbols.interface.required_modifiers =
74+
75+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
76+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
77+
dotnet_naming_symbols.types.required_modifiers =
78+
79+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
80+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
81+
dotnet_naming_symbols.non_field_members.required_modifiers =
82+
83+
# Naming styles
84+
85+
dotnet_naming_style.begins_with_i.required_prefix = I
86+
dotnet_naming_style.begins_with_i.required_suffix =
87+
dotnet_naming_style.begins_with_i.word_separator =
88+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
89+
90+
dotnet_naming_style.pascal_case.required_prefix =
91+
dotnet_naming_style.pascal_case.required_suffix =
92+
dotnet_naming_style.pascal_case.word_separator =
93+
dotnet_naming_style.pascal_case.capitalization = pascal_case
94+
95+
dotnet_naming_style.pascal_case.required_prefix =
96+
dotnet_naming_style.pascal_case.required_suffix =
97+
dotnet_naming_style.pascal_case.word_separator =
98+
dotnet_naming_style.pascal_case.capitalization = pascal_case
99+
dotnet_style_coalesce_expression = true:suggestion
100+
dotnet_style_null_propagation = true:suggestion
101+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
102+
dotnet_style_prefer_auto_properties = true:silent
103+
dotnet_style_object_initializer = true:suggestion
104+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
105+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
106+
dotnet_style_prefer_conditional_expression_over_return = true:silent
107+
dotnet_style_explicit_tuple_names = true:suggestion
108+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
109+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
110+
dotnet_style_prefer_compound_assignment = true:suggestion
111+
dotnet_style_prefer_simplified_interpolation = true:suggestion
112+
dotnet_style_namespace_match_folder = true:suggestion
113+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
114+
115+
# Collections
116+
dotnet_diagnostic.IDE0028.severity = suggestion
117+
dotnet_style_prefer_collection_expression = true
118+
dotnet_style_collection_initializer = true
119+
120+
# remove Migrations files from Analyzer
121+
[**/Migrations/*.cs]
122+
dotnet_diagnostic.IDE0005.severity = silent
123+
# doesn't work on VS Code apparently
124+
generated_code = true

RustPlusApi/Examples/GetTeamChatChanges/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var rustPlus = new RustPlus(Ip, Port, PlayerId, PlayerToken);
88

9-
rustPlus.OnTeamChatReceived += (sender, message) =>
9+
rustPlus.OnTeamChatReceived += (_, message) =>
1010
{
1111
Console.WriteLine($"Infos:\n{JsonConvert.SerializeObject(message, JsonSettings)}");
1212
};

RustPlusApi/Examples/SetSmartSwitchValue/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var rustPlus = new RustPlus(Ip, Port, PlayerId, PlayerToken);
88
const uint smartSwitchId = 0;
9-
var smartSwitchValue = true;
9+
const bool smartSwitchValue = true;
1010

1111
await rustPlus.ConnectAsync();
1212

RustPlusApi/Examples/SetSubscription/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var rustPlus = new RustPlus(Ip, Port, PlayerId, PlayerToken);
88
const uint smartSwitchId = 0;
9-
var smartSwitchValue = true;
9+
const bool smartSwitchValue = true;
1010

1111
await rustPlus.ConnectAsync();
1212

RustPlusApi/RustPlusApi.Fcm/Converters/BodyConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class BodyConverter : JsonConverter<Body>
1515

1616
public override void WriteJson(JsonWriter writer, Body? value, JsonSerializer serializer)
1717
{
18-
JObject jsonObject = JObject.FromObject(value!, serializer);
18+
var jsonObject = JObject.FromObject(value!, serializer);
1919
jsonObject.WriteTo(writer);
2020
}
2121
}

RustPlusApi/RustPlusApi.Fcm/Data/FcmMessage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Newtonsoft.Json;
22

33
using RustPlusApi.Fcm.Converters;
4+
// ReSharper disable ClassNeverInstantiated.Global
45

56
namespace RustPlusApi.Fcm.Data
67
{

RustPlusApi/RustPlusApi.Fcm/Extensions/MessageDataToEventModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace RustPlusApi.Fcm.Extensions
55
{
66
public static class MessageDataToEventModel
77
{
8-
public static AlarmEvent ToAlarmEvent(this MessageData data, Guid notifId)
8+
public static AlarmEvent ToAlarmEvent(this MessageData data, Guid notificationId)
99
{
1010
return new AlarmEvent
1111
{
12-
NotificationId = notifId,
12+
NotificationId = notificationId,
1313
Title = data.Title,
1414
Message = data.Message
1515
};

RustPlusApi/RustPlusApi.Fcm/RustPlusApi.Fcm.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<PackageId>RustPlusApi.Fcm</PackageId>
8-
<Version>1.2.0</Version>
8+
<Version>1.2.1</Version>
99
<Authors>HandyS11</Authors>
1010
<Owners>HandyS11</Owners>
1111
<Product>A Rust+ API websocket made in C#.</Product>

RustPlusApi/RustPlusApi.Fcm/RustPlusFcmListener.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ protected override void ParseNotification(string? message)
5151
}
5252
}
5353

54-
private void ParsePairing(Guid notifId, Body body)
54+
private void ParsePairing(Guid notificationId, Body body)
5555
{
5656
switch (body.Type)
5757
{
5858
case "entity":
59-
var entity = BuildGenericOutput(notifId, body, body.ToEntityEvent());
59+
var entity = BuildGenericOutput(notificationId, body, body.ToEntityEvent());
6060
OnEntityParing?.Invoke(this, entity);
61-
ParsePairingEntity(notifId, body);
61+
ParsePairingEntity(notificationId, body);
6262
break;
6363
case "server":
64-
var server = BuildGenericOutput(notifId, body, body.ToServerEvent());
64+
var server = BuildGenericOutput(notificationId, body, body.ToServerEvent());
6565
OnServerPairing?.Invoke(this, server);
6666
break;
6767
default:
@@ -70,9 +70,9 @@ private void ParsePairing(Guid notifId, Body body)
7070
}
7171
}
7272

73-
private void ParsePairingEntity(Guid notifId, Body body)
73+
private void ParsePairingEntity(Guid notificationId, Body body)
7474
{
75-
var response = BuildGenericOutput(notifId, body, body.ToEntityId());
75+
var response = BuildGenericOutput(notificationId, body, body.ToEntityId());
7676

7777
switch (body.EntityType)
7878
{

RustPlusApi/RustPlusApi.Fcm/RustPlusFcmListenerClient.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class RustPlusFcmListenerClient(Credentials credentials, ICollection<stri
3333
private SslStream? _sslStream;
3434

3535
private readonly CancellationTokenSource _cancellationTokenSource = new();
36-
private CancellationToken _cancellationToken => _cancellationTokenSource.Token;
36+
private CancellationToken CancellationToken => _cancellationTokenSource.Token;
3737

3838
public event EventHandler? Connecting;
3939
public event EventHandler? Connected;
@@ -51,7 +51,7 @@ public async Task ConnectAsync()
5151
Connecting?.Invoke(this, EventArgs.Empty);
5252

5353
_tcpClient = new TcpClient();
54-
await _tcpClient.ConnectAsync(Host, Port);
54+
await _tcpClient.ConnectAsync(Host, Port, CancellationToken);
5555

5656
_sslStream = new SslStream(_tcpClient.GetStream(), false);
5757
await _sslStream.AuthenticateAsClientAsync(Host);
@@ -81,7 +81,7 @@ public async Task ConnectAsync()
8181

8282
Connected?.Invoke(this, EventArgs.Empty);
8383

84-
_ = Task.Run(ReceiveMessages, _cancellationToken);
84+
_ = Task.Run(ReceiveMessages, CancellationToken);
8585
}
8686
catch (Exception ex)
8787
{
@@ -124,20 +124,20 @@ private void ReceiveMessages()
124124
if (version < KMcsVersion && version != 38)
125125
throw new InvalidOperationException($"Protocol version {version} unsupported");
126126

127-
var size = ReadVarint32();
127+
var size = ReadVarInt32();
128128
var payload = Read(size);
129129
var type = BuildProtobufFromTag((McsProtoTag)tag);
130130

131131
if (type != typeof(LoginResponse))
132-
throw new Exception($"Got wrong login response. Expected {typeof(LoginResponse).Name}, got {type.Name}");
132+
throw new Exception($"Got wrong login response. Expected {nameof(LoginResponse)}, got {type.Name}");
133133

134134
OnGotMessageBytes(payload, type);
135135

136-
while (!_cancellationToken.IsCancellationRequested)
136+
while (!CancellationToken.IsCancellationRequested)
137137
{
138138
// Read the tag and size
139139
tag = _sslStream!.ReadByte();
140-
size = ReadVarint32();
140+
size = ReadVarInt32();
141141
payload = Read(size);
142142
type = BuildProtobufFromTag((McsProtoTag)tag);
143143

@@ -183,8 +183,8 @@ private void OnGotMessageBytes(byte[] data, Type type)
183183
/// <returns>An array of bytes read from the stream.</returns>
184184
private byte[] Read(int size)
185185
{
186-
byte[] buffer = new byte[size];
187-
int bytesRead = 0;
186+
var buffer = new byte[size];
187+
var bytesRead = 0;
188188
while (bytesRead < size)
189189
{
190190
bytesRead += _sslStream!.Read(buffer, bytesRead, size - bytesRead);
@@ -196,13 +196,13 @@ private byte[] Read(int size)
196196
/// Reads a variable-length 32-bit integer from the SSL stream.
197197
/// </summary>
198198
/// <returns>The 32-bit integer read from the stream.</returns>
199-
private int ReadVarint32()
199+
private int ReadVarInt32()
200200
{
201-
int result = 0;
202-
int shift = 0;
201+
var result = 0;
202+
var shift = 0;
203203
while (true)
204204
{
205-
byte b = (byte)_sslStream!.ReadByte();
205+
var b = (byte)_sslStream!.ReadByte();
206206
result |= (b & 0x7F) << shift;
207207
if ((b & 0x80) == 0) break;
208208
shift += 7;
@@ -222,8 +222,8 @@ private void SendPacket(object packet)
222222
using var ms = new MemoryStream();
223223
Serializer.Serialize(ms, packet);
224224

225-
byte[] payload = ms.ToArray();
226-
_sslStream!.Write([.. header, .. EncodeVarint32(payload.Length), .. payload]);
225+
var payload = ms.ToArray();
226+
_sslStream!.Write([.. header, .. EncodeVarInt32(payload.Length), .. payload]);
227227
}
228228

229229
/// <summary>

0 commit comments

Comments
 (0)