🚧 Pre-release Alpha Version 0.2.0 - This is an early alpha release. Core infrastructure is complete (authentication, multiplayer, zone generation, campaign system), but the full game simulation and JavaScript sandbox execution are still in development. See Features for current implementation status, or check FEATURES.md for detailed feature documentation.
GeekCraft is a programming game inspired by Screeps and Starcraft, where players write JavaScript bots to control units in a real-time strategy environment.
The game engine is headless by design — it provides no integrated graphical interface. Players are free to create their own visualization using any technology they choose. A minimal HTML viewer is included as a simple example.
- Server in Rust
- Player Freedom (any scripting language via API, JavaScript example provided)
- English First
- Working Examples
- Simple Viewer
GeekCraft
├── src
│ ├── main.rs # Entry point, initializes the server and starts the engine
│ ├── lib.rs # Main library, exports modules
│ ├── game
│ │ ├── mod.rs
│ │ ├── world.rs
│ │ ├── entities.rs
│ │ └── simulation.rs
│ ├── api
│ │ ├── mod.rs
│ │ ├── scripting.rs # Scripting system for bots (storage/execution)
│ │ └── events.rs
│ ├── network
│ │ ├── mod.rs
│ │ └── server.rs # Axum HTTP + WebSocket server
│ └── scripting
│ ├── mod.rs
│ └── sandbox.rs
├── assets
│ └── textures
├── examples
│ ├── basic_bot.js
│ ├── advanced_bot.js
│ ├── template_bot.js
│ ├── API_REFERENCE.md
│ ├── README.md # API usage and client quick start
│ ├── api_client_example.js
│ ├── node_client_example.js
│ └── viewer
│ ├── index.html
│ ├── viewer.js
│ └── style.css
├── tests
│ └── integration_tests.rs
├── Cargo.toml
├── BUILD.md
└── README.md
✅ Implemented in v0.2.0:
- ✅ Rust Game Engine with Tokio async runtime
- ✅ Axum HTTP/WebSocket Server
- ✅ Authentication System (token-based, bcrypt password hashing)
- ✅ Multiplayer Support (concurrent users with session management)
- ✅ Flexible Database (In-Memory for dev, MongoDB for production)
- ✅ Procedural Zone Generation (30x30 tile zones with terrain types and exits)
- ✅ Campaign System (start, stop, save, load campaign runs)
- ✅ REST API for code submission and game state
- ✅ WebSocket for real-time multiplayer communication
- ✅ Code validation and storage
- ✅ Basic world simulation (tick counter, terrain, resources)
- ✅ Integration tests
- ✅ Example HTML Viewer (with authentication)
- ✅ Comprehensive API documentation
- ✅ Working JavaScript examples (authentication, multiplayer, zones, campaigns)
🚧 In Development:
- 🚧 JavaScript Sandbox execution (code storage implemented, Boa/Deno execution pending)
- 🚧 Entity and movement systems (structure exists, integration pending)
- 🚧 Real-time game tick simulation
📅 Planned:
- 📅 Combat and building systems
- 📅 Resource collection mechanics
- 📅 Zone interconnection
- 📅 Full game loop with bot execution
Prerequisites
- Rust 1.70+ (rustup.rs)
- Cargo
- Optional: Node.js 18+ for Node examples
- Optional: MongoDB server for production (see DATABASE.md)
Build
git clone https://github.com/xelfe/GeekCraft.git
cd GeekCraft
cargo build --releaseFor production with MongoDB:
cargo build --releaseStart the server
cargo run --release
# HTTP: http://localhost:3030
# WebSocket: ws://localhost:3030/ws
# Database: In-Memory (default, data lost on restart)For production with MongoDB:
export GEEKCRAFT_DB_BACKEND=MONGODB
export MONGODB_URL=mongodb://localhost:27017/geekcraft
cargo run --release- Start the server
cargo run --release- Register and login
# Register
curl -X POST http://localhost:3030/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username": "player1", "password": "mypassword"}'
# Login (get token)
curl -X POST http://localhost:3030/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "player1", "password": "mypassword"}'
# Response: {"success":true,"token":"...","username":"player1"}- Submit your bot code (requires authentication)
curl -X POST http://localhost:3030/api/submit \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-d '{"code": "class MyBot { onTick(gameState) { console.log(\"Hello\"); } }"}'- Connect via WebSocket (multiplayer)
// Browser or Node.js
const ws = new WebSocket('ws://localhost:3030/ws');
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
console.log('Received:', msg);
// Authenticate after welcome
if (msg.type === 'welcome') {
ws.send(JSON.stringify({
type: 'auth',
token: 'YOUR_TOKEN_HERE'
}));
}
};
// Request game state
ws.send(JSON.stringify({ type: 'getGameState' }));- Try the working examples
All examples are tested and working in v0.2.0-alpha:
Node.js Examples (require npm install ws node-fetch@2 in project root):
node examples/node_client_example.js- Complete example with all featuresnode examples/zone_generation_example.js- Zone generation demonode examples/campaign_local_save_example.js- Campaign system demo
Browser Examples (load directly in browser):
examples/auth_example.js- Authentication workflowexamples/multiplayer_example.js- Multiplayer clientexamples/api_client_example.js- HTTP/WebSocket client
HTML Viewer:
cd examples/viewer
# macOS: open index.html
# Linux: xdg-open index.html
# Windows: double-click index.htmlnode examples/node_client_example.js
More details and examples: see examples/README.md.
## Procedural Zone Generation
GeekCraft features a procedural zone generation system where each player starts in their own unique 30x30 tile zone:
```bash
# Generate a zone for a player
curl -X POST http://localhost:3030/api/zone/generate \
-H "Content-Type: application/json" \
-d '{"player_id": "alice"}'
# Get zone data
curl http://localhost:3030/api/zone/player_alice_zone
# List all zones
curl http://localhost:3030/api/zones
# Run the complete example
node examples/zone_generation_example.js
Zone Features:
- 30x30 tiles with procedural terrain
- Three terrain types: Plain (~60%), Swamp (~25%), Obstacle (~15%)
- 2-4 exits per zone for future zone interconnection
- Deterministic generation: Same player ID always generates same zone
- Server-side: All generation in Rust for security
See docs/ZONE_GENERATION.md for complete documentation.
- Base URL: http://localhost:3030
- WebSocket: ws://localhost:3030/ws
POST /api/auth/register— Register new user (body:{"username": "string", "password": "string"})POST /api/auth/login— Login (body:{"username": "string", "password": "string"}) → Returns token
POST /api/auth/logout— Logout and invalidate sessionPOST /api/submit— Submit player code (body:{"code": "string"})GET /api/players— List playersGET /api/gamestate— Current game state
GET /— API infoGET /api/health— Health check
POST /api/zone/generate— Generate zone for player (body:{"player_id": "string"})GET /api/zone/:zone_id— Get zone dataGET /api/zones— List all zone IDs
{"type": "auth", "token": "YOUR_TOKEN"}— Authenticate WebSocket connection{"type": "getPlayers"}— Get list of players (requires auth){"type": "getGameState"}— Get current game state (requires auth)
Note: CORS is permissive during development; restrict origins for production.
- Register and login
# Register
curl -X POST http://localhost:3030/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username": "myplayer", "password": "mypassword"}'
# Login and get token
TOKEN=$(curl -s -X POST http://localhost:3030/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "myplayer", "password": "mypassword"}' \
| grep -o '"token":"[^"]*"' | cut -d'"' -f4)- Create your bot
cp examples/template_bot.js my_bot.jsclass MyBot {
onTick(gameState) {
const units = gameState.getMyUnits();
// Your logic here
}
}
module.exports = MyBot;- Submit your bot (using the token from step 1)
curl -X POST http://localhost:3030/api/submit \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"code": "class MyBot { onTick(gs) { console.log(\"Hello\"); } } module.exports = MyBot;"}'# Development
cargo run # Debug run (In-Memory database)
cargo build --release # Release build
cargo test # Run tests
cargo doc --open # Generate and open docs
# Production (with MongoDB)
cargo build --release
export GEEKCRAFT_DB_BACKEND=MONGODB
export MONGODB_URL=mongodb://localhost:27017/geekcraft
cargo run --release
# Quick API checks (require authentication)
curl http://localhost:3030/api/health
curl -H "Authorization: Bearer $TOKEN" http://localhost:3030/api/players
curl -H "Authorization: Bearer $TOKEN" http://localhost:3030/api/gamestateSee DATABASE.md for detailed database options:
- In-Memory (default): Development, zero config, data lost on restart
- MongoDB (production): Persistent storage, horizontal scaling, rich queries
- Basic project structure
- Complete documentation
- JavaScript API for bots
- Axum HTTP/WebSocket server
- REST API endpoints (health, submit, players, gamestate)
- WebSocket real-time communication
- Authentication and authorization (token-based)
- Multiplayer session management
- Flexible database (In-Memory, MongoDB)
- Procedural zone generation (30x30 tiles, terrain types, exits)
- Campaign system (start, stop, save, load)
- Code validation and storage
- Basic world simulation (tick, terrain, resources)
- Integration tests
- JavaScript examples for all implemented features
- HTML viewer with authentication support
- Full JavaScript sandbox with execution (Boa/Deno)
- Complete world simulation engine with real-time ticks
- Entity system for units and buildings (full integration)
- Zone interconnection and world navigation
- Resource collection and management (gameplay mechanics)
- Movement system with pathfinding
- Combat system
- Building/construction system
- Tech tree and progression
- Replays and statistics
- Tournament system
Contributions are welcome! Here's how to participate:
- Fork the project
- Create a branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.