From 68e3ac5b4a1ff58ffa2ba4a57197926f61943b5e Mon Sep 17 00:00:00 2001 From: Moonbase Date: Wed, 7 Oct 2026 12:50:56 -0700 Subject: [PATCH] Remove WordRiotRoom (was mostly for prototyping) Load CDL Rooms From File Move ext.rslt To Game Specific Rooms --- Core/Rooms/GameRooms/WordRiotRoom.cs | 23 ----------------------- Core/Rooms/RoomManager.cs | 16 ++++++++++++++-- NotPogo.csproj | 1 + Program.cs | 6 ++---- TCPGameServer.cs | 23 ----------------------- 5 files changed, 17 insertions(+), 52 deletions(-) delete mode 100644 Core/Rooms/GameRooms/WordRiotRoom.cs diff --git a/Core/Rooms/GameRooms/WordRiotRoom.cs b/Core/Rooms/GameRooms/WordRiotRoom.cs deleted file mode 100644 index 3a1a0bd..0000000 --- a/Core/Rooms/GameRooms/WordRiotRoom.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace NotPogo.Core.Rooms.GameRooms -{ - [GameRoom("wordriot_cdl")] - public class WordRiotRoom(string ruleId) : IGameRoom - { - public Task OnGameJoinAsync(Room room, Player player) => Task.CompletedTask; - - public Task OnMessageAsync(Room room, Player player, string op, Dictionary msg) => Task.FromResult(true); - - public async Task OnPlayerJoinedAsync(Room room, Player player) - { - await player.SendAsync( - ("msg.op", "say"), - ("chnl", "serv"), - ("scrn", ""), - ("type", "stnd"), - ("text", "Welcome To Word Riot! Please Wait For Players To Join") - ); - } - - public Task OnPlayerLeftAsync(Room room, Player player) => Task.CompletedTask; - } -} diff --git a/Core/Rooms/RoomManager.cs b/Core/Rooms/RoomManager.cs index 200d1a9..4032a92 100644 --- a/Core/Rooms/RoomManager.cs +++ b/Core/Rooms/RoomManager.cs @@ -1,6 +1,6 @@ -using NotPogo.Core.Rooms.GameRooms; -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Reflection; +using System.Text.Json; namespace NotPogo.Core.Rooms { @@ -10,6 +10,18 @@ namespace NotPogo.Core.Rooms static readonly Dictionary> Factories = BuildFactories(); + public sealed record RoomDef(string Key, string Name, string Rule, int Capacity = 50); + + public static void LoadFromFile(string path) + { + var opts = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }; + var games = JsonSerializer.Deserialize>(File.ReadAllText(path), opts)!; + + foreach (var (gameCode, rooms) in games) + foreach (var r in rooms) + Define(r.Key, r.Name, gameCode, r.Rule, true, r.Capacity); + } + static Dictionary> BuildFactories() { var map = new Dictionary>(StringComparer.OrdinalIgnoreCase); diff --git a/NotPogo.csproj b/NotPogo.csproj index ac5b2b4..d4914a8 100644 --- a/NotPogo.csproj +++ b/NotPogo.csproj @@ -7,6 +7,7 @@ + diff --git a/Program.cs b/Program.cs index 4c936d5..3f9e84e 100644 --- a/Program.cs +++ b/Program.cs @@ -52,10 +52,8 @@ namespace NotPogo app.MapControllers(); app.MapFlashGateway(); - // Define Rooms For Word Riot Deluxe - RoomManager.Define("npwr_classic_1", "NotPogo Classic Room 1", "wordriot_cdl", "classic", true); - RoomManager.Define("npwr_rally_1", "NotPogo Rally Room 1", "wordriot_cdl", "rally", true); - RoomManager.Define("npwr_advanced_1", "NotPogo Advanced Room 1", "wordriot_cdl", "advanced", true); + // Define Rooms For CDL Games + RoomManager.LoadFromFile(Path.Combine(AppContext.BaseDirectory, "StaticFiles", "rooms.json")); app.Run(); } diff --git a/TCPGameServer.cs b/TCPGameServer.cs index b7d5f38..2236d38 100644 --- a/TCPGameServer.cs +++ b/TCPGameServer.cs @@ -77,29 +77,6 @@ namespace NotPogo { await player.Room.HandleAsync(player, op, received); } - else if (op == "ext.over") // TODO: move to rooms extending IGameRoom - { - // because we aren't actually keeping track of anything going on in the games, we can just send the correct placeholders - - bool isJackpot = (received["gm.won"] == "true") ? true : false; - int tokensWon = isJackpot ? Random.Shared.Next(0, 999) : 0; - - await SendAsync(stream, - ("msg.op", "ext.rslt"), - ("tokb", "9999"), - ("tokn.won", isJackpot ? "100" : "0"), - ("spin.rslt", isJackpot ? "2" : "0"), // we aren't doing anything with the other outcomes so always issue tokens - ("spin.tokn", tokensWon.ToString()), // standalone reference implementation - ("inst.desc", ""), - ("jpot", "0"), - ("pzpm", ""), - ("bmlt", "1"), - ("bspo", "0"), - ("xpup", "0") - ); - - _logger.LogInformation("Results Sent"); - } } } catch (Exception e) when (e is EndOfStreamException or IOException or SocketException) { _logger.LogInformation("plid {Plid} disconnected ({Reason})", player.Id, e.GetBaseException().Message); } catch(Exception e)