Jump to content
Eternal Lands Official Forums
Sign in to follow this  
kzar

Send_me_my_actors

Recommended Posts

Whenever someone comes in the room i always get the ADD_NEW_ENHANCED_ACTOR message to add them.

When i send the SEND_ME_MY_ACTORS request it works fine as long as its >= 2 people, but if theres any more it only sends me two ADD_NEW_ENHANCED_ACTOR's.

 

Im not sure if thats just what the SEND_ME_MY_ACTORS does or if its a bug with my program. If its a bug with my program fair enough, but if not how do I request a full list of people around me.

Edited by kzar

Share this post


Link to post
Share on other sites

Erm, you shouldn't be constantly asking for a list of actors. Just locally keep track of actors as you get the add actor commands.

Share this post


Link to post
Share on other sites

well thats what i ment, i have put it in a small house at the moment. Sometimes when there are more than two people i dont even get the information about me (the bot)! he cant be too far away

Edited by kzar

Share this post


Link to post
Share on other sites

Then you are using the data wrong or something, because:

 

1. The send me my actors is used ONLY for a resync - do not use it unless you get totally confused, wastes lots of bandwidth on the server

2. The client works perfectly

3. You just need to track the actros you are givin and the add/remove commands

Share this post


Link to post
Share on other sites

is it required to send the version to the server? same with the SEND_OPENING_SCREEN. anything else before the login packet either? before i was just connecting and then sending the login packet right away, and i thought that might be the cause of my problems.

Share this post


Link to post
Share on other sites

I was really hoping to perfect my code before i shared it, but im ovbiously doing somthing pretty wrong here. Im definately not getting messages about the people around me reliably as i connect. Here is my progress so far. Its a dev-c++ project file, nothing for linux yet. ( i want to make a makefile but i havnt got that far.)

 

If anyone clever does have time to look at it and see if ive done anything the wrong way it would be really helpfull.

 

If people want to download it to learn somthing / base their project on be my guest but bare in mind its not perfect at all.

Edited by kzar

Share this post


Link to post
Share on other sites

I bet you're only processing the first message in a packet, or are doing it wrong...

There can be more then one message, and you have to "walk" the packet.

 

Ofc i might be wrong, since i haven't looked at your code :/

Share this post


Link to post
Share on other sites

You aren't processing all your data. You read a block of data from the Net which might be shorter or larger then the first packet. You might get a partial packet or several packets in the single read.

 

This is a common problem people forget about when working with TCP.

Share this post


Link to post
Share on other sites

Which method is best, reading the first 3 bytes, figuring out the length and reading the rest, or reading such a large amount that it shouldnt get carried over to next time?

Share this post


Link to post
Share on other sites

not having alot of luck :P Probably got compleatly the wrong idea

 

int incoming_thread(void *unused)
{
   char smallbuffer[3], message[500];
   int protocol, status, i;
   unsigned short int packetlength; 
   
   while (thread_die != -1) 
   {
       /* Read the start of the message */
       status = (SDLNet_TCP_Recv(tcpsock, &smallbuffer, 3));
       if(status <= 0) 
       {
           printf("Recieved failed");
           quit();
       }    
       /* Set the protocol from the first byte */
       protocol = smallbuffer[0];
       /* Set the packetlength from the second two bytes */
       packetlength = *((unsigned short int*)(smallbuffer + 1)); /* Grum again! */
       
       /* Make sure it will fit in buffer */
       if (sizeof(message) <= packetlength - 3)
       {
           printf("Message two long! quiting");
           quit();
           exit(1);
       }    
       
       /* Read the rest of the message */
       status = (SDLNet_TCP_Recv(tcpsock, &message, packetlength - 3));
       if(status <= 0) 
       {
           printf("Recieved failed");
           quit();
       }    
       
       /* Now give the message and protocol code to dostuff, which does stuff */
       dostuff(protocol, message);
   }    
   return(0);    
}  

Share this post


Link to post
Share on other sites

I don't know if this helps you much but this is my java code, which does the same thing, Except i do get all add_actor messages:

 

public void getMessage()
{ 
  	 String message = null;
  	 
  	 try
  	 {
        if(input.available() >0) //check if there are bytes to read
        {
           int code = input.read(); //reads the "protocol"
     
           int b2 = input.read();
           int b3 = input.read();
     
           int length = (b3 << 8) + b2; //shift cuz of unsigned bytes
     
           //System.out.println("Server_Code: "+code);
           //System.out.println("Server_Length: "+length);
     
           byte [] buf = new byte [length];                  
           for(int i=0;i<length-1;i++)
           {
                   buf[i]=(byte)input.read(); 
           }
     
            handler.read(code, length, buf);
  	 }
  	 catch(IOException e){log.severe(e.getMessage())}
  	 
}

 

good luck :angry:

Share this post


Link to post
Share on other sites

huzah finaly figured it out. I was doing a few things wrong but the one that really got me was the message length check. It took away too much so it sometimes became a negative number which is actualy larger than 60k :angry: Incase anyone cares heres my new function.

 

int incoming_thread(void *unused)
{
   char smallbuffer[3], message[500];
   int protocol, status, i;
   unsigned short int packetlength; 
   
   while (thread_die != -1) 
   {
       /* Read the start of the message */
       status = (SDLNet_TCP_Recv(tcpsock, &smallbuffer, 3));
       if(status != 3) 
       {
           printf("early Received failed\n");
           quit();
       }    
       /* Set the protocol from the first byte */
       protocol = smallbuffer[0];
       
       /* Set the packetlength from the second two bytes */
       packetlength = *((unsigned short int*)(smallbuffer + 1)); /* Grum again! */
       printf("## Packet length: %d\n",packetlength);
       
       /* Make sure it will fit in buffer */
       if (sizeof(message) <= packetlength - 1)
       {
           printf("Message too long! (%d long) (to fit in: %d) quitting\n",packetlength,sizeof(message));
           quit();
           exit(1);
       }    
       /* Read the rest of the message */
       status = (SDLNet_TCP_Recv(tcpsock, &message, packetlength-1));
       if(status != packetlength-1) 
       {
           printf("late Recieved failed (%d actualy recieved)\n",status);
           quit();
       }    
       
       message[packetlength - 1] = '\0';
       
       /* Now give the message and protocol code to dostuff, which does stuff */
       dostuff(protocol, packetlength - 1, message + 1);
   }    
   return(0);    
}  

Share this post


Link to post
Share on other sites
I don't know if this helps you much but this is my java code, which does the same thing, Except i do get all add_actor messages:

lol you posted it just as i posted i fixed it :D thanks for the thought though :angry:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×