|
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
Donkano Server Help Squatter
Gender: Joined: Jul 02 2003 Posts: 763 Offline
|
Posted: 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?
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)); |
|
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
|
Back to top |
|
|
Donkano Server Help Squatter
Gender: Joined: Jul 02 2003 Posts: 763 Offline
|
Posted: Fri Dec 23, 2005 12:21 am Post subject: |
|
|
|
|
Okay, so here is my understanding of it:
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)
printf("%i - (INVALID)(1)(2)(3)(4)(5)(6)(7)(8)\n", Packet->Source->ScoreID,
1,
2,
3,
4,
5,
6,
7,
8)); |
|
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: 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). |
|
Back to top |
|
|
Donkano Server Help Squatter
Gender: Joined: Jul 02 2003 Posts: 763 Offline
|
Posted: 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?
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)); |
|
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:25 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: 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 |
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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:
One method uses semi-complex type-casts to convert indexes of the arrays to certain datatypes, like GetShort, which does something like this:
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:
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:
/* 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:
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. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Fri Dec 23, 2005 11:54 am Post subject: |
|
|
|
|
Don't forget: #pragma pack(1) |
|
Back to top |
|
|
Donkano Server Help Squatter
Gender: Joined: Jul 02 2003 Posts: 763 Offline
|
Posted: 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:
------ 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 ========== |
|
|
Back to top |
|
|
BDwinsAlt Agurus's Posse
Age:33 Gender: Joined: Jun 16 2003 Posts: 1145 Location: Alabama Offline
|
Posted: Sat Dec 31, 2005 2:16 am Post subject: |
|
|
|
|
I use Visual c++ and EVERYTHING by catid compiles fine. Dev C++ never worked |
|
Back to top |
|
|
Solo Ace Yeah, I'm in touch with reality...we correspond from time to time.
Age:36 Gender: Joined: Feb 06 2004 Posts: 2583 Location: The Netherlands Offline
|
|
Back to top |
|
|
BDwinsAlt Agurus's Posse
Age:33 Gender: Joined: Jun 16 2003 Posts: 1145 Location: Alabama Offline
|
Posted: Sat Dec 31, 2005 10:59 pm Post subject: |
|
|
|
|
Glad you reconized. |
|
Back to top |
|
|
Bak ?ls -s 0 in
Age:25 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. |
|
Back to top |
|
|
Solo Ace Yeah, I'm in touch with reality...we correspond from time to time.
Age:36 Gender: Joined: Feb 06 2004 Posts: 2583 Location: The Netherlands Offline
|
Posted: Mon Jan 02, 2006 1:45 am Post subject: |
|
|
|
|
The warning/error reporting level might be lower in your settings, Cyan. |
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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! |
|
Back to top |
|
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Software by php BB © php BB Group Server Load: 719 page(s) served in previous 5 minutes.
|