@@ -350,26 +350,43 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
350
350
s16 hp = 1 ;
351
351
v3f velocity;
352
352
v3f rotation;
353
- if (!data.empty ()) {
353
+
354
+ while (!data.empty ()) { // breakable, run for one iteration
354
355
std::istringstream is (data, std::ios::binary);
355
- // read version
356
+ // 'version' does not allow to incrementally extend the parameter list thus
357
+ // we need another variable to build on top of 'version=1'. Ugly hack but works™
358
+ u8 version2 = 0 ;
356
359
u8 version = readU8 (is);
357
- // check if version is supported
358
- if (version == 0 ){
359
- name = deSerializeString (is);
360
- state = deSerializeLongString (is);
361
- }
362
- else if (version == 1 ){
363
- name = deSerializeString (is);
364
- state = deSerializeLongString (is);
365
- hp = readS16 (is);
366
- velocity = readV3F1000 (is);
367
- rotation = readV3F1000 (is);
368
- }
360
+
361
+ name = deSerializeString (is);
362
+ state = deSerializeLongString (is);
363
+
364
+ if (version < 1 )
365
+ break ;
366
+
367
+ hp = readS16 (is);
368
+ velocity = readV3F1000 (is);
369
+ // yaw must be yaw to be backwards-compatible
370
+ rotation.Y = readF1000 (is);
371
+
372
+ if (is.good ()) // EOF for old formats
373
+ version2 = readU8 (is);
374
+
375
+ if (version2 < 1 ) // PROTOCOL_VERSION < 37
376
+ break ;
377
+
378
+ // version2 >= 1
379
+ rotation.X = readF1000 (is);
380
+ rotation.Z = readF1000 (is);
381
+
382
+ // if (version2 < 2)
383
+ // break;
384
+ // <read new values>
385
+ break ;
369
386
}
370
387
// create object
371
- infostream<< " LuaEntitySAO::create(name=\" " << name<< " \" state=\" "
372
- << state<< " \" )" << std::endl;
388
+ infostream << " LuaEntitySAO::create(name=\" " << name << " \" state=\" "
389
+ << state << " \" )" << std::endl;
373
390
LuaEntitySAO *sao = new LuaEntitySAO (env, pos, name, state);
374
391
sao->m_hp = hp;
375
392
sao->m_velocity = velocity;
@@ -527,7 +544,7 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
527
544
{
528
545
std::ostringstream os (std::ios::binary);
529
546
530
- // protocol >= 14
547
+ // PROTOCOL_VERSION >= 37
531
548
writeU8 (os, 1 ); // version
532
549
os << serializeString (" " ); // name
533
550
writeU8 (os, 0 ); // is_player
@@ -572,7 +589,7 @@ void LuaEntitySAO::getStaticData(std::string *result) const
572
589
{
573
590
verbosestream<<FUNCTION_NAME<<std::endl;
574
591
std::ostringstream os (std::ios::binary);
575
- // version
592
+ // version must be 1 to keep backwards-compatibility. See version2
576
593
writeU8 (os, 1 );
577
594
// name
578
595
os<<serializeString (m_init_name);
@@ -584,12 +601,18 @@ void LuaEntitySAO::getStaticData(std::string *result) const
584
601
} else {
585
602
os<<serializeLongString (m_init_state);
586
603
}
587
- // hp
588
604
writeS16 (os, m_hp);
589
- // velocity
590
605
writeV3F1000 (os, m_velocity);
591
- // rotation
592
- writeV3F1000 (os, m_rotation);
606
+ // yaw
607
+ writeF1000 (os, m_rotation.Y );
608
+
609
+ // version2. Increase this variable for new values
610
+ writeU8 (os, 1 ); // PROTOCOL_VERSION >= 37
611
+
612
+ writeF1000 (os, m_rotation.X );
613
+ writeF1000 (os, m_rotation.Z );
614
+
615
+ // <write new values>
593
616
594
617
*result = os.str ();
595
618
}
0 commit comments