8000 Added new parameters to message constructors to get tests working again. · randomcoding/PSAI-MessageRelay@df9956c · GitHub
[go: up one dir, main page]

Skip to content

Commit df9956c

Browse files
author
Tym The Enchanter
committed
Added new parameters to message constructors to get tests working again.
Tests are now up to date, as is main code. However, the xml schema, generation and tests need to be updated to include the new message variables.
1 parent ae5ec54 commit df9956c

File tree

6 files changed

+79
-38
lines changed

6 files changed

+79
-38
lines changed

src/message/PsaiMessageRedirector.cpp

Lines changed: 33 additions & 20 deletions
F438
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ PsaiMessageRedirector::PsaiMessageRedirector(MsgHandler* messageHandler, psEngin
2222
{
2323
setupSubscriptions(messageHandler);
2424
this->engine = engine;
25-
msgStrings = NULL;
25+
msgStringsHashReversable = NULL;
2626
xmlGenerator = new PsaiXmlGenerator();
2727
}
2828

2929
PsaiMessageRedirector::~PsaiMessageRedirector()
3030
{
31-
if (msgStrings)
31+
if (msgStringsHashReversable)
3232
{
33-
delete msgStrings;
33+
delete msgStringsHashReversable;
3434
}
3535
}
3636

@@ -58,9 +58,10 @@ void PsaiMessageRedirector::HandleMessage(MsgEntry* msg)
5858
}
5959
case MSGTYPE_DEAD_RECKONING:
6060
{
61-
if (msgStrings)
61+
if (msgStringsHashReversable)
6262
{
63-
psDRMessage drMsg(msg, msgStrings, engine->GetEngine());
63+
//new psDRMessage()
64+
psDRMessage drMsg(msg, 0, msgStringsHashReversable, engine->GetEngine());
6465
handleDeadReckonMessage(drMsg);
6566
}
6667
break;
@@ -103,17 +104,20 @@ void PsaiMessageRedirector::HandleMessage(MsgEntry* msg)
103104
}
104105
case MSGTYPE_PERSIST_ACTOR:
105106
{
106-
if (msgStrings)
107+
if (msgStringsHashReversable)
107108
{
108-
psPersistActor persistActorMsg(msg, msgStrings, engine->GetEngine());
109+
psPersistActor persistActorMsg(msg, 0, msgStringsHashReversable, engine->GetEngine());
109110
handlePersistActorMessage(persistActorMsg);
110111
}
111112
break;
112113
}
113114
case MSGTYPE_PERSIST_ITEM:
114115
{
115-
psPersistItem persistItemMsg(msg);
116-
handlePersistItemMessage(persistItemMsg);
116+
if (msgStringsHashReversable)
117+
{
118+
psPersistItem persistItemMsg(msg, msgStringsHashReversable);
119+
handlePersistItemMessage(persistItemMsg);
120+
}
117121
break;
118122
}
119123
case MSGTYPE_REMOVE_OBJECT:
@@ -179,8 +183,11 @@ void PsaiMessageRedirector::HandleMessage(MsgEntry* msg)
179183
}
180184
case MSGTYPE_GUIINVENTORY:
181185
{
182-
psGUIInventoryMessage guiInvMessage(msg);
183-
handleGuiInventoryMessage(guiInvMessage);
186+
if (msgStringsHashReversable)
187+
{
188+
psGUIInventoryMessage guiInvMessage(msg, msgStringsHashReversable);
189+
handleGuiInventoryMessage(guiInvMessage);
190+
}
184191
break;
185192
}
186193
case MSGTYPE_ACTIVEMAGIC:
@@ -299,8 +306,8 @@ void PsaiMessageRedirector::handleChatMessage(psChatMessage& msg)
299306

300307
void PsaiMessageRedirector::handleCombatEventMessage(psCombatEventMessage& msg)
301308
{
302-
printf("Handle Combat Message of type %s. Attack by %u on %u for %f damage on location %i\n", msg.GetMessageTypeName().GetDataSafe(), msg.attacker_id.Unbox(), msg.target_id.Unbox(), msg.damage,
303-
msg.target_location);
309+
printf("Handle Combat Message of type %s. Attack by %u on %u for %f damage on location %i\n", msg.GetMessageTypeName().GetDataSafe(),
310+
msg.attacker_id.Unbox(), msg.target_id.Unbox(), msg.damage, msg.target_location);
304311
}
305312

