Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offset error #61

Closed
EMREOYUN opened this issue Jul 9, 2020 · 22 comments
Closed

offset error #61

EMREOYUN opened this issue Jul 9, 2020 · 22 comments

Comments

@EMREOYUN
Copy link
Contributor

EMREOYUN commented Jul 9, 2020

Since we are working on PE Terraria Servers; when PE Clients tries to connect, this error shows up:
Client Handle Send Data Error: RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 8. Received 9

How we can fix this in code?

@popstarfreas
Copy link
Owner

PE? Are you talking about mobile? Dimensions will try to read packets as though they are from a PC client. You would need to update it so that it uses the right format. At this time I don't know what the best approach is. You could simply go through the source and edit the packet handlers and some of the other places it writes packets.

@EMREOYUN
Copy link
Contributor Author

EMREOYUN commented Jul 9, 2020

PE? Are you talking about mobile? Dimensions will try to read packets as though they are from a PC client. You would need to update it so that it uses the right format. At this time I don't know what the best approach is. You could simply go through the source and edit the packet handlers and some of the other places it writes packets.

Yes, version code updated but i don't find anything about this offset range. Can you explain how to change it's range?

@popstarfreas
Copy link
Owner

It's referring to reading from a buffer. It means that when it was reading a packet, it tried to read a byte at index 9 when the maximum index is 8. Likely because some packet (like player info) has more bytes on PC than mobile.

@EMREOYUN
Copy link
Contributor Author

EMREOYUN commented Jul 9, 2020

It's referring to reading from a buffer. It means that when it was reading a packet, it tried to read a byte at index 9 when the maximum index is 8. Likely because some packet (like player info) has more bytes on PC than mobile.

So question is how i can manage(change or remove) maximum index value?

@popstarfreas
Copy link
Owner

popstarfreas commented Jul 9, 2020

That's not what it means. The maximum index value is based on how much data there is to read from the packet. What you need to do is update dimensions where it reads packets to read the mobile packets instead of pc.

@EMREOYUN
Copy link
Contributor Author

EMREOYUN commented Jul 9, 2020

That's not what it means. The maximum index value is based on how much data there is to read from the packet. What you need to do is update dimensions where it reads packets to read the mobile packets instead of pc.

How i can do that? Since Mobile Version is hard-coded and we can't make changes on there.
Also searched PE TShock Code and only thing i found is buff time changed to Int16 format from Int32 format.

@popstarfreas
Copy link
Owner

To get the source of the error you can edit
https://github.com/popstarfreas/Dimensions/blob/dev/app/node_modules/dimensions/client.ts#L283
so that it prints out the stacktrace rather than just the message. Maybe just put console.log(e). That will tell you which packet it tried to read so you can see what needs to be changed.

@EMREOYUN
Copy link
Contributor Author

EMREOYUN commented Jul 10, 2020

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 8. Received 9
at boundsError (internal/buffer.js:77:9)
at Buffer.readInt16LE (internal/buffer.js:405:5)
at PacketReader.readInt16 (C:\Users\minecraft\Desktop\Dimensions\build\node_modules\dimensions\packets\bufferreader.js:88:34)
at ClientPacketHandler.handlePlayerInventorySlot (C:\Users\minecraft\Desktop\Dimensions\build\node_modules\dimensions\clientpackethandler.js:198:32)
at ClientPacketHandler.handlePacket (C:\Users\minecraft\Desktop\Dimensions\build\node_modules\dimensions\clientpackethandler.js:60:32)
at C:\Users\minecraft\Desktop\Dimensions\build\node_modules\dimensions\client.js:137:57
at arrayEach (C:\Users\minecraft\Desktop\Dimensions\node_modules\lodash\lodash.js:516:11)
at Function.forEach (C:\Users\minecraft\Desktop\Dimensions\node_modules\lodash\lodash.js:9342:14)
at Client.handleDataSend (C:\Users\minecraft\Desktop\Dimensions\build\node_modules\dimensions\client.js:136:19)
at Socket. (C:\Users\minecraft\Desktop\Dimensions\build\node_modules\dimensions\listenserver.js:477:24) {
code: 'ERR_OUT_OF_RANGE'
}

What is internal/buffer.js and how i can access that file? I searched on directory but no file found called buffer.js.

@popstarfreas
Copy link
Owner

popstarfreas commented Jul 10, 2020

I don't know your level of expertise, so this may or may not be outside of your current knowledge but that stacktrace starts at the internal node code, which isn't Dimensions. You have to follow it down until you see dimensions, which is where it says PacketReader.readInt16, that's fine so we know it's trying to read an int16 at bufferreader:88. What callls that is handlePlayerInventorySlot at line 198 in the js (the js is likely to have different line numbers than the original typescript code). So the guess here is that in 1.4 slots now use int16 instead of byte for the slot id. So to make it work with the mobile packet version https://github.com/popstarfreas/Dimensions/blob/dev/app/node_modules/dimensions/clientpackethandler.ts#L232 needs to be changed to readByte again.

@EMREOYUN
Copy link
Contributor Author

EMREOYUN commented Jul 10, 2020

I don't know your level of expertise, so this may or may not be outside of your current knowledge but that stacktrace starts at the internal node code, which isn't Dimensions. You have to follow it down until you see dimensions, which is where it says PacketReader.readInt16, that's fine so we know it's trying to read an int16 at bufferreader:88. What callls that is handlePlayerInventorySlot at line 198 in the js (the js is likely to have different line numbers than the original typescript code). So the guess here is that in 1.4 slots now use int16 instead of byte for the slot id. So to make it work with the mobile packet version https://github.com/popstarfreas/Dimensions/blob/dev/app/node_modules/dimensions/clientpackethandler.ts#L232 needs to be changed to readByte again.

@popstarfreas So after fixing this, i got many many errors but they are also fixed with your guidance. But there is less problems left now:

•IP redirection not works properly. Buffer keep sending buffers original IP(Example: Server runs in 0.0.0.1, Buffer runs in 0.0.0.2, while connecting to server, it shows connected from 0.0.0.2(buffers IP). Not causing problems on gameplay but will big issue on bans).
•Rest API not works well. Rest API keeps sending Invalid HTTP Response and how we can make Rest API actually count players in buffer(We need this because we are using counters to websites and status services).
•Server Switcher not works well. Typing /servername will sends command to server, not to buffer.

Also big thanks to helping to me. After everything works well, i can send pull request working PE Dimensions to your git.

@popstarfreas
Copy link
Owner

  • The ip thing requires the dimensions plugin. Are you using that?
  • I will have to look at REST API again, I made a change and I don't remember if I pushed it here yet
  • Not sure about that one other than that the chat packet in mobile might be the old one where dimensions reads the new one

@EMREOYUN
Copy link
Contributor Author

EMREOYUN commented Jul 11, 2020

  • The ip thing requires the dimensions plugin. Are you using that?
  • I will have to look at REST API again, I made a change and I don't remember if I pushed it here yet
  • Not sure about that one other than that the chat packet in mobile might be the old one where dimensions reads the new one
  • Yes with GeoIP enabled. But still IP Redirection not works.
  • So how we can edit REST API with counter variables?
  • How we can switch the old packets?

@popstarfreas
Copy link
Owner

  • Well no one has reported issues in normal tshock, so this is a problem you need to resolve
  • if I get time I will push the change I made locally
  • You have to edit clientpackethandler to add the old chat packet handling

@EMREOYUN
Copy link
Contributor Author

  • Well no one has reported issues in normal tshock, so this is a problem you need to resolve
  • if I get time I will push the change I made locally
  • You have to edit clientpackethandler to add the old chat packet handling
  • Alright, i will try your old code to add IP Ban system onto Dimensions instead of using TShock's one.
  • I will waiting you ;)
  • I will work on it.

@EMREOYUN
Copy link
Contributor Author

Closed #61

@EMREOYUN
Copy link
Contributor Author

@popstarfreas Well there is no old packet handler in your code. How i can find old handler?

@popstarfreas
Copy link
Owner

handled = this.handleChatMessage(chatMessage);

you need to add a method that reads the old chat packet and calls the same method that line of code does.

@EMREOYUN
Copy link
Contributor Author

handled = this.handleChatMessage(chatMessage);

you need to add a method that reads the old chat packet and calls the same method that line of code does.

That didn't work. Thanks for helping anyway :)

@EMREOYUN
Copy link
Contributor Author

EMREOYUN commented Sep 7, 2020

@popstarfreas After tracing the code, i verified this code will not work in Mobile.
https://github.com/popstarfreas/Dimensions/blob/dev/app/node_modules/dimensions/clientpackethandler.ts#L108

I changed it with ChatMessage packet but ChatMessage sends null.
Did you know what causes this problem(about sending null)?

@EMREOYUN
Copy link
Contributor Author

EMREOYUN commented Sep 7, 2020

Reopened #61

@EMREOYUN EMREOYUN reopened this Sep 7, 2020
@EMREOYUN
Copy link
Contributor Author

Nvm i solved this myelf

@EMREOYUN
Copy link
Contributor Author

Closed #61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants