Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NetBuffer Class Reference

#include <netbuffer.h>

Public Member Functions

 NetBuffer ()
 
 NetBuffer (int bufsize)
 
 NetBuffer (const char *buf, int bufsize)
 
 ~NetBuffer ()
 
void Reset ()
 
ObjSerial version ()
 
void setVersion (ObjSerial ver)
 
char * getData ()
 
unsigned int getOffset () const
 
void resizeBuffer (unsigned int newsize)
 
bool checkBuffer (int len, const char *fun)
 
void addClientState (ClientState cs)
 
ClientState getClientState ()
 
void addVector (Vector v)
 
Vector getVector ()
 
void addQVector (QVector v)
 
QVector getQVector ()
 
void addColor (GFXColor col)
 
GFXColor getColor ()
 
void addMatrix (Matrix m)
 
Matrix getMatrix ()
 
void addQuaternion (Quaternion quat)
 
Quaternion getQuaternion ()
 
void addTransformation (Transformation trans)
 
Transformation getTransformation ()
 
void addShield (const Shield &shield)
 
Shield getShield ()
 
void addArmor (const Armor &armor)
 
Armor getArmor ()
 
void addSerial (ObjSerial serial)
 
ObjSerial getSerial ()
 
void addFloat (float f)
 
float getFloat ()
 
void addFloat8 (float f)
 
float getFloat8 ()
 
void addDouble (double d)
 
double getDouble ()
 
void addShort (unsigned short s)
 
unsigned short getShort ()
 
void addInt32 (int i)
 
int getInt32 ()
 
void addUInt32 (unsigned int i)
 
unsigned int getUInt32 ()
 
void addChar (char c)
 
char getChar ()
 
void addType (unsigned char t)
 
bool checkType (unsigned char t)
 
unsigned char getType ()
 
void addBuffer (const unsigned char *buf, int bufsize)
 
unsigned char * extAddBuffer (int bufsize)
 
unsigned char * getBuffer (int offt)
 
void addString (const string &str)
 
string getString ()
 
GFXMaterial getGFXMaterial ()
 
void addGFXMaterial (const GFXMaterial &mat)
 
GFXLight getGFXLight ()
 
void addGFXLight (const GFXLight &light)
 
GFXLightLocal getGFXLightLocal ()
 
void addGFXLightLocal (const GFXLightLocal &light)
 
unsigned int getDataLength ()
 
unsigned int getSize ()
 

Detailed Description

Definition at line 20 of file netbuffer.h.

Constructor & Destructor Documentation

NetBuffer::NetBuffer ( )

Definition at line 56 of file netbuffer.cpp.

References buffer, MAXBUFFER, NETWORK_VERSION, and size.

57 {
58  buffer = new char[MAXBUFFER];
59  offset = 0;
60  size = MAXBUFFER;
61  memset( buffer, 0x20, size );
62  this->buffer[size-1] = 0;
63  ver = NETWORK_VERSION;
64 }
NetBuffer::NetBuffer ( int  bufsize)

Definition at line 66 of file netbuffer.cpp.

References buffer, bufsize, NETWORK_VERSION, and size.

67 {
68  buffer = new char[bufsize];
69  offset = 0;
70  size = bufsize;
71  memset( buffer, 0x20, size );
72  this->buffer[size-1] = 0;
73  ver = NETWORK_VERSION;
74 }
NetBuffer::NetBuffer ( const char *  buf,
int  bufsize 
)

If there is a platform where b in the call VsnetOSS::memcpy(a,b,c) must be char* instead of const char* or const void*, that systems header files are badly broken. That requirement must be a lie. If you have that, implement an ifdef in VsnetOSS::VsnetOSS::memcpy

Definition at line 81 of file netbuffer.cpp.

References buffer, VsnetOSS::memcpy(), NETWORK_VERSION, and size.

82 {
83  offset = 0;
84  ver =
85  size = bufsize+1;
86  this->buffer = new char[size];
87  memset( buffer, 0x20, size );
89  this->buffer[size-1] = 0;
90  ver = NETWORK_VERSION;
91 }
NetBuffer::~NetBuffer ( )

Definition at line 93 of file netbuffer.cpp.

References buffer.

94 {
95  if (buffer != NULL)
96  delete[] buffer;
97 }

Member Function Documentation

void NetBuffer::addArmor ( const Armor armor)

Definition at line 479 of file netbuffer.cpp.

References ADD_NB, addFloat(), Armor::backleftbottom, Armor::backlefttop, Armor::backrightbottom, Armor::backrighttop, Armor::frontleftbottom, Armor::frontlefttop, Armor::frontrightbottom, Armor::frontrighttop, and NB_ARMOR.

