This commit is contained in:
MasterGordon 2022-10-25 13:31:07 +02:00
commit 0da8abdeca
124 changed files with 2052 additions and 0 deletions

View File

@ -0,0 +1,32 @@
name: .NET
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Publish
run: dotnet publish -r linux-x64
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.1.0
with:
# Artifact name
name: Linux build
# A file, directory or wildcard pattern that describes what to upload
path: bin/Debug/net6.0/linux-x64/publish/asdlteroids

2
boulder-dash/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
bin/
obj/

10
boulder-dash/Program.cs Normal file
View File

@ -0,0 +1,10 @@
class Program
{
static void Main(string[] args)
{
// bool isHost = args.Contains("--host");
bool isHost = true;
var game = new MultiPlayerGame(isHost);
game.Run();
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,90 @@
[
[
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
],
[
1, 2, 2, 2, 2, 2, 2, 0, 2, 2, 3, 2, 4, 0, 2, 2, 2, 2, 2, 4, 2, 4, 2, 2, 2,
2, 2, 2, 2, 0, 2, 2, 2, 2, 4, 2, 2, 2, 2, 1
],
[
1, 2, 4, 9, 4, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 3, 2, 2,
4, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 0, 2, 2, 1
],
[
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 0, 2, 2, 2, 2, 2, 4, 2, 4, 2, 2,
4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 1
],
[
1, 4, 2, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4,
2, 2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 2, 2, 1
],
[
1, 4, 2, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2,
2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 4, 0, 2, 1
],
[
1, 2, 2, 2, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 4, 2, 0,
4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 4, 4, 2, 1
],
[
1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 2, 2, 2, 4, 2, 2, 4, 2, 1
],
[
1, 2, 0, 2, 2, 2, 4, 2, 2, 3, 2, 0, 2, 2, 4, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 3, 2, 4, 0, 2, 2, 2, 2, 2, 2, 4, 2, 1
],
[
1, 2, 2, 3, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 4,
0, 0, 4, 2, 2, 3, 2, 2, 2, 2, 4, 2, 2, 2, 1
],
[
1, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4,
4, 2, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 1
],
[
1, 2, 0, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 2, 2, 2, 2,
2, 2, 4, 2, 2, 4, 2, 3, 2, 2, 2, 2, 0, 2, 1
],
[
1, 2, 4, 2, 2, 2, 2, 2, 4, 2, 2, 0, 0, 2, 2, 2, 2, 4, 2, 4, 3, 2, 2, 3, 2,
2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 3, 2, 4, 2, 1
],
[
1, 2, 3, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 2, 2, 4, 2,
2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 4, 1
],
[
1, 2, 2, 2, 2, 2, 2, 2, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1
],
[
1, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 3, 2, 2, 2, 2, 4, 2, 2, 2,
2, 2, 4, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 1
],
[
1, 0, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 4, 2, 2, 0, 0, 0, 2, 2, 2,
4, 2, 2, 2, 2, 2, 2, 4, 2, 4, 0, 2, 2, 1, 1
],
[
1, 2, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 4, 2, 0, 0, 2,
2, 2, 2, 3, 2, 2, 2, 4, 2, 4, 4, 2, 2, 2, 1
],
[
1, 2, 2, 2, 2, 4, 3, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2,
4, 2, 4, 3, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 1
],
[
1, 2, 2, 2, 0, 2, 2, 0, 2, 4, 2, 2, 4, 2, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2,
4, 2, 4, 3, 2, 2, 2, 2, 2, 2, 4, 2, 2, 4, 1
],
[
1, 2, 3, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2,
4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 1
],
[
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
]
]

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>boulder-dash</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ppy.SDL2-CS" Version="1.0.596-alpha" />
<PackageReference Include="WatsonTcp" Version="4.8.14.14" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="assets/*" />
</ItemGroup>
</Project>

2
boulder-dash/readme.md Normal file
View File

@ -0,0 +1,2 @@
# Boulder Dash SDL

View File

@ -0,0 +1,41 @@
class Context
{
public bool IsHost { get; set; }
public IBackend Backend { get; set; }
public IFrontend Frontend { get; set; }
public GameState GameState { get; set; }
public FrontendGameState FrontendGameState { get; set; }
public Window Window { get; set; }
public Renderer Renderer { get; set; }
public static Context? instance { get; set; }
public Context(
bool isHost,
IBackend backend,
IFrontend frontend,
GameState gameState,
FrontendGameState frontendGameState,
Renderer renderer,
Window window
)
{
this.IsHost = isHost;
this.Backend = backend;
this.Frontend = frontend;
this.GameState = gameState;
this.FrontendGameState = frontendGameState;
this.Renderer = renderer;
this.Window = window;
Context.instance = this;
}
public static Context Get()
{
if (Context.instance == null)
{
throw new Exception("Context not initialized");
}
return Context.instance;
}
}

View File

@ -0,0 +1,35 @@
using static SDL2.SDL;
enum Control
{
UP,
DOWN,
LEFT,
RIGHT,
STAY,
CONFIRM,
}
static class ControlKeyExtension
{
public static SDL_Keycode Key(this Control c)
{
switch (c)
{
case Control.UP:
return SDL_Keycode.SDLK_w;
case Control.DOWN:
return SDL_Keycode.SDLK_s;
case Control.LEFT:
return SDL_Keycode.SDLK_a;
case Control.RIGHT:
return SDL_Keycode.SDLK_d;
case Control.STAY:
return SDL_Keycode.SDLK_LCTRL;
case Control.CONFIRM:
return SDL_Keycode.SDLK_SPACE;
default:
throw new ArgumentException("Invalid control");
}
}
}

View File

@ -0,0 +1,45 @@
class MultiPlayerGame : Game
{
private Context ctx;
public MultiPlayerGame(bool isHost)
{
var window = new Window("MultiPlayerGame", 1200, 800);
if (isHost)
{
this.ctx = new Context(
isHost,
new Backend(),
new Frontend(),
new GameState(),
new FrontendGameState(),
new Renderer(window),
window
);
}
else
{
this.ctx = new Context(
isHost,
new RemoteBackend(),
new Frontend(),
new GameState(),
new FrontendGameState(),
new Renderer(window),
window
);
}
ctx.Frontend.Init();
ctx.Backend.Init();
}
protected override void draw()
{
ctx.Frontend.Process();
}
protected override void update(double dt)
{
ctx.Backend.Process(dt);
}
}

View File

@ -0,0 +1,73 @@
using System.Numerics;
using System.Text;
using Newtonsoft.Json;
using WatsonTcp;
class Backend : IBackend
{
public void Process(double dt)
{
var ctx = Context.Get();
ctx.GameState.PlayerPositions.ForEach(player =>
{
player.position += player.movement;
});
}
public void ProcessPacket(ValueType packet)
{
var gameState = Context.Get().GameState;
if (packet is MovePacket movePacket)
{
if (gameState.PlayerPositions.Find(player => player.name == movePacket.playerName) is Player player)
{
player.movement = movePacket.movement;
}
}
if (packet is ConnectPacket connectPacket)
{
gameState.PlayerPositions.Add(new Player
{
name = connectPacket.playerName,
position = new Vector2(50, 50),
movement = new Vector2(0, 0)
});
}
}
public void Init()
{
Task.Run(Run);
}
public void Run()
{
var server = new WatsonTcpServer("127.0.0.1", 42069);
server.Events.ClientConnected += this.clientConnected;
server.Events.ClientDisconnected += this.clientDisconnected;
server.Events.MessageReceived += this.messageReceived;
server.Start();
}
private void clientConnected(object? sender, ConnectionEventArgs args)
{
Console.WriteLine("Client connected: " + args.IpPort);
var gameState = Context.Get().GameState;
var json = JsonConvert.SerializeObject(gameState);
if (sender is WatsonTcpServer server)
{
server.Send(args.IpPort, Encoding.UTF8.GetBytes(json));
}
}
private void clientDisconnected(object? sender, DisconnectionEventArgs args)
{
Console.WriteLine("Client disconnected: " + args.IpPort);
}
private void messageReceived(object? sender, MessageReceivedEventArgs args)
{
var message = Encoding.UTF8.GetString(args.Data);
Console.WriteLine("Message received: " + args.IpPort + " " + message);
}
}

View File

@ -0,0 +1,6 @@
interface IBackend
{
public void Process(double dt);
public void ProcessPacket(ValueType packet);
public void Init();
}

View File

@ -0,0 +1,17 @@
class RemoteBackend : IBackend
{
public void Process(double dt)
{
}
public void ProcessPacket(ValueType packet)
{
throw new NotImplementedException();
}
public void Init()
{
}
}

View File

@ -0,0 +1,25 @@
using System.Numerics;
readonly struct MovePacket
{
readonly public string type = "move";
readonly public string playerName;
readonly public Vector2 movement;
public MovePacket(string playerName, Vector2 movement)
{
this.playerName = playerName;
this.movement = movement;
}
}
readonly struct ConnectPacket
{
public readonly string type = "connect";
public readonly string playerName;
public ConnectPacket(string playerName)
{
this.playerName = playerName;
}
}

View File

@ -0,0 +1,27 @@
enum Sound
{
}
class AudioPlayer
{
private Dictionary<Sound, byte[]> audioFiles = new();
private ResourceLoader resourceLoader = new();
public AudioPlayer()
{
SDL2.SDL_mixer.Mix_OpenAudio(44100, SDL2.SDL_mixer.MIX_DEFAULT_FORMAT, 2, 2048);
}
public void Register(Sound name, string path)
{
var buffer = resourceLoader.LoadBytes(path);
this.audioFiles.Add(name, buffer);
}
public void Play(Sound name)
{
var buffer = this.audioFiles[name];
var sound = SDL2.SDL_mixer.Mix_QuickLoad_WAV(buffer);
SDL2.SDL_mixer.Mix_PlayChannel((int)name, sound, 0);
}
}

View File

@ -0,0 +1,35 @@
using static SDL2.SDL_ttf;
using static SDL2.SDL;
class FontManager
{
private Dictionary<string, IntPtr> fonts = new();
private ResourceLoader resourceLoader;
public FontManager(ResourceLoader resourceLoader)
{
this.resourceLoader = resourceLoader;
if (TTF_Init() != 0)
{
throw new Exception("TTF_Init failed");
}
}
public void RegisterFont(string name, string path, int fontSize)
{
if (fonts.ContainsKey(name)) return;
var res = resourceLoader.LoadToIntPtr(path);
var sdlBuffer = SDL_RWFromConstMem(res.ptr, res.size);
var font = TTF_OpenFontRW(sdlBuffer, 1, fontSize);
if (font == IntPtr.Zero)
{
throw new Exception("TTF_OpenFont failed");
}
fonts.Add(name, font);
}
public IntPtr GetFont(string name)
{
return fonts[name];
}
}

View File

@ -0,0 +1,30 @@
abstract class Game
{
public const int TPS = 64;
private Queue<int> fpsQueue = new Queue<int>();
protected abstract void update(double dt);
protected abstract void draw();
public void Run()
{
var tLast = DateTime.Now;
var tAcc = TimeSpan.Zero;
while (true)
{
var dt = DateTime.Now - tLast;
tLast = DateTime.Now;
tAcc += dt;
var fps = (int)(1 / dt.TotalSeconds);
fpsQueue.Enqueue(fps);
while (fpsQueue.Count > fps)
fpsQueue.Dequeue();
while (tAcc >= TimeSpan.FromSeconds(1.0 / TPS))
{
update(dt.TotalSeconds);
tAcc -= TimeSpan.FromSeconds(1.0 / TPS);
}
draw();
}
}
}

View File

@ -0,0 +1,107 @@
using static SDL2.SDL;
using static SDL2.SDL_ttf;
class Renderer
{
private IntPtr renderer;
private IntPtr font;
private SDL_Color color;
public Renderer(Window window)
{
this.renderer = SDL_CreateRenderer(window.GetWindow(), -1, SDL_RendererFlags.SDL_RENDERER_ACCELERATED);
}
public void Clear()
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
}
public void Present()
{
SDL_RenderPresent(renderer);
}
public void DrawRect(double x, double y, int w, int h)
{
this.DrawRect((int)x, (int)y, w, h);
}
public void DrawRect(int x, int y, int w, int h)
{
SDL_Rect rect = new SDL_Rect();
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
SDL_RenderFillRect(renderer, ref rect);
}
public void DrawLines(double[][] points)
{
SDL_Point[] sdlPoints = new SDL_Point[points.Length];
for (int i = 0; i < points.Length; i++)
{
sdlPoints[i].x = (int)points[i][0];
sdlPoints[i].y = (int)points[i][1];
}
SDL_RenderDrawLines(renderer, sdlPoints, points.Length);
}
public void SetColor(int r, int g, int b, int a = 255)
{
SDL_SetRenderDrawColor(renderer, (byte)r, (byte)g, (byte)b, (byte)a);
}
public void SetFont(IntPtr font, SDL_Color color)
{
this.font = font;
this.color = color;
}
public void SetFont(IntPtr font, Color color)
{
this.font = font;
this.color = color.toSDLColor();
}
public void DrawText(string text, int x, int y, bool center = false)
{
var surfaceMessage = TTF_RenderText_Solid(this.font, text, this.color);
var texture = SDL_CreateTextureFromSurface(this.renderer, surfaceMessage);
int width;
int height;
SDL_QueryTexture(texture, out _, out _, out width, out height);
SDL_Rect rect = new SDL_Rect();
rect.x = x;
rect.y = y;
rect.w = width;
rect.h = height;
if (center)
{
rect.x -= width / 2;
rect.y -= height / 2;
}
SDL_RenderCopy(this.renderer, texture, IntPtr.Zero, ref rect);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surfaceMessage);
}
public IntPtr GetRaw()
{
return renderer;
}
public IntPtr CreateTextureFromSurface(IntPtr surface)
{
return SDL_CreateTextureFromSurface(renderer, surface);
}
}

