Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Biller Coding

 
Post new topic   Reply to topic Printable version
 View previous topic  How can I attach sounds to messages fr... Post :: Post Simple Contact Manager (java)  View next topic  
Author Message
Donkano
Server Help Squatter


Gender:Gender:Male
Joined: Jul 02 2003
Posts: 763
Offline

PostPosted: Fri Dec 23, 2005 12:08 am    Post subject: Biller Coding Reply to topic Reply with quote

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));
Back to top
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Dec 23, 2005 12:11 am    Post subject: Reply to topic Reply with quote

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.
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
Donkano
Server Help Squatter


Gender:Gender:Male
Joined: Jul 02 2003
Posts: 763
Offline

PostPosted: Fri Dec 23, 2005 12:21 am    Post subject: Reply to topic Reply with quote

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));
Back to top
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Dec 23, 2005 1:17 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Donkano
Server Help Squatter


Gender:Gender:Male
Joined: Jul 02 2003
Posts: 763
Offline

PostPosted: Fri Dec 23, 2005 9:02 am    Post subject: Reply to topic Reply with quote

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));
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:24
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Fri Dec 23, 2005 11:15 am    Post subject: Reply to topic Reply with quote

GetShort is a function that returns an integer. look up the function to see what it does
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Cyan~Fire
I'll count you!
I'll count you!


Age:36
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Dec 23, 2005 11:43 am    Post subject: Reply to topic Reply with quote

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.
_________________
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
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Dec 23, 2005 11:54 am    Post subject: Reply to topic Reply with quote

Don't forget: #pragma pack(1)
Back to top
View users profile Send private message Add User to Ignore List
Donkano
Server Help Squatter


Gender:Gender:Male
Joined: Jul 02 2003
Posts: 763
Offline

PostPosted: Fri Dec 23, 2005 1:06 pm    Post subject: Reply to topic Reply with quote

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 ==========
Back to top
View users profile Send private message Add User to Ignore List
BDwinsAlt
Agurus's Posse


Age:33
Gender:Gender:Male
Joined: Jun 16 2003
Posts: 1145
Location: Alabama
Offline

PostPosted: Sat Dec 31, 2005 2:16 am    Post subject: Reply to topic Reply with quote

I use Visual c++ and EVERYTHING by catid compiles fine. Dev C++ never worked icon_mad.gif
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Solo Ace
Yeah, I'm in touch with reality...we correspond from time to time.


Age:36
Gender:Gender:Male
Joined: Feb 06 2004
Posts: 2583
Location: The Netherlands
Offline

PostPosted: Sat Dec 31, 2005 7:15 am    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List
BDwinsAlt
Agurus's Posse


Age:33
Gender:Gender:Male
Joined: Jun 16 2003
Posts: 1145
Location: Alabama
Offline

PostPosted: Sat Dec 31, 2005 10:59 pm    Post subject: Reply to topic Reply with quote

icon_lol.gif Glad you reconized.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Bak
?ls -s
0 in


Age:24
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Sun Jan 01, 2006 12:08 pm    Post subject: Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Cyan~Fire
I'll count you!
I'll count you!


Age:36
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sun Jan 01, 2006 7:56 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Solo Ace
Yeah, I'm in touch with reality...we correspond from time to time.


Age:36
Gender:Gender:Male
Joined: Feb 06 2004
Posts: 2583
Location: The Netherlands
Offline

PostPosted: Mon Jan 02, 2006 1:45 am    Post subject: Reply to topic Reply with quote

The warning/error reporting level might be lower in your settings, Cyan. sa_tongue.gif
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:36
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Mon Jan 02, 2006 11:36 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Misc User Apps All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 651 page(s) served in previous 5 minutes.

phpBB Created this page in 0.609098 seconds : 41 queries executed (76.2%): GZIP compression disabled