Referenced by ZoneMgr::addDamage(), and NetServer::sendDamages().

480 {
481  ADD_NB( NB_ARMOR );
482  this->addFloat( armor.frontrighttop );
483  this->addFloat( armor.backrighttop );
484  this->addFloat( armor.frontlefttop );
485  this->addFloat( armor.backlefttop );
486  this->addFloat( armor.frontrightbottom );
487  this->addFloat( armor.backrightbottom );
488  this->addFloat( armor.frontleftbottom );
489  this->addFloat( armor.backleftbottom );
490 }
void NetBuffer::addBuffer ( const unsigned char *  buf,
int  bufsize 
)

Definition at line 669 of file netbuffer.cpp.

References ADD_NB, buffer, bufsize, VsnetOSS::memcpy(), NB_BUFFER, and resizeBuffer().

670 {
671  ADD_NB( NB_BUFFER );
674  offset += bufsize;
675 }
void NetBuffer::addClientState ( ClientState  cs)

Definition at line 261 of file netbuffer.cpp.

References ADD_NB, addSerial(), addTransformation(), addVector(), and NB_CLIENTSTATE.

Referenced by UnitFactory::addMissileBuffer(), ZoneMgr::addPosition(), UnitFactory::addUnitBuffer(), NetServer::sendForcePosition(), and NetClient::sendPosition().

262 {
264  //this->addFloat( cs.delay);
265  this->addSerial( cs.client_serial );
266  this->addTransformation( cs.pos );
267  this->addVector( cs.veloc );
268  this->addVector( cs.angveloc );
269 }
void NetBuffer::addColor ( GFXColor  col)

Definition at line 321 of file netbuffer.cpp.

References GFXColor::a, ADD_NB, addFloat(), GFXColor::b, GFXColor::g, NB_COLOR, and GFXColor::r.

Referenced by NetServer::sendDamages().

322 {
323  ADD_NB( NB_COLOR );
324  this->addFloat( col.r );
325  this->addFloat( col.g );
326  this->addFloat( col.b );
327  this->addFloat( col.a );
328 }
void NetBuffer::addDouble ( double  d)

Definition at line 568 of file netbuffer.cpp.

References ADD_NB, buffer, NB_DOUBLE, POSH_DoubleBits(), and resizeBuffer().

Referenced by addQVector().

569 {
570  ADD_NB( NB_DOUBLE );
571  int tmpsize = sizeof (d);
572  resizeBuffer( offset+tmpsize );
573  POSH_DoubleBits( d, (posh_byte_t*) this->buffer+offset );
574  offset += tmpsize;
575 }
void NetBuffer::addFloat8 ( float  f)

Definition at line 542 of file netbuffer.cpp.

References addChar(), addFloat(), and version().

Referenced by ZoneMgr::addDamage().

543 {
544  if (version() < 4500) {
545  addFloat( f );
546  } else {
547  unsigned char ch;
548  if (f > 1.0) ch = 255;
549  else if (f < 0.0)
550  ch = 0;
551  else ch = (unsigned char) (f*255);
552  char sch( ch );
553  addChar( sch );
554  }
555 }
void NetBuffer::addGFXLight ( const GFXLight light)

Definition at line 829 of file netbuffer.cpp.

References ADD_NB, addFloat(), addInt32(), GFXLight::ambient, GFXLight::attenuate, GFXLight::cutoff, GFXLight::diffuse, GFXLight::direction, GFXLight::exp, i, NB_GFXLIGHT, GFXLight::options, GFXLight::specular, GFXLight::target, and GFXLight::vect.

Referenced by addGFXLightLocal().

830 {
831  ADD_NB( NB_GFXLIGHT );
832  int i = 0;
833  this->addInt32( light.target );
834  for (i = 0; i < 3; i++)
835  this->addFloat( light.vect[i] );
836  this->addInt32( light.options );
837  for (i = 0; i < 4; i++)
838  this->addFloat( light.diffuse[i] );
839  for (i = 0; i < 4; i++)
840  this->addFloat( light.specular[i] );
841  for (i = 0; i < 4; i++)
842  this->addFloat( light.ambient[i] );
843  for (i = 0; i < 3; i++)
844  this->addFloat( light.attenuate[i] );
845  for (i = 0; i < 3; i++)
846  this->addFloat( light.direction[i] );
847  this->addFloat( light.exp );
848  this->addFloat( light.cutoff );
849 }
void NetBuffer::addGFXLightLocal ( const GFXLightLocal light)

Definition at line 860 of file netbuffer.cpp.