View File

@ -0,0 +1,50 @@
using System.Runtime.InteropServices;
class ResourceLoader
{
private string assemblyName;
public ResourceLoader()
{
this.assemblyName = this.GetType().Assembly.GetName().Name!;
}
public string LoadString(string resourceName)
{
#if (DEBUG)
Console.WriteLine("Loading resource: " + resourceName);
return File.ReadAllText(ToPath(resourceName));
#endif
using var stream = this.GetType().Assembly.GetManifestResourceStream($"{this.assemblyName}.{resourceName}");
using var reader = new StreamReader(stream!);
return reader.ReadToEnd();
}
public byte[] LoadBytes(string resourceName)
{
using var stream = this.GetType().Assembly.GetManifestResourceStream($"{this.assemblyName}.{resourceName}");
using var memoryStream = new MemoryStream();
stream!.CopyTo(memoryStream);
return memoryStream.ToArray();
}
public (IntPtr ptr, int size) LoadToIntPtr(string resourceName)
{
var bytes = this.LoadBytes(resourceName);
var handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
var ptr = handle.AddrOfPinnedObject();
return (ptr, bytes.Length);
}
public void SaveString(string resourceName, string content)
{
using var stream = new StreamWriter(ToPath(resourceName));
stream.Write(content);
}
private static string ToPath(string resourceName)
{
var s = resourceName.Split('.');
return String.Join('/', s[..^1]) + "." + s[^1];
}
}

