kzar Report post Posted October 31, 2004 (edited) 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 October 31, 2004 by kzar Share this post Link to post Share on other sites
Cicero Report post Posted October 31, 2004 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
kzar Report post Posted October 31, 2004 Yea but im not getting a full list when i login, so i thought i had to ask for them at login. Share this post Link to post Share on other sites
Learner Report post Posted October 31, 2004 You only get the actors that are near you, not everyone in that game or the map. Share this post Link to post Share on other sites
kzar Report post Posted October 31, 2004 (edited) 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 October 31, 2004 by kzar Share this post Link to post Share on other sites
Learner Report post Posted October 31, 2004 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
kzar Report post Posted October 31, 2004 ok il see what ive done wrong in that case Share this post Link to post Share on other sites
kzar Report post Posted October 31, 2004 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
Entropy Report post Posted October 31, 2004 No, the version is not required for bots. Share this post Link to post Share on other sites
kzar Report post Posted November 1, 2004 (edited) 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 November 1, 2004 by kzar Share this post Link to post Share on other sites
Xilcox Report post Posted November 1, 2004 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
Learner Report post Posted November 1, 2004 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
kzar Report post Posted November 1, 2004 AHH i see ! *works on doing it properly* Share this post Link to post Share on other sites
kzar Report post Posted November 1, 2004 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
kzar Report post Posted November 1, 2004 not having alot of luck 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
DaVinci Report post Posted November 3, 2004 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 Share this post Link to post Share on other sites
kzar Report post Posted November 3, 2004 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 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
kzar Report post Posted November 3, 2004 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 thanks for the thought though Share this post Link to post Share on other sites