306313
void PsaiMessageRedirector::handleDeadReckonMessage(psDRMessage& msg)
@@ -325,22 +332,26 @@ void PsaiMessageRedirector::handleMoveLockMessage(psMoveLockMessage& msg)
325332

326333
void PsaiMessageRedirector::handleNewSectorMessage(psNewSectorMessage& msg)
327334
{
328-
printf("Handle message of type %s. Changed sector to %s from %s.\n", msg.GetMessageTypeName().GetDataSafe(), msg.newSector.GetDataSafe(), msg.oldSector.GetDataSafe());
335+
printf("Handle message of type %s. Changed sector to %s from %s.\n", msg.GetMessageTypeName().GetDataSafe(), msg.newSector.GetDataSafe(),
336+
msg.oldSector.GetDataSafe());
329337
}
330338

331339
void PsaiMessageRedirector::handlePersistActionLocationMessage(psPersistActionLocation& msg)
332340
{
333-
printf("Handle message of type %s. Persisted Action Location %s in sector %s.\n", msg.GetMessageTypeName().GetDataSafe(), msg.name.GetDataSafe(), msg.sector.GetDataSafe());
341+
printf("Handle message of type %s. Persisted Action Location %s in sector %s.\n", msg.GetMessageTypeName().GetDataSafe(), msg.name.GetDataSafe(),
342+
msg.sector.GetDataSafe());
334343
}
335344

336345
void PsaiMessageRedirector::handlePersistActorMessage(psPersistActor& msg)
337346
{
338-
printf("Handle message of type %s. Player id %u - name %s\n", msg.GetMessageTypeName().GetDataSafe(), msg.playerID.Unbox(), msg.name.GetDataSafe());
347+
printf("Handle message of type %s. Player id %u - name %s\n", msg.GetMessageTypeName().GetDataSafe(), msg.playerID.Unbox(),
348+
msg.name.GetDataSafe());
339349
}
340350

341351
void PsaiMessageRedirector::handlePersistItemMessage(psPersistItem& msg)
342352
{
343-
printf("Handle message of type %s. Persisting item with id %u named %s\n", msg.GetMessageTypeName().GetDataSafe(), msg.eid.Unbox(), msg.name.GetDataSafe());
353+
printf("Handle message of type %s. Persisting item with id %u named %s\n", msg.GetMessageTypeName().GetDataSafe(), msg.eid.Unbox(),
354+
msg.name.GetDataSafe());
344355
}
345356

346357
void PsaiMessageRedirector::handlePlaySoundMessage(psPlaySoundMessage& msg)
@@ -355,7 +366,8 @@ void PsaiMessageRedirector::handleRemoveObjectMessage(psRemoveObject& msg)
355366

356367
void PsaiMessageRedirector::handleSoundEventMessage(psSoundEventMessage& msg)
357368
{
358-
printf("Handle message of type %s. Sound type is %u and it %s valid.\n", msg.GetMessageTypeName().GetDataSafe(), msg.type, (msg.valid ? "is" : "is not"));
369+
printf("Handle message of type %s. Sound type is %u and it %s valid.\n", msg.GetMessageTypeName().GetDataSafe(), msg.type, (msg.valid ? "is"
370+
: "is not"));
359371
}
360372

361373
void PsaiMessageRedirector::handleSpellCancelMessage(psSpellCancelMessage& msg)
@@ -385,7 +397,8 @@ void PsaiMessageRedirector::handleStopEffectMessage(psStopEffectMessage& msg)
385397

386398
void PsaiMessageRedirector::handleWeatherMessage(psWeatherMessage& msg)
387399
{
388-
printf("Handle message of type %s. Weather for sector %s is unknown (TDB) \n", msg.GetMessageTypeName().GetDataSafe(), msg.weather.sector.GetDataSafe());
400+
printf("Handle message of type %s. Weather for sector %s is unknown (TDB) \n", msg.GetMessageTypeName().GetDataSafe(),
401+
msg.weather.sector.GetDataSafe());
389402
}
390403