View File

@ -0,0 +1,33 @@
using static SDL2.SDL;
class Window
{
IntPtr window;
public Window(string title, int w, int h)
{
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WindowFlags.SDL_WINDOW_VULKAN | SDL_WindowFlags.SDL_WINDOW_RESIZABLE);
}
public Window(string title, int x, int y, int w, int h, SDL_WindowFlags flags)
{
this.window = SDL_CreateWindow(title, x, y, w, h, flags);
}
public void Dispose()
{
SDL_DestroyWindow(this.window);
}
public IntPtr GetWindow()
{
return this.window;
}
public (int width, int height) GetSize()
{
int w, h;
SDL_GetWindowSize(this.window, out w, out h);
return (w, h);
}
}

View File

@ -0,0 +1,9 @@
enum EventPriority : int
{
Lowest = 0,
Low = 1,
Normal = 2,
High = 3,
Highest = 4,
Important = 5,
}

View File

@ -0,0 +1,35 @@
[AttributeUsage(AttributeTargets.Method)]
class OnECSEvent : Attribute
{
public EventPriority Priority = EventPriority.Normal;
}
class OnTickEvent : OnECSEvent
{
}
struct TickEvent
{
public int Tick;
}
class OnKeyDownEvent : OnECSEvent
{
public SDL2.SDL.SDL_Scancode? Scancode;
}
class KeyEvent
{
public SDL2.SDL.SDL_Scancode Scancode;
public bool Canceled;
}
class OnKeyUpEvent : OnECSEvent
{
public SDL2.SDL.SDL_Scancode? Scancode;
}
class OnMouseButtonDownEvent : OnECSEvent
{
public SDL2.SDL.SDL_Scancode? Scancode;
}