References ADD_NB, addChar(), addGFXLight(), GFXLightLocal::islocal, GFXLightLocal::ligh, and NB_GFXLIGHTLOCAL.

Referenced by UnitFactory::addPlanetBuffer().

861 {
863  this->addGFXLight( light.ligh );
864  this->addChar( light.islocal );
865 }
void NetBuffer::addGFXMaterial ( const GFXMaterial mat)

Definition at line 778 of file netbuffer.cpp.

References GFXMaterial::aa, GFXMaterial::ab, ADD_NB, addFloat(), GFXMaterial::ag, GFXMaterial::ar, GFXMaterial::da, GFXMaterial::db, GFXMaterial::dg, GFXMaterial::dr, GFXMaterial::ea, GFXMaterial::eb, GFXMaterial::eg, GFXMaterial::er, NB_GFXMAT, GFXMaterial::power, GFXMaterial::sa, GFXMaterial::sb, GFXMaterial::sg, and GFXMaterial::sr.

Referenced by UnitFactory::addPlanetBuffer().

779 {
780  ADD_NB( NB_GFXMAT );
781  this->addFloat( mat.ar );
782  this->addFloat( mat.ag );
783  this->addFloat( mat.ab );
784  this->addFloat( mat.aa );
785 
786  this->addFloat( mat.dr );
787  this->addFloat( mat.dg );
788  this->addFloat( mat.db );
789  this->addFloat( mat.da );
790 
791  this->addFloat( mat.sr );
792  this->addFloat( mat.sg );
793  this->addFloat( mat.sb );
794  this->addFloat( mat.sa );
795 
796  this->addFloat( mat.er );
797  this->addFloat( mat.eg );
798  this->addFloat( mat.eb );
799  this->addFloat( mat.ea );
800 
801  this->addFloat( mat.power );
802 }
void NetBuffer::addMatrix ( Matrix  m)

Definition at line 341 of file netbuffer.cpp.

References ADD_NB, addFloat(), addQVector(), i, NB_MATRIX, Matrix::p, and Matrix::r.

342 {
343  ADD_NB( NB_MATRIX );
344  for (int i = 0; i < 9; i++)
345  this->addFloat( m.r[i] );
346  this->addQVector( m.p );
347 }
void NetBuffer::addQuaternion ( Quaternion  quat)

Definition at line 357 of file netbuffer.cpp.

References ADD_NB, addFloat(), addVector(), NB_QUATERNION, Quaternion::s, and Quaternion::v.

Referenced by addTransformation().

358 {
360  this->addFloat( quat.s );
361  this->addVector( quat.v );
362 }
void NetBuffer::addQVector ( QVector  v)

Definition at line 303 of file netbuffer.cpp.

References ADD_NB, addDouble(), and NB_QVECTOR.

Referenced by addMatrix(), UnitFactory::addPlanetBuffer(), ZoneMgr::addPosition(), addTransformation(), and NetServer::sendForcePosition().

304 {
305  ADD_NB( NB_QVECTOR );
306  this->addDouble( v.i );
307  this->addDouble( v.j );
308  this->addDouble( v.k );
309 }
void NetBuffer::addShield ( const Shield shield)

Definition at line 386 of file netbuffer.cpp.

References ADD_NB, addChar(), addFloat(), Shield::efficiency, Shield::leak, NB_SHIELD, Shield::number, Shield::recharge, Shield::shield2fb, Shield::shield4fbrl, and Shield::shield8.

Referenced by ZoneMgr::addDamage(), and NetServer::sendDamages().

