-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPacketMaker.cpp
624 lines (534 loc) · 16.5 KB
/
PacketMaker.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
#include "PacketMaker.h"
// ACKパケット
// msg : out作成パケット
INT PacketMaker::MakePacketData_ACK(BYTE* msg)
{
int datIndex = 2;
if (!msg) return 0;
datIndex += SetByteData(&msg[datIndex], PK_ACK);
// 1
datIndex += SetByteData(&msg[datIndex], 1);
// 1
datIndex += SetDwordData(&msg[datIndex], 1);
// エンドマーカ
datIndex += SetEndMarker(&msg[datIndex]);
SetWordData(&msg[0], datIndex);
return datIndex;
}
//> 認証要求パケット
INT PacketMaker::MakePacketData_Authentication(WCHAR* name, WCHAR* pass, BYTE* msg)
{
int datIndex = 2;
if (!msg || !name) return 0;
int nNameLen = (_tcslen(name)) * sizeof(WCHAR);
int nPassLen = (_tcslen(pass)) * sizeof(WCHAR);
datIndex += SetByteData(&msg[datIndex], PK_USER_AUTH);
// キャラ名長
datIndex += SetByteData(&msg[datIndex], nNameLen);
// キャラ名
datIndex += SetMultiByteData(&msg[datIndex], (BYTE*)name, nNameLen, MAX_USER_NAME*sizeof(WCHAR));
// パスワード長
datIndex += SetByteData(&msg[datIndex], nPassLen);
// パスワード
datIndex += SetMultiByteData(&msg[datIndex], (BYTE*)pass, nPassLen, MAX_SRV_PASS*sizeof(WCHAR));
// エンドマーカ
datIndex += SetEndMarker(&msg[datIndex]);
SetWordData(&msg[0], datIndex);
return datIndex;
}
//< 認証要求パケット
//> チャットパケット
INT PacketMaker::MakePacketData_ChatMessage(BYTE type, WCHAR* message, BYTE* data)
{
int datIndex = 2;
if (!data || !message) return 0;
int nMessageLen = _tcslen(message)*sizeof(WCHAR);
datIndex += SetByteData(&data[datIndex], PK_USER_CHAT);
// 送信範囲
datIndex += SetByteData(&data[datIndex], type);
// メッセージ長
datIndex += SetByteData(&data[datIndex], (BYTE)nMessageLen);
// メッセージ
datIndex += SetMultiByteData(&data[datIndex], (BYTE*)message, nMessageLen, MAX_CHAT_MSG*sizeof(WCHAR));
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< チャットパケット
//>> チームランダム化コマンドパケット
// data : out作成パケット
INT PacketMaker::MakePacketData_TeamRandomize(BYTE* data, BYTE teams)
{
int datIndex = 2;
if (!data) return 0;
datIndex += SetByteData(&data[datIndex], PK_REQ_TEAM_RAND);
datIndex += SetByteData(&data[datIndex], teams); // extra data
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//<< チームランダム化コマンドパケット
//> 部屋移動パケット
// PK_USER_ROOMINFO_MOVE
// size : 2 0
// header : 1 2
// mv_x : 1 3 (char)
// mv_y : 1 4 (char)
// footer : 2 6
INT PacketMaker::MakePacketData_RoomInfoMove(short vx, short vy, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_MV);
// 移動値X
datIndex += SetShortData(&data[datIndex], vx);
// 移動値Y
datIndex += SetShortData(&data[datIndex], vy);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< 部屋移動パケット
#if RTRIAL
#else
//> キャラ選択パケット
// id : キャラID
// data : out作成パケット
INT PacketMaker::MakePacketData_RoomCharacterSelect(BYTE id, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_CHARA_SEL);
// キャラID
datIndex += SetByteData(&data[datIndex], id);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< キャラ選択パケット
#endif
//> 準備OKパケット
// b : 準備状態変更要求
// data : out作成パケット
INT PacketMaker::MakePacketData_RoomReady(BOOL b, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_READY);
// 移動値X
datIndex += SetByteData(&data[datIndex], (BYTE)b);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< 準備OKパケット
//> アイテム選択パケット
// index : アイテム使用欄インデックス
// item_flg : アイテム
// data : out作成パケット
INT PacketMaker::MakePacketData_RoomSelectItem(int index, DWORD item_flg, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_ITEM_SEL);
// アイテム使用欄インデックス
datIndex += SetByteData(&data[datIndex], (BYTE)index);
// アイテム使用欄インデックス
datIndex += SetDwordData(&data[datIndex], item_flg);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< アイテム選択パケット
//> チーム設定パケット
// team_count : チーム数変更値
// data : out作成パケット
INT PacketMaker::MakePacketData_RoomTeamCount(int team_count, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_TEAM_COUNT);
// アイテム使用欄インデックス
datIndex += SetByteData(&data[datIndex], (BYTE)team_count);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< チーム設定パケット
//> ルール設定パケット
// rule_flg : ルール変更フラグ
// data : out作成パケット
INT PacketMaker::MakePacketData_RoomRule(BYTE flg, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_RULE);
// アイテム使用欄インデックス
datIndex += SetByteData(&data[datIndex], flg);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< ルール設定パケット
//> ルール(制限ターン数)設定パケット
// turn : 制限ターン数
// data : out作成パケット
INT PacketMaker::MakePacketData_RoomRuleTurnLimit(int turn, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_RULE_TURN_LIMIT);
// 制限ターン数
datIndex += SetWordData(&data[datIndex], (short)turn);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< ルール設定パケット
//> 制限時間設定パケット
INT PacketMaker::MakePacketData_RoomRuleActTimeLimit(int obj_no, int time, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_RULE_ACT_TIME_LIMIT);
// obj_no
datIndex += SetByteData(&data[datIndex], (BYTE)obj_no);
// 制限ターン数
datIndex += SetByteData(&data[datIndex], (BYTE)time);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< 制限時間設定パケット
//> ステージ選択パケット
// stage_index : ステージインデックス値
// data : out作成パケット
INT PacketMaker::MakePacketData_RoomSelectStage(int stage_index, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_ROOM_STAGE_SEL);
// ステージインデックス値
datIndex += SetByteData(&data[datIndex], stage_index);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< ステージ選択パケット
//> ロード完了パケット
// data : out作成パケット
INT PacketMaker::MakePacketData_LoadComplete(BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_LOAD_COMPLETE);
// 1
datIndex += SetByteData(&data[datIndex], 1);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//> ロード完了パケット
//> ステージ移動パケット
// vx : 移動値x
// data : out作成パケット
INT PacketMaker::MakePacketData_MainInfoMove(short vx, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_MAIN_MV);
// 移動値X
datIndex += SetShortData(&data[datIndex], vx);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//> ステージ移動パケット
//> 更新パケット
// vx : 移動値x
// data : out作成パケット
INT PacketMaker::MakePacketData_MainInfoFlip(E_TYPE_USER_DIRECTION dir, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_MAIN_FLIP);
// 向き
datIndex += SetByteData(&data[datIndex], dir);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//> ステージ移動パケット
//> 発射パケット
// angle : 角度
// power : 初速
// blt_type : 弾の種類
// data : out作成パケット
INT PacketMaker::MakePacketData_MainInfoShot(short angle, int power, int blt_type, int proc_type, int indicatorAngle, int indicatorPower, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_MAIN_SHOT);
// 角度
datIndex += SetShortData(&data[datIndex], angle);
//
datIndex += SetByteData(&data[datIndex], (BYTE)power);
// 弾の種類
datIndex += SetByteData(&data[datIndex], (BYTE)blt_type);
// 処理の種類
datIndex += SetByteData(&data[datIndex], (BYTE)proc_type);
// インジケーター角度
datIndex += SetShortData(&data[datIndex], (short)indicatorAngle);
// インジケーターパワー
datIndex += SetByteData(&data[datIndex], (BYTE)indicatorPower);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< 発射パケット
//> ターンパスパケット
// data : out作成パケット
INT PacketMaker::MakePacketData_MainInfoTurnPass(int obj_no, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_MAIN_TURN_PASS);
// 1
datIndex += SetShortData(&data[datIndex], (short)obj_no);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< ターンパスパケット
// アイテム使用要求パケット
// item_index
// data : out作成パケット
INT PacketMaker::MakePacketData_MainInfoItemOrder(int item_index, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_MAIN_ITEM);
// item index
datIndex += SetByteData(&data[datIndex], (BYTE)item_index);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
// トリガーパケット
INT PacketMaker::MakePacketData_MainInfoTrigger(ptype_session sess, int nProcType, int nBltType, int nShotAngle, int nShotPower, int nShotIndicatorAngle, int nShotIndicatorPower, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_MAIN_TRIGGER);
// キャラ番号
datIndex += SetShortData(&data[datIndex], sess->obj_no );
// スクリプト/アイテムのタイプ
datIndex += SetByteData(&data[datIndex], (BYTE)nProcType);
// 演出のタイプ
datIndex += SetByteData(&data[datIndex], (BYTE)nBltType);
// 角度
datIndex += SetShortData(&data[datIndex], (short)nShotAngle);
// パワー
datIndex += SetShortData(&data[datIndex], (short)nShotPower);
// indicator角度
datIndex += SetShortData(&data[datIndex], (short)nShotIndicatorAngle);
// indicatorパワー
datIndex += SetShortData(&data[datIndex], (short)nShotIndicatorPower);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
// トリガー終了
INT PacketMaker::MakePacketData_MainInfoTriggerEnd(ptype_session sess, int nProcType, int nBltType, int nShotAngle, int nShotPower, int nShotIndicatorAngle, int nShotIndicatorPower, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_USER_MAIN_TRIGGER_END);
// キャラ番号
datIndex += SetShortData(&data[datIndex], sess->obj_no );
// スクリプト/アイテムのタイプ
datIndex += SetByteData(&data[datIndex], (BYTE)nProcType);
// 演出のタイプ
datIndex += SetByteData(&data[datIndex], (BYTE)nBltType);
// 角度
datIndex += SetShortData(&data[datIndex], (short)nShotAngle);
// パワー
datIndex += SetShortData(&data[datIndex], (short)nShotPower);
// indicator角度
datIndex += SetShortData(&data[datIndex], (short)nShotIndicatorAngle);
// indicatorパワー
datIndex += SetShortData(&data[datIndex], (short)nShotIndicatorPower);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
// ショットパワースタートパケット
INT PacketMaker::MakePacketData_MainInfoShotPowerStart(ptype_session sess, int nProcType, int nBltType, int nShotAngle, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_MAIN_SHOTPOWER);
// キャラ番号
datIndex += SetShortData(&data[datIndex], sess->obj_no );
// スクリプト/アイテムのタイプ
datIndex += SetByteData(&data[datIndex], (BYTE)nProcType);
// 演出のタイプ
datIndex += SetByteData(&data[datIndex], (BYTE)nBltType);
// 角度
datIndex += SetShortData(&data[datIndex], (short)nShotAngle);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//> 結果確認パケット
// data : out作成パケット
INT PacketMaker::MakePacketData_Confirm(int nCharaIndex, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CMD_CONFIRM);
// chara index
datIndex += SetByteData(&data[datIndex], (BYTE)nCharaIndex);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
//< 結果確認パケット
// ハッシュ値を返すパケットパケット
INT PacketMaker::MakePacketData_AuthRetHash(int hash_group, int hash_id, const char* code, int code_size, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_RET_HASH);
// hash_group
datIndex += SetByteData(&data[datIndex], (BYTE)hash_group);
// hash_id
datIndex += SetWordData(&data[datIndex], (WORD)hash_id);
// hash_code_size
datIndex += SetByteData(&data[datIndex], (BYTE)code_size);
// hash_code
datIndex += SetMultiByteData(&data[datIndex], (BYTE*)code, code_size, MAX_PACKET_SIZE);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
// ファイル要求パケット
INT PacketMaker::MakePacketData_ReqFileData(BOOL bScrChara, int id, int no, int file_index, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_REQ_FILE_DATA);
// chara
datIndex += SetByteData(&data[datIndex], (BYTE)bScrChara);
// id
datIndex += SetWordData(&data[datIndex], (WORD)id);
// fileno
datIndex += SetByteData(&data[datIndex], (BYTE)no);
// file_index
datIndex += SetDwordData(&data[datIndex], (DWORD)file_index);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
// ファイル要求パケット
INT PacketMaker::MakePacketData_FileHash(BOOL bScrChara, std::map < int, TCHARA_SCR_INFO > *pCharaScrInfo, std::map <int, TSTAGE_SCR_INFO> *pStageScrInfo, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_CHK_FILE_HASH);
// chara count
datIndex += SetWordData(&data[datIndex], (WORD)pCharaScrInfo->size());
std::map < int, TCHARA_SCR_INFO >::iterator itCharaEnd = pCharaScrInfo->end();
for (std::map < int, TCHARA_SCR_INFO >::iterator itChara = pCharaScrInfo->begin();
itChara != itCharaEnd;
++itChara)
{
// id
datIndex += SetWordData(&data[datIndex], (WORD)(*itChara).second.ID);
// hash
BytesFromHexString(&data[datIndex], (*itChara).second.md5);
datIndex += 16;
// datIndex += SetMultiByteData(&data[datIndex], (BYTE*)md5.code(), len, MAX_PACKET_SIZE);
}
// stage count
datIndex += SetWordData(&data[datIndex], (WORD)pStageScrInfo->size());
std::map < int, TSTAGE_SCR_INFO >::iterator itStageEnd = pStageScrInfo->end();
for (std::map < int, TSTAGE_SCR_INFO >::iterator itStage = pStageScrInfo->begin();
itStage != itStageEnd;
++itStage)
{
// id
datIndex += SetWordData(&data[datIndex], (WORD)(*itStage).second.ID);
// hash
BytesFromHexString(&data[datIndex], (*itStage).second.md5);
datIndex += 16;
// datIndex += SetMultiByteData(&data[datIndex], (BYTE*)md5.code(), len, MAX_PACKET_SIZE);
}
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}
// ファイル要求パケット
INT PacketMaker::MakePacketData_ReqFileHash(BOOL bScrChara, int id, int no, BYTE* data)
{
int datIndex = 2;
if (!data) return 0;
// ヘッダ
datIndex += SetByteData(&data[datIndex], PK_REQ_FILE_HASH);
// chara
datIndex += SetByteData(&data[datIndex], (BYTE)bScrChara);
// id
datIndex += SetWordData(&data[datIndex], (WORD)id);
// fileno
datIndex += SetByteData(&data[datIndex], (BYTE)no);
// エンドマーカ
datIndex += SetEndMarker(&data[datIndex]);
SetWordData(&data[0], datIndex);
return datIndex;
}