Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (Dico), 16,767 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Length stored in a Byte #291608
09/26/09 18:09
09/26/09 18:09
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline OP
Junior Member
GorNaKosh  Offline OP
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
While reading the manual I fall over this here:
Originally Posted By: Online Manual
If the length of the buffer is not known to the client, it can be stored in a byte, short, or long at the beginning of the buffer.
http://www.conitec.net/beta/send_data.htm

How can I manage this - storing as well as reading?

indetify different incomming structs [Re: GorNaKosh] #291995
09/29/09 15:28
09/29/09 15:28
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline OP
Junior Member
GorNaKosh  Offline OP
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
I found a solution for my problem identifying incomming structs. Here is an example (not tested):
Code:
//flags for identify the structs
#define STRUCT_TYPE_A (1<<0)
#define STRUCT_TYPE_B (1<<1)
#define STRUCT_TYPE_C (1<<2)

//our test struct
typedef struct TEST_STRUCT {
     char flags;   //importent: the flag-char have to be the first property
                   //char = 1Byte -> can store 8flags
     var value;    //content of the struct
     char msg[25];
} TEST_STRUCT;

//example for a sending function
void sendingStruct(var reciever, var type, var value, char msg) {
     TEST_STRUCT *newPacket = malloc(sizeof(TEST_STRUCT));
     newPacket.flags = NULL;
     newPacket.flags |= type;
     newPacket.value = value;
     newPacket.msg = msg;
     
     send_struct_id(reciever,newPacket,sizeof(TEST_STRUCT));
     
     wait(-dplay_entrate/16);
     free(newPacket);
}

//example for a recieving function
on_server_event(void *clientBuf, var clientID) {
     
     if(event_type == EVENT_DATA) {
          
          char *tempBuf = clientBuf;
          
          //now tempBuf[0] points to the first byte of the
          //incomming struct - its the flag-property
          //so with this you can check the type
          
          if((tempBuf[0] & STRUCT_TYPE_A) == STRUCT_TYPE_A) {
          error("Type A");
          }

          if((tempBuf[0] & STRUCT_TYPE_B) == STRUCT_TYPE_B) {
          error("Type B");
          }

          if((tempBuf[0] & STRUCT_TYPE_C) == STRUCT_TYPE_C) {
          error("Type C");
          }
     }
}

//test main
void main() {
     
     //if it's a client
     if(connection == CONNECT_CLIENT) {

          //after connecting
          while (dplay_status < 2) { wait(1); }
          
          //sending a test
          sendingStruct(NULL, STRUCT_TYPE_A, 3, "Test!");
     }     

     return;
}


Anyone with other ideas or improvements???
Gor Na Kosh

Last edited by GorNaKosh; 09/29/09 15:32.

Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1