XEChat-Idea Documentation

repository·main·Indexed 21 days ago

https://github.com/anlingyi/xechat-idea

A Netty-based instant messaging and gaming plugin for JetBrains IDEs. It allows developers to chat, play mini-games (such as Gomoku, Dou Dizhu, 2048, and Sudoku), and use tools like weather queries and browsers within their coding environment. The project consists of xechat-commons, xechat-server for backend logic, and xechat-plugin for the IDEA client.

Tokens
5.6K
Snippets
28
Records
31
Agent score
74%

What's inside XEChat-Idea

  1. Overview of XEChat-Idea

    main

    XEChat-Idea is a Netty-based instant messaging plugin for JetBrains IDEs. It enables users to chat, play games (such as Gomoku, Dou Dizhu, 2048, Sudoku, etc.), and use tools (like weather queries and browsers) directly within their development environment. It consists of three main components:

    1. xechat-commons: Common modules used by both server and plugin.
    2. xechat-server: The backend server responsible for managing connections and game logic.
    3. xechat-plugin: The IDEA plugin client.

    Note: The browser-based client is maintained in a separate repository: XEChat-Web.

  2. Develop and run the IDEA Plugin locally

    main

    To develop the plugin, you can modify the target IDEA version in build.gradle:

    intellij {
        version '2021.3'
    }

    To run the plugin in a local development instance of IntelliJ IDEA, use the Gradle task: Tasks > intellij > runIde

  3. Add your server to the public list

    main

    To make your server public to other users, add your server information to the server_list.json file in the repository using the following format:

    {
        "name": "xxx", // Name of your server
        "ip": "127.0.0.1", // Your server IP or domain
        "port": 1024 // Port number
    }

    Submit a Pull Request with these changes to be reviewed and added to the official list.

    {
        "name": "xxx",
        "ip": "127.0.0.1",
        "port": 1024
    }
  4. Build and install the XEChat IDEA Plugin

    main

    To package the plugin for manual installation:

    1. Configure Server Address: In cn.xeblog.plugin.client.XEChatClient, update the HOST and PORT constants to point to your server:

      private static final String HOST = "localhost"; // Server IP
      private static final int PORT = 1024; // Server port
    2. Build the plugin: Run the Gradle task: Tasks > build > assemble. The resulting file will be located at: build/distributions/xechat-plugin-xxx.zip.

    3. Install in IDEA: Go to IDEA > Preferences > Plugins, click the gear icon, select Manage Plugin Repositories..., and add the plugin repository if necessary, or simply install the .zip file directly via Install Plugin....

  5. Build and deploy the XEChat Server

    main

    Before building the server, you must first build and install the common modules to your local Maven repository.

    1. Install common modules:
    cd xechat-commons
    mvn install
    1. Build and run the server:
    cd xechat-server
    # Build the jar
    mvn package
    # Run the jar
    java -jar target/xechat-server-xxx.jar

    Note: You can configure the log path by adjusting src/main/resources/logback.xml. Ensure the ROOT_LOG_PATH property is set to a valid directory.

    # Install common modules
    cd xechat-commons
    mvn install
    
    # Build and run server
    cd xechat-server
    mvn package
    java -jar target/xechat-server-xxx.jar
  6. Run XEChat Server via Docker Compose

    main

    You can deploy the server using Docker. Use the following docker-compose.yml configuration:

    version: '3'
    services:
      xechat:
        image: anlingyi/xechat-server:1.6.7-beta
        container_name: xechat-server
        restart: always
        ports:
          - 1024:1024
          - 1025:1025
        volumes:
          - /home/xechat/logs:/var/log/xechat-server
          - /home/xechat/config/config.setting:/home/xechat/config/config.setting
          - /home/xechat/db:/home/xechat/db
  7. Reference: XEChat Server startup arguments

    main

    When running the xechat-server JAR, you can use the following command-line arguments to configure its behavior:

    • -p {port}: Set the server port.
    • -swfile {path}: Set the path to the sensitive words file.
    • -weather {api_key}: Set the QWeather (和风天气) API key.
    • -fyAppId {appId}: Set the Baidu Translate App ID.
    • -fyAppKey {appKey}: Set the Baidu Translate App Key.
    • -ipfile {path}: Set the path to the ip2region file.
    • -token {token}: Set the administrator token.
    • -path {path}: Specify an external configuration file.
    • -enableWS {true|false}: Enable or disable the WebSocket protocol.

    Detailed configuration options for the external file can be found in xechat-server/src/main/resources/config.setting.

    # Example usage
    java -jar target/xechat-server-xxx.jar -p 1024 -swfile /Users/anlingyi/local/test/words.txt -weather {和风天气api key}
  8. Use the AIService interface for Gobang AI logic

    main

    The AIService interface defines the contract for implementing or interacting with a Gobang (Five in a Row) AI. The primary method getPoint calculates the next optimal move based on the current board state and a specific point of interest (likely the opponent's last move).

    Method: getPoint

    • Parameters:
      • int[][] chessData: A 2D integer array representing the current state of the chessboard.
      • Point point: A Point object representing the opponent's last move or a specific coordinate to consider.
    • Returns: A Point object representing the AI's chosen move.
    // Example usage of an AIService implementation
    Point nextMove = aiService.getPoint(chessData, opponentLastMove);
  9. Configure the login command with flags

    main

    The login command supports several flags to customize the connection parameters and server selection:

    FlagKeyDescription
    Host-hSpecifies the server IP address or hostname.
    Port-pSpecifies the server port.
    Clean-cClears existing cached server configuration information.
    Server-sSpecifies a server index from the available online server list.

    Server Selection (-s): When using the -s flag, you provide an integer index. The command will look up the server from the DataCache.serverList (or fetch it via ServerUtils.getServerList() if the cache is empty). The host and port will be automatically set based on the selected server's configuration.

    login [username] -h <host> -p <port> -s <server_index> -c
  10. Use the login command

    main

    The login command is used to establish a connection to a server and authenticate a user. It can be used with a positional username or via specific flags to configure the connection details. If no username is provided, it will fail validation.

    Usage Rules:

    • Username: The first argument is treated as the username if it does not match any known configuration flags.
    • Validation: Usernames must be valid according to CheckUtils.checkUsername and cannot exceed 12 characters.
    • State: If the client is already online or currently in the middle of a connection attempt, the command will return an error message and abort.
    # Example: Login with username 'admin'
    login admin
    
    # Example: Login with specific host and port
    login admin -h 127.0.0.1 -p 8080