specprotocol 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +174 -0
- package/bin/specprotocol.js +136 -0
- package/dist/auth/microsoft.d.ts +23 -0
- package/dist/auth/microsoft.d.ts.map +1 -0
- package/dist/auth/microsoft.js +167 -0
- package/dist/auth/microsoft.js.map +1 -0
- package/dist/auth/offline.d.ts +20 -0
- package/dist/auth/offline.d.ts.map +1 -0
- package/dist/auth/offline.js +67 -0
- package/dist/auth/offline.js.map +1 -0
- package/dist/bot.d.ts +190 -0
- package/dist/bot.d.ts.map +1 -0
- package/dist/bot.js +624 -0
- package/dist/bot.js.map +1 -0
- package/dist/entity/entity.d.ts +71 -0
- package/dist/entity/entity.d.ts.map +1 -0
- package/dist/entity/entity.js +157 -0
- package/dist/entity/entity.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/built-in/chat.d.ts +19 -0
- package/dist/plugins/built-in/chat.d.ts.map +1 -0
- package/dist/plugins/built-in/chat.js +62 -0
- package/dist/plugins/built-in/chat.js.map +1 -0
- package/dist/plugins/built-in/combat.d.ts +20 -0
- package/dist/plugins/built-in/combat.d.ts.map +1 -0
- package/dist/plugins/built-in/combat.js +42 -0
- package/dist/plugins/built-in/combat.js.map +1 -0
- package/dist/plugins/plugin-manager.d.ts +49 -0
- package/dist/plugins/plugin-manager.d.ts.map +1 -0
- package/dist/plugins/plugin-manager.js +76 -0
- package/dist/plugins/plugin-manager.js.map +1 -0
- package/dist/protocol/compression.d.ts +23 -0
- package/dist/protocol/compression.d.ts.map +1 -0
- package/dist/protocol/compression.js +85 -0
- package/dist/protocol/compression.js.map +1 -0
- package/dist/protocol/connection.d.ts +73 -0
- package/dist/protocol/connection.d.ts.map +1 -0
- package/dist/protocol/connection.js +212 -0
- package/dist/protocol/connection.js.map +1 -0
- package/dist/protocol/encryption.d.ts +29 -0
- package/dist/protocol/encryption.d.ts.map +1 -0
- package/dist/protocol/encryption.js +116 -0
- package/dist/protocol/encryption.js.map +1 -0
- package/dist/protocol/packet.d.ts +75 -0
- package/dist/protocol/packet.d.ts.map +1 -0
- package/dist/protocol/packet.js +140 -0
- package/dist/protocol/packet.js.map +1 -0
- package/dist/protocol/states/handshake.d.ts +19 -0
- package/dist/protocol/states/handshake.d.ts.map +1 -0
- package/dist/protocol/states/handshake.js +32 -0
- package/dist/protocol/states/handshake.js.map +1 -0
- package/dist/protocol/states/login.d.ts +77 -0
- package/dist/protocol/states/login.d.ts.map +1 -0
- package/dist/protocol/states/login.js +125 -0
- package/dist/protocol/states/login.js.map +1 -0
- package/dist/protocol/states/play.d.ts +187 -0
- package/dist/protocol/states/play.d.ts.map +1 -0
- package/dist/protocol/states/play.js +316 -0
- package/dist/protocol/states/play.js.map +1 -0
- package/dist/protocol/types.d.ts +210 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +495 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/events.d.ts +23 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +44 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +47 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/vec3.d.ts +25 -0
- package/dist/utils/vec3.d.ts.map +1 -0
- package/dist/utils/vec3.js +66 -0
- package/dist/utils/vec3.js.map +1 -0
- package/dist/world/block.d.ts +39 -0
- package/dist/world/block.d.ts.map +1 -0
- package/dist/world/block.js +84 -0
- package/dist/world/block.js.map +1 -0
- package/dist/world/world.d.ts +55 -0
- package/dist/world/world.d.ts.map +1 -0
- package/dist/world/world.js +95 -0
- package/dist/world/world.js.map +1 -0
- package/docs/README.md +29 -0
- package/docs/api/auth.md +210 -0
- package/docs/api/bot.md +137 -0
- package/docs/api/events.md +166 -0
- package/docs/api/plugins.md +207 -0
- package/docs/api/protocol.md +129 -0
- package/docs/api/world.md +138 -0
- package/docs/first-bot.md +114 -0
- package/docs/getting-started.md +103 -0
- package/docs/guides/architecture.md +122 -0
- package/docs/guides/custom-plugins.md +211 -0
- package/docs/guides/raw-packets.md +80 -0
- package/package.json +55 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# 🔌 Protokol Katmanı
|
|
2
|
+
|
|
3
|
+
SpecProtocol, Minecraft Java Edition protokolünü sıfırdan implemente eder.
|
|
4
|
+
|
|
5
|
+
## Bağlantı Akışı
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
[TCP Connect] → [Handshake] → [Login] → [Compression] → [Configuration] → [Play]
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Connection Sınıfı
|
|
12
|
+
|
|
13
|
+
TCP bağlantısını yönetir: paket framing, compression, encryption.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { Connection } from 'specprotocol';
|
|
17
|
+
|
|
18
|
+
const conn = new Connection({
|
|
19
|
+
host: 'localhost',
|
|
20
|
+
port: 25565,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await conn.connect();
|
|
24
|
+
conn.on('packet', (packet) => { /* ... */ });
|
|
25
|
+
conn.sendPacket(0x00, data);
|
|
26
|
+
|
|
27
|
+
conn.enableCompression(256);
|
|
28
|
+
conn.enableEncryption(sharedSecret);
|
|
29
|
+
conn.disconnect();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Veri Tipleri
|
|
33
|
+
|
|
34
|
+
Minecraft protokolü özel veri tipleri kullanır:
|
|
35
|
+
|
|
36
|
+
| Tip | Boyut | Açıklama |
|
|
37
|
+
|-----|-------|----------|
|
|
38
|
+
| VarInt | 1-5 byte | Değişken uzunluklu integer |
|
|
39
|
+
| VarLong | 1-10 byte | Değişken uzunluklu long |
|
|
40
|
+
| String | N byte | Length-prefixed UTF-8 |
|
|
41
|
+
| UUID | 16 byte | İki Long olarak |
|
|
42
|
+
| Boolean | 1 byte | 0x00 veya 0x01 |
|
|
43
|
+
| Byte | 1 byte | İşaretli (-128 to 127) |
|
|
44
|
+
| UByte | 1 byte | İşaretsiz (0-255) |
|
|
45
|
+
| Short | 2 byte | Big-endian |
|
|
46
|
+
| Int | 4 byte | Big-endian |
|
|
47
|
+
| Long | 8 byte | Big-endian, BigInt |
|
|
48
|
+
| Float | 4 byte | IEEE 754 |
|
|
49
|
+
| Double | 8 byte | IEEE 754 |
|
|
50
|
+
| Position | 8 byte | x(26) \| z(26) \| y(12) |
|
|
51
|
+
|
|
52
|
+
## Paket Yapısı
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
Sıkıştırmasız:
|
|
56
|
+
┌─────────┬───────────┬──────┐
|
|
57
|
+
│ Length │ Packet ID │ Data │
|
|
58
|
+
│ VarInt │ VarInt │ ... │
|
|
59
|
+
└─────────┴───────────┴──────┘
|
|
60
|
+
|
|
61
|
+
Sıkıştırmalı:
|
|
62
|
+
┌─────────┬─────────────┬──────────────────┐
|
|
63
|
+
│ Length │ Data Length │ Compressed Data │
|
|
64
|
+
│ VarInt │ VarInt (0=no)│ Zlib │
|
|
65
|
+
└─────────┴─────────────┴──────────────────┘
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Encryption
|
|
69
|
+
|
|
70
|
+
AES/CFB8 şifreleme, Login sırasında etkinleştirilir:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { generateSharedSecret, encryptRSA, computeServerHash } from 'specprotocol';
|
|
74
|
+
|
|
75
|
+
const secret = generateSharedSecret(); // 16 byte random
|
|
76
|
+
const encrypted = encryptRSA(publicKey, secret); // RSA PKCS1
|
|
77
|
+
const hash = computeServerHash(serverId, secret, publicKey); // Notch's hex digest
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Protokol State'leri
|
|
81
|
+
|
|
82
|
+
### Handshake (0x00)
|
|
83
|
+
```typescript
|
|
84
|
+
import { buildHandshakePacket, PROTOCOL_VERSION, NextState } from 'specprotocol';
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Login
|
|
88
|
+
```typescript
|
|
89
|
+
import {
|
|
90
|
+
LoginServerboundPackets,
|
|
91
|
+
LoginClientboundPackets,
|
|
92
|
+
buildLoginStartPacket,
|
|
93
|
+
buildEncryptionResponsePacket,
|
|
94
|
+
// ...
|
|
95
|
+
} from 'specprotocol';
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Play (1.21.4)
|
|
99
|
+
|
|
100
|
+
**Serverbound (Client → Server):**
|
|
101
|
+
|
|
102
|
+
| ID | Paket |
|
|
103
|
+
|----|-------|
|
|
104
|
+
| `0x00` | Confirm Teleportation |
|
|
105
|
+
| `0x06` | Chat Message |
|
|
106
|
+
| `0x0A` | Client Information |
|
|
107
|
+
| `0x13` | Interact |
|
|
108
|
+
| `0x18` | Keep Alive |
|
|
109
|
+
| `0x1A` | Position |
|
|
110
|
+
| `0x1B` | Position + Rotation |
|
|
111
|
+
| `0x24` | Player Action |
|
|
112
|
+
| `0x2F` | Set Held Item |
|
|
113
|
+
| `0x36` | Swing Arm |
|
|
114
|
+
|
|
115
|
+
**Clientbound (Server → Client):**
|
|
116
|
+
|
|
117
|
+
| ID | Paket |
|
|
118
|
+
|----|-------|
|
|
119
|
+
| `0x01` | Spawn Entity |
|
|
120
|
+
| `0x09` | Block Update |
|
|
121
|
+
| `0x1D` | Disconnect |
|
|
122
|
+
| `0x27` | Keep Alive |
|
|
123
|
+
| `0x28` | Chunk Data |
|
|
124
|
+
| `0x2C` | Login (Play) |
|
|
125
|
+
| `0x3A` | Player Abilities |
|
|
126
|
+
| `0x40` | Player Info Update |
|
|
127
|
+
| `0x42` | Synchronize Player Position |
|
|
128
|
+
| `0x5B` | Set Health |
|
|
129
|
+
| `0x73` | System Chat |
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# 🌍 World (Dünya) Yönetimi
|
|
2
|
+
|
|
3
|
+
## World Sınıfı
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
bot.world // World instance'ına erişim
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
### Properties
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
bot.world.dimension // string — "minecraft:overworld", "minecraft:the_nether", vb.
|
|
13
|
+
bot.world.seaLevel // number — Deniz seviyesi (varsayılan: 63)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Blok Erişimi
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
// Tek blok oku
|
|
20
|
+
const block = bot.world.getBlock(10, 64, 20);
|
|
21
|
+
// Döndürür: { stateId: number } | null
|
|
22
|
+
|
|
23
|
+
// Blok güncelle
|
|
24
|
+
bot.world.setBlock(10, 64, 20, 1);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Chunk Yönetimi
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// Chunk var mı?
|
|
31
|
+
bot.world.hasChunk(0, 0); // boolean (chunk X, chunk Z)
|
|
32
|
+
|
|
33
|
+
// Chunk al
|
|
34
|
+
const chunk = bot.world.getChunk(0, 0); // ChunkColumn | undefined
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## ChunkColumn
|
|
38
|
+
|
|
39
|
+
Bir chunk kolonu, 24 tane `ChunkSection` (16x16x16) içerir (Y: -64 → 319).
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const chunk = bot.world.getChunk(0, 0);
|
|
43
|
+
|
|
44
|
+
// Section'a erişim (0-23 arası, Y offset: -64)
|
|
45
|
+
const section = chunk?.getSection(4); // Y: 0-15 arası section
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## ChunkSection
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
// Blok al (section-içi koordinatlar: 0-15)
|
|
52
|
+
const block = section?.getBlock(8, 0, 8); // { stateId: number }
|
|
53
|
+
|
|
54
|
+
// Blok set et
|
|
55
|
+
section?.setBlock(8, 0, 8, 42);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Block Update Event
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
bot.on('blockUpdate', (x, y, z, stateId) => {
|
|
62
|
+
console.log(`(${x}, ${y}, ${z}) → stateId: ${stateId}`);
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
# 👾 Entity (Varlık) Yönetimi
|
|
69
|
+
|
|
70
|
+
## EntityManager
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
bot.entities // EntityManager instance'ına erişim
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Varlık Sorgulama
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// ID ile bul
|
|
80
|
+
const entity = bot.entities.getById(42);
|
|
81
|
+
|
|
82
|
+
// UUID ile bul
|
|
83
|
+
const player = bot.entities.getByUUID('550e8400-...');
|
|
84
|
+
|
|
85
|
+
// En yakını bul
|
|
86
|
+
const nearest = bot.entities.getNearestTo(bot.position);
|
|
87
|
+
|
|
88
|
+
// Filtreli en yakın
|
|
89
|
+
const nearestMob = bot.entities.getNearestTo(bot.position, (e) => {
|
|
90
|
+
return e.id !== bot.entityId; // Kendini hariç tut
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Yarıçapta ara
|
|
94
|
+
const nearby = bot.entities.getInRadius(bot.position, 10);
|
|
95
|
+
|
|
96
|
+
// Tüm varlıklar
|
|
97
|
+
const all = bot.entities.getAll();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Entity Sınıfı
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
entity.id // number — Entity ID
|
|
104
|
+
entity.uuid // string — UUID
|
|
105
|
+
entity.type // number — Entity type ID
|
|
106
|
+
entity.position // Vec3 — Pozisyon
|
|
107
|
+
entity.velocity // Vec3 — Hız vektörü
|
|
108
|
+
entity.yaw // number — Yatay yön (derece)
|
|
109
|
+
entity.pitch // number — Dikey yön (derece)
|
|
110
|
+
entity.onGround // boolean — Yerde mi?
|
|
111
|
+
entity.metadata // Map<number, any> — NBT metadata
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## PlayerEntity
|
|
115
|
+
|
|
116
|
+
`Entity`'den türer, ek player bilgileri içerir:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
if (entity instanceof PlayerEntity) {
|
|
120
|
+
entity.username // string
|
|
121
|
+
entity.gameMode // number
|
|
122
|
+
entity.ping // number
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Entity Events
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// Yeni varlık doğduğunda
|
|
130
|
+
bot.on('entitySpawn', (entity: Entity) => {
|
|
131
|
+
console.log(`Yeni: ${entity.id} pos=${entity.position}`);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Varlık kaldırıldığında
|
|
135
|
+
bot.on('entityRemove', (entityId: number) => {
|
|
136
|
+
console.log(`Kaldırıldı: ${entityId}`);
|
|
137
|
+
});
|
|
138
|
+
```
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# 🤖 İlk Botunuzu Yazın
|
|
2
|
+
|
|
3
|
+
Bu rehber adım adım bir Minecraft botu oluşturmanızı gösterir.
|
|
4
|
+
|
|
5
|
+
## 1. Proje Oluşturun
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
mkdir my-mc-bot && cd my-mc-bot
|
|
9
|
+
npm init -y
|
|
10
|
+
npm install specprotocol
|
|
11
|
+
npm install -D typescript @types/node tsx
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 2. Bot Kodunu Yazın
|
|
15
|
+
|
|
16
|
+
`src/index.ts` dosyası oluşturun:
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { createBot, LogLevel } from 'specprotocol';
|
|
20
|
+
|
|
21
|
+
async function main() {
|
|
22
|
+
// Sunucuya bağlan
|
|
23
|
+
const bot = await createBot({
|
|
24
|
+
host: 'localhost',
|
|
25
|
+
port: 25565,
|
|
26
|
+
username: 'MyFirstBot',
|
|
27
|
+
auth: 'offline',
|
|
28
|
+
logLevel: LogLevel.INFO,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Dünyada doğduğunda
|
|
32
|
+
bot.on('spawn', () => {
|
|
33
|
+
console.log(`✅ Bot doğdu! Pozisyon: ${bot.position}`);
|
|
34
|
+
bot.chat('Merhaba herkese!');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Chat mesajı geldiğinde
|
|
38
|
+
bot.on('chat', (message, isOverlay) => {
|
|
39
|
+
if (isOverlay) return; // Actionbar mesajlarını atla
|
|
40
|
+
|
|
41
|
+
console.log(`💬 ${message}`);
|
|
42
|
+
|
|
43
|
+
// Komutlara yanıt ver
|
|
44
|
+
if (message.includes('!ping')) {
|
|
45
|
+
bot.chat('Pong! 🏓');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (message.includes('!pos')) {
|
|
49
|
+
const pos = bot.position;
|
|
50
|
+
bot.chat(`Pozisyonum: X=${pos.x.toFixed(1)} Y=${pos.y.toFixed(1)} Z=${pos.z.toFixed(1)}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (message.includes('!health')) {
|
|
54
|
+
bot.chat(`❤️ Can: ${bot.health}/20 | 🍖 Açlık: ${bot.food}/20`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Sağlık değiştiğinde
|
|
59
|
+
bot.on('health', (health, food, saturation) => {
|
|
60
|
+
console.log(`❤️ Can: ${health} | 🍖 Yemek: ${food}`);
|
|
61
|
+
|
|
62
|
+
if (health <= 0) {
|
|
63
|
+
console.log('💀 Bot öldü!');
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Pozisyon sunucu tarafından güncellendiğinde
|
|
68
|
+
bot.on('position', (pos) => {
|
|
69
|
+
console.log(`📍 Yeni pozisyon: ${pos}`);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Sunucudan atıldığında
|
|
73
|
+
bot.on('kicked', (reason) => {
|
|
74
|
+
console.log(`🚫 Sunucudan atıldı: ${reason}`);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Bağlantı hatası
|
|
78
|
+
bot.on('error', (err) => {
|
|
79
|
+
console.error('❌ Hata:', err.message);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Bağlantı kesildiğinde
|
|
83
|
+
bot.on('end', () => {
|
|
84
|
+
console.log('🔌 Bağlantı kesildi');
|
|
85
|
+
process.exit(0);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// CTRL+C ile düzgün kapatma
|
|
89
|
+
process.on('SIGINT', () => {
|
|
90
|
+
bot.disconnect();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
main().catch(console.error);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 3. Çalıştırın
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npx tsx src/index.ts
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 4. Test Edin
|
|
104
|
+
|
|
105
|
+
Minecraft istemcinizle aynı sunucuya bağlanın ve chat'e yazın:
|
|
106
|
+
- `!ping` — Bot "Pong! 🏓" yanıtı verir
|
|
107
|
+
- `!pos` — Bot kendi pozisyonunu yazar
|
|
108
|
+
- `!health` — Bot sağlık bilgisini yazar
|
|
109
|
+
|
|
110
|
+
## Sonraki Adımlar
|
|
111
|
+
|
|
112
|
+
- [Bot API Referansı](./api/bot.md) — Tüm bot metodları
|
|
113
|
+
- [Event Sistemi](./api/events.md) — Tüm olaylar
|
|
114
|
+
- [Plugin Sistemi](./api/plugins.md) — Kendi eklentinizi yazın
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# 🚀 Kurulum & Hızlı Başlangıç
|
|
2
|
+
|
|
3
|
+
## Kurulum
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install specprotocol
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
> **Gereksinimler:** Node.js ≥ 18, Minecraft Java Edition 1.21.4 sunucusu
|
|
10
|
+
|
|
11
|
+
## Hızlı Başlangıç
|
|
12
|
+
|
|
13
|
+
### Offline Mod (Cracked Sunucu)
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createBot } from 'specprotocol';
|
|
17
|
+
|
|
18
|
+
const bot = await createBot({
|
|
19
|
+
host: 'localhost',
|
|
20
|
+
port: 25565,
|
|
21
|
+
username: 'MyBot',
|
|
22
|
+
auth: 'offline',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
bot.on('spawn', () => {
|
|
26
|
+
console.log('Bot dünyada doğdu!');
|
|
27
|
+
bot.chat('Merhaba dünya! 🤖');
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Microsoft Girişli (Online Sunucu)
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { createBot } from 'specprotocol';
|
|
35
|
+
|
|
36
|
+
const bot = await createBot({
|
|
37
|
+
host: 'play.example.com',
|
|
38
|
+
port: 25565,
|
|
39
|
+
username: 'SteveBot',
|
|
40
|
+
auth: 'microsoft',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Microsoft giriş yapıldığında terminalde bir kod ve URL gösterilir.
|
|
44
|
+
// Tarayıcıda URL'yi açıp kodu girin, bot otomatik bağlanacak.
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Tüm Seçenekler
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const bot = await createBot({
|
|
51
|
+
// Zorunlu
|
|
52
|
+
host: 'localhost', // Sunucu adresi
|
|
53
|
+
username: 'BotAdi', // Bot kullanıcı adı
|
|
54
|
+
|
|
55
|
+
// Opsiyonel
|
|
56
|
+
port: 25565, // Sunucu portu (varsayılan: 25565)
|
|
57
|
+
auth: 'offline', // 'offline' veya 'microsoft'
|
|
58
|
+
viewDistance: 10, // İstenen görüş mesafesi
|
|
59
|
+
logLevel: LogLevel.INFO, // DEBUG, INFO, WARN, ERROR
|
|
60
|
+
plugins: [], // Yüklenecek eklentiler
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## LogLevel Seviyeleri
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { LogLevel } from 'specprotocol';
|
|
68
|
+
|
|
69
|
+
LogLevel.DEBUG // Her şeyi logla (paket detayları dahil)
|
|
70
|
+
LogLevel.INFO // Normal bilgiler (bağlantı, spawn, vb.)
|
|
71
|
+
LogLevel.WARN // Sadece uyarılar ve hatalar
|
|
72
|
+
LogLevel.ERROR // Sadece hatalar
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Proje Yapısı
|
|
76
|
+
|
|
77
|
+
Tipik bir bot projesi şöyle görünür:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
my-bot/
|
|
81
|
+
├── package.json
|
|
82
|
+
├── tsconfig.json
|
|
83
|
+
├── src/
|
|
84
|
+
│ ├── index.ts # Ana bot dosyası
|
|
85
|
+
│ └── plugins/
|
|
86
|
+
│ └── my-plugin.ts # Kendi eklentiniz
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Minimal tsconfig.json
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"compilerOptions": {
|
|
94
|
+
"target": "ES2022",
|
|
95
|
+
"module": "Node16",
|
|
96
|
+
"moduleResolution": "Node16",
|
|
97
|
+
"outDir": "dist",
|
|
98
|
+
"strict": true,
|
|
99
|
+
"esModuleInterop": true
|
|
100
|
+
},
|
|
101
|
+
"include": ["src"]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# 🏗️ Mimari & Tasarım Kararları
|
|
2
|
+
|
|
3
|
+
## Genel Bakış
|
|
4
|
+
|
|
5
|
+
SpecProtocol, modüler katmanlı bir mimariye sahiptir:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌──────────────────────────────────────────┐
|
|
9
|
+
│ Bot (Orkestratör) │
|
|
10
|
+
├────────┬─────────┬───────────┬───────────┤
|
|
11
|
+
│ World │ Entity │ Plugins │ Auth │
|
|
12
|
+
│ Manager│ Manager │ Manager │ Module │
|
|
13
|
+
├────────┴─────────┴───────────┴───────────┤
|
|
14
|
+
│ Protocol Layer │
|
|
15
|
+
├────────┬─────────┬───────────┬───────────┤
|
|
16
|
+
│ Packet │ Types │ Compress │ Encrypt │
|
|
17
|
+
│ Frame │ VarInt │ Zlib │ AES/CFB8 │
|
|
18
|
+
├────────┴─────────┴───────────┴───────────┤
|
|
19
|
+
│ TCP Connection (net) │
|
|
20
|
+
└──────────────────────────────────────────┘
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Tasarım Kararları
|
|
24
|
+
|
|
25
|
+
### 1. Sıfırdan Yazılmış Protokol
|
|
26
|
+
|
|
27
|
+
**Neden?**
|
|
28
|
+
- `node-minecraft-protocol` gibi kütüphanelere bağımlılık yok
|
|
29
|
+
- Her byte üzerinde tam kontrol
|
|
30
|
+
- Eğitim amaçlı: protokolün nasıl çalıştığını anlama
|
|
31
|
+
- Özelleştirme: istenen herhangi bir versiyona uyarlama
|
|
32
|
+
|
|
33
|
+
### 2. TypeScript-First
|
|
34
|
+
|
|
35
|
+
**Neden?**
|
|
36
|
+
- Compile-time hata yakalama
|
|
37
|
+
- IDE otomatik tamamlama
|
|
38
|
+
- Tip-güvenli event sistemi
|
|
39
|
+
- Daha okunabilir API
|
|
40
|
+
|
|
41
|
+
### 3. Event-Driven Mimari
|
|
42
|
+
|
|
43
|
+
**Neden?**
|
|
44
|
+
- Node.js'in doğal async yapısına uygun
|
|
45
|
+
- Gevşek bağlı bileşenler
|
|
46
|
+
- Plugin sistemi kolayca entegre olur
|
|
47
|
+
- Kullanıcı dostane API
|
|
48
|
+
|
|
49
|
+
### 4. Plugin Sistemi
|
|
50
|
+
|
|
51
|
+
**Neden?**
|
|
52
|
+
- Modülerlik: özellikler bağımsız olarak eklenebilir/kaldırılabilir
|
|
53
|
+
- Genişletilebilirlik: topluluk katkısına açık
|
|
54
|
+
- Test edilebilirlik: her plugin bağımsız test edilebilir
|
|
55
|
+
- BotAPI interface ile circular dependency önleme
|
|
56
|
+
|
|
57
|
+
## Bağlantı Akışı (Detaylı)
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
1. TCP Socket → net.createConnection()
|
|
61
|
+
2. Handshake Paketi → Protocol Version + Host + Port + NextState
|
|
62
|
+
3. Login Start → Username + UUID
|
|
63
|
+
4. [Opsiyonel] Encryption Request/Response → RSA + AES/CFB8
|
|
64
|
+
5. Set Compression → Zlib threshold
|
|
65
|
+
6. Login Success → Authenticated username + UUID
|
|
66
|
+
7. Login Acknowledged → Geçiş: Login → Configuration
|
|
67
|
+
8. Configuration State:
|
|
68
|
+
- Plugin Message → Sunucu bilgileri
|
|
69
|
+
- Feature Flags → Sunucu özellikleri
|
|
70
|
+
- Known Packs → Kaynak paket müzakeresi
|
|
71
|
+
- Registry Data × 12 → Biome, dimension, entity tipleri vb.
|
|
72
|
+
- Update Tags → Blok/item etiketleri
|
|
73
|
+
- Finish Configuration → Geçiş: Configuration → Play
|
|
74
|
+
9. Play State:
|
|
75
|
+
- Login (Play) → Entity ID, dimension, game mode
|
|
76
|
+
- Player Abilities → Uçma hızı, yürüme hızı
|
|
77
|
+
- Synchronize Player Position → İlk spawn pozisyonu
|
|
78
|
+
- Chunk Data × N → Dünya verisi
|
|
79
|
+
- Keep Alive ← → 30 saniyede bir, cevap verilmezse kick
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Dosya Yapısı
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
src/
|
|
86
|
+
├── index.ts # Public API — sadece gerekli exportlar
|
|
87
|
+
├── bot.ts # Bot: ana sınıf, tüm alt sistemleri koordine eder
|
|
88
|
+
├── types.ts # BotAPI interface (circular dep çözümü)
|
|
89
|
+
│
|
|
90
|
+
├── utils/
|
|
91
|
+
│ ├── vec3.ts # 3D vektör: pozisyon, hız, yön hesaplamaları
|
|
92
|
+
│ ├── logger.ts # Seviyeli loglama: DEBUG → INFO → WARN → ERROR
|
|
93
|
+
│ └── events.ts # TypedEventEmitter: tip-güvenli olaylar
|
|
94
|
+
│
|
|
95
|
+
├── protocol/
|
|
96
|
+
│ ├── types.ts # VarInt, VarLong, String, UUID, BufferReader/Writer
|
|
97
|
+
│ ├── packet.ts # Paket framing, splitting, registry
|
|
98
|
+
│ ├── connection.ts # TCP bağlantı yönetimi + compression + encryption
|
|
99
|
+
│ ├── compression.ts # Zlib deflate/inflate
|
|
100
|
+
│ ├── encryption.ts # AES/CFB8 + RSA + server hash
|
|
101
|
+
│ └── states/
|
|
102
|
+
│ ├── handshake.ts # Handshake paketi
|
|
103
|
+
│ ├── login.ts # Login state paketleri
|
|
104
|
+
│ └── play.ts # Play state paketleri (1.21.4 packet ID'leri)
|
|
105
|
+
│
|
|
106
|
+
├── auth/
|
|
107
|
+
│ ├── offline.ts # Offline UUID generation (MD5-based v3)
|
|
108
|
+
│ └── microsoft.ts # Microsoft OAuth2 → Xbox → XSTS → MC → Profile
|
|
109
|
+
│
|
|
110
|
+
├── entity/
|
|
111
|
+
│ └── entity.ts # Entity, PlayerEntity, EntityManager
|
|
112
|
+
│
|
|
113
|
+
├── world/
|
|
114
|
+
│ ├── block.ts # Block, ChunkSection, ChunkColumn
|
|
115
|
+
│ └── world.ts # World: chunk depolama, blok erişimi
|
|
116
|
+
│
|
|
117
|
+
└── plugins/
|
|
118
|
+
├── plugin-manager.ts # Plugin yaşam döngüsü yönetimi
|
|
119
|
+
└── built-in/
|
|
120
|
+
├── chat.ts # ChatPlugin: mesaj gönder/al
|
|
121
|
+
└── combat.ts # CombatPlugin: saldırı, item kullanma
|
|
122
|
+
```
|