391404
void PsaiMessageRedirector::handleSystemMessage(psSystemMessage& msg)
@@ -396,7 +409,7 @@ void PsaiMessageRedirector::handleSystemMessage(psSystemMessage& msg)
396409
void PsaiMessageRedirector::handleMessageStringsMessage(psMsgStringsMessage& msg)
397410
{
398411
printf("Updating msgstrings\n");
399-
msgStrings = msg.msgstrings;
412+
msgStringsHashReversable = msg.msgstrings;
400413
}
401414

402415
void PsaiMessageRedirector::handleCharacterDetailsMessage(psCharacterDetailsMessage& msg)

src/message/PsaiMessageRedirector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class PsaiMessageRedirector: public psClientNetSubscriber
136136
void handleEquipmentMessage(psEquipmentMessage& msg);
137137

138138

139-
csStringHashReversible* msgStrings;
139+
csStringHashReversible* msgStringsHashReversable;
140140

141141
psEngine* engine;
142142

src/util/PsaiStringUtilities.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ String PsaiStringUtilities::convertToString(const unsigned short int value) cons
7070
return valueString;
7171
}
7272

73-
String PsaiStringUtilities::convertToString(const uint8_t value) const
73+
/*String PsaiStringUtilities::convertToString(const uint8_t value) const
7474
{
7575
String valueString;
7676
std::stringstream out;
7777
out << value;
7878
valueString = out.str();
7979
8080
return valueString;
81-
}
81+
}*/
8282

