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

Having trouble figuring out WITHDRAW_ITEM

Recommended Posts

Hi,

 

I'm trying to get WITHDRAW_ITEM working, and based on what I can see in the WIKI/client it's supposed to be something like this:

 

*((Uint8*)(str+0))=WITHDRAW_ITEM;

*((Uint16*)(str+1))=length;

*((Uint8*)(str+3))=storage_pos;

*((Uint32*)(str+4))=quantity;

 

Similar to DEPOSITE_ITEM:

*((Uint8*)(str+0))=DEPOSITE_ITEM;

*((Uint16*)(str+1))=length;

*((Uint8*)(str+3))=inventory_pos;//Position in the items_list

*((Uint32*)(str+4))=quantity;

 

Deposit seems to work, but withdraw isn't... So, I went to look at the cheat sheet (the client code) and found something odd there:

 

Uint8 str[6];

 

str[0]=DEPOSITE_ITEM;(1)

str[1]=item_list[item_dragged].pos;(2)

*((Uint32*)(str+2))=SDL_SwapLE32(item_quantity);(3-6)

my_tcp_send(my_socket, str, 6);

--------------------------------------------------------------

Uint8 str[100];

 

str[0]=WITHDRAW_ITEM; (1)

*((Uint16*)(str+1))=SDL_SwapLE16(storage_items[storage_item_dragged].pos); (2-3)

*((Uint32*)(str+3))=SDL_SwapLE32(item_quantity);(4-7)

my_tcp_send(my_socket, str, 6);

 

According to the wiki, these are supposed to be formatted the same (I realize the wiki could be out of date...) What seems odd is the withdraw seems to be using a 16 bit for the pos and the deposit an 8 bit. But what seems even more odd is it seems to be sending the same length message to the server yet deposit appears to have one less byte in it.

 

Is the withdraw really supposed to have one more byte in it (16 bit pos instead of 8 bit?) If so, shouldn't it be passing a length of 7 with the message?

 

Could anyone please help clear this up for me? Or at least let me know how far off base I am here?

 

Thanks,

 

DB

(I assume this is working right because the byte swapping is leaving space at the end of the number and the server is accepting it because it's a valid number where it 'should' be (or maybe the client is adjusting the size before it acutally sends it based on the array?))

Share this post


Link to post
Share on other sites
There are now 300 storage slots, so two bytes are needed.

Ty for the clarification.

I looked into this a little further, to try and understand it completely, and I noticed that (the client) for PUT_OBJECT_ON_TRADE it's using a variable length record (depending on the size of pos.) Is it possible for me to use a fixed length for all of these (two bytes for all pos?) It seems like that's how the client is approaching WITHDRAW, using two bytes no matter what the size of pos is.

 

I'm still a bit new at this and it's kind of fuzzy to me what the server will accept (I didn't know it'd accept variable length data for the same transaction type.)

 

EDIT: got things working now, ty for the help :)

Edited by DogBreath

Share this post


Link to post
Share on other sites
str[0]=WITHDRAW_ITEM; (1)

*((Uint16*)(str+1))=SDL_SwapLE16(storage_items[storage_item_dragged].pos); (2-3)

*((Uint32*)(str+3))=SDL_SwapLE32(item_quantity);(4-7)

my_tcp_send(my_socket, str, 6);

 

According to the wiki, these are supposed to be formatted the same (I realize the wiki could be out of date...) What seems odd is the withdraw seems to be using a 16 bit for the pos and the deposit an 8 bit. But what seems even more odd is it seems to be sending the same length message to the server yet deposit appears to have one less byte in it.

 

Is the withdraw really supposed to have one more byte in it (16 bit pos instead of 8 bit?) If so, shouldn't it be passing a length of 7 with the message?

I agree. I think this should be 7 bytes not 6. I guess if the last byte is the MSB however, it wouldn't show as a bug as the client doesn't allow you to remove more than 9999 at a time (IIRC). It probably should still be changed next time someone's checking in the file however (items.c (line 826)).

 

Just my 2c :P

Share this post


Link to post
Share on other sites
str[0]=WITHDRAW_ITEM; (1)

*((Uint16*)(str+1))=SDL_SwapLE16(storage_items[storage_item_dragged].pos); (2-3)

*((Uint32*)(str+3))=SDL_SwapLE32(item_quantity);(4-7)

my_tcp_send(my_socket, str, 6);

 

According to the wiki, these are supposed to be formatted the same (I realize the wiki could be out of date...) What seems odd is the withdraw seems to be using a 16 bit for the pos and the deposit an 8 bit. But what seems even more odd is it seems to be sending the same length message to the server yet deposit appears to have one less byte in it.

 

Is the withdraw really supposed to have one more byte in it (16 bit pos instead of 8 bit?) If so, shouldn't it be passing a length of 7 with the message?

I agree. I think this should be 7 bytes not 6. I guess if the last byte is the MSB however, it wouldn't show as a bug as the client doesn't allow you to remove more than 9999 at a time (IIRC). It probably should still be changed next time someone's checking in the file however (items.c (line 826)).

 

Just my 2c :P

This is more about the slot than the quantity. Since inventory has a maximum of 42 (I think, off the top of my head) slots, and storage has a maximum of 300 slots (more than one byte can handle) if you're working with storage, you need to give a 'bigger' value for the slot if it's above 256 (well 255 since it's 0 based...) I did find out that it does't 'care' on the server side, as long as you tell it the right size of the data you're sending it (that was most of my problem, sending it 7 and telling it I was sending 6...)

 

Ty for your input (yes, I agree, the client needs fixing to be consistant with what is really happening, it's working, but only because the array was decalred as 100 length in the withdraw function... this is an 'easy' workaround, but isn't very 'strong' imo...)

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.

×