View File

@ -0,0 +1,28 @@
class ECSystemRegistry
{
private HashSet<object> hybridSystems;
private HashSet<object> clientSystems;
private HashSet<object> serverSystems;
public ECSystemRegistry()
{
hybridSystems = new HashSet<object>();
clientSystems = new HashSet<object>();
serverSystems = new HashSet<object>();
object obj = new object();
}
public void RegisterSystem(object system, ECSystemKind kind)
{
this.GetSystems(kind).Add(system);
}
public HashSet<object> GetSystems(ECSystemKind kind) =>
kind switch
{
ECSystemKind.Hybrid => hybridSystems,
ECSystemKind.Client => clientSystems,
ECSystemKind.Server => serverSystems,
_ => throw new ArgumentException("Invalid ECSystemKind")
};
}

View File

@ -0,0 +1,17 @@
enum ECSystemKind
{
Client,
Server,
Hybrid
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
class ECSystem : Attribute
{
public ECSystemKind Kind;
public ECSystem(ECSystemKind kind)
{
this.Kind = kind;
}
}

View File

@ -0,0 +1,32 @@
using static SDL2.SDL;
class Color
{
int r, g, b, a;
public Color(int r, int g, int b, int a)
{
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
public Color(int r, int g, int b)
{
this.r = r;
this.g = g;
this.b = b;
this.a = 255;
}
public SDL_Color toSDLColor()
{
SDL_Color color = new SDL_Color();
color.r = (byte)r;
color.g = (byte)g;
color.b = (byte)b;
color.a = (byte)a;
return color;
}
}

View File

@ -0,0 +1,7 @@
class Point
{
public static double Distance(double x1, double y1, double x2, double y2)
{
return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
}
}

View File

@ -0,0 +1,85 @@
using System.Numerics;
using static SDL2.SDL;
class Frontend : IFrontend
{
public void Init()
{
var conntectPacket = new ConnectPacket("Gordon");
Context.Get().Backend.ProcessPacket(conntectPacket);
}
public void Process()
{
var ctx = Context.Get();
while (SDL_PollEvent(out var e) != 0)
{
if (e.type == SDL_EventType.SDL_QUIT)
{
System.Environment.Exit(0);
}
if (e.type == SDL_EventType.SDL_KEYDOWN && e.key.repeat == 0)
{
var movementInput = ctx.FrontendGameState.movementInput;
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_A)
{
movementInput.X -= 1;
}
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_D)
{
movementInput.X += 1;
}
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_W)
{
movementInput.Y -= 1;
}
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_S)
{
movementInput.Y += 1;
}
ctx.FrontendGameState.movementInput = movementInput;
}
if (e.type == SDL_EventType.SDL_KEYUP && e.key.repeat == 0)
{
var movementInput = ctx.FrontendGameState.movementInput;
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_A)
{
movementInput.X += 1;
}
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_D)
{
movementInput.X -= 1;
}
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_W)
{
movementInput.Y += 1;
}
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_S)
{
movementInput.Y -= 1;
}
ctx.FrontendGameState.movementInput = movementInput;
}
if (e.key.keysym.scancode is
SDL_Scancode.SDL_SCANCODE_A or SDL_Scancode.SDL_SCANCODE_D or SDL_Scancode.SDL_SCANCODE_W or SDL_Scancode.SDL_SCANCODE_S)
{
var movement = ctx.FrontendGameState.movementInput;
if (movement.Length() > 0)
movement = Vector2.Normalize(movement);
ctx.Backend.ProcessPacket(new MovePacket("Gordon", movement));
}
if (e.key.keysym.scancode == SDL_Scancode.SDL_SCANCODE_ESCAPE)
{
System.Environment.Exit(0);
}
}
ctx.Renderer.Clear();
ctx.Renderer.SetColor(255, 0, 0, 255);
ctx.GameState.PlayerPositions.ForEach(player =>
{
ctx.Renderer.DrawRect(player.position.X, player.position.Y, 10, 10);
});
ctx.Renderer.Present();
}
}

View File

@ -0,0 +1,5 @@
interface IFrontend
{
public void Process();
public void Init();
}

View File

@ -0,0 +1,34 @@
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
class Converter
{
public static ValueType ParsePacket(byte[] bytes)
{
var jsonString = Encoding.UTF8.GetString(bytes);
return ParsePacket(jsonString);
}
public static ValueType ParsePacket(string jsonString)
{
var parsedRaw = JObject.Parse(jsonString);
var type = parsedRaw.GetValue("type");
if (type == null)
{
throw new System.Exception("Packet has no type");
}
var packetType = type.Value<string>();
return packetType switch
{
"move" => parsedRaw.ToObject<MovePacket>(),
_ => throw new System.Exception("Unknown packet type")
};
}
public static byte[] SerializePacket(ValueType packet)
{
var jsonString = JsonConvert.SerializeObject(packet);
return Encoding.UTF8.GetBytes(jsonString);
}
}

View File

@ -0,0 +1,18 @@
using System.Numerics;
class Player
{
public string name;
public Vector2 position;
public Vector2 movement;
}
class FrontendGameState
{
public Vector2 movementInput;
}
class GameState
{
public List<Player> PlayerPositions { get; set; } = new List<Player>();
}

10
cli-args/Program.cs Normal file
View File

@ -0,0 +1,10 @@
class Program
{
public static void Main(String[] args)
{
foreach (var arg in args)
{
Console.WriteLine(arg);
}
}
}

Binary file not shown.

View File

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"cli-args/1.0.0": {
"runtime": {
"cli-args.dll": {}
}
}
}
},
"libraries": {
"cli-args/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}

11
cli-args/cli-args.csproj Normal file
View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>cli_args</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

BIN
cli-args/obj/Debug/net6.0/apphost Executable file

Binary file not shown.

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("cli-args")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("cli-args")]
[assembly: System.Reflection.AssemblyTitleAttribute("cli-args")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -0,0 +1 @@
1daa636f2fccb0338c228f257b0aa19d9e2dc078

View File

@ -0,0 +1,10 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = cli_args
build_property.ProjectDir = /home/gordon/git/dotnet-tests/cli-args/

View File

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

Binary file not shown.

View File

@ -0,0 +1 @@
5552358914d7d5b0fe79713d56499f99dc42a1f6

View File

@ -0,0 +1,15 @@
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/cli-args.csproj.AssemblyReference.cache
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/cli-args.GeneratedMSBuildEditorConfig.editorconfig
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/cli-args.AssemblyInfoInputs.cache
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/cli-args.AssemblyInfo.cs
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/cli-args.csproj.CoreCompileInputs.cache
/home/gordon/git/dotnet-tests/cli-args/bin/Debug/net6.0/cli-args
/home/gordon/git/dotnet-tests/cli-args/bin/Debug/net6.0/cli-args.deps.json
/home/gordon/git/dotnet-tests/cli-args/bin/Debug/net6.0/cli-args.runtimeconfig.json
/home/gordon/git/dotnet-tests/cli-args/bin/Debug/net6.0/cli-args.dll
/home/gordon/git/dotnet-tests/cli-args/bin/Debug/net6.0/cli-args.pdb
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/cli-args.dll
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/refint/cli-args.dll
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/cli-args.pdb
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/cli-args.genruntimeconfig.cache
/home/gordon/git/dotnet-tests/cli-args/obj/Debug/net6.0/ref/cli-args.dll

Binary file not shown.

View File

@ -0,0 +1 @@
88240fd2853022da532f77fffab91759b052cbad

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,67 @@
{
"format": 1,
"restore": {
"/home/gordon/git/dotnet-tests/cli-args/cli-args.csproj": {}
},
"projects": {
"/home/gordon/git/dotnet-tests/cli-args/cli-args.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/gordon/git/dotnet-tests/cli-args/cli-args.csproj",
"projectName": "cli-args",
"projectPath": "/home/gordon/git/dotnet-tests/cli-args/cli-args.csproj",
"packagesPath": "/home/gordon/.nuget/packages/",
"outputPath": "/home/gordon/git/dotnet-tests/cli-args/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/gordon/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[6.0.9, 6.0.9]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/6.0.401/RuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/gordon/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/gordon/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.3.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/gordon/.nuget/packages/" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@ -0,0 +1,72 @@
{
"version": 3,
"targets": {
"net6.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net6.0": []
},
"packageFolders": {
"/home/gordon/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/gordon/git/dotnet-tests/cli-args/cli-args.csproj",
"projectName": "cli-args",
"projectPath": "/home/gordon/git/dotnet-tests/cli-args/cli-args.csproj",
"packagesPath": "/home/gordon/.nuget/packages/",
"outputPath": "/home/gordon/git/dotnet-tests/cli-args/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/gordon/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[6.0.9, 6.0.9]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/6.0.401/RuntimeIdentifierGraph.json"
}
}
}
}

View File

@ -0,0 +1,10 @@
{
"version": 2,
"dgSpecHash": "VXwvmEpGzLbECp4Qyzgib2vDk6jac91EiD5q4QJWAjeDVVEkPw4dzFyAeEe/762KrL6mhQSKEJ+courypaBOMg==",
"success": true,
"projectFilePath": "/home/gordon/git/dotnet-tests/cli-args/cli-args.csproj",
"expectedPackageFiles": [
"/home/gordon/.nuget/packages/microsoft.aspnetcore.app.ref/6.0.9/microsoft.aspnetcore.app.ref.6.0.9.nupkg.sha512"
],
"logs": []
}

16
client-server/Program.cs Normal file
View File

@ -0,0 +1,16 @@
public class Program
{
public static async Task Main(string[] args)
{
if (args.Contains("--host"))
{
var TcpListener = new TcpServer();
await TcpListener.Run();
}
if (args.Contains("--client"))
{
var TcpClient = new TcpClient();
await TcpClient.Run();
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,59 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"client-server/1.0.0": {
"dependencies": {
"WatsonTcp": "4.8.14.14"
},
"runtime": {
"client-server.dll": {}
}
},
"Newtonsoft.Json/13.0.1": {
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"assemblyVersion": "13.0.0.0",
"fileVersion": "13.0.1.25517"
}
}
},
"WatsonTcp/4.8.14.14": {
"dependencies": {
"Newtonsoft.Json": "13.0.1"
},
"runtime": {
"lib/net6.0/WatsonTcp.dll": {
"assemblyVersion": "4.8.14.14",
"fileVersion": "4.8.14.14"
}
}
}
}
},
"libraries": {
"client-server/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Newtonsoft.Json/13.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==",
"path": "newtonsoft.json/13.0.1",
"hashPath": "newtonsoft.json.13.0.1.nupkg.sha512"
},
"WatsonTcp/4.8.14.14": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ANq8kEqFcyvgxq/CrKJAFwxDS01T0U9t+H4f7WVrRjf0XMw8aaRRd1WQi5lNS/8W9gf9FOUVLHSY0Gfsn6vN6g==",
"path": "watsontcp/4.8.14.14",
"hashPath": "watsontcp.4.8.14.14.nupkg.sha512"
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>client_server</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WatsonTcp" Version="4.8.14.14" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

