From 8addc321f89e9d49f8c21d6f92adaebd108a458d Mon Sep 17 00:00:00 2001 From: HandyS11 Date: Wed, 20 Mar 2024 20:15:58 +0100 Subject: [PATCH] add samples --- RustPlusApi.sln | 37 ++++++++++++++++++- RustPlusApi/Exemples/GetInfo/GetInfo.csproj | 15 ++++++++ RustPlusApi/Exemples/GetInfo/Program.cs | 17 +++++++++ RustPlusApi/Exemples/GetMap/GetMap.csproj | 15 ++++++++ RustPlusApi/Exemples/GetMap/Program.cs | 16 ++++++++ .../Exemples/GetTeamInfo/GetTeamInfo.csproj | 15 ++++++++ RustPlusApi/Exemples/GetTeamInfo/Program.cs | 17 +++++++++ RustPlusApi/Exemples/GetTime/GetTime.csproj | 15 ++++++++ RustPlusApi/Exemples/GetTime/Program.cs | 15 ++++++++ RustPlusApi/Exemples/SendTeamChat/Program.cs | 7 +--- .../Exemples/SendTeamChat/SendTeamChat.csproj | 1 + .../Exemples/__Constants/RustPlusConst.cs | 10 +++++ .../Exemples/__Constants/__Constants.csproj | 9 +++++ 13 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 RustPlusApi/Exemples/GetInfo/GetInfo.csproj create mode 100644 RustPlusApi/Exemples/GetInfo/Program.cs create mode 100644 RustPlusApi/Exemples/GetMap/GetMap.csproj create mode 100644 RustPlusApi/Exemples/GetMap/Program.cs create mode 100644 RustPlusApi/Exemples/GetTeamInfo/GetTeamInfo.csproj create mode 100644 RustPlusApi/Exemples/GetTeamInfo/Program.cs create mode 100644 RustPlusApi/Exemples/GetTime/GetTime.csproj create mode 100644 RustPlusApi/Exemples/GetTime/Program.cs create mode 100644 RustPlusApi/Exemples/__Constants/RustPlusConst.cs create mode 100644 RustPlusApi/Exemples/__Constants/__Constants.csproj diff --git a/RustPlusApi.sln b/RustPlusApi.sln index a2e8b13..e5b8331 100644 --- a/RustPlusApi.sln +++ b/RustPlusApi.sln @@ -7,7 +7,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RustPlusApi", "RustPlusApi\ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exemples", "Exemples", "{BC948ADE-1674-4955-B27C-F0E96100978E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendTeamChat", "RustPlusApi\Exemples\SendTeamChat\SendTeamChat.csproj", "{FC788BAA-BB25-48AD-BE3D-2046C111AD00}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SendTeamChat", "RustPlusApi\Exemples\SendTeamChat\SendTeamChat.csproj", "{FC788BAA-BB25-48AD-BE3D-2046C111AD00}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GetTime", "RustPlusApi\Exemples\GetTime\GetTime.csproj", "{C0EB15FC-CB79-4F37-9459-78E9CAEF3647}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GetMap", "RustPlusApi\Exemples\GetMap\GetMap.csproj", "{7F5365D9-7E71-452D-8534-4B3A69B5B7E4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetTeamInfo", "RustPlusApi\Exemples\GetTeamInfo\GetTeamInfo.csproj", "{D23BC4F3-47DF-4E31-96BE-9A4C730D308F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "__Constants", "RustPlusApi\Exemples\__Constants\__Constants.csproj", "{9CDFDCBE-7EC1-4951-B685-62D5EFB79D15}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetInfo", "RustPlusApi\Exemples\GetInfo\GetInfo.csproj", "{50B6AABF-6BC2-4B7B-BB48-27200B05476F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -23,12 +33,37 @@ Global {FC788BAA-BB25-48AD-BE3D-2046C111AD00}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC788BAA-BB25-48AD-BE3D-2046C111AD00}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC788BAA-BB25-48AD-BE3D-2046C111AD00}.Release|Any CPU.Build.0 = Release|Any CPU + {C0EB15FC-CB79-4F37-9459-78E9CAEF3647}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0EB15FC-CB79-4F37-9459-78E9CAEF3647}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0EB15FC-CB79-4F37-9459-78E9CAEF3647}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0EB15FC-CB79-4F37-9459-78E9CAEF3647}.Release|Any CPU.Build.0 = Release|Any CPU + {7F5365D9-7E71-452D-8534-4B3A69B5B7E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F5365D9-7E71-452D-8534-4B3A69B5B7E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F5365D9-7E71-452D-8534-4B3A69B5B7E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F5365D9-7E71-452D-8534-4B3A69B5B7E4}.Release|Any CPU.Build.0 = Release|Any CPU + {D23BC4F3-47DF-4E31-96BE-9A4C730D308F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D23BC4F3-47DF-4E31-96BE-9A4C730D308F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D23BC4F3-47DF-4E31-96BE-9A4C730D308F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D23BC4F3-47DF-4E31-96BE-9A4C730D308F}.Release|Any CPU.Build.0 = Release|Any CPU + {9CDFDCBE-7EC1-4951-B685-62D5EFB79D15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9CDFDCBE-7EC1-4951-B685-62D5EFB79D15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9CDFDCBE-7EC1-4951-B685-62D5EFB79D15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9CDFDCBE-7EC1-4951-B685-62D5EFB79D15}.Release|Any CPU.Build.0 = Release|Any CPU + {50B6AABF-6BC2-4B7B-BB48-27200B05476F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50B6AABF-6BC2-4B7B-BB48-27200B05476F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50B6AABF-6BC2-4B7B-BB48-27200B05476F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50B6AABF-6BC2-4B7B-BB48-27200B05476F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {FC788BAA-BB25-48AD-BE3D-2046C111AD00} = {BC948ADE-1674-4955-B27C-F0E96100978E} + {C0EB15FC-CB79-4F37-9459-78E9CAEF3647} = {BC948ADE-1674-4955-B27C-F0E96100978E} + {7F5365D9-7E71-452D-8534-4B3A69B5B7E4} = {BC948ADE-1674-4955-B27C-F0E96100978E} + {D23BC4F3-47DF-4E31-96BE-9A4C730D308F} = {BC948ADE-1674-4955-B27C-F0E96100978E} + {9CDFDCBE-7EC1-4951-B685-62D5EFB79D15} = {BC948ADE-1674-4955-B27C-F0E96100978E} + {50B6AABF-6BC2-4B7B-BB48-27200B05476F} = {BC948ADE-1674-4955-B27C-F0E96100978E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A4B4251F-ADA4-418D-95B5-27BA99A307A3} diff --git a/RustPlusApi/Exemples/GetInfo/GetInfo.csproj b/RustPlusApi/Exemples/GetInfo/GetInfo.csproj new file mode 100644 index 0000000..0aa3ca6 --- /dev/null +++ b/RustPlusApi/Exemples/GetInfo/GetInfo.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/RustPlusApi/Exemples/GetInfo/Program.cs b/RustPlusApi/Exemples/GetInfo/Program.cs new file mode 100644 index 0000000..05fa1b9 --- /dev/null +++ b/RustPlusApi/Exemples/GetInfo/Program.cs @@ -0,0 +1,17 @@ +using __Constants; + +var rustPlus = new RustPlusApi.RustPlusApi(RustPlusConst.Ip, RustPlusConst.Port, RustPlusConst.PlayerId, RustPlusConst.PlayerToken); + +rustPlus.Connected += async (sender, e) => +{ + await rustPlus.GetInfoAsync(message => + { + Console.WriteLine($"Infos: " + + $"\nServer Name: {message.Response.Info.Name}" + + $"\nServer Url: {message.Response.Info.Url}"); + rustPlus.Dispose(); + return true; + }); +}; + +await rustPlus.ConnectAsync(); \ No newline at end of file diff --git a/RustPlusApi/Exemples/GetMap/GetMap.csproj b/RustPlusApi/Exemples/GetMap/GetMap.csproj new file mode 100644 index 0000000..0aa3ca6 --- /dev/null +++ b/RustPlusApi/Exemples/GetMap/GetMap.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/RustPlusApi/Exemples/GetMap/Program.cs b/RustPlusApi/Exemples/GetMap/Program.cs new file mode 100644 index 0000000..900e89d --- /dev/null +++ b/RustPlusApi/Exemples/GetMap/Program.cs @@ -0,0 +1,16 @@ +using __Constants; + +var rustPlus = new RustPlusApi.RustPlusApi(RustPlusConst.Ip, RustPlusConst.Port, RustPlusConst.PlayerId, RustPlusConst.PlayerToken); + +rustPlus.Connected += async (sender, e) => +{ + await rustPlus.GetMapAsync(message => + { + var imageData = message.Response.Map.JpgImage.ToByteArray(); + File.WriteAllBytes("map.jpg", imageData); + rustPlus.Dispose(); + return true; + }); +}; + +await rustPlus.ConnectAsync(); \ No newline at end of file diff --git a/RustPlusApi/Exemples/GetTeamInfo/GetTeamInfo.csproj b/RustPlusApi/Exemples/GetTeamInfo/GetTeamInfo.csproj new file mode 100644 index 0000000..0aa3ca6 --- /dev/null +++ b/RustPlusApi/Exemples/GetTeamInfo/GetTeamInfo.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/RustPlusApi/Exemples/GetTeamInfo/Program.cs b/RustPlusApi/Exemples/GetTeamInfo/Program.cs new file mode 100644 index 0000000..ee7a0cc --- /dev/null +++ b/RustPlusApi/Exemples/GetTeamInfo/Program.cs @@ -0,0 +1,17 @@ +using __Constants; + +var rustPlus = new RustPlusApi.RustPlusApi(RustPlusConst.Ip, RustPlusConst.Port, RustPlusConst.PlayerId, RustPlusConst.PlayerToken); + +rustPlus.Connected += async (sender, e) => +{ + await rustPlus.GetTeamInfoAsync(message => + { + Console.WriteLine($"Infos:" + + $"\nLeader SteamId: {message.Response.TeamInfo.LeaderSteamId}" + + $"\nMembers Count: {message.Response.TeamInfo.Members.Count}"); + rustPlus.Dispose(); + return true; + }); +}; + +await rustPlus.ConnectAsync(); \ No newline at end of file diff --git a/RustPlusApi/Exemples/GetTime/GetTime.csproj b/RustPlusApi/Exemples/GetTime/GetTime.csproj new file mode 100644 index 0000000..0aa3ca6 --- /dev/null +++ b/RustPlusApi/Exemples/GetTime/GetTime.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/RustPlusApi/Exemples/GetTime/Program.cs b/RustPlusApi/Exemples/GetTime/Program.cs new file mode 100644 index 0000000..8aeb58e --- /dev/null +++ b/RustPlusApi/Exemples/GetTime/Program.cs @@ -0,0 +1,15 @@ +using __Constants; + +var rustPlus = new RustPlusApi.RustPlusApi(RustPlusConst.Ip, RustPlusConst.Port, RustPlusConst.PlayerId, RustPlusConst.PlayerToken); + +rustPlus.Connected += async (sender, e) => +{ + await rustPlus.GetTimeAsync(message => + { + Console.WriteLine($"Time: {message.Response.Time.Time}"); + rustPlus.Dispose(); + return true; + }); +}; + +await rustPlus.ConnectAsync(); \ No newline at end of file diff --git a/RustPlusApi/Exemples/SendTeamChat/Program.cs b/RustPlusApi/Exemples/SendTeamChat/Program.cs index 46785e0..e0f1cfc 100644 --- a/RustPlusApi/Exemples/SendTeamChat/Program.cs +++ b/RustPlusApi/Exemples/SendTeamChat/Program.cs @@ -1,9 +1,6 @@ -const string ip = ""; -const int port = 0; -const ulong playerId = 0; -const int playerToken = 0; +using __Constants; -var rustPlus = new RustPlusApi.RustPlusApi(ip, port, playerId, playerToken); +var rustPlus = new RustPlusApi.RustPlusApi(RustPlusConst.Ip, RustPlusConst.Port, RustPlusConst.PlayerId, RustPlusConst.PlayerToken); rustPlus.Connected += async (sender, e) => { diff --git a/RustPlusApi/Exemples/SendTeamChat/SendTeamChat.csproj b/RustPlusApi/Exemples/SendTeamChat/SendTeamChat.csproj index 4ed4d22..0aa3ca6 100644 --- a/RustPlusApi/Exemples/SendTeamChat/SendTeamChat.csproj +++ b/RustPlusApi/Exemples/SendTeamChat/SendTeamChat.csproj @@ -9,6 +9,7 @@ + diff --git a/RustPlusApi/Exemples/__Constants/RustPlusConst.cs b/RustPlusApi/Exemples/__Constants/RustPlusConst.cs new file mode 100644 index 0000000..9bb3b5c --- /dev/null +++ b/RustPlusApi/Exemples/__Constants/RustPlusConst.cs @@ -0,0 +1,10 @@ +namespace __Constants +{ + public record RustPlusConst + { + public const string Ip = ""; + public const int Port = 0; + public const ulong PlayerId = 0; + public const int PlayerToken = 0; + } +} diff --git a/RustPlusApi/Exemples/__Constants/__Constants.csproj b/RustPlusApi/Exemples/__Constants/__Constants.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/RustPlusApi/Exemples/__Constants/__Constants.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + +