Server Help

Misc User Apps - Biller Coding

Donkano - Fri Dec 23, 2005 12:08 am
Post subject: Biller Coding
I see through-out catid's SSBiller2 source in the rpc.h a bunch of % commands. Is there a full list of all of them and what they do some-where or is someone willing to explain here?


printf("%i - New player connected: %s\n", Packet->Source->ScoreID, &Packet->Message[6]);
Would come out as:
<ZoneScoreID> - New player connected: <Their name>


But now something like the code below, how would I know what that is to output?
Code: Show/Hide
printf("%i - (INVALID)(%i)(%i)(%i)(%i)(%i)(%i)(%i)(%i)\n", Packet->Source->ScoreID,
                                                GetShort(Packet->Message, 5),
                                                GetShort(Packet->Message, 9),
                                                GetShort(Packet->Message, 13),
                                                GetShort(Packet->Message, 17),
                                                GetShort(Packet->Message, 5),
                                                GetShort(Packet->Message, 9),
                                                GetShort(Packet->Message, 13),
                                                GetShort(Packet->Message, 17));

Mr Ekted - Fri Dec 23, 2005 12:11 am
Post subject:
http://www.cplusplus.com/ref/cstdio/printf.html

They are not commands; they are formatting specifiers. There is no such thing as a command in C.
Donkano - Fri Dec 23, 2005 12:21 am
Post subject:
Okay, so here is my understanding of it:

Code: Show/Hide
printf("%i - (INVALID)(%i)(%i)(%i)(%i)(%i)(%i)(%i)(%i)\n", Packet->Source->ScoreID,
                                                GetShort(Packet->Message, 5),
                                                GetShort(Packet->Message, 9),
                                                GetShort(Packet->Message, 13),
                                                GetShort(Packet->Message, 17),
                                                GetShort(Packet->Message, 5),
                                                GetShort(Packet->Message, 9),
                                                GetShort(Packet->Message, 13),
                                                GetShort(Packet->Message, 17));

is the same as (using matching on the next 1, not programming)
Code: Show/Hide
printf("%i - (INVALID)(1)(2)(3)(4)(5)(6)(7)(8)\n", Packet->Source->ScoreID,
                                                1,
                                                2,
                                                3,
                                                4,
                                                5,
                                                6,
                                                7,
                                                8));

Mr Ekted - Fri Dec 23, 2005 1:17 am
Post subject:
Basically, yes. The % format codes describe not only how to interpret each parameter, but also how to show it. You can control width, padding, precision, etc. with simple descriptors.

printf("%s is %d years old.", "Jim", 41);

would output:

Jim is 41 years old.

Note that you can screw up since types are not checked:

printf("%s is %d years old.", 41, "Jim");

will crash the app because 41 will be interpretted as a pointer to a string (%s), which will cause an access violation. The second parameter "Jim" would be interpretted as an integer, so the pointer to the string would be displayed (if the first parameter didn't make it crash).
Donkano - Fri Dec 23, 2005 9:02 am
Post subject:
Okay. Can you explain about these "Packet->Message" values and what the integer at the end of it is meaning?

Code: Show/Hide
                                                GetShort(Packet->Message, 5),
                                                GetShort(Packet->Message, 9),
                                                GetShort(Packet->Message, 13),
                                                GetShort(Packet->Message, 17),
                                                GetShort(Packet->Message, 5),
                                                GetShort(Packet->Message, 9),
                                                GetShort(Packet->Message, 13),
                                                GetShort(Packet->Message, 17));

Bak - Fri Dec 23, 2005 11:15 am
Post subject:
GetShort is a function that returns an integer. look up the function to see what it does
Cyan~Fire - Fri Dec 23, 2005 11:43 am
Post subject:
There are two primary ways of dealing with packets in C.

You start of with a byte array like this:
Code: Show/Hide
char packet[3];


One method uses semi-complex type-casts to convert indexes of the arrays to certain datatypes, like GetShort, which does something like this:
Code: Show/Hide
short GetShort(char *buffer, int offset)
{
   return *(short*)(buffer + offset);
}

If you can't see what that's doing offhand, here are the individual instructions written out:
Code: Show/Hide
short GetShort(char *buffer, int offset)
{
   //get the point in the array that contains the value we're looking for
   char *location = buffer + offset;

   //since we want to return a short, type-cast it to a short* instead of a char*
   short *sLocation = (short*)location;

   //now dereference the pointer (load the value of the memory it points to)
   short ret = *sLocation;

   //now return this value
   return ret;
}

You may now be thinking "how confusing!" And you would be right, which is why I use this method:

First, I define a structure that represents the layout of the packet in memory:
Code: Show/Hide
/* 0x04 */
struct pkt_PlayerLeaving
{
   char type;
   short ident;
};


