Skip to content

Add auto-connect for local development and refactor main.cpp#260

Draft
Copilot wants to merge 11 commits intomainfrom
copilot/update-login-flow-for-play
Draft

Add auto-connect for local development and refactor main.cpp#260
Copilot wants to merge 11 commits intomainfrom
copilot/update-login-flow-for-play

Conversation

Copy link

Copilot AI commented Nov 3, 2025

Manual login on every startup is cumbersome for local development. Added optional auto-connect to localhost with pre-configured username. Additionally, refactored the monolithic main.cpp file into a well-structured ClientApp class for better maintainability.

Changes

client/main.cpp

  • Refactored from 264 lines to 10 lines
  • Now creates ClientApp instance and calls Run()

client/client-app.hpp & client/client-app.cpp (NEW)

  • Extracted all initialization logic into ClientApp class
  • Separated concerns into logical methods:
    • InitializeLogger() - Logger setup
    • InitializeWindow() - OpenGL window creation
    • InitializeGame() - Game system initialization
    • InitializeGUI() - GUI system and windows
    • RegisterConsoleCommands() - Console command registration
    • SetupAutoConnect() - Auto-connect logic
    • RegisterGUIWindows() - GUI window registration
    • Run() - Main game loop
  • Improved resource management using smart pointers and RAII
  • Cleaner lambda captures with explicit lifetime management
  • Better testability and maintainability

client/CMakeLists.txt

  • Added client-app.cpp to build

README.md

  • Documented auto-connect configuration options and usage

Auto-Connect Configuration

-- assets/scripts/config.lua
auto_connect = true
default_username = "player"

Auto-connect follows same pattern as existing GUI and console connection methods: RegisterConnectFuncRegisterMessageHandlerConnect. Registers handlers before Connect() to avoid race condition with AUTHENTICATED message.

Refactoring Benefits

  • Separation of Concerns: Related code grouped logically
  • Reduced Complexity: Each initialization phase has its own method
  • Better Resource Management: RAII with smart pointers, clear ownership
  • Improved Testability: Components can be tested in isolation
  • Maintainability: Much easier to understand and modify

[!WARNING]

Original prompt

A lot of the code is not very declarative and could use a face-lift. The biggest change that needs to happen is that you shouldn't need to login to play. Update the flow so that you can play without logging in, or suggest ways to fix the login flow, for local development

If this change is too complex, identify another change that improves the code in a meaningful way for the best way to follow the code execution flow, or to improve the develop experience.

The build may not work, I have changes coming in a seperate commit to improve that.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits November 3, 2025 00:23
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Copilot AI changed the title [WIP] Update flow to allow playing without login Add auto-connect for local development Nov 3, 2025
Copilot AI requested a review from adam4813 November 3, 2025 00:31
@adam4813
Copy link
Member

adam4813 commented Nov 3, 2025

@copilot That main file looks pretty gnarly, what sort of improvements can be made. You don't have to be super surgical as this file doesn't follow best practices very well

Co-authored-by: adam4813 <3011917+adam4813@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 3, 2025

@copilot That main file looks pretty gnarly, what sort of improvements can be made. You don't have to be super surgical as this file doesn't follow best practices very well

Refactored the 264-line main() function into a clean ClientApp class with proper separation of concerns. Main improvements:

  • main.cpp: Reduced from 264 lines to 10 lines
  • New ClientApp class: Organized into logical methods (InitializeLogger, InitializeWindow, InitializeGame, etc.)
  • Better resource management: Using smart pointers and RAII
  • Cleaner lambda captures: Explicit lifetime management
  • Improved testability: Each component can be tested in isolation

The refactoring maintains all existing functionality while making the code significantly more maintainable. See commit bdc7407.

Copilot AI changed the title Add auto-connect for local development Add auto-connect for local development and refactor main.cpp Nov 3, 2025
@adam4813 adam4813 requested a review from Copilot November 3, 2025 00:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the client's main entry point by extracting initialization and lifecycle logic from main.cpp into a new ClientApp class, improving code organization and maintainability. It also adds auto-connect functionality for local development.

  • Extracted ~220 lines of initialization code into a dedicated ClientApp class with proper encapsulation
  • Added auto-connect feature to streamline local development workflow
  • Converted helper functions to anonymous namespace for better encapsulation

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
client/main.cpp Simplified to create and run ClientApp instance
client/client-app.hpp Defines ClientApp class with initialization methods and member variables
client/client-app.cpp Implements ClientApp with refactored initialization logic and auto-connect feature
client/CMakeLists.txt Adds client-app.cpp to build configuration
README.md Documents auto-connect configuration for local development

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants