From d818b735e57935e69220e220efef1782c786e323 Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Thu, 22 May 2025 14:19:37 -0400 Subject: [PATCH 1/4] add color to server --- server/Lib.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/server/Lib.cs b/server/Lib.cs index 044257e..19f8d61 100644 --- a/server/Lib.cs +++ b/server/Lib.cs @@ -8,6 +8,7 @@ public static partial class Module [PrimaryKey] public Identity Identity; public string? Name; + public string? Color; public bool Online; } @@ -42,6 +43,30 @@ public static partial class Module return name; } + [Reducer] + public static void SetColor(ReducerContext ctx, string color) + { + color = ValidateColor(color); + + var user = ctx.Db.User.Identity.Find(ctx.Sender); + + if (user is null) + { + return; + } + user.Color = color; + ctx.Db.User.Identity.Update(user); + } + + private static string ValidateColor(string color) + { + if (color[0] == '#' && color.Length != 4 || color.Length != 7) + { + throw new Exception("Invalid Hex color code"); + } + return color; + } + [Reducer] public static void SendMessage(ReducerContext ctx, string text) { @@ -113,4 +138,3 @@ public static partial class Module } } } - From c8d4423ba86ca927cd3a2c3fb2564e449b93e9db Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Thu, 22 May 2025 15:39:48 -0400 Subject: [PATCH 2/4] DOCS --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 398a3b6..43168e0 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,13 @@ And enable WebAssembly: ```bash dotnet workload install wasi-experimental ``` + +```bash +bun server:up +``` + +Add the spacetime docker server to your cli + +```bash +spacetime server add --url http://localhost:3000 massive +``` From 2d321a3d53dddc0a6dff3414061379fa597dad11 Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Thu, 22 May 2025 14:19:37 -0400 Subject: [PATCH 3/4] add color to server --- server/Lib.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/server/Lib.cs b/server/Lib.cs index 044257e..735a59e 100644 --- a/server/Lib.cs +++ b/server/Lib.cs @@ -1,3 +1,4 @@ +using System.Text.RegularExpressions; using SpacetimeDB; public static partial class Module @@ -8,6 +9,7 @@ public static partial class Module [PrimaryKey] public Identity Identity; public string? Name; + public string? Color; public bool Online; } @@ -42,6 +44,31 @@ public static partial class Module return name; } + [Reducer] + public static void SetColor(ReducerContext ctx, string color) + { + color = ValidateColor(color); + + var user = ctx.Db.User.Identity.Find(ctx.Sender); + + if (user is null) + { + return; + } + user.Color = color; + ctx.Db.User.Identity.Update(user); + } + + private static string ValidateColor(string color) + { + var regex = new Regex("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"); + if (regex.IsMatch(color)) + { + throw new Exception("Invalid color code"); + } + return color; + } + [Reducer] public static void SendMessage(ReducerContext ctx, string text) { @@ -113,4 +140,3 @@ public static partial class Module } } } - From 8860138999152650f9afd9d2d78f14694b1a1b80 Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Thu, 22 May 2025 15:39:48 -0400 Subject: [PATCH 4/4] DOCS --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 398a3b6..43168e0 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,13 @@ And enable WebAssembly: ```bash dotnet workload install wasi-experimental ``` + +```bash +bun server:up +``` + +Add the spacetime docker server to your cli + +```bash +spacetime server add --url http://localhost:3000 massive +```