387 {
388  ADD_NB( NB_SHIELD );
389  this->addChar( shield.number );
390  this->addChar( shield.leak );
391  this->addFloat( shield.recharge );
392  this->addFloat( shield.efficiency );
393  switch (shield.number)
394  {
395  case 2:
396  this->addFloat( shield.shield2fb.front );
397  this->addFloat( shield.shield2fb.back );
398  this->addFloat( shield.shield2fb.frontmax );
399  this->addFloat( shield.shield2fb.backmax );
400  break;
401  case 4:
402  this->addFloat( shield.shield4fbrl.front );
403  this->addFloat( shield.shield4fbrl.back );
404  this->addFloat( shield.shield4fbrl.right );
405  this->addFloat( shield.shield4fbrl.left );
406  this->addFloat( shield.shield4fbrl.frontmax );
407  this->addFloat( shield.shield4fbrl.backmax );
408  this->addFloat( shield.shield4fbrl.rightmax );
409  this->addFloat( shield.shield4fbrl.leftmax );
410  break;
411  case 8:
412  this->addFloat( shield.shield8.frontrighttop );
413  this->addFloat( shield.shield8.backrighttop );
414  this->addFloat( shield.shield8.frontlefttop );
415  this->addFloat( shield.shield8.backlefttop );
416  this->addFloat( shield.shield8.frontrightbottom );
417  this->addFloat( shield.shield8.backrightbottom );
418  this->addFloat( shield.shield8.frontleftbottom );
419  this->addFloat( shield.shield8.backleftbottom );
420  this->addFloat( shield.shield8.frontrighttopmax );
421  this->addFloat( shield.shield8.backrighttopmax );
422  this->addFloat( shield.shield8.frontlefttopmax );
423  this->addFloat( shield.shield8.backlefttopmax );
424  this->addFloat( shield.shield8.frontrightbottommax );
425  this->addFloat( shield.shield8.backrightbottommax );
426  this->addFloat( shield.shield8.frontleftbottommax );
427  this->addFloat( shield.shield8.backleftbottommax );
428  break;
429  }
430 }
void NetBuffer::addTransformation ( Transformation  trans)
void NetBuffer::addType ( unsigned char  t)

Definition at line 211 of file netbuffer.cpp.

References buffer, c, VsnetOSS::memcpy(), and resizeBuffer().

212 {
213  int tmpsize = sizeof (c);
214  resizeBuffer( offset+tmpsize );
215  VsnetOSS::memcpy( buffer+offset, &c, sizeof (c) );
216  offset += tmpsize;
217 }
void NetBuffer::addUInt32 ( unsigned int  i)

Definition at line 629 of file netbuffer.cpp.

References ADD_NB, buffer, NB_UINT32, POSH_WriteU32ToBig(), and resizeBuffer().

630 {
631  ADD_NB( NB_UINT32 );
632  int tmpsize = sizeof (i);
633  resizeBuffer( offset+tmpsize );
634  POSH_WriteU32ToBig( this->buffer+offset, i );
635  offset += tmpsize;
636 }
void NetBuffer::addVector ( Vector  v)

Definition at line 284 of file netbuffer.cpp.

References ADD_NB, addFloat(), and NB_VECTOR.

Referenced by addClientState(), UnitFactory::addPlanetBuffer(), addQuaternion(), NetServer::sendDamages(), and NetClient::sendPosition().

285 {
286  ADD_NB( NB_VECTOR );
287  this->addFloat( v.i );
288  this->addFloat( v.j );
289  this->addFloat( v.k );
290 }
bool NetBuffer::checkBuffer ( int  len,
const char *  fun 
)

Definition at line 134 of file netbuffer.cpp.

References size, and x.

Referenced by checkType(), getBuffer(), getChar(), getDouble(), getFloat(), getInt32(), getShort(), getString(), getType(), and getUInt32().

135 {
136  if (offset+len >= size) {
137  std::cerr<<"!!! ERROR : trying to read more data than buffer size (offset="<<offset<<" - size="<<size<<" - to read="
138  <<len<<") in "<<fun<<" !!!"<<std::endl;
139 
140  //NETFIXME: Be more graceful... but this is nice for Debugging in GDB.
141  int *x = NULL;
142  ( const_cast< char* > (fun) )[0] += *x;
143 
144  return false;
145  }
146  return true;
147 }
bool NetBuffer::checkType ( unsigned char  t)

Definition at line 229 of file netbuffer.cpp.

References checkBuffer(), getType(), getTypeStr(), and x.

230 {
231  const char *typ = getTypeStr( c );
232  checkBuffer( 1, typ ); //Does this type exist?
233  unsigned char got = getType();
234  if (got != c) {
235  const char *typgot = getTypeStr( got );
236  std::cerr<<"!!! ERROR : attempt to read invalid data at offset="<<offset<<": Actual type is a "<<typgot
237  <<" but I wanted a "<<typ<<" !!!"<<std::endl;
238 
239  //NETFIXME: Be more graceful... but this is nice for Debugging in GDB.
240  int *x = NULL;
241  ( const_cast< char* > (typ) )[0] += *x;
242 
243  return false;
244  }
245  return true;
246 }
unsigned char * NetBuffer::extAddBuffer ( int  bufsize)

Definition at line 677 of file netbuffer.cpp.

References ADD_NB, buffer, bufsize, NB_BUFFER, and resizeBuffer().

678 {
679  ADD_NB( NB_BUFFER );
681  unsigned char *retval = (unsigned char*) buffer+offset;
682  offset += bufsize;
683  return retval;
684 }
Armor NetBuffer::getArmor ( )

Definition at line 492 of file netbuffer.cpp.

References Armor::backleftbottom, Armor::backlefttop, Armor::backrightbottom, Armor::backrighttop, CHECK_NB, Armor::frontleftbottom, Armor::frontlefttop, Armor::frontrightbottom, Armor::frontrighttop, getFloat(), and NB_ARMOR.

493 {
494  CHECK_NB( NB_ARMOR );
495  Armor armor;
496  armor.frontrighttop = this->getFloat();
497  armor.backrighttop = this->getFloat();
498  armor.frontlefttop = this->getFloat();
499  armor.backlefttop = this->getFloat();
500  armor.frontrightbottom = this->getFloat();
501  armor.backrightbottom = this->getFloat();
502  armor.frontleftbottom = this->getFloat();
503  armor.backleftbottom = this->getFloat();
504 
505  return armor;
506 }
unsigned char * NetBuffer::getBuffer ( int  offt)

Definition at line 688 of file netbuffer.cpp.

References buffer, CHECK_NB, checkBuffer(), NB_BUFFER, and null.

Referenced by VsnetDownload::RecvCmdDownload::parse().

689 {
690  CHECK_NB( NB_BUFFER );
691  if ( !checkBuffer( offt, "getBuffer" ) )
692  return &null;
693  unsigned char *tmp = (unsigned char*) buffer+offset;
694  offset += offt;
695  return tmp;
696 }
char NetBuffer::getChar ( )

Definition at line 658 of file netbuffer.cpp.

References buffer, c, CHECK_NB, checkBuffer(), VsnetOSS::memcpy(), and NB_CHAR.

Referenced by NetClient::AddObjects(), getFloat8(), getGFXLightLocal(), getShield(), VsnetDownload::RecvCmdDownload::parse(), UnitFactory::parseNebulaBuffer(), UnitFactory::parsePlanetBuffer(), UnitFactory::parseUnitBuffer(), and VsnetDownload::Client::Manager::processCmdDownload().

659 {
660  CHECK_NB( NB_CHAR );
661  char c;
662  if ( !checkBuffer( sizeof (c), "getChar" ) )
663  return 0;
664  VsnetOSS::memcpy( &c, buffer+offset, sizeof (c) );
665  offset += sizeof (c);
666  return c;
667 }
ClientState NetBuffer::getClientState ( )

Definition at line 271 of file netbuffer.cpp.

References CHECK_NB, getSerial(), getTransformation(), getVector(), and NB_CLIENTSTATE.

Referenced by UnitFactory::parseMissileBuffer(), and UnitFactory::parseUnitBuffer().

272 {
274  ClientState cs;
275  //cs.delay = this->getFloat();
276  cs.client_serial = this->getSerial();
277  cs.pos = this->getTransformation();
278  cs.veloc = this->getVector();
279  cs.angveloc = this->getVector();
280 
281  return cs;
282 }
GFXColor NetBuffer::getColor ( )

Definition at line 330 of file netbuffer.cpp.

References GFXColor::a, GFXColor::b, CHECK_NB, GFXColor::g, getFloat(), NB_COLOR, and GFXColor::r.

331 {
332  CHECK_NB( NB_COLOR );
333  GFXColor col;
334  col.r = this->getFloat();
335  col.g = this->getFloat();
336  col.b = this->getFloat();
337  col.a = this->getFloat();
338  return col;
339 }
double NetBuffer::getDouble ( )

Definition at line 577 of file netbuffer.cpp.

References buffer, CHECK_NB, checkBuffer(), NB_DOUBLE, and POSH_DoubleFromBits().

Referenced by getQVector(), and NetClient::synchronizeTime().

578 {
579  CHECK_NB( NB_DOUBLE );
580  double s;
581  if ( !checkBuffer( sizeof (s), "getDouble" ) )
582  return 0;
584  offset += sizeof (s);
585  return s;
586 }
float NetBuffer::getFloat ( )

Definition at line 530 of file netbuffer.cpp.

References bits, buffer, CHECK_NB, checkBuffer(), NB_FLOAT, and POSH_FloatFromBigBits().

Referenced by getArmor(), getColor(), getFloat8(), getGFXLight(), getGFXMaterial(), getQuaternion(), getShield(), getVector(), UnitFactory::parseAsteroidBuffer(), UnitFactory::parseMissileBuffer(), and UnitFactory::parsePlanetBuffer().

531 {
532  CHECK_NB( NB_FLOAT );
533  float s;
534  if ( !checkBuffer( sizeof (s), "getFloat" ) )
535  return 0;
536  posh_u32_t bits = *( (posh_u32_t*) (this->buffer+offset) );
537  s = POSH_FloatFromBigBits( bits );
538  offset += sizeof (s);
539  return s;
540 }
float NetBuffer::getFloat8 ( )

Definition at line 557 of file netbuffer.cpp.

References getChar(), getFloat(), and version().

558 {
559  if (version() < 4500) {
560  return getFloat();
561  } else {
562  char sch( getChar() );
563  unsigned char ch( sch );
564  return ( (float) ch )/255.0;
565  }
566 }
GFXLight NetBuffer::getGFXLight ( )

Definition at line 804 of file netbuffer.cpp.

References GFXLight::ambient, GFXLight::attenuate, CHECK_NB, GFXLight::cutoff, GFXLight::diffuse, GFXLight::direction, GFXLight::exp, getFloat(), getInt32(), i, NB_GFXLIGHT, GFXLight::options, GFXLight::specular, GFXLight::target, and GFXLight::vect.

Referenced by getGFXLightLocal().

805 {
807  GFXLight light;
808  int i = 0;
809  light.target = this->getInt32();
810  for (i = 0; i < 3; i++)
811  light.vect[i] = this->getFloat();
812  light.options = this->getInt32();
813  for (i = 0; i < 4; i++)
814  light.diffuse[i] = this->getFloat();
815  for (i = 0; i < 4; i++)
816  light.specular[i] = this->getFloat();
817  for (i = 0; i < 4; i++)
818  light.ambient[i] = this->getFloat();
819  for (i = 0; i < 3; i++)
820  light.attenuate[i] = this->getFloat();
821  for (i = 0; i < 3; i++)
822  light.direction[i] = this->getFloat();
823  light.exp = this->getFloat();
824  light.cutoff = this->getFloat();
825 
826  return light;
827 }
GFXLightLocal NetBuffer::getGFXLightLocal ( )

Definition at line 851 of file netbuffer.cpp.

References CHECK_NB, getChar(), getGFXLight(), GFXLightLocal::islocal, GFXLightLocal::ligh, and NB_GFXLIGHTLOCAL.

Referenced by UnitFactory::parsePlanetBuffer().

852 {
854  GFXLightLocal light;
855  light.ligh = this->getGFXLight();
856  light.islocal = this->getChar();
857  return light;
858 }
GFXMaterial NetBuffer::getGFXMaterial ( )

Definition at line 749 of file netbuffer.cpp.

References GFXMaterial::aa, GFXMaterial::ab, GFXMaterial::ag, GFXMaterial::ar, CHECK_NB, GFXMaterial::da, GFXMaterial::db, GFXMaterial::dg, GFXMaterial::dr, GFXMaterial::ea, GFXMaterial::eb, GFXMaterial::eg, GFXMaterial::er, getFloat(), NB_GFXMAT, GFXMaterial::power, GFXMaterial::sa, GFXMaterial::sb, GFXMaterial::sg, and GFXMaterial::sr.

Referenced by UnitFactory::parsePlanetBuffer().

750 {
751  CHECK_NB( NB_GFXMAT );
752  GFXMaterial mat;
753 
754  mat.ar = this->getFloat();
755  mat.ag = this->getFloat();
756  mat.ab = this->getFloat();
757  mat.aa = this->getFloat();
758 
759  mat.dr = this->getFloat();
760  mat.dg = this->getFloat();
761  mat.db = this->getFloat();
762  mat.da = this->getFloat();
763 
764  mat.sr = this->getFloat();
765  mat.sg = this->getFloat();
766  mat.sb = this->getFloat();
767  mat.sa = this->getFloat();
768 
769  mat.er = this->getFloat();
770  mat.eg = this->getFloat();
771  mat.eb = this->getFloat();
772  mat.ea = this->getFloat();
773 
774  mat.power = this->getFloat();
775  return mat;
776 }
int NetBuffer::getInt32 ( )

Definition at line 618 of file netbuffer.cpp.

References buffer, CHECK_NB, checkBuffer(), NB_INT32, and POSH_ReadS32FromBig().

Referenced by getGFXLight(), getString(), VsnetDownload::RecvCmdDownload::parse(), UnitFactory::parseAsteroidBuffer(), UnitFactory::parseMissileBuffer(), UnitFactory::parseNebulaBuffer(), UnitFactory::parsePlanetBuffer(), and UnitFactory::parseUnitBuffer().

619 {
620  CHECK_NB( NB_INT32 );
621  int s;
622  if ( !checkBuffer( sizeof (s), "getInt32" ) )
623  return 0;
624  s = POSH_ReadS32FromBig( this->buffer+offset );
625  offset += sizeof (s);
626  return s;
627 }
Matrix NetBuffer::getMatrix ( )

Definition at line 348 of file netbuffer.cpp.

References CHECK_NB, getQVector(), i, NB_MATRIX, Matrix::p, and Matrix::r.

349 {
350  CHECK_NB( NB_MATRIX );
351  Matrix m;
352  for (int i = 0; i < 9; i++)
353  m.r[i] = this->getFloat();
354  m.p = this->getQVector();
355  return m;
356 }
unsigned int NetBuffer::getOffset ( ) const
inline

Definition at line 36 of file netbuffer.h.

Referenced by NetClient::AddObjects(), and ZoneMgr::broadcastSnapshots().

37  {
38  return offset;
39  } //useful to see if it's at the end of data
Quaternion NetBuffer::getQuaternion ( )

Definition at line 363 of file netbuffer.cpp.

References CHECK_NB, getFloat(), getVector(), NB_QUATERNION, q, Quaternion::s, and Quaternion::v.

Referenced by getTransformation().

364 {
366  Quaternion q;
367  q.s = this->getFloat();
368  q.v = this->getVector();
369  return q;
370 }
QVector NetBuffer::getQVector ( )

Definition at line 311 of file netbuffer.cpp.

References CHECK_NB, getDouble(), NB_QVECTOR, QVector, and v.

Referenced by getMatrix(), getTransformation(), and UnitFactory::parsePlanetBuffer().

312 {
313  CHECK_NB( NB_QVECTOR );
314  QVector v;
315  v.i = this->getDouble();
316  v.j = this->getDouble();
317  v.k = this->getDouble();
318  return v;
319 }
Shield NetBuffer::getShield ( )

Definition at line 431 of file netbuffer.cpp.

References CHECK_NB, Shield::efficiency, getChar(), getFloat(), Shield::leak, NB_SHIELD, Shield::number, Shield::recharge, Shield::shield2fb, Shield::shield4fbrl, and Shield::shield8.

432 {
433  CHECK_NB( NB_SHIELD );
434  Shield shield;
435  shield.number = this->getChar();
436  shield.leak = this->getChar();
437  shield.recharge = this->getFloat();
438  shield.efficiency = this->getFloat();
439  switch (shield.number)
440  {
441  case 2:
442  shield.shield2fb.front = this->getFloat();
443  shield.shield2fb.back = this->getFloat();
444  shield.shield2fb.frontmax = this->getFloat();
445  shield.shield2fb.backmax = this->getFloat();
446  break;
447  case 4:
448  shield.shield4fbrl.front = this->getFloat();
449  shield.shield4fbrl.back = this->getFloat();
450  shield.shield4fbrl.right = this->getFloat();
451  shield.shield4fbrl.left = this->getFloat();
452  shield.shield4fbrl.frontmax = this->getFloat();
453  shield.shield4fbrl.backmax = this->getFloat();
454  shield.shield4fbrl.rightmax = this->getFloat();
455  shield.shield4fbrl.leftmax = this->getFloat();
456  break;
457  case 8:
458  shield.shield8.frontrighttop = this->getFloat();
459  shield.shield8.backrighttop = this->getFloat();
460  shield.shield8.frontlefttop = this->getFloat();
461  shield.shield8.backlefttop = this->getFloat();
462  shield.shield8.frontrightbottom = this->getFloat();
463  shield.shield8.backrightbottom = this->getFloat();
464  shield.shield8.frontleftbottom = this->getFloat();
465  shield.shield8.backleftbottom = this->getFloat();
466  shield.shield8.frontrighttopmax = this->getFloat();
467  shield.shield8.backrighttopmax = this->getFloat();
468  shield.shield8.frontlefttopmax = this->getFloat();
469  shield.shield8.backlefttopmax = this->getFloat();
470  shield.shield8.frontrightbottommax = this->getFloat();
471  shield.shield8.backrightbottommax = this->getFloat();
472  shield.shield8.frontleftbottommax = this->getFloat();
473  shield.shield8.backleftbottommax = this->getFloat();
474  break;
475  }
476  return shield;
477 }
unsigned short NetBuffer::getShort ( )

Definition at line 597 of file netbuffer.cpp.

References buffer, CHECK_NB, checkBuffer(), NB_SHORT, and POSH_ReadU16FromBig().

Referenced by getSerial(), getString(), VsnetDownload::RecvCmdDownload::parse(), and UnitFactory::parsePlanetBuffer().

598 {
599  CHECK_NB( NB_SHORT );
600  unsigned short s;
601  if ( !checkBuffer( sizeof (s), "getShort" ) )
602  return 0;
603  s = POSH_ReadU16FromBig( this->buffer+offset );
604  //cerr<<"getShort :: offset="<<offset<<" - length="<<sizeof( s)<<" - value="<<s<<endl;
605  offset += sizeof (s);
606  return s;
607 }
unsigned int NetBuffer::getSize ( )

Definition at line 872 of file netbuffer.cpp.

References size.

Referenced by NetClient::AddObjects().

873 {
874  return size;
875 }
string NetBuffer::getString ( )

Definition at line 719 of file netbuffer.cpp.

References buffer, c, CHECK_NB, checkBuffer(), getInt32(), getShort(), and NB_STRING.

Referenced by FileUtil::GetSaveFromBuffer(), VsnetDownload::RecvCmdDownload::parse(), UnitFactory::parseAsteroidBuffer(), UnitFactory::parseMissileBuffer(), UnitFactory::parseNebulaBuffer(), UnitFactory::parsePlanetBuffer(), and UnitFactory::parseUnitBuffer().

720 {
721  CHECK_NB( NB_STRING );
722  unsigned short s;
723  s = this->getShort();
724  if (s != 0xffff) {
725  if ( !checkBuffer( s, "getString" ) )
726  return std::string();
727  char c = buffer[offset+s];
728  buffer[offset+s] = 0;
729  string str( buffer+offset );
730  buffer[offset+s] = c;
731  offset += s;
732 
733  return str;
734  } else {
735  //NETFIXME: Possible DOS attack here...
736  unsigned int len = this->getInt32();
737  if ( !checkBuffer( len, "getString" ) )
738  return std::string();
739  char c = buffer[offset+len];
740  buffer[offset+len] = 0;
741  string str( buffer+offset );
742  buffer[offset+len] = c;
743  offset += len;
744 
745  return str;
746  }
747 }
Transformation NetBuffer::getTransformation ( )
unsigned char NetBuffer::getType ( )

Definition at line 219 of file netbuffer.cpp.

References buffer, c, checkBuffer(), and VsnetOSS::memcpy().

Referenced by checkType().

220 {
221  unsigned char c;
222  if ( !checkBuffer( sizeof (c), "getChar" ) )
223  return 0;
224  VsnetOSS::memcpy( &c, buffer+offset, sizeof (c) );
225  offset += sizeof (c);
226  return c;
227 }
unsigned int NetBuffer::getUInt32 ( )

Definition at line 638 of file netbuffer.cpp.

References buffer, CHECK_NB, checkBuffer(), NB_UINT32, and POSH_ReadU32FromBig().

639 {
640  CHECK_NB( NB_UINT32 );
641  unsigned int s;
642  if ( !checkBuffer( sizeof (s), "getUInt32" ) )
643  return 0;
644  s = POSH_ReadU32FromBig( this->buffer+offset );
645  offset += sizeof (s);
646  return s;
647 }
Vector NetBuffer::getVector ( )

Definition at line 292 of file netbuffer.cpp.

References CHECK_NB, getFloat(), NB_VECTOR, v, and Vector.

Referenced by getClientState(), getQuaternion(), and UnitFactory::parsePlanetBuffer().

293 {
294  CHECK_NB( NB_VECTOR );
295  Vector v;
296  v.i = this->getFloat();
297  v.j = this->getFloat();
298  v.k = this->getFloat();
299 
300  return v;
301 }
void NetBuffer::Reset ( )

Definition at line 99 of file netbuffer.cpp.

References buffer, and size.

Referenced by NetServer::BroadcastTarget().

100 {
101  memset( buffer, 0x20, size );
102  offset = 0;
103 }
void NetBuffer::resizeBuffer ( unsigned int  newsize)

Definition at line 121 of file netbuffer.cpp.

References buffer, VsnetOSS::memcpy(), and size.

Referenced by addBuffer(), addChar(), addDouble(), addFloat(), addInt32(), addShort(), addString(), addType(), addUInt32(), and extAddBuffer().

122 {
123  if (size-1 < newsize) {
124  char *tmp = new char[newsize+1];
125  memset( tmp, 0, newsize+1 );
126  VsnetOSS::memcpy( tmp, buffer, size );
127  delete[] buffer;
128  buffer = tmp;
129  size = newsize+1;
130  }
131 }
void NetBuffer::setVersion ( ObjSerial  ver)

Definition at line 110 of file netbuffer.cpp.

Referenced by NetServer::sendNewUnitQueue(), and Client::versionBuf().

111 {
112  ver = newver;
113 }

The documentation for this class was generated from the following files: