-
Notifications
You must be signed in to change notification settings - Fork 5
File Structure
-
appsettings.json: Server configuration with network settings, spawn coordinates, debug options -
sphdbsettings.json: Database-specific settings -
project.godot: Godot engine project configuration -
SphServer.sln: Visual Studio solution file -
SphServer.csproj: C# project file with .NET 9.0 target
-
MonsterSpawnData.txt: Monster spawn definitions -
AlchemyResourceSpawnData.txt: Alchemy resource spawn points -
sphereclient_patched.exe: Client executable
Purpose: Main server class managing TCP connections and server initialization.
Methods:
-
override void _Ready(): Initializes server, database, connection handlers -
override void _Process(double delta): Main server loop handling incoming connections -
static void InitializeCollections(): Initializes database collections -
static void SetupTcpServer(): Configures TCP server on specified port
Purpose: Configuration management with JSON loading and automatic defaults.
Classes:
-
AppConfig: Configuration data model -
ServerConfig: Static configuration manager
Methods:
-
static AppConfig Get(): Loads configuration from appsettings.json with defaults -
static void CreateDefaultAppConfig(string configPath): Creates default configuration file -
static Dictionary<string, string> GetDefaultAppConfigDict(): Returns default values -
static void SaveAppConfig(string configPath, Dictionary<string, string> config): Saves configuration
Purpose: Handles new client connections.
Methods:
-
void Handle(StreamPeerTcp streamPeer): Processes new client connection, creates SphereClient instance
Purpose: Player authentication and account management.
Methods:
-
static PlayerDbEntry? CheckLoginAndGetPlayer(string login, string password, ushort playerIndex, bool createOnNewLogin = true): Validates login credentials -
static bool IsNameValid(string name): Checks character name availability -
static string GetHashedString(string str): Creates PBKDF2 password hash -
static bool EqualsHashed(string password, string hashedPassword): Verifies password hash
Purpose: Connected client management and state handling.
Methods:
-
void Setup(StreamPeerTcp streamPeer, ushort localId): Initializes client with network connection -
override void _Ready(): Client initialization -
override void _Process(double delta): Client update loop for packet processing
Purpose: Client connection states definition.
Enum Values:
-
I_AM_BREAD: Initial connection state -
INIT_READY_FOR_INITIAL_DATA: Ready for server data -
INIT_WAITING_FOR_LOGIN_DATA: Awaiting login credentials -
INIT_WAITING_FOR_CHARACTER_SELECT: Character selection phase -
INIT_WAITING_FOR_CLIENT_INGAME_ACK: Game entry confirmation -
INIT_NEW_DUNGEON_TELEPORT_DELAY: Teleport preparation -
INIT_NEW_DUNGEON_TELEPORT_READY_TO_INIT: Teleport initialization -
INIT_NEW_DUNGEON_TELEPORT_INITIATED: Teleport execution -
INGAME_DEFAULT: In-game state
Purpose: Client network connection management.
Purpose: Interface for client packet handlers.
Purpose: Factory for creating handlers based on client state.
Methods:
-
static ISphereClientNetworkingHandler? GetHandlerForState(ClientState currentState, StreamPeerTcp streamPeerTcp, ushort localId, ClientConnection clientConnection): Returns appropriate handler for current state
Purpose: Handles initial client handshake (I_AM_BREAD state).
Methods:
-
async Task Handle(double delta): Sends ReadyToLoadInitialData packet and advances to next state
Purpose: Handles server credential exchange (INIT_READY_FOR_INITIAL_DATA state).
Methods:
-
async Task Handle(double delta): Waits for client data, sends server credentials with client ID
Purpose: Handles login credential processing (INIT_WAITING_FOR_LOGIN_DATA state).
Methods:
-
async Task Handle(double delta): Processes login credentials, validates with LoginManager, sends character list
Purpose: Handles character selection, creation, deletion (INIT_WAITING_FOR_CHARACTER_SELECT state).
Methods:
-
async Task Handle(double delta): Processes character selection packets, handles create/delete operations
Purpose: Handles client acknowledgment to enter game (INIT_WAITING_FOR_CLIENT_INGAME_ACK state).
Purpose: Handles new player dungeon teleport initialization.
Purpose: Handles client-server ping/keepalive packets.
Methods:
-
async Task Keepalive(double delta): Manages periodic ping timers (15s, 6s, 3s intervals) -
async Task Handle(double delta): Processes incoming ping responses and maintains connection
Purpose: Handles chat message processing and broadcasting.
Purpose: Handles object movement synchronization for clients.
Purpose: Item interaction handlers.
-
PickupItemHandler.cs: Handles item pickup from ground -
UseItemHandler.cs: Handles item usage -
MoveItemHandler.cs: Handles item movement between containers -
DropItemToGroundHandler.cs: Handles dropping items to ground -
MainhandTakeItemHandler.cs: Handles taking items to main hand -
BuyItemFromTargetHandler.cs: Handles item purchase from NPCs
Purpose: Database connection management and LiteDB collection access.
Purpose: Logging system with console and file output, automatic log rotation.
Methods:
-
static void Initialize(string? filePath, bool enableConsole, bool enableFile, LogLevel minConsoleLevel, LogLevel minFileLevel): Configures logging -
static void Debug/Info/Warning/Error(string message): Log messages at different levels -
static void CleanupOldLogFiles(string? logDirectory): Removes old log files, keeps latest 20 -
static string GenerateTimestampedLogPath(string originalPath): Creates timestamped log file names
-
LootRarity.cs: Item rarity levels -
MonsterTypes.cs: Monster classification types
-
Packet.cs: Base packet class -
PacketPart.cs: Packet component system
Purpose: Global world state and active entity collections management.
Purpose: Binary data serialization for network packets.
-
MainServer.tscn: Main server scene -
Client.tscn: Client scene template
- Godot-specific node scripts
Purpose: Encoding utilities for text processing.
Purpose: Random number generation utilities.
Purpose: Timer functionality for game systems.
Purpose: Game object database management.
Purpose: World object implementations and spawning.
Purpose: Loot system implementation.
-
.gitignore: Git exclusions -
LICENSE.md: Project license -
README.md: Project overview -
logs/: Runtime log files (auto-managed, keeps latest 20)
-
Server
- SphereServer
- Connection Handling
- Authentication
- Configuration
-
Client
- SphereClient
- Client States
- Networking
-
Shared
- Database
- Logging
- Game Data
- BitStream
- Development Setup
- Code Standards
- Testing Guidelines
- Debugging Guide
- Configuration Options
- API Documentation
- Database Schema
- Packet Definitions