Skip to content
This repository was archived by the owner on Dec 23, 2022. It is now read-only.

Commit 28b873e

Browse files
committed
Added documentation to client
Added Log, Auth and ConnectionState events to client Added server unittests More structured examples
1 parent 783090c commit 28b873e

File tree

15 files changed

+410
-87
lines changed

15 files changed

+410
-87
lines changed

RCONServerLibClientExample/RCONServerLibClientExample.csproj renamed to Examples/ClientExample/ClientExample.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
<ProjectGuid>{F394E5AB-E3C0-4BF9-9BE7-BAE048B61B40}</ProjectGuid>
88
<OutputType>Exe</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>RCONServerLibClientExample</RootNamespace>
11-
<AssemblyName>RCONServerLibClientExample</AssemblyName>
10+
<RootNamespace>ClientExample</RootNamespace>
11+
<AssemblyName>ClientExample</AssemblyName>
1212
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<LangVersion>6</LangVersion>
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -42,7 +43,7 @@
4243
<Compile Include="Properties\AssemblyInfo.cs" />
4344
</ItemGroup>
4445
<ItemGroup>
45-
<ProjectReference Include="..\RCONServerLib\RCONServerLib.csproj">
46+
<ProjectReference Include="..\..\RCONServerLib\RCONServerLib.csproj">
4647
<Project>{2efa0311-14ce-414b-9867-fc0d1ff6f6c4}</Project>
4748
<Name>RCONServerLib</Name>
4849
</ProjectReference>

Examples/ClientExample/Program.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using RCONServerLib;
3+
4+
namespace ClientExample
5+
{
6+
public static class Program
7+
{
8+
private static bool _authProcessed;
9+
10+
public static void Main(string[] args)
11+
{
12+
var ip = "127.0.0.1";
13+
var port = 27015;
14+
var password = "changeme";
15+
if (args.Length == 3)
16+
{
17+
ip = args[0];
18+
int.TryParse(args[1], out port);
19+
password = args[2];
20+
}
21+
22+
var client = new RemoteConClient();
23+
client.OnLog += message => { Console.WriteLine(string.Format("Client Log: {0}", message)); };
24+
client.OnAuthResult += result => { _authProcessed = true; };
25+
client.OnConnectionStateChange += state =>
26+
{
27+
Console.WriteLine("Connection changed: " + state);
28+
if (state == 0)
29+
{
30+
client.Authenticate(password);
31+
}
32+
};
33+
34+
client.Connect(ip, port);
35+
while (true)
36+
{
37+
if (!client.Connected)
38+
{
39+
Console.ReadKey();
40+
client.Connect(ip, port);
41+
continue;
42+
}
43+
44+
if (_authProcessed && !client.Authenticated)
45+
{
46+
_authProcessed = false;
47+
Console.WriteLine("Password: ");
48+
var enteredPwd = Console.ReadLine();
49+
client.Authenticate(enteredPwd);
50+
continue;
51+
}
52+
53+
if (!client.Authenticated)
54+
continue;
55+
56+
var cmd = Console.ReadLine();
57+
if (cmd == "exit" || cmd == "quit")
58+
{
59+
client.Disconnect();
60+
return;
61+
}
62+
63+
client.SendCommand(cmd, result => { Console.WriteLine("CMD Result: " + result); });
64+
}
65+
}
66+
}
67+
}
File renamed without changes.

Examples/ServerExample/Program.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Net;
3+
using RCONServerLib;
4+
5+
namespace ServerExample
6+
{
7+
public static class Program
8+
{
9+
public static void Main(string[] args)
10+
{
11+
var server = new RemoteConServer(IPAddress.Any, 27015)
12+
{
13+
SendAuthImmediately = true,
14+
Debug = true,
15+
};
16+
server.CommandManager.Add("hello", "", (command, arguments) => { return "world"; });
17+
18+
server.StartListening();
19+
20+
Console.WriteLine("Server started. Press any key to stop.");
21+
Console.ReadKey();
22+
}
23+
}
24+
}
File renamed without changes.

RCONServerLibExample/RCONServerLibExample.csproj renamed to Examples/ServerExample/ServerExample.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<ProjectGuid>{EDB656EE-634B-4080-8293-73205470FCCF}</ProjectGuid>
88
<OutputType>Exe</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>RCONServerLibExample</RootNamespace>
11-
<AssemblyName>RCONServerLibExample</AssemblyName>
10+
<RootNamespace>ServerExample</RootNamespace>
11+
<AssemblyName>ServerExample</AssemblyName>
1212
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<LangVersion>6</LangVersion>
@@ -43,7 +43,7 @@
4343
<Compile Include="Properties\AssemblyInfo.cs" />
4444
</ItemGroup>
4545
<ItemGroup>
46-
<ProjectReference Include="..\RCONServerLib\RCONServerLib.csproj">
46+
<ProjectReference Include="..\..\RCONServerLib\RCONServerLib.csproj">
4747
<Project>{2efa0311-14ce-414b-9867-fc0d1ff6f6c4}</Project>
4848
<Name>RCONServerLib</Name>
4949
</ProjectReference>

