forked from InfiniteRasa/Game-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacterMgr.cpp
494 lines (455 loc) · 16.7 KB
/
CharacterMgr.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
#include"Global.h"
void charMgr_beginCharacterSelection(clientGamemain_t *cgm)
{
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addUnicode(&pms, (sint8*)"Name"); // familyName // this should be null if hasCharacters is 0
pym_addInt(&pms, 0); // hasCharacters
pym_addInt(&pms, cgm->userID); // userId
//pym_addInt(&pms, 5); // enabledRaceList
pym_tuple_begin(&pms);
pym_addInt(&pms, 1); // human
pym_addInt(&pms, 2); // forean_hybrid
pym_addInt(&pms, 3); // brann_hybrid
pym_addInt(&pms, 4); // thrax_hybrid
pym_tuple_end(&pms);
pym_addInt(&pms, 1); // bCanSkipBootcamp
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, 5, METHODID_BEGINCHARACTERSELETION, pym_getData(&pms), pym_getLen(&pms));
}
void charMgr_sendCharacterCreateSuccess(clientGamemain_t *cgm, sint8* familyName, sint32 slotNum)
{
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, slotNum); // slotNum
pym_addUnicode(&pms, familyName); // familyName
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, 5, METHODID_CHARACTERCREATESUCCESS, pym_getData(&pms), pym_getLen(&pms)); // 426 = CharacterCreateSuccess
}
void charMgr_sendCharacterCreateFailed(clientGamemain_t *cgm, sint32 errorCode)
{
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, errorCode); // errorCode
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, 5, METHODID_USERCREATIONFAILED, pym_getData(&pms), pym_getLen(&pms));
}
void charMgr_sendCharacterDeleteSuccess(clientGamemain_t *cgm)
{
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, 1); // hasCharacters
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, 5, METHODID_CHARACTERDELETESUCCESS, pym_getData(&pms), pym_getLen(&pms));
}
void charMgr_sendGeneratedCharacterName(clientGamemain_t *cgm, bool isMale)
{
pym_init(&cgm->pyms);
pym_tuple_begin(&cgm->pyms);
if( isMale )
pym_addUnicode(&cgm->pyms, (sint8*)"Richard");
else
pym_addUnicode(&cgm->pyms, (sint8*)"Rachel");
pym_tuple_end(&cgm->pyms);
netMgr_pythonAddMethodCallRaw(cgm, 5, METHODID_GENERATEDCHARACTERNAME, pym_getData(&cgm->pyms), pym_getLen(&cgm->pyms));
}
void charMgr_sendGeneratedFamilyName(clientGamemain_t *cgm)
{
pym_init(&cgm->pyms);
pym_tuple_begin(&cgm->pyms);
pym_addUnicode(&cgm->pyms, (sint8*)"Garriott");
pym_tuple_end(&cgm->pyms);
netMgr_pythonAddMethodCallRaw(cgm, 5, 456, pym_getData(&cgm->pyms), pym_getLen(&cgm->pyms));
}
// podIdx --> 0 to 15
void _charMgr_sendUpdateEmptyPod(clientGamemain_t *cgm, sint32 podIdx)
{
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_dict_begin(&pms);
//SlotId
pym_dict_addKey(&pms, (sint8*)"SlotId");
pym_addInt(&pms, podIdx);
//IsSelected
pym_dict_addKey(&pms, (sint8*)"IsSelected");
if( podIdx == 1 )
pym_addInt(&pms, 1);
else
pym_addInt(&pms, 0);
//BodyData
pym_dict_addKey(&pms, (sint8*)"BodyData");
pym_addNoneStruct(&pms);
pym_dict_addKey(&pms, (sint8*)"AppearanceData");
pym_tuple_begin(&pms);
pym_tuple_end(&pms);
//CharacterData
pym_dict_addKey(&pms, (sint8*)"CharacterData");
pym_addNoneStruct(&pms);
//UserName
pym_dict_addKey(&pms, (sint8*)"UserName");
pym_addNoneStruct(&pms);
//GameContextId
pym_dict_addKey(&pms, (sint8*)"GameContextId");
pym_addNoneStruct(&pms);
//LoginData
pym_dict_addKey(&pms, (sint8*)"LoginData");
pym_addNoneStruct(&pms);
//ClanData
pym_dict_addKey(&pms, (sint8*)"ClanData");
pym_addNoneStruct(&pms);
pym_dict_end(&pms);
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, entityID_charPodFirst+podIdx-1, METHODID_CHARACTERINFO, pym_getData(&pms), pym_getLen(&pms));
}
void charMgr_createSelectionPodEntitys(clientGamemain_t *cgm)
{
pyMarshalString_t pms;
for(sint32 i=0; i<16; i++)
{
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, entityID_charPodFirst+i); // entityID
pym_addInt(&pms, 3543); // classID
pym_addNoneStruct(&pms); // entityData (dunno)
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, 5, METHODID_CREATEPYHSICALENTITY, pym_getData(&pms), pym_getLen(&pms));
}
}
// slotId: 1-16
void charMgr_sendCharacterInfo(clientGamemain_t *cgm, sint32 slotId, di_characterPreview_t *charInfo)
{
if( charInfo == NULL )
{
_charMgr_sendUpdateEmptyPod(cgm, slotId);
return;
}
pyMarshalString_t pms;
pym_init(&pms);
pym_tuple_begin(&pms);
pym_dict_begin(&pms);
//SlotId
pym_dict_addKey(&pms, (sint8*)"SlotId");
pym_addInt(&pms, slotId);
//IsSelected
pym_dict_addKey(&pms, (sint8*)"IsSelected");
if( slotId == 0 )
pym_addInt(&pms, 1);
else
pym_addInt(&pms, 0);
//BodyData
pym_dict_addKey(&pms, (sint8*)"BodyData");
pym_tuple_begin(&pms);
pym_addInt(&pms, charInfo->genderIsMale?692:691); // 0 - genderClassId (human: m692,f691 )
pym_addInt(&pms, 1); // 1 - scale, actually is a float!
pym_tuple_end(&pms);
//CharacterData
pym_dict_addKey(&pms, (sint8*)"CharacterData");
pym_tuple_begin(&pms);
pym_addUnicode(&pms, charInfo->unicodeName); // 0 charname
pym_addInt(&pms, 1); // 1 Pos
pym_addInt(&pms, 41); // 2 XPPtrs
pym_addInt(&pms, 10); // 3 XPLvl
pym_addInt(&pms, 111); // 4 Body
pym_addInt(&pms, 12); // 5 Mind
pym_addInt(&pms, 21); // 6 Spirit
pym_addInt(&pms, charInfo->classID); // 7 Class
pym_addInt(&pms, 3); // 8 CloneCredits
pym_addInt(&pms, charInfo->raceID); // 9 RaceID
pym_tuple_end(&pms);
//AppearanceData
pym_dict_addKey(&pms, (sint8*)"AppearanceData");
pym_dict_begin(&pms);
for(sint32 i=0; i<SWAPSET_SIZE; i++)
{
if( charInfo->appearanceData[i].classId )
{
pym_addInt(&pms, i+1); // index(equipmentSlotId)
pym_tuple_begin(&pms);
pym_addInt(&pms, charInfo->appearanceData[i].classId); // classId
pym_tuple_begin(&pms);
uint32 hueR = (charInfo->appearanceData[i].hue>>0)&0xFF;
uint32 hueG = (charInfo->appearanceData[i].hue>>8)&0xFF;
uint32 hueB = (charInfo->appearanceData[i].hue>>16)&0xFF;
uint32 hueA = (charInfo->appearanceData[i].hue>>24)&0xFF;
pym_addInt(&pms, (sint32)hueR);
pym_addInt(&pms, (sint32)hueG);
pym_addInt(&pms, (sint32)hueB);
pym_addInt(&pms, (sint32)hueA);
pym_tuple_end(&pms);
pym_tuple_end(&pms);
}
}
pym_dict_end(&pms);
//UserName
pym_dict_addKey(&pms, (sint8*)"UserName");
pym_addUnicode(&pms, charInfo->unicodeFamily);
//GameContextId
pym_dict_addKey(&pms, (sint8*)"GameContextId");
pym_addInt(&pms, charInfo->currentContextId); // see gamecontextlanguage.txt
//LoginData
pym_dict_addKey(&pms, (sint8*)"LoginData");
pym_tuple_begin(&pms);
pym_addInt(&pms, 0); // 0 numLogins
pym_addInt(&pms, 0); // 1 totalTimePlayed
pym_addInt(&pms, 0); // 2 timeSinceLastPlayed
pym_tuple_end(&pms);
//ClanData
pym_dict_addKey(&pms, (sint8*)"ClanData");
pym_tuple_begin(&pms);
pym_addInt(&pms, 123); // 0 clanID (0 marks no-clan)
pym_addUnicode(&pms, (sint8*)"Infinite Salsa"); // 1 clanName
pym_tuple_end(&pms);
pym_dict_end(&pms);
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, entityID_charPodFirst+slotId-1, METHODID_CHARACTERINFO, pym_getData(&pms), pym_getLen(&pms));
}
sint32 charMgr_recv_requestCharacterName(clientGamemain_t *cgm, uint8 *pyString, sint32 pyStringLen)
{
pym_init(&cgm->pyums, pyString, pyStringLen);
if( pym_unpackTuple_begin(&cgm->pyums) == false )
return 0;
uint32 gender = pym_unpackInt(&cgm->pyums); // gender (0 - male, 1 - female)
uint32 langID = pym_unpackInt(&cgm->pyums); // Language ID "always 1"
charMgr_sendGeneratedCharacterName(cgm, gender==0);
return 1;
}
sint32 charMgr_recv_requestFamilyName(clientGamemain_t *cgm, uint8 *pyString, sint32 pyStringLen)
{
pym_init(&cgm->pyums, pyString, pyStringLen);
if( pym_unpackTuple_begin(&cgm->pyums) == false )
return 0;
uint32 langID = pym_unpackInt(&cgm->pyums); // Language ID "always 1"
charMgr_sendGeneratedFamilyName(cgm);
return 1;
}
void _cb_charMgr_recv_requestCreateCharacterInSlot(void *param, di_characterLayout_t *characterData)
{
clientGamemain_t *cgm = (clientGamemain_t*)param;
if( characterData->error )
{
if( characterData->error_nameAlreadyInUse )
charMgr_sendCharacterCreateFailed(cgm, 7); // name in use
free(characterData);
return;
}
charMgr_sendCharacterCreateSuccess(cgm, characterData->unicodeFamily, characterData->slotIndex);
charMgr_updateCharacterSelection(cgm);
free(characterData);
}
sint32 charMgr_recv_requestCreateCharacterInSlot(clientGamemain_t *cgm, uint8 *pyString, sint32 pyStringLen)
{
di_characterLayout_t *characterData = (di_characterLayout_t*)malloc(sizeof(di_characterLayout_t));
RtlZeroMemory((void*)characterData, sizeof(di_characterLayout_t));
pym_init(&cgm->pyums, pyString, pyStringLen);
if( pym_unpackTuple_begin(&cgm->pyums) == false )
return 0;
uint32 slotNum = pym_unpackInt(&cgm->pyums);
characterData->slotIndex = slotNum;
sint8 familyName[128];
sint8 firstName[128];
characterData->unicodeFamily[0] = '\0';
characterData->unicodeName[0] = '\0';
pym_unpackUnicode(&cgm->pyums, characterData->unicodeFamily, CHARACTER_FIRSTNAMELIMIT);
pym_unpackUnicode(&cgm->pyums, characterData->unicodeName, CHARACTER_FIRSTNAMELIMIT);
sint8 gender = pym_unpackInt(&cgm->pyums); // 0 --> male, 1 --> female
float scale = pym_unpackFloat(&cgm->pyums);
if( pym_unpackDict_begin(&cgm->pyums) == false )
return 0;
characterData->genderIsMale = gender == 0;
// scale is still todo
sint32 aCount = pym_getContainerSize(&cgm->pyums);
for(sint32 i=0; i<aCount; i++)
{
sint32 key = pym_unpackInt(&cgm->pyums);
if( pym_unpackTuple_begin(&cgm->pyums) == false )
return 0;
sint32 templateId = pym_unpackInt(&cgm->pyums);
sint32 classId = gameData_getStarterItemTemplateClassId(templateId);
if( classId == 0 )
return 0; // unknown starter item
sint32 equipmentSlotId = gameData_getEquipmentClassIdSlot(classId);
if( equipmentSlotId == 0 )
return 0; // unknown starter item class id
if( key != equipmentSlotId )
return 0; // client has unsychrounous data
if( pym_unpackTuple_begin(&cgm->pyums) == false )
return 0;
sint32 cLen = pym_getContainerSize(&cgm->pyums);
if( cLen != 4 ) // no 4 subelements
return 0;
sint32 hue1 = pym_unpackLongLong(&cgm->pyums); // R
sint32 hue2 = pym_unpackLongLong(&cgm->pyums); // G
sint32 hue3 = pym_unpackLongLong(&cgm->pyums); // B
sint32 hue4 = pym_unpackLongLong(&cgm->pyums); // A
uint32 hueRGBA = (hue1) | (hue2<<8) | (hue3<<16) | (hue4<<24);
characterData->appearanceData[equipmentSlotId-1].classId = classId;
characterData->appearanceData[equipmentSlotId-1].hue = hueRGBA;
}
// Default armor
characterData->appearanceData[0].classId = 10908; // helm
characterData->appearanceData[0].hue = 0xFF808080;
characterData->appearanceData[1].classId = 7054; // boots
characterData->appearanceData[1].hue = 0xFF808080;
characterData->appearanceData[2].classId = 10909; // gloves
characterData->appearanceData[2].hue = 0xFF808080;
characterData->appearanceData[14].classId = 7052; // torso
characterData->appearanceData[14].hue = 0xFF808080;
characterData->appearanceData[15].classId = 7053; // legs
characterData->appearanceData[15].hue = 0xFF808080;
// Default armor end
sint32 raceId = pym_unpackInt(&cgm->pyums);
if( raceId < 1 || raceId > 4 )
return 0; // invalid race
// setup other characterData
characterData->userID = cgm->userID;
characterData->raceID = raceId;
characterData->classId = 1; // recruit
// setup starting location
characterData->currentContextId = 1220 ; // wilderness (alia das)
characterData->posX = 894.9f;
characterData->posY = 307.9f;
characterData->posZ = 347.1f;
// check name for valid letters
bool validName = true;
sint32 nameLength = strlen((char*)characterData->unicodeName);
for(sint32 i=0; i<127; i++)
{
sint8 c = characterData->unicodeName[i];
if( !c )
break;
if( c >= 'a' && c <= 'z' )
continue;
if( c >= 'A' && c <= 'Z' )
continue;
if( c >= '0' && c <= '9' )
continue;
if( c == '_' || c == ' ' )
continue;
// passed through all, invalid character
validName = false;
break;
}
if( nameLength < 3 )
{
charMgr_sendCharacterCreateFailed(cgm, 2);
return 1;
}
if( nameLength > 20 )
{
charMgr_sendCharacterCreateFailed(cgm, 3);
return 1;
}
if( validName == false )
{
charMgr_sendCharacterCreateFailed(cgm, 4);
return 1;
}
// queue job for character creation
DataInterface_Character_createCharacter(characterData, _cb_charMgr_recv_requestCreateCharacterInSlot, cgm);
return 1;
}
void _cb_charMgr_recv_requestDeleteCharacterInSlot(void *param, diJob_deleteCharacter_t *jobData)
{
clientGamemain_t *cgm = (clientGamemain_t*)param;
charMgr_sendCharacterDeleteSuccess(cgm);
if( jobData->error == false )
if( jobData->slotId >= 1 && jobData->slotId <= 12 )
_charMgr_sendUpdateEmptyPod(cgm, jobData->slotId);
}
sint32 charMgr_recv_requestDeleteCharacterInSlot(clientGamemain_t *cgm, uint8 *pyString, sint32 pyStringLen)
{
pym_init(&cgm->pyums, pyString, pyStringLen);
if( pym_unpackTuple_begin(&cgm->pyums) == false )
return 0;
uint32 slotId = pym_unpackInt(&cgm->pyums); // slotIndex
DataInterface_Character_deleteCharacter(cgm->userID, slotId, _cb_charMgr_recv_requestDeleteCharacterInSlot, cgm);
return 1;
}
void _cb_charMgr_initCharacterSelection(void *param, diJob_getCharacterPreviewInfo_t *jobData)
{
for(sint32 i=0; i<16; i++)
charMgr_sendCharacterInfo((clientGamemain_t*)param, i+1, jobData->outPreviewData[i]);
}
void charMgr_initCharacterSelection(clientGamemain_t *cgm)
{
charMgr_beginCharacterSelection(cgm);
charMgr_createSelectionPodEntitys(cgm);
// request character info
DataInterface_Character_getCharacterPreviewInfo(cgm->userID, -1, _cb_charMgr_initCharacterSelection, cgm);
}
void charMgr_updateCharacterSelection(clientGamemain_t *cgm)
{
// request character info
DataInterface_Character_getCharacterPreviewInfo(cgm->userID, -1, _cb_charMgr_initCharacterSelection, cgm);
}
/*selects the current character*/
void _cb_charMgr_recv_requestSwitchToCharacterInSlot(void *param, diJob_getCharacterPreviewInfo_t *jobData)
{
clientGamemain_t *cgm = (clientGamemain_t*)param;
sint32 slotIndex = jobData->slotIndex;
if( slotIndex < 1 || slotIndex > 16 )
return;
// check if character was found
di_characterPreview_t *characterData;
characterData = jobData->outPreviewData[slotIndex-1];
if( !characterData )
return;
cgm->mapLoadSlotId = slotIndex;
pyMarshalString_t pms;
// Test: send GM enabled
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addBool(&pms, true);
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, 5, 366, pym_getData(&pms), pym_getLen(&pms));
// send PreWonkavate (clientMethod.134)
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, 0); // wonkType - actually not used by the game
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, 5, 134, pym_getData(&pms), pym_getLen(&pms));
// send Wonkavate (inputstateRouter.242)
pym_init(&pms);
pym_tuple_begin(&pms);
pym_addInt(&pms, characterData->currentContextId); // gameContextId (alias mapId)
cgm->mapLoadContextId = characterData->currentContextId;
pym_addInt(&pms, 0); // instanceId ( not important for now )
// find map version
sint32 mapVersion = 0;
for(sint32 i=0; i<mapInfoCount; i++)
{
if( mapInfoArray[i].contextId == characterData->currentContextId )
{
mapVersion = mapInfoArray[i].version;
break;
}
}
pym_addInt(&pms, mapVersion); // templateVersion ( from the map file? )
pym_tuple_begin(&pms); // startPosition
pym_addInt(&pms, characterData->posX); // x (todo: send as float)
pym_addInt(&pms, characterData->posY); // y (todo: send as float)
pym_addInt(&pms, characterData->posZ); // z (todo: send as float)
pym_tuple_end(&pms);
pym_addInt(&pms, 0); // startRotation (todo, read from db and send as float)
pym_tuple_end(&pms);
netMgr_pythonAddMethodCallRaw(cgm, 6, METHODID_WONKAVATE, pym_getData(&pms), pym_getLen(&pms));
// early pass the client to the mapChannel ( since it must load character )
cgm->State = GAMEMAIN_STATE_RELIEVED; // the gameMain thread will pass the client to the mapChannel
return;
}
sint32 charMgr_recv_requestSwitchToCharacterInSlot(clientGamemain_t *cgm, uint8 *pyString, sint32 pyStringLen)
{
pym_init(&cgm->pyums, pyString, pyStringLen);
if( pym_unpackTuple_begin(&cgm->pyums) == false )
return 0;
uint32 slotId = pym_unpackInt(&cgm->pyums); // slotIndex
//bool canSkipBootcamp = pym_readBool(&cgm->pymus); --> bool: 02(true false?)
// request character info
DataInterface_Character_getCharacterPreviewInfo(cgm->userID, slotId, _cb_charMgr_recv_requestSwitchToCharacterInSlot, cgm);
return true;
}