File size: 1,538 Bytes
551ad28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
"""
Start script for RTS game with MCP server
"""

import asyncio
import subprocess
import sys
import os
import signal

# Add the web directory to the path
sys.path.insert(0, os.path.dirname(__file__))

def start_main_server():
    """Start the main game server."""
    print("Starting main game server...")
    # Start the main server in a subprocess
    main_server = subprocess.Popen(
        [sys.executable, "start.py"],
        cwd=os.path.dirname(__file__),
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
    )
    return main_server

async def start_mcp_server():
    """Start the MCP server."""
    print("Starting MCP server...")
    # Import and start the MCP server
    from mcp_server import RTSGameMCP
    mcp_server = RTSGameMCP()
    await mcp_server.run()

def signal_handler(signum, frame):
    """Handle shutdown signals."""
    print("\nShutting down servers...")
    sys.exit(0)

def main():
    """Main entry point."""
    # Set up signal handlers for graceful shutdown
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)
    
    # Start the main server
    main_server = start_main_server()
    
    try:
        # Start the MCP server
        asyncio.run(start_mcp_server())
    except KeyboardInterrupt:
        print("\nShutting down...")
    finally:
        # Clean up processes
        if main_server.poll() is None:
            main_server.terminate()
            main_server.wait()

if __name__ == "__main__":
    main()