Skip to content

Commit

Permalink
n/a
Browse files Browse the repository at this point in the history
  • Loading branch information
andreakarasho committed Jul 23, 2024
0 parents commit eb965b5
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/preset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Preset
about: new shard preset
title: "<SHARD_NAME> preset"
labels: new-preset
assignees: ''

---

name=
ip=
port=
encryption=
32 changes: 32 additions & 0 deletions .github/workflows/automatic-presets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on:
schedule:
- cron: "0 * * * *"
#push:
# branches:
# - main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup .NET 6
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.*

- name: Build presets.xml
run: dotnet run PresetsGenerator.csproj

- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: presets.xml
asset_name: presets.xml
tag: release-${{ github.ref }}
overwrite: true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bin/
obj/

.suo
.vs
presets.xml
8 changes: 8 additions & 0 deletions PresetsGenerator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

</Project>
199 changes: 199 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;

namespace PresetsGenerator
{
class Program
{
static void Main(string[] args)
{
GenerateXML(AnalyzeAllPresets());
}




static List<PresetEntry> AnalyzeAllPresets()
{
List<PresetEntry> list = new List<PresetEntry>();

var dirs = Directory.GetDirectories("./presets");

Trace($"found {dirs.Length} directories");

foreach (var dir in dirs)
{
Trace("reading dir --> " + dir);

var files = Directory.GetFiles(dir);

Trace($"found {files.Length} files");

foreach (var file in files)
{
if (file.EndsWith(".txt"))
{
var content = File.ReadAllText(file);

if (!string.IsNullOrWhiteSpace(content))
{
var name = ReadValue(content, "name");
var ip = ReadValue(content, "ip");
var port = ReadValue(content, "port");
var clientVersion = ReadValue(content, "client_version");
var encryption = ReadValue(content, "encryption");

bool error = false;

if (name.IsEmpty)
{
Error("invalid name value");
error = true;
}

if (ip.IsEmpty)
{
Error("invalid ip value");
error = true;
}

if (port.IsEmpty || !ushort.TryParse(port, out var _))
{
Error("invalid port value");
error = true;
}

if (clientVersion.IsEmpty)
{
Error("invalid client_version value");
error = true;
}

bool useEncryption = false;
if (encryption == "yes")
{
useEncryption = true;
}
else if (encryption == "no")
{
useEncryption = false;
}
else if (encryption.IsEmpty || !bool.TryParse(encryption, out useEncryption))
{
Warn("invalid encryption value. Value will be set to 'false'");
}

if (!error)
{
Trace("storing data to the list");

list.Add(new PresetEntry()
{
Name = name.ToString(),
IP = ip.ToString(),
Port = port.ToString(),
ClientVersion = clientVersion.ToString(),
Encryption = useEncryption
});
}
else
{
Warn("error :(");
}
}
else
{
Error($"file '{file}' does not contains valid data");
}
}
}
}

return list;
}

static void GenerateXML(List<PresetEntry> list)
{
using System.Xml.XmlTextWriter xml = new XmlTextWriter("presets.xml", Encoding.UTF8)
{
Formatting = Formatting.Indented,
IndentChar = '\t',
Indentation = 1
};

xml.WriteStartDocument(true);

xml.WriteStartElement("presets");

foreach (var e in list)
{
xml.WriteStartElement("preset");

xml.WriteAttributeString("name", e.Name);
xml.WriteAttributeString("ip", e.IP);
xml.WriteAttributeString("port", e.Port);
xml.WriteAttributeString("client_version", e.ClientVersion);
xml.WriteAttributeString("encryption", e.Encryption.ToString());

xml.WriteEndElement();
}

xml.WriteEndElement();

xml.WriteEndDocument();
}


static ReadOnlySpan<char> ReadValue(string entry, string key)
{
int keyIdx = entry.IndexOf(key);
if (keyIdx >= 0)
{
int valueIdx = entry.IndexOf('=', keyIdx);

if (valueIdx >= 0)
{
valueIdx++;
int endOfLineIdx = entry.IndexOf('\n', valueIdx);

if (endOfLineIdx <= 0)
{
endOfLineIdx = entry.Length;
}

var span = entry.AsSpan(valueIdx, endOfLineIdx - valueIdx);

int rnIdx = span.IndexOf('\r');
if (rnIdx >= 0)
{
span = span.Slice(0, rnIdx);
}

if (!span.IsWhiteSpace())
{
return span;
}
}
}

return default;
}

class PresetEntry
{
public string Name = string.Empty;
public string IP = string.Empty;
public string Port = string.Empty;
public string ClientVersion = string.Empty;
public bool Encryption;
}


static void Trace(string msg) => Console.WriteLine("[TRACE] {0}", msg);
static void Warn(string msg) => Console.WriteLine("[WARN] {0}", msg);
static void Error(string msg) => Console.WriteLine("[ERROR] {0}", msg);
}
}
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ClassicUO shard presets for the Launcher
A collection of UO presets for the ClassicUO Launcher app


# Template
- Fork the repo
- Create a folder in "presets"
- Save the "preset.txt" using the template below in the folder created the step before
- Send the PR


```
name=
ip=
port=
client_version=
encryption=
```
5 changes: 5 additions & 0 deletions presets/Eclipse/preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name=Eclipse
ip=play.uoeclipse.com
port=2593
client_version=7.0.95.0
encryption=0
5 changes: 5 additions & 0 deletions presets/Elemental/preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name=Elemental
ip=login.uoelemental.com
port=2593
client_version=7.0.88.1
encryption=false
5 changes: 5 additions & 0 deletions presets/Heritage/preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name=Heritage
ip=play.trueuo.com
port=2593
client_version=7.0.90.16
encryption=false
5 changes: 5 additions & 0 deletions presets/LegenD/preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name=LegenD
ip=login.legendshard.com.br
port=2593
client_version=7.0.20.0
encryption=false
5 changes: 5 additions & 0 deletions presets/Millenia/preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name=Millenia
ip=millenia.ultimaonline-freeshard.de
port=2011
client_version=6.0.1.10
encryption=false
5 changes: 5 additions & 0 deletions presets/UO Felucca/preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name=UO: Felucca
ip=login.uofelucca.com
port=2593
client_version=7.0.97.25
encryption=false
5 changes: 5 additions & 0 deletions presets/UOAlive/preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name=UOAlive
ip=login.uoalive.com
port=2593
client_version=7.0.99.0
encryption=false
5 changes: 5 additions & 0 deletions presets/Utopia/preset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name=Utopia
ip=login.uoutopia.com
port=2593
client_version=7.0.31.0
encryption=false

0 comments on commit eb965b5

Please # to comment.