Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[New G2O][Shared] packetListener
#3
Well, your code is pretty simple and readable, but this:
Squirrel Script
  1. function receivedPacket(pid, packet)
  2. {
  3. if(packet.readUInt8() == packetList.id)
  4. {
  5. switch(packet.readUInt8())
  6. {
  7. case packetList.option_lineChat: changeLine(pid, packet.readInt8()); break;
  8. case packetList.option_hud: changeHud(pid, packet.readInt8()); break;
  9. case packetList.option_password: changePassword(pid, packet.readString(), packet.readString()); break;
  10. case packetList.option_notifications: changeNotifications(pid, packet.readBool()); break;
  11. }
  12. }
  13. }



Can cause problems because in this method, you are reading first packet value, I belive that you connect this method to onPacket event.
So, what if you have more similar functions/methods, and trying to read packet id in this way:

Squirrel Script
  1. if(packet.readUInt8() == packetList.id)



Even if this condition won't pass, you still read first value from packet, which was id.

Take a look at this code:
https://www97.zippyshare.com/v/LxAq6iiv/file.html

To simply avoid this problem, you must have ONLY ONE function connected to onPacket event on each side, then ONLY ONCE read packet Id, and check which function should be called based on it's value.

Even if you try to call two diffrent functions and pass them a packet object, it won't work, because this function will be working with an object reference, not it's copy.

In my opinion, this simple script makes it a little bit easier to add some new function(s) to call when packet with specific id arrive to it's location, but it's only my opinion, maybe i'm wrong Big Grin.
Reply


Messages In This Thread
[New G2O][Shared] packetListener - by Patrix - 04.06.2018, 20:22
RE: [New G2O][Shared] packetListener - by Patrix - 20.06.2018, 17:26

Possibly Related Threads…
Thread Author Replies Views Last Post
  [New G2O][Client-Side] bindKey Patrix 6 9,304 14.11.2018, 02:32
Last Post: Patrix
  [New G2O][Shared] Command Handler Patrix 3 6,386 05.09.2018, 15:42
Last Post: Patrix
  [G2O v.0.1.2][Server-Side] NPC Manager Quarchodron 16 18,180 21.01.2018, 19:59
Last Post: Quarchodron
  [New G2O][Client-Side] Key Combination Patrix 1 3,928 23.12.2017, 13:16
Last Post: Patrix
  [G2O v.0.1.0][Client-Side] Notice Board Quarchodron 0 3,225 27.06.2017, 14:28
Last Post: Quarchodron

Forum Jump:


Users browsing this thread: 1 Guest(s)