8383
String PsaiStringUtilities::convertToString(const bool value) const
8484
{

src/util/PsaiStringUtilities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PsaiStringUtilities
2828
String convertToString(const double value) const;
2929
String convertToString(const bool value) const;
3030
String convertToString(const unsigned short int value) const;
31-
String convertToString(const uint8_t value) const;
31+
//String convertToString(const uint8_t value) const;
3232

3333
/**
3434
* @return A single @class PsaiStringUtilities instance

src/xml/PsaiXmlGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ String PsaiXmlGenerator::toXml(const psPersistItem& msg)
158158
String factName(msg.factname.GetDataSafe());
159159
xmlUtils.createDomElement(doc, messageElement, PsaiXmlConstants::ELEMENT_PERSIST_ITEM_FACT_NAME, factName);
160160

161-
String fileName(msg.filename.GetDataSafe());
162-
xmlUtils.createDomElement(doc, messageElement, PsaiXmlConstants::ELEMENT_PERSIST_ITEM_FILE_NAME, fileName);
161+
/*String fileName(msg.filename.GetDataSafe());
162+
xmlUtils.createDomElement(doc, messageElement, PsaiXmlConstants::ELEMENT_PERSIST_ITEM_FILE_NAME, fileName);*/
163163

164164
String flags = stringUtils.convertToString(msg.flags);
165165
xmlUtils.createDomElement(doc, messageElement, PsaiXmlConstants::ELEMENT_PERSIST_ITEM_FLAGS, flags);

tests/XmlGeneratorTests.cpp

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class XmlGeneratorTest: public testing::Test
5555
static int soundEventType;
5656
static int persistItemFlags;
5757
static int persistItemType;
58+
static float defaultXRotation;
5859
static float defaultYRotation;
60+
static float defaultZRotation;
5961

6062
// persist actor message
6163
static int actorType;
@@ -64,23 +66,31 @@ class XmlGeneratorTest: public testing::Test
6466
static String actorName;
6567
static String guildName;
6668
static String raceName;
69+
static String mounterAnim;
70+
static String mountGroup;
71+
static String mountFactionName;
6772
static unsigned short int gender;
6873
static String helmGroup;
74+
static String beltGroup;
75+
static String cloakGroup;
76+
static String bracerGroup;
77+
static String matName;
6978
static csVector3 collisionTop;
7079
static csVector3 collisionBottom;
7180
static csVector3 collisionOffset;
7281
static String texParts;
7382
static String equipmentParts;
7483
static uint8_t counter;
7584
static EID mappedEid;
76-
static csStringHashReversible* msgStrings;
85+
static csStringHashReversible* msgStringsHashReversable;
7786
static psLinearMovement* linearMovement;
7887
static uint8_t movementMode;
7988
static uint8_t serverMode;
8089
static PID playerId;
8190
static uint32_t groupId;
8291
static EID ownerEid;
8392
static uint32_t persistActorMessageFlags;
93+
static csStringSet* msgStrings;
8494

8595
static int actionLocationType;
8696
static String actionLocationName;
@@ -217,7 +227,7 @@ class XmlGeneratorTest: public testing::Test
217227

218228
String getTextTag(String tagName, uint8_t tagContent)
219229
{
220-
return getTextTag(tagName, getStringUtils().convertToString(tagContent));
230+
return getTextTag(tagName, getStringUtils().convertToString((int)tagContent));
221231
}
222232

223233
String getVectorTag(csVector3 vector)
@@ -402,7 +412,9 @@ int XmlGeneratorTest::soundEventType = 10;
402412
String XmlGeneratorTest::soundName("aSound");
403413
int XmlGeneratorTest::persistItemFlags = 1;
404414
int XmlGeneratorTest::persistItemType = 3;
415+
float XmlGeneratorTest::defaultXRotation = 43.5;
405416
float XmlGeneratorTest::defaultYRotation = 34.5;
417+
float XmlGeneratorTest::defaultZRotation = 54.3;
406418
EID XmlGeneratorTest::objectEid(44);
407419

408420
// persist actor message
@@ -412,22 +424,29 @@ bool XmlGeneratorTest::control = true;
412424
String XmlGeneratorTest::actorName("Actor Name");
413425
String XmlGeneratorTest::guildName("Guild Name");
414426
String XmlGeneratorTest::raceName("Race Name");
427+
String XmlGeneratorTest::matName("Mat Name");
428+
String XmlGeneratorTest::mountFactionName("Mount Faction");
415429
unsigned short int XmlGeneratorTest::gender = 1;
416430
String XmlGeneratorTest::helmGroup("Helm Group");
431+
String XmlGeneratorTest::beltGroup("Belt Group");
432+
String XmlGeneratorTest::cloakGroup("Cloak Group");
433+
String XmlGeneratorTest::bracerGroup("Bracer Group");
417434
csVector3 XmlGeneratorTest::collisionTop(23.4, 32.1, 2.3);
418435
csVector3 XmlGeneratorTest::collisionBottom(23.4, 32.1, 0.3);
419436
csVector3 XmlGeneratorTest::collisionOffset(1.0, 1.0, 2.0);
420437
String XmlGeneratorTest::texParts("Tex Parts");
421438
String XmlGeneratorTest::equipmentParts("Equipment Parts");
422439
uint8_t XmlGeneratorTest::counter = 2;
423440
EID XmlGeneratorTest::mappedEid(43);
424-
csStringHashReversible* XmlGeneratorTest::msgStrings = new csStringHashReversible(10);
441+
csStringHashReversible* XmlGeneratorTest::msgStringsHashReversable = new csStringHashReversible(10);
425442
uint8_t XmlGeneratorTest::movementMode = 5;
426 10000 443
uint8_t XmlGeneratorTest::serverMode = 3;
427444
PID XmlGeneratorTest::playerId(123);
428445
uint32_t XmlGeneratorTest::groupId = 9876;
429446
EID XmlGeneratorTest::ownerEid(789);
430447
uint32_t XmlGeneratorTest::persistActorMessageFlags = 45;
448+
csStringSet* XmlGeneratorTest::msgStrings = new csStringSet();
449+
String XmlGeneratorTest::mounterAnim("Mounter Anim");
431450

432451
// persist action location
433452
int XmlGeneratorTest::actionLocationType = 10;
@@ -454,7 +473,7 @@ int XmlGeneratorTest::defenseAnimation = 7;
454473
// Test Fixtures
455474
TEST_F(XmlGeneratorTest, testChatMessageToXml)
456475
{
457-
psChatMessage msg(defaultClientNum, me.c_str(), you.c_str(), chatMessage.c_str(), CHAT_SAY, false);
476+
psChatMessage msg(defaultClientNum, defaultEid, me.c_str(), you.c_str(), chatMessage.c_str(), CHAT_SAY, false);
458477

459478
String chatXml = getGenerator().toXml(msg);
460479

@@ -484,18 +503,20 @@ TEST_F(XmlGeneratorTest, testSoundEventMessageToXml)
484503

485504
TEST_F(XmlGeneratorTest, testPersistItemMessageToXml)
486505
{
487-
psPersistItem
488-
msg(defaultClientNum, defaultEid, persistItemType, itemName.c_str(), factionName.c_str(), fileName.c_str(), sector.c_str(), defaultPositionVector, defaultYRotation, persistItemFlags);
506+
psPersistItem msg(defaultClientNum, defaultEid, persistItemType, itemName.c_str(), factionName.c_str(), matName.c_str(), sector.c_str(),
507+
defaultPositionVector, defaultXRotation, defaultYRotation, defaultZRotation, persistItemFlags, msgStrings);
489508

490509
msg.name = itemName.c_str();
491510
msg.eid = defaultEid;
492511
msg.factname = factionName.c_str();
493-
msg.filename = fileName.c_str();
512+
msg.matname = matName.c_str();
494513
msg.flags = persistItemFlags;
495514
msg.pos = defaultPositionVector;
496515
msg.sector = sector.c_str();
497516
msg.type = persistItemType;
498517
msg.yRot = defaultYRotation;
518+
msg.xRot = defaultXRotation;
519+
msg.zRot = defaultZRotation;
499520

500521
String msgXml = getGenerator().toXml(msg);
501522

@@ -506,17 +527,22 @@ TEST_F(XmlGeneratorTest, testPersistItemMessageToXml)
506527
TEST_F(XmlGeneratorTest, DISABLED_testPersistActorMessageToXml)
507528
{
508529
psLinearMovement* linearMove = createLinearMovement();
509-
psPersistActor msg(defaultClientNum, actorType, masqueradeType, control, actorName.c_str(), guildName.c_str(), factionName.c_str(), fileName.c_str(), raceName.c_str(), gender, helmGroup.c_str(),
510-
collisionTop, collisionBottom, collisionOffset, texParts.c_str(), equipmentParts.c_str(), counter, mappedEid, msgStrings, linearMove, movementMode, serverMode, playerId, groupId,
511-
ownerEid, persistActorMessageFlags);
530+
psPersistActor msg(defaultClientNum, actorType, masqueradeType, control, actorName.c_str(), guildName.c_str(), factionName.c_str(),
531+
matName.c_str(), raceName.c_str(), mountFactionName.c_str(), mounterAnim.c_str(), gender, helmGroup.c_str(), bracerGroup.c_str(),
532+
beltGroup.c_str(), cloakGroup.c_str(), collisionTop, collisionBottom, collisionOffset, texParts.c_str(), equipmentParts.c_str(), counter,
533+
mappedEid, msgStrings, linearMove, movementMode, serverMode, playerId, groupId, ownerEid, persistActorMessageFlags);
512534

513535
msg.bottom = collisionBottom;
514536
msg.masqueradeType = masqueradeType;
515537
msg.guild = guildName.c_str();
516538
msg.factname = factionName.c_str();
517-
msg.filename = fileName.c_str();
539+
msg.mountFactname = mountFactionName.c_str();
540+
msg.matname = matName.c_str();
541+
msg.MounterAnim = mounterAnim.c_str();
518542
msg.race = raceName.c_str();
519543
msg.helmGroup = helmGroup.c_str();
544+
msg.BeltGroup = beltGroup.c_str();
545+
msg.CloakGroup = cloakGroup.c_str();
520546
msg.top = collisionTop;
521547
msg.offset = collisionOffset;
522548
msg.texParts = texParts.c_str();
@@ -561,7 +587,8 @@ TEST_F(XmlGeneratorTest, testRemoveObjectMessageToXml)
561587
// Disabled for the same reason as testPersistActorMessageToXml
562588
TEST_F(XmlGeneratorTest, DISABLED_testDeadReckoningMessageToXml)
563589
{
564-
psDRMessage msg(defaultClientNum, mappedEid, true, movementMode, counter, position, yRot, iSec, velocity, worldVelocity, ang_velocity, msgStrings);
590+
psDRMessage msg(defaultClientNum, mappedEid, true, movementMode, counter, position, yRot, iSec, sector.c_str(), velocity, worldVelocity,
591+
ang_velocity, msgStrings, msgStringsHashReversable);
565592

566593
msg.entityid = mappedEid;
567594
msg.on_ground = true;
@@ -573,6 +600,7 @@ TEST_F(XmlGeneratorTest, DISABLED_testDeadReckoningMessageToXml)
573600
msg.vel = velocity;
574601
msg.worldVel = worldVelocity;
575602
msg.ang_vel = ang_velocity;
603+
msg.sectorName = sector.c_str();
576604

577605
String msgXml = getGenerator().toXml(msg);
578606

0 commit comments

Comments
 (0)
0