Binary file not shown.

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("client-server")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("client-server")]
[assembly: System.Reflection.AssemblyTitleAttribute("client-server")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -0,0 +1 @@
c7088ec762d1d64cd13ee1cec0afaa471a0f69d3

View File

@ -0,0 +1,10 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = client_server
build_property.ProjectDir = /home/gordon/git/dotnet-tests/client-server/

View File

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View File

@ -0,0 +1 @@
c07f56ba41176466d03d79fc9315548334378d3c

View File

@ -0,0 +1,18 @@
/home/gordon/git/dotnet-tests/client-server/bin/Debug/net6.0/client-server
/home/gordon/git/dotnet-tests/client-server/bin/Debug/net6.0/client-server.deps.json
/home/gordon/git/dotnet-tests/client-server/bin/Debug/net6.0/client-server.runtimeconfig.json
/home/gordon/git/dotnet-tests/client-server/bin/Debug/net6.0/client-server.dll
/home/gordon/git/dotnet-tests/client-server/bin/Debug/net6.0/client-server.pdb
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.csproj.AssemblyReference.cache
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.GeneratedMSBuildEditorConfig.editorconfig
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.AssemblyInfoInputs.cache
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.AssemblyInfo.cs
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.csproj.CoreCompileInputs.cache
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.dll
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/refint/client-server.dll
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.pdb
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.genruntimeconfig.cache
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/ref/client-server.dll
/home/gordon/git/dotnet-tests/client-server/bin/Debug/net6.0/Newtonsoft.Json.dll
/home/gordon/git/dotnet-tests/client-server/bin/Debug/net6.0/WatsonTcp.dll
/home/gordon/git/dotnet-tests/client-server/obj/Debug/net6.0/client-server.csproj.CopyComplete

Binary file not shown.

View File

@ -0,0 +1 @@
5a54e844328afcd510367ddc9200bbdb96332e01

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,73 @@
{
"format": 1,
"restore": {
"/home/gordon/git/dotnet-tests/client-server/client-server.csproj": {}
},
"projects": {
"/home/gordon/git/dotnet-tests/client-server/client-server.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/gordon/git/dotnet-tests/client-server/client-server.csproj",
"projectName": "client-server",
"projectPath": "/home/gordon/git/dotnet-tests/client-server/client-server.csproj",
"packagesPath": "/home/gordon/.nuget/packages/",
"outputPath": "/home/gordon/git/dotnet-tests/client-server/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/gordon/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"WatsonTcp": {
"target": "Package",
"version": "[4.8.14.14, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[6.0.10, 6.0.10]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/6.0.402/RuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/gordon/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/gordon/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.3.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/home/gordon/.nuget/packages/" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@ -0,0 +1,165 @@
{
"version": 3,
"targets": {
"net6.0": {
"Newtonsoft.Json/13.0.1": {
"type": "package",
"compile": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"related": ".xml"
}
}
},
"WatsonTcp/4.8.14.14": {
"type": "package",
"dependencies": {
"Newtonsoft.Json": "13.0.1"
},
"compile": {
"lib/net6.0/WatsonTcp.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net6.0/WatsonTcp.dll": {
"related": ".xml"
}
}
}
}
},
"libraries": {
"Newtonsoft.Json/13.0.1": {
"sha512": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==",
"type": "package",
"path": "newtonsoft.json/13.0.1",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.md",
"lib/net20/Newtonsoft.Json.dll",
"lib/net20/Newtonsoft.Json.xml",
"lib/net35/Newtonsoft.Json.dll",
"lib/net35/Newtonsoft.Json.xml",
"lib/net40/Newtonsoft.Json.dll",
"lib/net40/Newtonsoft.Json.xml",
"lib/net45/Newtonsoft.Json.dll",
"lib/net45/Newtonsoft.Json.xml",
"lib/netstandard1.0/Newtonsoft.Json.dll",
"lib/netstandard1.0/Newtonsoft.Json.xml",
"lib/netstandard1.3/Newtonsoft.Json.dll",
"lib/netstandard1.3/Newtonsoft.Json.xml",
"lib/netstandard2.0/Newtonsoft.Json.dll",
"lib/netstandard2.0/Newtonsoft.Json.xml",
"newtonsoft.json.13.0.1.nupkg.sha512",
"newtonsoft.json.nuspec",
"packageIcon.png"
]
},
"WatsonTcp/4.8.14.14": {
"sha512": "ANq8kEqFcyvgxq/CrKJAFwxDS01T0U9t+H4f7WVrRjf0XMw8aaRRd1WQi5lNS/8W9gf9FOUVLHSY0Gfsn6vN6g==",
"type": "package",
"path": "watsontcp/4.8.14.14",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.md",
"lib/net461/WatsonTcp.dll",
"lib/net461/WatsonTcp.xml",
"lib/net472/WatsonTcp.dll",
"lib/net472/WatsonTcp.xml",
"lib/net5.0/WatsonTcp.dll",
"lib/net5.0/WatsonTcp.xml",
"lib/net6.0/WatsonTcp.dll",
"lib/net6.0/WatsonTcp.xml",
"lib/netcoreapp3.1/WatsonTcp.dll",
"lib/netcoreapp3.1/WatsonTcp.xml",
"lib/netstandard2.0/WatsonTcp.dll",
"lib/netstandard2.0/WatsonTcp.xml",
"lib/netstandard2.1/WatsonTcp.dll",
"lib/netstandard2.1/WatsonTcp.xml",
"watson.png",
"watsontcp.4.8.14.14.nupkg.sha512",
"watsontcp.nuspec"
]
}
},
"projectFileDependencyGroups": {
"net6.0": [
"WatsonTcp >= 4.8.14.14"
]
},
"packageFolders": {
"/home/gordon/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/home/gordon/git/dotnet-tests/client-server/client-server.csproj",
"projectName": "client-server",
"projectPath": "/home/gordon/git/dotnet-tests/client-server/client-server.csproj",
"packagesPath": "/home/gordon/.nuget/packages/",
"outputPath": "/home/gordon/git/dotnet-tests/client-server/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/home/gordon/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"WatsonTcp": {
"target": "Package",
"version": "[4.8.14.14, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[6.0.10, 6.0.10]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/6.0.402/RuntimeIdentifierGraph.json"
}
}
}
}

