SignalR Integration Design Document - wwestlake/Labyrinth GitHub Wiki
SignalR Integration Design Document
Overview
This document outlines the design and implementation of a real-time communication system using SignalR in the Labyrinth game. The system will facilitate various chat channels, including room-based chats, general server chat, and channels for different administrative roles. The chat system will ensure that players and administrators can communicate effectively within the game environment.
Chat Channels Overview
-
Room-Based Chat:
- Description: Each room in the game will have its own chat channel. When two or more players (characters) are in the same room, they can communicate with each other through this room-specific chat.
- Association: The chat channel is dynamically associated with the room and participants based on their current location.
- Visibility: Only characters in the same room can see and participate in the room chat.
-
General Chat:
- Description: A server-wide chat channel that is associated with users rather than characters. It is open to all players on the server.
- Purpose: The general chat is used for broad communication, including social interaction, server-wide announcements, and general discussions.
-
Moderator Channel:
- Description: A private chat channel accessible only to moderators.
- Purpose: This channel is used for discussions between moderators about in-game events, player management, and other moderation activities.
-
Admin Channel:
- Description: A private chat channel accessible only to administrators.
- Purpose: Admins use this channel for higher-level discussions, technical actions, and coordination of server management tasks.
-
Owner Channel:
- Description: A private chat channel for the server owner(s).
- Purpose: This channel is reserved for critical server management and owner-level decisions.
-
Command Channel:
- Description: A dedicated channel for admins and owners to issue technical commands and manage server operations.
- Purpose: The command channel is used for executing technical actions, server maintenance, and other administrative commands. It is not visible to regular players or moderators.
-
Notices:
- Description: Admins and Owners can post notices that will appear in the general chat. These notices are used for server announcements, event notifications, and other important communications.
SignalR Implementation Details
-
Hub Design:
- Central Hub: A SignalR hub will be created to manage all chat channels. The hub will dynamically handle room-specific chats, general chat, and administrative channels.
- Methods:
JoinRoom(string roomId, string characterId)
: Allows a character to join the chat for a specific room.LeaveRoom(string roomId, string characterId)
: Allows a character to leave the chat for a specific room.SendMessage(string channelId, string message)
: Sends a message to the specified chat channel.SendNotice(string message)
: Sends a notice to the general chat channel.
-
Room-Based Chat Automation:
- Dynamic Room Association: The SignalR hub will automatically create and manage chat channels based on the active rooms in the game. When a character enters a room, they are automatically connected to the room's chat channel.
- Room Lifecycle: When the last participant leaves a room, the room’s chat channel can be archived or removed to optimize resources.
-
General Chat and Administrative Channels:
- Persistent Channels: General, Moderator, Admin, Owner, and Command channels will be persistent and always available. These channels are tied to the server roles and are not dependent on room presence.
- Role-Based Access Control: Access to each channel will be controlled based on the user's role (e.g., player, moderator, admin, owner).
-
Security and Access Management:
- Authentication: Only authenticated users can connect to the SignalR hub. User roles will be verified upon connection to determine their access to different channels.
- Authorization: The hub will enforce authorization rules to ensure that only users with the appropriate roles can join certain channels (e.g., only admins can join the Admin Channel).
-
Message Handling:
- Private Messaging: Future enhancements could include private messaging between users, but the initial focus is on public and role-based channels.
- Message Logging: Messages in administrative channels (Moderator, Admin, Owner, Command) may be logged for audit and review purposes.
-
Server Notices:
- Automatic Notices: System-generated notices (e.g., server restarts, maintenance warnings) will be automatically sent to the general chat channel.
- Manual Notices: Admins and Owners can manually post notices to the general chat for important announcements.
Scalability Considerations
-
Room Capacity Management:
- Load Balancing: As the server scales, room chat channels may need to be load-balanced across multiple SignalR hubs or servers.
- Sharding: Consider sharding chat channels across different SignalR instances based on room IDs or user roles.
-
High Availability:
- Redundancy: Ensure that SignalR hubs are deployed in a redundant manner to avoid a single point of failure.
- Failover: Implement failover mechanisms to reroute traffic in case a SignalR hub goes down.
Conclusion
This design document outlines the implementation strategy for integrating SignalR into the Labyrinth game to provide real-time communication capabilities. The system is designed to be dynamic, scalable, and secure, with various chat channels tailored to different needs within the game. By implementing this system, the Labyrinth game will facilitate better communication between players and provide robust tools for server administration.