RCON.sln

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCONServerLibExample", "RCONServerLibExample\RCONServerLibExample.csproj", "{EDB656EE-634B-4080-8293-73205470FCCF}"
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientExample", "Examples\ServerExample\ServerExample.csproj", "{EDB656EE-634B-4080-8293-73205470FCCF}"
44
EndProject
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCONServerLib", "RCONServerLib\RCONServerLib.csproj", "{2EFA0311-14CE-414B-9867-FC0D1FF6F6C4}"
66
EndProject
77
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCONServerLib.Tests", "RCONServerLib.Tests\RCONServerLib.Tests.csproj", "{A1FDCE93-4C35-4A04-AD3E-F67949607BA9}"
88
EndProject
9-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCONServerLibClientExample", "RCONServerLibClientExample\RCONServerLibClientExample.csproj", "{F394E5AB-E3C0-4BF9-9BE7-BAE048B61B40}"
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientExample", "Examples\ClientExample\ClientExample.csproj", "{F394E5AB-E3C0-4BF9-9BE7-BAE048B61B40}"
10+
EndProject
11+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{177279F4-A4D8-4320-A3D4-F2062CBBB1B6}"
1012
EndProject
1113
Global
1214
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -31,4 +33,8 @@ Global
3133
{F394E5AB-E3C0-4BF9-9BE7-BAE048B61B40}.Release|Any CPU.ActiveCfg = Release|Any CPU
3234
{F394E5AB-E3C0-4BF9-9BE7-BAE048B61B40}.Release|Any CPU.Build.0 = Release|Any CPU
3335
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{EDB656EE-634B-4080-8293-73205470FCCF} = {177279F4-A4D8-4320-A3D4-F2062CBBB1B6}
38+
{F394E5AB-E3C0-4BF9-9BE7-BAE048B61B40} = {177279F4-A4D8-4320-A3D4-F2062CBBB1B6}
39+
EndGlobalSection
3440
EndGlobal
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System.Net;
2+
using Xunit;
3+
4+
namespace RCONServerLib.Tests
5+
{
6+
public class ConnectionTests
7+
{
8+
[Fact]
9+
public void TestAuthFail()
10+
{
11+
var server = new RemoteConServer(IPAddress.Any, 27015);
12+
server.StartListening();
13+
14+
var client = new RemoteConClient();
15+
client.OnAuthResult += Assert.False;
16+
17+
client.Connect("127.0.0.1", 27015);
18+
client.Authenticate("unitfail");
19+
20+
client.Disconnect();
21+
server.StopListening();
22+
}
23+
24+
[Fact]
25+
public void TestAuthSuccess()
26+
{
27+
var server = new RemoteConServer(IPAddress.Any, 27015);
28+
server.StartListening();
29+
30+
var client = new RemoteConClient();
31+
client.OnAuthResult += Assert.True;
32+
33+
client.Connect("127.0.0.1", 27015);
34+
client.Authenticate("changeme");
35+
36+
client.Disconnect();
37+
server.StopListening();
38+
}
39+
40+
[Fact]
41+
public void TestCommandFail()
42+
{
43+
var server = new RemoteConServer(IPAddress.Any, 27015);
44+
server.StartListening();
45+
46+
var client = new RemoteConClient();
47+
client.OnAuthResult += success =>
48+
{
49+
//Assert.True(success);
50+
client.SendCommand("testing", result =>
51+
{
52+
Assert.Contains("invalid command", result);
53+
});
54+
};
55+
56+
client.Connect("127.0.0.1", 27015);
57+
client.Authenticate("changeme");
58+
59+
client.Disconnect();
60+
server.StopListening();
61+
}
62+
63+
[Fact]
64+
public void TestCommandSuccess()
65+
{
66+
var server = new RemoteConServer(IPAddress.Any, 27015);
67+
server.StartListening();
68+
69+
var client = new RemoteConClient();
70+
client.OnAuthResult += success =>
71+
{
72+
//Assert.True(success);
73+
client.SendCommand("hello", result =>
74+
{
75+
Assert.Contains("world", result);
76+
});
77+
};
78+
79+
client.Connect("127.0.0.1", 27015);
80+
client.Authenticate("changeme");
81+
82+
client.Disconnect();
83+
server.StopListening();
84+
}
85+
}
86+
}

RCONServerLib.Tests/RCONServerLib.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
</Reference>
5353
</ItemGroup>
5454
<ItemGroup>
55+
<Compile Include="ConnectionTests.cs" />
5556
<Compile Include="Properties\AssemblyInfo.cs" />
5657
<Compile Include="RemoteConTests.cs" />
5758
<Compile Include="Tests.cs" />

RCONServerLib/RCONServerLib.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>source-rcon-server</id>
5-
<version>1.0.0</version>
5+
<version>1.2.1</version>
66
<title>Source RCON Server Lib</title>
77
<authors>Julien H. (Subtixx)</authors>
88
<owners>Julien H. (Subtixx)</owners>

0 commit comments

Comments
 (0)