View File

@ -0,0 +1,12 @@
{
"version": 2,
"dgSpecHash": "gHPzrDYiBQaB4R8iWmVFMrYK0Jd+RWwZD6Pdazvg2LzkcJKrAYjAl/Qb9rUWhm0BfEmhD8zhW+R1qS0k9nkWXA==",
"success": true,
"projectFilePath": "/home/gordon/git/dotnet-tests/client-server/client-server.csproj",
"expectedPackageFiles": [
"/home/gordon/.nuget/packages/newtonsoft.json/13.0.1/newtonsoft.json.13.0.1.nupkg.sha512",
"/home/gordon/.nuget/packages/watsontcp/4.8.14.14/watsontcp.4.8.14.14.nupkg.sha512",
"/home/gordon/.nuget/packages/microsoft.aspnetcore.app.ref/6.0.10/microsoft.aspnetcore.app.ref.6.0.10.nupkg.sha512"
],
"logs": []
}

View File

@ -0,0 +1,20 @@
using System.Text;
using WatsonTcp;
class TcpClient
{
public async Task Run()
{
var client = new WatsonTcpClient("127.0.0.1", 42069);
client.Events.MessageReceived += this.onMessageReceived;
client.Connect();
await client.SendAsync("Hello World!");
await Task.Delay(-1);
}
private void onMessageReceived(object? sender, MessageReceivedEventArgs args)
{
var messageString = Encoding.UTF8.GetString(args.Data);
Console.WriteLine("Message received: " + messageString);
}
}

View File

@ -0,0 +1,31 @@
using System.Text;
using WatsonTcp;
class TcpServer
{
public async Task Run()
{
var server = new WatsonTcpServer("127.0.0.1", 42069);
server.Events.ClientConnected += this.clientConnected;
server.Events.ClientDisconnected += this.clientDisconnected;
server.Events.MessageReceived += this.messageReceived;
server.Start();
await Task.Delay(-1);
}
private void clientConnected(object? sender, ConnectionEventArgs args)
{
Console.WriteLine("Client connected: " + args.IpPort);
}
private void clientDisconnected(object? sender, DisconnectionEventArgs args)
{
Console.WriteLine("Client disconnected: " + args.IpPort);
}
private void messageReceived(object? sender, MessageReceivedEventArgs args)
{
var message = Encoding.UTF8.GetString(args.Data);
Console.WriteLine("Message received: " + args.IpPort + " " + message);
}
}

19
di-test/Program.cs Normal file
View File

@ -0,0 +1,19 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
var masterService = new MasterService();
masterService.Respond();
var services = new HashSet<object>();
services.Add(new ServiceA());
services.Add(new ServiceB());
foreach (var service in services)
{
var methods = (service.GetType().GetMethods());
foreach (var method in methods)
{
Console.WriteLine(method.Name);
}
Console.WriteLine("-----");
service.GetType().GetMethod("Respond")!.Invoke(service, null);
}

BIN
di-test/bin/Debug/net6.0/di-test Executable file

Binary file not shown.

View File

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"di-test/1.0.0": {
"runtime": {
"di-test.dll": {}
}
}
}
},
"libraries": {
"di-test/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}

11
di-test/di-test.csproj Normal file
View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>di_test</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

Some files were not shown because too many files have changed in this diff Show More