Then, I simply type-cast the pointer to the packet to a pointer to this struct, and I can access each member just like a normal structure:
Code: Show/Hide
void __stdcall handlePlayerLeaving(Host *h, char *msg, Uint32 len)
{
   struct pkt_PlayerLeaving *pkt = (pkt_PlayerLeaving *)msg;
   Player *p;

   CHECK(len != sizeof(pkt_PlayerLeaving));

   if (p = h->getPlayer(pkt->ident))
// and so on...

In this specific example, all we access is the ident of the player, but in larger packets with, say, 20 members, the 1st method can become very cumbersome while this remains simple.
Mr Ekted - Fri Dec 23, 2005 11:54 am
Post subject:
Don't forget: #pragma pack(1)
Donkano - Fri Dec 23, 2005 1:06 pm
Post subject:
Hmmm... strangely when I compile I get a series of errors. So I tried taking catid's source directly from the website, extracted it and tried to build it and here is what I got:
Code: Show/Hide
------ Build started: Project: SubBill3, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\continuum server\server\subbill3\linkedlist.h(381) : warning C4267: '=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(425) : warning C4267: '=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(433) : warning C4996: 'itoa' was declared deprecated
        c:\program files\microsoft visual studio 8\vc\include\stdlib.h(820) : see declaration of 'itoa'
        Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa. See online help for details.'
c:\continuum server\server\subbill3\linkedlist.h(437) : warning C4267: '=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(444) : warning C4996: 'itoa' was declared deprecated
        c:\program files\microsoft visual studio 8\vc\include\stdlib.h(820) : see declaration of 'itoa'
        Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa. See online help for details.'
c:\continuum server\server\subbill3\linkedlist.h(448) : warning C4267: '=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(478) : warning C4267: '+=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(485) : warning C4996: 'itoa' was declared deprecated
        c:\program files\microsoft visual studio 8\vc\include\stdlib.h(820) : see declaration of 'itoa'
        Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa. See online help for details.'
c:\continuum server\server\subbill3\linkedlist.h(496) : warning C4267: '+=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(502) : warning C4996: 'itoa' was declared deprecated
        c:\program files\microsoft visual studio 8\vc\include\stdlib.h(820) : see declaration of 'itoa'
        Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa. See online help for details.'
c:\continuum server\server\subbill3\linkedlist.h(513) : warning C4267: '+=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(533) : warning C4267: '=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(543) : warning C4996: 'itoa' was declared deprecated
        c:\program files\microsoft visual studio 8\vc\include\stdlib.h(820) : see declaration of 'itoa'
        Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa. See online help for details.'
c:\continuum server\server\subbill3\linkedlist.h(547) : warning C4267: '=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\linkedlist.h(557) : warning C4996: 'itoa' was declared deprecated
        c:\program files\microsoft visual studio 8\vc\include\stdlib.h(820) : see declaration of 'itoa'
        Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _itoa. See online help for details.'
c:\continuum server\server\subbill3\linkedlist.h(561) : warning C4267: '=' : conversion from 'size_t' to 'LONG', possible loss of data
c:\continuum server\server\subbill3\prng.h(98) : error C2065: 'i' : undeclared identifier
c:\continuum server\server\subbill3\declares.h(372) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\continuum server\server\subbill3\declares.h(372) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\declares.h(479) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\declares.h(523) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\declares.h(554) : warning C4267: 'return' : conversion from 'size_t' to 'SHORT', possible loss of data
c:\continuum server\server\subbill3\declares.h(564) : warning C4267: 'return' : conversion from 'size_t' to 'SHORT', possible loss of data
c:\continuum server\server\subbill3\declares.h(622) : warning C4244: '=' : conversion from 'SOCKET' to 'unsigned int', possible loss of data
c:\continuum server\server\subbill3\declares.h(665) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\encryption.h(133) : error C2065: 'L' : undeclared identifier
c:\continuum server\server\subbill3\rpc.h(1582) : warning C4267: '+=' : conversion from 'size_t' to 'SHORT', possible loss of data
c:\continuum server\server\subbill3\rpc.h(1612) : warning C4267: '+=' : conversion from 'size_t' to 'SHORT', possible loss of data
c:\continuum server\server\subbill3\rpc.h(1740) : warning C4267: '=' : conversion from 'size_t' to 'SHORT', possible loss of data
c:\continuum server\server\subbill3\dbase.h(481) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(486) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(491) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(821) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(860) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(979) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(1115) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(1116) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(1130) : warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
c:\continuum server\server\subbill3\dbase.h(2264) : warning C4244: '=' : conversion from 'LONG' to 'short', possible loss of data
Build log was saved at "file://c:\Continuum Server\Server\SubBill3\Debug\BuildLog.htm"
SubBill3 - 3 error(s), 36 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

BDwinsAlt - Sat Dec 31, 2005 2:16 am
Post subject:
I use Visual c++ and EVERYTHING by catid compiles fine. Dev C++ never worked icon_mad.gif
Solo Ace - Sat Dec 31, 2005 7:15 am
Post subject:
You don't have to worry about the 'warning' messages (well, the author should, but it's not a big deal in this case).

What you'll need to worry about (if you want to build it) is this:
Code: Show/Hide
c:\continuum server\server\subbill3\prng.h(98) : error C2065: 'i' : undeclared identifier
c:\continuum server\server\subbill3\declares.h(372) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\continuum server\server\subbill3\encryption.h(133) : error C2065: 'L' : undeclared identifier


BDAlt: That's because you're an idiot.
BDwinsAlt - Sat Dec 31, 2005 10:59 pm
Post subject:
icon_lol.gif Glad you reconized.
Bak - Sun Jan 01, 2006 12:08 pm
Post subject:
You can disable warning by putting, at the top of your code,

Code: Show/Hide
#pragma warning( disable : 4267 )


where 4705 is the warning number:

c:\continuum server\server\subbill3\linkedlist.h(381) : warning C4267: '=' : conversion from 'size_t' to 'LONG', possible loss of data
Cyan~Fire - Sun Jan 01, 2006 7:56 pm
Post subject:
Disabling the type conversion warning is a bad idea... C/C++ lets you do whatever you want to do regarding types but at least let it warn you. Find out what's causing the warning, I never got it before.
Solo Ace - Mon Jan 02, 2006 1:45 am
Post subject:
The warning/error reporting level might be lower in your settings, Cyan. sa_tongue.gif
Cyan~Fire - Mon Jan 02, 2006 11:36 am
Post subject:
Lol, actually my compiler doesn't even have that warning (MSVC6). But I'm sure we're using the same warning level because I use 3 and that report that Donkano reported is definitely not 4. 4 Reports a bunch of junk that nobody would ever want to read.

"This warning is informative." Then shut up!
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group