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,211 @@
|
|
|
1
|
+
# 🧩 Kendi Plugin'inizi Yazın
|
|
2
|
+
|
|
3
|
+
Bu rehber, sıfırdan gelişmiş bir plugin oluşturmayı adım adım gösterir.
|
|
4
|
+
|
|
5
|
+
## Plugin Yaşam Döngüsü
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
register() → initialize(bot) → [bot çalışırken] → destroy()
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Temel Şablon
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { type Plugin, type BotAPI } from 'specprotocol';
|
|
15
|
+
|
|
16
|
+
export class MyPlugin implements Plugin {
|
|
17
|
+
name = 'my-plugin'; // Benzersiz olmalı
|
|
18
|
+
|
|
19
|
+
private bot!: BotAPI;
|
|
20
|
+
|
|
21
|
+
initialize(bot: BotAPI): void {
|
|
22
|
+
this.bot = bot;
|
|
23
|
+
// Event listener'ları buraya ekleyin
|
|
24
|
+
// Timer'ları buraya başlatın
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
destroy(): void {
|
|
28
|
+
// Temizlik: timer'ları durdurun, kaynakları serbest bırakın
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Örnek 1: Auto-Respawn Plugin
|
|
34
|
+
|
|
35
|
+
Öldüğünde otomatik yeniden doğar:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { type Plugin, type BotAPI, BufferWriter, PlayServerboundPackets } from 'specprotocol';
|
|
39
|
+
|
|
40
|
+
export class AutoRespawnPlugin implements Plugin {
|
|
41
|
+
name = 'auto-respawn';
|
|
42
|
+
private bot!: BotAPI;
|
|
43
|
+
|
|
44
|
+
initialize(bot: BotAPI): void {
|
|
45
|
+
this.bot = bot;
|
|
46
|
+
|
|
47
|
+
bot.on('death', () => {
|
|
48
|
+
console.log('💀 Öldüm, yeniden doğuyorum...');
|
|
49
|
+
|
|
50
|
+
// 1 saniye bekle sonra respawn
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
// Client Status paketi: 0 = Perform Respawn
|
|
53
|
+
const writer = new BufferWriter();
|
|
54
|
+
writer.writeVarInt(0);
|
|
55
|
+
bot.sendPacket(0x09, writer.toBuffer());
|
|
56
|
+
}, 1000);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Örnek 2: AFK Prevention Plugin
|
|
63
|
+
|
|
64
|
+
Düzenli olarak hareket ederek AFK kick'i önler:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { type Plugin, type BotAPI } from 'specprotocol';
|
|
68
|
+
|
|
69
|
+
export class AntiAFKPlugin implements Plugin {
|
|
70
|
+
name = 'anti-afk';
|
|
71
|
+
private bot!: BotAPI;
|
|
72
|
+
private interval?: ReturnType<typeof setInterval>;
|
|
73
|
+
|
|
74
|
+
initialize(bot: BotAPI): void {
|
|
75
|
+
this.bot = bot;
|
|
76
|
+
|
|
77
|
+
bot.on('spawn', () => {
|
|
78
|
+
this.interval = setInterval(() => {
|
|
79
|
+
// Küçük bir hareket yap
|
|
80
|
+
const pos = bot.position;
|
|
81
|
+
bot.setPosition(
|
|
82
|
+
pos.x + (Math.random() - 0.5) * 0.1,
|
|
83
|
+
pos.y,
|
|
84
|
+
pos.z + (Math.random() - 0.5) * 0.1
|
|
85
|
+
);
|
|
86
|
+
}, 30000); // 30 saniyede bir
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
destroy(): void {
|
|
91
|
+
if (this.interval) {
|
|
92
|
+
clearInterval(this.interval);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Örnek 3: Chat Logger Plugin
|
|
99
|
+
|
|
100
|
+
Chat mesajlarını dosyaya kaydeder:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { type Plugin, type BotAPI } from 'specprotocol';
|
|
104
|
+
import * as fs from 'fs';
|
|
105
|
+
|
|
106
|
+
export class ChatLoggerPlugin implements Plugin {
|
|
107
|
+
name = 'chat-logger';
|
|
108
|
+
private stream?: fs.WriteStream;
|
|
109
|
+
|
|
110
|
+
initialize(bot: BotAPI): void {
|
|
111
|
+
this.stream = fs.createWriteStream('chat.log', { flags: 'a' });
|
|
112
|
+
|
|
113
|
+
bot.on('chat', (message: string, isOverlay: boolean) => {
|
|
114
|
+
if (isOverlay) return;
|
|
115
|
+
const timestamp = new Date().toISOString();
|
|
116
|
+
this.stream?.write(`[${timestamp}] ${message}\n`);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
destroy(): void {
|
|
121
|
+
this.stream?.end();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Örnek 4: Guard Bot Plugin
|
|
127
|
+
|
|
128
|
+
Belirli bir alanı korur ve yaklaşan varlıklara saldırır:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { type Plugin, type BotAPI, type Entity, Vec3 } from 'specprotocol';
|
|
132
|
+
|
|
133
|
+
export class GuardPlugin implements Plugin {
|
|
134
|
+
name = 'guard';
|
|
135
|
+
private bot!: BotAPI;
|
|
136
|
+
private guardCenter!: Vec3;
|
|
137
|
+
private guardRadius: number;
|
|
138
|
+
private interval?: ReturnType<typeof setInterval>;
|
|
139
|
+
|
|
140
|
+
constructor(radius: number = 10) {
|
|
141
|
+
this.guardRadius = radius;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
initialize(bot: BotAPI): void {
|
|
145
|
+
this.bot = bot;
|
|
146
|
+
|
|
147
|
+
bot.on('spawn', () => {
|
|
148
|
+
this.guardCenter = bot.position.clone();
|
|
149
|
+
this.startGuarding();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private startGuarding(): void {
|
|
154
|
+
this.interval = setInterval(() => {
|
|
155
|
+
const nearest = this.bot.entities.getNearestTo(
|
|
156
|
+
this.guardCenter,
|
|
157
|
+
(entity: Entity) => {
|
|
158
|
+
if (entity.id === this.bot.entityId) return false;
|
|
159
|
+
return entity.position.distanceTo(this.guardCenter) <= this.guardRadius;
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
if (nearest && nearest.position.distanceTo(this.bot.position) <= 3) {
|
|
164
|
+
this.bot.lookAt(nearest.position);
|
|
165
|
+
this.bot.attack(nearest);
|
|
166
|
+
}
|
|
167
|
+
}, 500);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
destroy(): void {
|
|
171
|
+
if (this.interval) clearInterval(this.interval);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Kullanım:
|
|
176
|
+
// const bot = await createBot({ ..., plugins: [new GuardPlugin(15)] });
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Plugin'leri Kullanma
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { createBot } from 'specprotocol';
|
|
183
|
+
import { AutoRespawnPlugin } from './plugins/auto-respawn';
|
|
184
|
+
import { AntiAFKPlugin } from './plugins/anti-afk';
|
|
185
|
+
import { ChatLoggerPlugin } from './plugins/chat-logger';
|
|
186
|
+
|
|
187
|
+
const bot = await createBot({
|
|
188
|
+
host: 'localhost',
|
|
189
|
+
username: 'Bot',
|
|
190
|
+
plugins: [
|
|
191
|
+
new AutoRespawnPlugin(),
|
|
192
|
+
new AntiAFKPlugin(),
|
|
193
|
+
new ChatLoggerPlugin(),
|
|
194
|
+
],
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Runtime'da Plugin Yönetimi
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// Çalışırken plugin ekle
|
|
202
|
+
bot.plugins.register(new MyPlugin());
|
|
203
|
+
|
|
204
|
+
// Plugin kaldır
|
|
205
|
+
bot.plugins.unregister('my-plugin');
|
|
206
|
+
|
|
207
|
+
// Plugin var mı kontrol
|
|
208
|
+
if (bot.plugins.has('auto-respawn')) {
|
|
209
|
+
console.log('Auto-respawn aktif');
|
|
210
|
+
}
|
|
211
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# 📦 Raw Packet Erişimi
|
|
2
|
+
|
|
3
|
+
SpecProtocol, protokol paketlerine doğrudan erişim sağlar.
|
|
4
|
+
|
|
5
|
+
## Tüm Paketleri Dinleme
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
bot.on('rawPacket', (packet) => {
|
|
9
|
+
console.log(`ID: 0x${packet.id.toString(16)} | ${packet.data.length} bytes`);
|
|
10
|
+
});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Belirli Paketleri Dinleme
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { PlayClientboundPackets, BufferReader } from 'specprotocol';
|
|
17
|
+
|
|
18
|
+
// Keep Alive paketlerini dinle
|
|
19
|
+
bot.onPacket(PlayClientboundPackets.KEEP_ALIVE, (data) => {
|
|
20
|
+
const reader = new BufferReader(data);
|
|
21
|
+
const keepAliveId = reader.readLong();
|
|
22
|
+
console.log(`Keep Alive: ${keepAliveId}`);
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Ham Paket Gönderme
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { BufferWriter, PlayServerboundPackets } from 'specprotocol';
|
|
30
|
+
|
|
31
|
+
// Özel paket oluştur ve gönder
|
|
32
|
+
const writer = new BufferWriter();
|
|
33
|
+
writer.writeVarInt(1); // Entity ID
|
|
34
|
+
writer.writeVarInt(1); // Type: Attack
|
|
35
|
+
writer.writeBool(false); // Sneaking
|
|
36
|
+
|
|
37
|
+
bot.sendPacket(PlayServerboundPackets.INTERACT, writer.toBuffer());
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Hex Dump ile Debug
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
bot.on('rawPacket', (packet) => {
|
|
44
|
+
const hex = packet.data.subarray(0, 32).toString('hex');
|
|
45
|
+
console.log(`[0x${packet.id.toString(16).padStart(2, '0')}] ${packet.data.length}b | ${hex}`);
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Bilinmeyen Paketleri Analiz Etme
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
bot.on('rawPacket', (packet) => {
|
|
53
|
+
// Tanınmayan paketleri logla
|
|
54
|
+
const knownIds = new Set([0x01, 0x09, 0x1D, 0x27, 0x28, 0x2C, 0x3A, 0x42, 0x5B, 0x73]);
|
|
55
|
+
if (!knownIds.has(packet.id)) {
|
|
56
|
+
console.log(`Bilinmeyen paket: 0x${packet.id.toString(16)} (${packet.data.length} bytes)`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Paket Istatistikleri
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const stats = new Map<number, { count: number; bytes: number }>();
|
|
65
|
+
|
|
66
|
+
bot.on('rawPacket', (packet) => {
|
|
67
|
+
const existing = stats.get(packet.id) ?? { count: 0, bytes: 0 };
|
|
68
|
+
existing.count++;
|
|
69
|
+
existing.bytes += packet.data.length;
|
|
70
|
+
stats.set(packet.id, existing);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Her 10 saniyede istatistikleri yazdır
|
|
74
|
+
setInterval(() => {
|
|
75
|
+
console.log('\n--- Paket İstatistikleri ---');
|
|
76
|
+
for (const [id, stat] of [...stats.entries()].sort((a, b) => b[1].count - a[1].count)) {
|
|
77
|
+
console.log(`0x${id.toString(16).padStart(2, '0')}: ${stat.count} paket, ${stat.bytes} bytes`);
|
|
78
|
+
}
|
|
79
|
+
}, 10000);
|
|
80
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "specprotocol",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A Minecraft bot framework built from scratch in TypeScript — Mineflayer alternative with full protocol support for Java Edition 1.21.4",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"specprotocol": "./bin/specprotocol.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"type": "commonjs",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"dev": "tsc --watch",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest",
|
|
16
|
+
"lint": "eslint src/",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"example:basic": "npx tsx examples/basic-bot.ts",
|
|
19
|
+
"example:guard": "npx tsx examples/guard-bot.ts"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"minecraft",
|
|
23
|
+
"bot",
|
|
24
|
+
"mineflayer",
|
|
25
|
+
"typescript",
|
|
26
|
+
"protocol",
|
|
27
|
+
"minecraft-bot",
|
|
28
|
+
"java-edition",
|
|
29
|
+
"game-bot",
|
|
30
|
+
"automation"
|
|
31
|
+
],
|
|
32
|
+
"author": "",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": ""
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^25.3.3",
|
|
43
|
+
"eslint": "^10.0.2",
|
|
44
|
+
"tsx": "^4.7.0",
|
|
45
|
+
"typescript": "^5.9.3",
|
|
46
|
+
"vitest": "^4.0.18"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist/",
|
|
50
|
+
"bin/",
|
|
51
|
+
"docs/",
|
|
52
|
+
"README.md",
|
|
53
|
+
"LICENSE"
|
|
54
|
+
]
|
|
55
|
+
}
|