├── .gitignore ├── LICENSE ├── PalworldRcon.sln ├── PalworldRcon ├── App.xaml ├── App.xaml.cs ├── AssemblyInfo.cs ├── Logging │ ├── Log.cs │ ├── LogLevel.cs │ ├── Logger.cs │ ├── LoggerTarget.cs │ └── Targets │ │ ├── ConsoleTarget.cs │ │ └── FileTarget.cs ├── Logic │ ├── ConsoleWriter.cs │ ├── RCONClient.cs │ ├── Responses │ │ ├── Player.cs │ │ ├── PlayerList.cs │ │ └── ServerInfo.cs │ └── Settings.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── PalworldRcon.csproj └── icon.ico └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | 400 | .idea 401 | riderModule.iml 402 | /_ReSharper.Caches/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 DDAkebono 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PalworldRcon.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PalworldRcon", "PalworldRcon\PalworldRcon.csproj", "{69341FBF-6804-47DE-91F1-68948B1DB528}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Any CPU = Debug|Any CPU 8 | Release|Any CPU = Release|Any CPU 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {69341FBF-6804-47DE-91F1-68948B1DB528}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 12 | {69341FBF-6804-47DE-91F1-68948B1DB528}.Debug|Any CPU.Build.0 = Debug|Any CPU 13 | {69341FBF-6804-47DE-91F1-68948B1DB528}.Release|Any CPU.ActiveCfg = Release|Any CPU 14 | {69341FBF-6804-47DE-91F1-68948B1DB528}.Release|Any CPU.Build.0 = Release|Any CPU 15 | EndGlobalSection 16 | EndGlobal 17 | -------------------------------------------------------------------------------- /PalworldRcon/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /PalworldRcon/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace PalworldRcon 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } -------------------------------------------------------------------------------- /PalworldRcon/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] -------------------------------------------------------------------------------- /PalworldRcon/Logging/Log.cs: -------------------------------------------------------------------------------- 1 | using PalworldRcon.Logging.Targets; 2 | 3 | namespace PalworldRcon.Logging 4 | { 5 | /// 6 | /// Logs messages to command line and file. 7 | /// 8 | public static class Log 9 | { 10 | private static Logger _logger = Logger.Get(); 11 | 12 | static Log() 13 | { 14 | _logger.AddTarget(new ConsoleTarget()); 15 | _logger.AddTarget(new FileTarget("logs")); 16 | } 17 | 18 | /// 19 | /// Logs an info message. 20 | /// 21 | /// 22 | public static void Info(string value) { _logger.Info(value); } 23 | 24 | /// 25 | /// Logs an info message. 26 | /// 27 | /// 28 | /// 29 | public static void Info(string format, params object[] args) { _logger.Info(format, args); } 30 | 31 | /// 32 | /// Logs an info message. 33 | /// 34 | /// 35 | public static void Info(object obj) { _logger.Info(obj); } 36 | 37 | /// 38 | /// Logs a warning message. 39 | /// 40 | /// 41 | public static void Warning(string value) { _logger.Warning(value); } 42 | 43 | /// 44 | /// Logs a warning message. 45 | /// 46 | /// 47 | /// 48 | public static void Warning(string format, params object[] args) { _logger.Warning(format, args); } 49 | 50 | /// 51 | /// Logs a warning message. 52 | /// 53 | /// 54 | public static void Warning(object obj) { _logger.Warning(obj); } 55 | 56 | /// 57 | /// Logs an error message. 58 | /// 59 | /// 60 | public static void Error(string value) { _logger.Error(value); } 61 | 62 | /// 63 | /// Logs an error message. 64 | /// 65 | /// 66 | /// 67 | public static void Error(string format, params object[] args) { _logger.Error(format, args); } 68 | 69 | /// 70 | /// Logs an error message. 71 | /// 72 | /// 73 | public static void Error(object obj) { _logger.Error(obj); } 74 | 75 | /// 76 | /// Logs a debug message. 77 | /// 78 | /// 79 | public static void Debug(string value) { _logger.Debug(value); } 80 | 81 | /// 82 | /// Logs a debug message. 83 | /// 84 | /// 85 | /// 86 | public static void Debug(string format, params object[] args) { _logger.Debug(format, args); } 87 | 88 | /// 89 | /// Logs a debug message. 90 | /// 91 | /// 92 | public static void Debug(object obj) { _logger.Debug(obj); } 93 | 94 | /// 95 | /// Logs a status message. 96 | /// 97 | /// 98 | public static void Status(string value) { _logger.Status(value); } 99 | 100 | /// 101 | /// Logs a status message. 102 | /// 103 | /// 104 | /// 105 | public static void Status(string format, params object[] args) { _logger.Status(format, args); } 106 | 107 | /// 108 | /// Logs a status message. 109 | /// 110 | /// 111 | public static void Status(object obj) { _logger.Status(obj); } 112 | 113 | /// 114 | /// Sets levels that should not be logged. 115 | /// 116 | /// 117 | public static void SetFilter(LogLevel levels) 118 | { 119 | var targets = _logger.GetTargets(); 120 | 121 | foreach (var target in targets) 122 | target.Filter = levels; 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /PalworldRcon/Logging/LogLevel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PalworldRcon.Logging 4 | { 5 | /// 6 | /// Specifies a log message's type. 7 | /// 8 | [Flags] 9 | public enum LogLevel 10 | { 11 | /// 12 | /// Informational message. 13 | /// 14 | Info = 0x0001, 15 | 16 | /// 17 | /// A warning that something went wrong. 18 | /// 19 | Warning = 0x0002, 20 | 21 | /// 22 | /// A error message. 23 | /// 24 | Error = 0x0004, 25 | 26 | /// 27 | /// A debug log. 28 | /// 29 | Debug = 0x0008, 30 | 31 | /// 32 | /// A status information, comparable to Info. 33 | /// 34 | Status = 0x0010, 35 | 36 | /// 37 | /// No/all levels, used to filter log levels. 38 | /// 39 | None = 0x7FFF, 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /PalworldRcon/Logging/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text.RegularExpressions; 5 | 6 | namespace PalworldRcon.Logging 7 | { 8 | /// 9 | /// Logging class with support for codes that are passed down to the 10 | /// log targets. 11 | /// 12 | /// 13 | /// Codes have the format "^[a-z]+[0-9]*;", with targets getting the raw 14 | /// message passed to the logger, incl. codes, and a clean one, without 15 | /// them. It's up to the loggers to decide what to do with them, 16 | /// and there's no rules as to what codes there can be, or what the 17 | /// target will do with them. 18 | /// 19 | /// For example, the ConsoleTarget will recognize c[0-9]*, b[0-9]*, 20 | /// and r, for color, background color, and resetting the colors 21 | /// respectively. 22 | /// 23 | public sealed class Logger 24 | { 25 | private Regex _codeRegex = new Regex(@"\^[a-z]+[0-9]*;", RegexOptions.Compiled); 26 | 27 | private static Dictionary _loggers; 28 | private List _targets; 29 | 30 | /// 31 | /// Name of the logger. 32 | /// 33 | public string Name { get; private set; } 34 | 35 | /// 36 | /// Creates new logger. 37 | /// 38 | /// 39 | private Logger(string name) 40 | { 41 | _targets = new List(); 42 | this.Name = name; 43 | } 44 | 45 | /// 46 | /// Initializes logger collection. 47 | /// 48 | static Logger() 49 | { 50 | _loggers = new Dictionary(); 51 | } 52 | 53 | /// 54 | /// Creates new logger, named after the entry assembly. 55 | /// 56 | /// 57 | public static Logger Get() 58 | { 59 | var asm = Assembly.GetEntryAssembly(); 60 | if (asm == null) 61 | asm = Assembly.GetCallingAssembly(); 62 | 63 | return Get(asm.GetName().Name); 64 | } 65 | 66 | /// 67 | /// Creates new named logger. 68 | /// 69 | /// 70 | /// 71 | public static Logger Get(string name) 72 | { 73 | if (_loggers.ContainsKey(name)) 74 | return _loggers[name]; 75 | 76 | return (_loggers[name] = new Logger(name)); 77 | } 78 | 79 | /// 80 | /// Creates new named logger. 81 | /// 82 | /// 83 | /// 84 | public static Logger Get(object name) 85 | { 86 | return Get(name.ToString()); 87 | } 88 | 89 | /// 90 | /// Creates new named logger. 91 | /// 92 | /// 93 | public static Logger Get() 94 | { 95 | return Get(typeof(T).ToString()); 96 | } 97 | 98 | /// 99 | /// Adds target to this logger. 100 | /// 101 | /// 102 | /// 103 | public Logger AddTarget(LoggerTarget target) 104 | { 105 | target.Logger = this; 106 | lock (_targets) 107 | _targets.Add(target); 108 | 109 | return this; 110 | } 111 | 112 | /// 113 | /// Returns list of all targets. 114 | /// 115 | /// 116 | public LoggerTarget[] GetTargets() 117 | { 118 | lock (_targets) 119 | return _targets.ToArray(); 120 | } 121 | 122 | /// 123 | /// Logs information. 124 | /// 125 | /// 126 | public void Info(string value) 127 | { 128 | this.WriteLine(LogLevel.Info, value); 129 | } 130 | 131 | /// 132 | /// Logs information. 133 | /// 134 | /// 135 | /// 136 | public void Info(string format, params object[] args) 137 | { 138 | this.Info(string.Format(format, args)); 139 | } 140 | 141 | /// 142 | /// Logs information. 143 | /// 144 | /// 145 | /// Uses obj's ToString method. 146 | /// 147 | /// 148 | public void Info(object obj) { this.Info(obj?.ToString()); } 149 | 150 | /// 151 | /// Logs warning. 152 | /// 153 | /// 154 | public void Warning(string value) 155 | { 156 | this.WriteLine(LogLevel.Warning, value); 157 | } 158 | 159 | /// 160 | /// Logs warning. 161 | /// 162 | /// 163 | /// 164 | public void Warning(string format, params object[] args) 165 | { 166 | this.Warning(string.Format(format, args)); 167 | } 168 | 169 | /// 170 | /// Logs warning. 171 | /// 172 | /// 173 | /// Uses obj's ToString method. 174 | /// 175 | /// 176 | public void Warning(object obj) { this.Warning(obj?.ToString()); } 177 | 178 | /// 179 | /// Logs error. 180 | /// 181 | /// 182 | public void Error(string value) 183 | { 184 | WriteLine(LogLevel.Error, value); 185 | } 186 | 187 | /// 188 | /// Logs error. 189 | /// 190 | /// 191 | /// 192 | public void Error(string format, params object[] args) 193 | { 194 | this.Error(string.Format(format, args)); 195 | } 196 | 197 | /// 198 | /// Logs error. 199 | /// 200 | /// 201 | /// Uses obj's ToString method. 202 | /// 203 | /// 204 | public void Error(object obj) { this.Error(obj?.ToString()); } 205 | 206 | /// 207 | /// Logs status message. 208 | /// 209 | /// 210 | public void Status(string value) 211 | { 212 | this.WriteLine(LogLevel.Status, value); 213 | } 214 | 215 | /// 216 | /// Logs status message. 217 | /// 218 | /// 219 | /// 220 | public void Status(string format, params object[] args) 221 | { 222 | this.Status(string.Format(format, args)); 223 | } 224 | 225 | /// 226 | /// Logs status message. 227 | /// 228 | /// 229 | /// Uses obj's ToString method. 230 | /// 231 | /// 232 | public void Status(object obj) { this.Status(obj?.ToString()); } 233 | 234 | /// 235 | /// Logs debug message. 236 | /// 237 | /// 238 | public void Debug(string value) 239 | { 240 | this.WriteLine(LogLevel.Debug, value); 241 | } 242 | 243 | /// 244 | /// Logs debug message. 245 | /// 246 | /// 247 | /// 248 | public void Debug(string format, params object[] args) 249 | { 250 | this.Debug(string.Format(format, args)); 251 | } 252 | 253 | /// 254 | /// Logs debug message. 255 | /// 256 | /// 257 | /// Uses obj's ToString method. 258 | /// 259 | /// 260 | public void Debug(object obj) { this.Debug(obj?.ToString()); } 261 | 262 | /// 263 | /// Writes message to log. 264 | /// 265 | /// 266 | /// 267 | public void Write(LogLevel level, string message) 268 | { 269 | var dt = DateTime.Now; 270 | 271 | lock (_targets) 272 | { 273 | foreach (var target in _targets) 274 | { 275 | if (target.Filtered(level)) 276 | continue; 277 | 278 | var messageRaw = string.Format(target.GetFormat(level), level, message); 279 | var messageClean = _codeRegex.Replace(messageRaw, ""); 280 | 281 | target.Write(level, message, messageRaw, messageClean); 282 | } 283 | } 284 | } 285 | 286 | /// 287 | /// Writes message + line break to log. 288 | /// 289 | /// 290 | /// 291 | public void WriteLine(LogLevel level, string message) 292 | { 293 | this.Write(level, message + Environment.NewLine); 294 | } 295 | } 296 | } 297 | -------------------------------------------------------------------------------- /PalworldRcon/Logging/LoggerTarget.cs: -------------------------------------------------------------------------------- 1 | namespace PalworldRcon.Logging 2 | { 3 | /// 4 | /// A target for a Logger, that gets send all log messages passed to 5 | /// the logger. 6 | /// 7 | public abstract class LoggerTarget 8 | { 9 | /// 10 | /// LogLevels to hide. 11 | /// 12 | public LogLevel Filter { get; set; } 13 | 14 | /// 15 | /// The logger this target belongs to, set automatically. 16 | /// 17 | public Logger Logger { get; internal set; } 18 | 19 | /// 20 | /// Called when logger has something to log. 21 | /// 22 | /// 23 | /// 24 | /// 25 | /// 26 | public abstract void Write(LogLevel level, string message, string messageRaw, string messageClean); 27 | 28 | /// 29 | /// Format for the log message. 30 | /// 31 | /// 32 | /// return "[{0}] - {1}"; 33 | /// 34 | /// {0}: Log level 35 | /// {1}: Log message 36 | /// 37 | /// 38 | /// 39 | public abstract string GetFormat(LogLevel level); 40 | 41 | /// 42 | /// Returns true if given level is being filtered on this target. 43 | /// 44 | /// 45 | /// 46 | public bool Filtered(LogLevel level) 47 | { 48 | return ((this.Filter & level) != 0); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PalworldRcon/Logging/Targets/ConsoleTarget.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.ComponentModel; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace PalworldRcon.Logging.Targets 8 | { 9 | public class ConsoleTarget : LoggerTarget 10 | { 11 | public static ConsoleTarget Instance; 12 | 13 | public ObservableCollection OutputText { get; } = new(); 14 | 15 | public ConsoleTarget() 16 | { 17 | Instance = this; 18 | } 19 | 20 | /// 21 | /// Writes message to Console standard output. 22 | /// 23 | /// 24 | /// 25 | /// 26 | /// 27 | public override void Write(LogLevel level, string message, string messageRaw, string messageClean) 28 | { 29 | messageRaw = messageRaw.TrimEnd(Environment.NewLine.ToCharArray()); 30 | 31 | MainWindow.Instance.Dispatcher.Invoke(() => 32 | { 33 | OutputText.Add(messageRaw); 34 | }); 35 | } 36 | 37 | /// 38 | /// Returns color coded formats, based on log level. 39 | /// 40 | /// 41 | /// 42 | public override string GetFormat(LogLevel level) 43 | { 44 | return "[{0}] - {1}"; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /PalworldRcon/Logging/Targets/FileTarget.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | namespace PalworldRcon.Logging.Targets 6 | { 7 | /// 8 | /// Logger target logging to a text file. 9 | /// 10 | public class FileTarget : LoggerTarget 11 | { 12 | /// 13 | /// The folder the log file is in. 14 | /// 15 | public string FolderPath { get; private set; } 16 | 17 | /// 18 | /// The path to the log file. 19 | /// 20 | public string FilePath { get; private set; } 21 | 22 | private DateTime _logStartTime; 23 | 24 | /// 25 | /// Creates new instance, with the file going into the given folder. 26 | /// 27 | /// 28 | public FileTarget(string folderPath = "") 29 | { 30 | this.FolderPath = folderPath; 31 | } 32 | 33 | /// 34 | /// Writes clean message to the log file, prepending it with the 35 | /// time and date the message was written at. 36 | /// 37 | /// 38 | /// 39 | /// 40 | /// 41 | public override void Write(LogLevel level, string message, string messageRaw, string messageClean) 42 | { 43 | var time = DateTime.Now; 44 | 45 | //Every 24 hours generate a new log file 46 | if (this.FilePath != null && time.Subtract(this._logStartTime).TotalHours >= 24) 47 | this.FilePath = null; 48 | 49 | if (this.FilePath == null) 50 | { 51 | this._logStartTime = time; 52 | 53 | this.FilePath = Path.Combine(this.FolderPath, $"{this.Logger.Name}_{this._logStartTime:MM.dd.yyyy-HH.mm}_.txt"); 54 | 55 | if (File.Exists(this.FilePath)) 56 | File.Delete(this.FilePath); 57 | 58 | if (!Directory.Exists(this.FolderPath)) 59 | { 60 | Directory.CreateDirectory(this.FolderPath); 61 | } 62 | else 63 | { 64 | //Check for log clean 65 | var logs = new DirectoryInfo(this.FolderPath).GetFiles(); 66 | 67 | if (logs.Length > 15) 68 | { 69 | foreach (var file in logs.OrderByDescending(x => x.LastWriteTime).Skip(15)) 70 | { 71 | file.Delete(); 72 | } 73 | } 74 | } 75 | } 76 | 77 | messageClean = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} {messageClean}"; 78 | 79 | File.AppendAllText(this.FilePath, messageClean); 80 | } 81 | 82 | /// 83 | /// Returns the format for the raw log message. 84 | /// 85 | /// 86 | /// 87 | public override string GetFormat(LogLevel level) 88 | { 89 | return "[{0}] - {1}"; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /PalworldRcon/Logic/ConsoleWriter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows.Controls; 6 | 7 | namespace PalworldRcon; 8 | 9 | public class ConsoleWriter : TextWriter 10 | { 11 | private TextBlock _textbox; 12 | private ScrollViewer _scrollViewer; 13 | public ConsoleWriter(TextBlock textbox, ScrollViewer scrollViewer) 14 | { 15 | _textbox = textbox; 16 | _scrollViewer = scrollViewer; 17 | } 18 | 19 | public override void Write(char value) 20 | { 21 | _textbox.Text += value; 22 | _scrollViewer.ScrollToBottom(); 23 | } 24 | 25 | public override void Write(string value) 26 | { 27 | _textbox.Text += value; 28 | _scrollViewer.ScrollToBottom(); 29 | } 30 | 31 | public override Encoding Encoding => Encoding.UTF8; 32 | } -------------------------------------------------------------------------------- /PalworldRcon/Logic/RCONClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Net; 5 | using System.Runtime.CompilerServices; 6 | using System.Text.RegularExpressions; 7 | using System.Threading.Tasks; 8 | using CoreRCON; 9 | using CoreRCON.PacketFormats; 10 | using MahApps.Metro.Controls.Dialogs; 11 | using PalworldRcon.Logging; 12 | using PalworldRcon.Logic.Responses; 13 | using ToastNotifications.Messages; 14 | 15 | namespace PalworldRcon.Logic; 16 | 17 | public class RCONClient(Settings settings) : INotifyPropertyChanged 18 | { 19 | public Action OnAuth; 20 | 21 | public string ServerVersion 22 | { 23 | get => _serverVersion; 24 | private set 25 | { 26 | _serverVersion = value; 27 | OnPropertyChanged(); 28 | } 29 | } 30 | 31 | public string ServerName 32 | { 33 | get => _serverName; 34 | private set 35 | { 36 | _serverName = value; 37 | OnPropertyChanged(); 38 | } 39 | } 40 | 41 | public int PlayerCount 42 | { 43 | get => _playerCount; 44 | private set 45 | { 46 | _playerCount = value; 47 | OnPropertyChanged(); 48 | } 49 | } 50 | 51 | public bool? IsConnectedAndAuthed => _client?.Authenticated; 52 | 53 | public Action Disconnected; 54 | 55 | private string _serverVersion = "v0.0.0.0"; 56 | private string _serverName = "PalWorld"; 57 | private RCON _client; 58 | private bool _clientDisposed; 59 | private int _playerCount; 60 | 61 | private void CreateRconClient(IPAddress address, ushort port) 62 | { 63 | if (_client != null && _client.Connected) _client.Dispose(); 64 | 65 | _client = new RCON(address, port, settings.RCONPassword, sourceMultiPacketSupport: false, strictCommandPacketIdMatching: false, autoConnect: true); 66 | 67 | _client.OnDisconnected += RconDisconnect; 68 | _client.OnPacketReceived += OnPacketReceived; 69 | 70 | Log.Debug("Created RCON client, ready to connect."); 71 | } 72 | 73 | private void OnPacketReceived(RCONPacket obj) 74 | { 75 | if(settings.DebugMode) 76 | Log.Debug($"Packet - Body: {obj.Body} | ID: {obj.Id} | Type: {obj.Type}"); 77 | } 78 | 79 | private void OnConnectionFailed() 80 | { 81 | Log.Error("Unable to connect to the rcon server, check your address and port! You can check console for more info."); 82 | 83 | MainWindow.Instance.Dispatcher.Invoke(async () => 84 | { 85 | await MainWindow.Instance.ShowMessageAsync("Connection Error", "Unable to connect to the rcon server, check your address and port! You can check console for more info."); 86 | MainWindow.Instance.ConnectBtn.Content = "Connect"; 87 | }); 88 | 89 | Disconnected?.Invoke(); 90 | } 91 | 92 | public void Disconnect() 93 | { 94 | if (_clientDisposed) return; 95 | 96 | _clientDisposed = true; 97 | 98 | _client.Dispose(); 99 | 100 | _client = null; 101 | 102 | RconDisconnect(); 103 | 104 | Log.Info("Disconnected from the rcon server."); 105 | } 106 | 107 | public async Task ConnectToRCON(bool testConn = false) 108 | { 109 | if (!IPAddress.TryParse(settings.ServerAddress, out var address)) return false; 110 | 111 | if (_client is { Connected: true }) 112 | { 113 | //Disconnect client first 114 | Disconnect(); 115 | } 116 | 117 | _clientDisposed = false; 118 | 119 | //Create new client after dispose and cleanup 120 | CreateRconClient(address, settings.ServerPort); 121 | 122 | MainWindow.Instance.ConnectBtn.Content = "Connecting..."; 123 | 124 | await _client.ConnectAsync(); 125 | 126 | if (!_client.Connected) 127 | { 128 | //Failed to connect 129 | if(!testConn) 130 | OnConnectionFailed(); 131 | return false; 132 | } 133 | 134 | var success = await _client.AuthenticateAsync(); 135 | 136 | if (testConn) 137 | { 138 | _client.Dispose(); 139 | _client = null; 140 | return success; 141 | } 142 | 143 | if (success) 144 | { 145 | OnAuth?.Invoke(true); 146 | 147 | //Poll server info 148 | var info = await GetInfo(); 149 | ServerName = info.ServerName; 150 | ServerVersion = info.ServerVersion; 151 | } 152 | else 153 | { 154 | OnAuth?.Invoke(false); 155 | } 156 | 157 | return success; 158 | } 159 | 160 | public async Task SendNotice(string notice) 161 | { 162 | if(string.IsNullOrWhiteSpace(notice) || !_client.Authenticated) return null; 163 | 164 | return await _client.SendCommandAsync($"Broadcast {notice}"); 165 | } 166 | 167 | public async Task DoQuit(string shutdownMessage) 168 | { 169 | if (!_client.Authenticated) return null; 170 | 171 | return await _client.SendCommandAsync($"Shutdown 30 {shutdownMessage}"); 172 | } 173 | 174 | public async Task Save() 175 | { 176 | if (!_client.Authenticated) return null; 177 | 178 | return await _client.SendCommandAsync("Save"); 179 | } 180 | 181 | public async Task GetPlayers() 182 | { 183 | if(!_client.Authenticated) return null; 184 | 185 | var players = await _client.SendCommandAsync("ShowPlayers"); 186 | PlayerCount = players.Players.Count; 187 | 188 | return players; 189 | } 190 | 191 | public async Task SendRawCommand(string command) 192 | { 193 | if (string.IsNullOrWhiteSpace(command)) return null; 194 | 195 | return await _client.SendCommandAsync(command); 196 | } 197 | 198 | public async Task KickPlayer(string steamid) 199 | { 200 | if (string.IsNullOrWhiteSpace(steamid)) return null; 201 | 202 | return await _client.SendCommandAsync($"KickPlayer {steamid}"); 203 | } 204 | 205 | public async Task BanPlayer(string steamid) 206 | { 207 | if (string.IsNullOrWhiteSpace(steamid)) return null; 208 | 209 | return await _client.SendCommandAsync($"BanPlayer {steamid}"); 210 | } 211 | 212 | public async Task GetInfo() 213 | { 214 | if(!_client.Authenticated) return null; 215 | return await _client.SendCommandAsync("info"); 216 | } 217 | 218 | private void RconDisconnect() 219 | { 220 | ServerName = "Disconnected"; 221 | ServerVersion = "v0.0.0.0"; 222 | 223 | MainWindow.Instance.Dispatcher.Invoke(() => 224 | { 225 | MainWindow.Instance.Notifier.ShowError("Disconnected from Palworld server!"); 226 | }); 227 | 228 | Disconnected?.Invoke(); 229 | } 230 | 231 | public event PropertyChangedEventHandler PropertyChanged; 232 | 233 | protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) 234 | { 235 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 236 | } 237 | 238 | protected bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) 239 | { 240 | if (EqualityComparer.Default.Equals(field, value)) return false; 241 | field = value; 242 | OnPropertyChanged(propertyName); 243 | return true; 244 | } 245 | } -------------------------------------------------------------------------------- /PalworldRcon/Logic/Responses/Player.cs: -------------------------------------------------------------------------------- 1 | namespace PalworldRcon; 2 | 3 | public class Player 4 | { 5 | public string PlayerName; 6 | public string CharacterID; 7 | public string SteamID; 8 | 9 | public Player(string playerName, string characterID, string steamID) 10 | { 11 | PlayerName = playerName; 12 | CharacterID = characterID; 13 | SteamID = steamID; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return $"Player Name: {PlayerName} | SteamID: {SteamID}"; 19 | } 20 | } -------------------------------------------------------------------------------- /PalworldRcon/Logic/Responses/PlayerList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.RegularExpressions; 3 | using CoreRCON.Parsers; 4 | 5 | namespace PalworldRcon.Logic.Responses; 6 | 7 | public class PlayerList : IParseable 8 | { 9 | public List Players { get; set; } = new(); 10 | } 11 | 12 | public class PlayerListParser : IParser 13 | { 14 | public bool IsMatch(string input) 15 | { 16 | return input.StartsWith("name,playeruid,steamid"); 17 | } 18 | 19 | public PlayerList Load(GroupCollection groups) 20 | { 21 | throw new System.NotImplementedException(); 22 | } 23 | 24 | public PlayerList Parse(string input) 25 | { 26 | Regex regex = new Regex(Pattern, RegexOptions.Compiled); 27 | MatchCollection matches = regex.Matches(input); 28 | 29 | var playerList = new PlayerList(); 30 | 31 | foreach (Match match in matches) 32 | { 33 | playerList.Players.Add(new Player(match.Groups["playername"].Value, match.Groups["charid"].Value, match.Groups["steamid"].Value)); 34 | } 35 | 36 | return playerList; 37 | } 38 | 39 | public PlayerList Parse(Group group) 40 | { 41 | throw new System.NotImplementedException(); 42 | } 43 | 44 | public string Pattern => "(?'playername'.*),(?'charid'(?!playeruid).*),(?'steamid'.*)"; 45 | } -------------------------------------------------------------------------------- /PalworldRcon/Logic/Responses/ServerInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | using CoreRCON.Parsers; 3 | 4 | namespace PalworldRcon.Logic.Responses; 5 | 6 | public class ServerInfo : IParseable 7 | { 8 | public string ServerName { get; set; } = "Not Connected"; 9 | public string ServerVersion { get; set; } = "v0.0.0.0"; 10 | } 11 | 12 | public class ServerInfoParser : DefaultParser 13 | { 14 | public override ServerInfo Load(GroupCollection groups) 15 | { 16 | return new ServerInfo() 17 | { 18 | ServerName = groups["servername"].Value, 19 | ServerVersion = groups["version"].Value, 20 | }; 21 | } 22 | 23 | public override string Pattern => "\\[(?'version'.*)\\] (?'servername'.*)"; 24 | } -------------------------------------------------------------------------------- /PalworldRcon/Logic/Settings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using Microsoft.Win32; 4 | 5 | namespace PalworldRcon 6 | { 7 | public class Settings 8 | { 9 | public string ServerAddress { get; set; } 10 | public string RCONPassword { get; set; } 11 | public ushort ServerPort { get; set; } 12 | public bool ShowJoinLeaves { get; set; } 13 | public bool DebugMode { get; set; } 14 | 15 | private readonly RegistryKey _rconSubkey; 16 | 17 | public Settings() 18 | { 19 | _rconSubkey = Registry.CurrentUser.OpenSubKey(@"Software\BTK-Development\PalworldRcon", true) ?? Registry.CurrentUser.CreateSubKey(@"Software\BTK-Development\PalworldRcon"); 20 | 21 | LoadSettings(); 22 | } 23 | 24 | public void SaveSettings() 25 | { 26 | if (_rconSubkey == null) return; 27 | 28 | _rconSubkey.SetValue("RCONPassword", RCONPassword); 29 | _rconSubkey.SetValue("ServerAddress", ServerAddress); 30 | _rconSubkey.SetValue("ServerPort", ServerPort); 31 | _rconSubkey.SetValue("ShowJoinLeaves", ShowJoinLeaves); 32 | _rconSubkey.SetValue("DebugMode", DebugMode); 33 | } 34 | 35 | public void LoadSettings() 36 | { 37 | if (_rconSubkey == null) return; 38 | 39 | RCONPassword = Convert.ToString(_rconSubkey.GetValue("RCONPassword", "")); 40 | ServerAddress = Convert.ToString(_rconSubkey.GetValue("ServerAddress", "")); 41 | ServerPort = Convert.ToUInt16(_rconSubkey.GetValue("ServerPort", 25575)); 42 | ShowJoinLeaves = Convert.ToBoolean(_rconSubkey.GetValue("ShowJoinLeaves", true)); 43 | DebugMode = Convert.ToBoolean(_rconSubkey.GetValue("DebugMode", false)); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /PalworldRcon/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |