glob2-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [glob2-devel] session.cpp


From: Bradley Arsenault
Subject: Re: [glob2-devel] session.cpp
Date: Wed, 4 Apr 2007 11:55:18 -0400

On 4/4/07, donkyhotay <address@hidden> wrote:
I updated setData() and getData() and it compiles correctly however for
some reason is still isn't synchronized to the other players. Netgames
with this code play correctly (meaning all other data like mapnames are
still being passed through) except one player has custom prestige while
the other is set for 0 prestige (game reads a setting of 0 prestige as
infinite which is what I have configured for testing purposes). I have
read through setData() and getData() multiple times and I can not see
the flaw that is keeping this data from being passed through. Here is my
current version of setData() and getData(), if anyone can see the
problem and help me out I would appreciate it. BTW I also updated
NET_PROTOCOL_VERSION within NetConsts.h for when I'm ready to commit to
CVS.



Uint8 *SessionGame::getData(bool compressed)
{
       if (compressed)
       {
               fprintf(logFile, "getData::[%d, %d, %d, %d, %d, %d, %d, %d, 
%p]\n",
                       versionMajor, versionMinor, numberOfPlayer, numberOfTeam,
varPrestige, gameTPF, gameLatency, fileIsAMap, mapGenerationDescriptor);
               if (mapGenerationDescriptor)
                       fprintf(logFile, "mgscs=%x\n", 
mapGenerationDescriptor->checkSum());
               addSint8(data, (Sint8)versionMajor, 0);
               addSint8(data, (Sint8)versionMinor, 1);
               addSint8(data, (Sint8)numberOfPlayer, 2);
               addSint8(data, (Sint8)numberOfTeam, 3);
               addSint8(data, (Sint8)varPrestige, 4);
               addSint8(data, (Sint8)gameTPF, 5);
               addSint8(data, (Sint8)gameLatency, 6);
               addSint8(data, (Sint8)fileIsAMap, 7);

               int l=Utilities::strmlen(mapName, sizeof(mapName));
               memcpy(data+8, mapName, l);

               if (mapGenerationDescriptor)
               {
                       addSint8(data, 1, 8+l);
                       // TODO: make a compression for mapGenerationDescriptor

assert(mapGenerationDescriptor->getDataLength()==MapGenerationDescriptor::DATA_SIZE);
                       memcpy(data+9+l, mapGenerationDescriptor->getData(),
MapGenerationDescriptor::DATA_SIZE);
               }
               else
                       addSint8(data, 0, 8+l);

       }
       else
       {
               addSint32(data, versionMajor, 0);
               addSint32(data, versionMinor, 4);
               addSint32(data, numberOfPlayer, 8);
               addSint32(data, numberOfTeam, 12);
               addSint32(data, varPrestige, 16);
               addSint32(data, gameTPF, 20);
               addSint32(data, gameLatency, 24);
               addSint32(data, fileIsAMap, 28);
               if (mapGenerationDescriptor)
               {
                       addSint32(data, 1, 32);

assert(mapGenerationDescriptor->getDataLength()==MapGenerationDescriptor::DATA_SIZE);
                       memcpy(data+36, mapGenerationDescriptor->getData(),
MapGenerationDescriptor::DATA_SIZE);
               }
               else
                       addSint32(data, 0, 32);
               memcpy(data+36, mapName, sizeof(mapName));
       }
       return data;
}

bool SessionGame::setData(const Uint8 *data, int dataLength, bool
compressed)
{
       if (compressed)
       {
               if (dataLength!=SessionGame::getDataLength(true))
                       return false;

               versionMajor=getSint8(data, 0);
               versionMinor=getSint8(data, 1);
               numberOfPlayer=getSint8(data, 2);
               numberOfTeam=getSint8(data, 3);
               varPrestige=getSint8(data, 4);
               gameTPF=getSint8(data, 5);
               gameLatency=getSint8(data, 6);
               fileIsAMap=getSint8(data, 7);

               int l=Utilities::strmlen((char *)(data+8), sizeof(mapName));
               memcpy(mapName, data+8, l);
               assert(mapName[sizeof(mapName)-1]==0);

               if (mapGenerationDescriptor)
                       delete mapGenerationDescriptor;
               mapGenerationDescriptor=NULL;
               bool isDescriptor=getSint8(data, 9+l);
               if (isDescriptor)
               {
                       mapGenerationDescriptor=new MapGenerationDescriptor();
                       mapGenerationDescriptor->setData(data+8+l,
MapGenerationDescriptor::DATA_SIZE);
               }
               else
                       mapGenerationDescriptor=NULL;
               fprintf(logFile, "setData::[%d, %d, %d, %d, %d, %d, %d, %d, 
%p]\n",
                       versionMajor, versionMinor, numberOfPlayer, numberOfTeam,
varPrestige, gameTPF, gameLatency, fileIsAMap, mapGenerationDescriptor);
               if (mapGenerationDescriptor)
                       fprintf(logFile, "mgscs=%x\n", 
mapGenerationDescriptor->checkSum());
       }
       else
       {
               if (dataLength!=SessionGame::getDataLength())
                       return false;

               versionMajor=getSint32(data, 0);
               versionMinor=getSint32(data, 4);
               numberOfPlayer=getSint32(data, 8);
               numberOfTeam=getSint32(data, 12);
               varPrestige=getSint32(data, 16);
               gameTPF=getSint32(data, 20);
               gameLatency=getSint32(data, 24);
               fileIsAMap=getSint32(data, 28);
               if (mapGenerationDescriptor)
                       delete mapGenerationDescriptor;
               mapGenerationDescriptor=NULL;
               bool isDescriptor=getSint32(data, 32);
               if (isDescriptor)
               {
                       mapGenerationDescriptor=new MapGenerationDescriptor();
                       mapGenerationDescriptor->setData(data+36,
MapGenerationDescriptor::DATA_SIZE);
               }
               else
                       mapGenerationDescriptor=NULL;

               memcpy(mapName, data+36+MapGenerationDescriptor::DATA_SIZE,
sizeof(mapName));
               assert( Utilities::strnlen(mapName, sizeof(mapName)) <
(int)sizeof(mapName) );
       }

       return true;
}


--
Do not be afraid to joust a giant just because some people insist on
believing in windmills.



_______________________________________________
glob2-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/glob2-devel


I am very certain that mapGenerationDescriptor has long since been
removed, I remember quite vividly removing it myself a long time ago,
when solving a bug in the map preview (it was due to this attempt to
make live random map generation, I removed the idea in its entirety).
Perhaps you should do an update.

Otherwise I can't really tell whats wrong. I suggest you do debugging,
seeing what variables are being read in in their exact forms using
std::cout and the likes.

--
Really. I'm not lieing. Bradley Arsenault.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]