Author Topic: TNet extensibility + keeping upgrade compatibility questions  (Read 634 times)

mattplay

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Hi all,

For the most part I have been able to inherit or extend the functionality of TNet quite well without any upgrade issues each time a new version comes out.

However, I have two areas that are problematic.

1) Custom packets in the Packet enum
I'm implementing a couple custom packets for authentication in my game, and I've upgraded to the latest TNet 3 with the same issues each time. The main problem is that onCustomerPacket delegate requires Packet as part of the parameters, so ultimately to get any custom packets, I have to modify TNPacket.cs and add my own packets at the end of the list.

But when I update TNet and copy over all the files, I have to overwrite TNPacket.cs, which means I lose my changes there.

I noticed that TcpProtocol has two versions of BeginSend() - one that takes Packet and one that takes byte.
I'm wondering if it would be possible to change the onCustomerPacket delegate to use byte instead of Packet, that way I can implement my own custom packet enum separately like this:

    public enum CustomPacket : byte
    {
        UserPacket = (byte)TNet.Packet.UserPacket,

        RequestSignin,

        ResponseSignin,
    }

2) Private vs. Protected members in GameServer
There are several lists / dictionaries inside TNet.GameServer that I want to get access to. In my case, I've inherited GameServer and want to add a readonly count of channels very similar to the playerCount property on GameServer. But mChannelList is private, so I can't do that. Is there a better way to get this data? Or would it be possible to change the scope of mPlayerList, mPlayerDict, mChannelList, and mChannelDict to protected?

Thanks,
Matt

mattplay

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: TNet extensibility + keeping upgrade compatibility questions
« Reply #1 on: June 10, 2017, 05:55:28 AM »
I would also need to use byte instead of Packet for the GameClient OnPacket delegate.
I can see that this was already done in TNManager with SetPacketHandler.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: TNet extensibility + keeping upgrade compatibility questions
« Reply #2 on: June 10, 2017, 06:57:28 AM »
That makes sense to me. I'll change OnCustomPacket to pass a byte. That said, you should really be versioning your files then merging in the update changes rather than overwriting them. This would keep your custom packets -- which I would suggest adding to the Packet.cs file instead of some separate file.

I'll mark everything in the GameServer as protected. I originally wrote it with the idea that devs will simply be modifying the GameServer file, but I can understand how that would make it more difficult to stay up to date.