Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Zlib Packet Compression


Richy420Rich
 Share

Recommended Posts

Hello, I figured I would release this under the credits of Robin and jcsnider.

What is it?

zlib API utilizes packet compression and decompression, ya'know those tons of packets you send from the server when a player joins the game?

**_For i = 1 To MAX_ITEMS_**!!!

What this does is caches all of that data, Example: **ItemsCache_Create**. Sends it all in one packet, Example: **SendAllItems(index)**.

zlib compresses that packet to make it smaller and decompresses it on the client side.

How do I haz it?

I simplified this very easily. I have added everything inside a vanilla EO 2.0\. [You may download the source here](https://www.dropbox.com/s/gc4fezbzn6rfr7a/EO%202.0%20Zlib%20Finished.zip?dl=0).

Use CTRL+F and search: 'zlib

Everything I've ported has this quickfind comment so you can just breeze through adding it all inside your engine.

I errors?

I forgot to mention that the zlib.dll file must be present in both the server and client folder. :D

Final: As I said, this is credited under Robin, and to jcsnider for porting it in my project. I don't even know if I'm allowed to release this but since VB6 is uh, yeah. I'm just gon' do it.
Link to comment
Share on other sites

Pros

Map cache compression is probably the best thing really worth having. As Rob pointed out, compressing is very good with the map data.

This ends sending X amount of packets as a vanilla would iterate and send the data as individual packets, caching and sending the cache only requires one compressed packet.

Example of what a vanilla does:

```

Sub SendItems(index)
Dim i as long

For i = 1 To MAX_ITEMS
SendItemUpdateTo(index) 'Sends each item data separately
Next

End Sub
```
Example of what this will do:

```

Sub SendAllItems(ByVal index As Long)

    Dim Buffer As clsBuffer
    Set Buffer = New clsBuffer
    Buffer.WriteLong SAllItems
    Buffer.WriteBytes AllItemsCache.Data 'Sends the entire cache as 1 packet.
    SendDataTo index, Buffer.ToArray()
    Set Buffer = Nothing

End Sub
```
Cons

Caching Items/Npcs & etc; still goes through 'For Loop' iterations on the server after each update made to said data, as they need to be re-cached.
Link to comment
Share on other sites

> Pros
>
> Map cache compression is probably the best thing really worth having. As Rob pointed out, compressing is very good with the map data.
>
> This ends sending X amount of packets as a vanilla would iterate and send the data as individual packets, caching and sending the cache only requires one compressed packet.
>
>  
>
> Example of what a vanilla does:
>
> ```
>
> Sub SendItems(index)
> Dim i as long
>
> For i = 1 To MAX_ITEMS
> SendItemUpdateTo(index) 'Sends each item data separately
> Next
>
> End Sub
> ```
> Example of what this will do:
>
> ```
>
> Sub SendAllItems(ByVal index As Long)
>
>     Dim Buffer As clsBuffer
>     Set Buffer = New clsBuffer
>     Buffer.WriteLong SAllItems
>     Buffer.WriteBytes AllItemsCache.Data 'Sends the entire cache as 1 packet.
>     SendDataTo index, Buffer.ToArray()
>     Set Buffer = Nothing
>
> End Sub
> ```
> Cons
>
> Caching Items/Npcs & etc; still goes through 'For Loop' iterations on the server after each update made to said data, as they need to be re-cached.

I really didn't get the cons part. They are automatically re-cached or should I do something? If yes, what and when?
Link to comment
Share on other sites

@[member="Marsh"] All of the data gets cached before it gets compressed and sent, so there shouldn't be no small packets.

@J. Black whenever an item/npc - etc; gets changed and saved from the client editors, it sends the changed data to the server to be saved, on the server end, it saves the data and then it calls for an entire re-cache to include the changes. This con can be primarily due to server spikes when *constantly* messing around with client editors, as it re-iterates 'For Loops' whenever something is saved/changed.

```

Public Sub ItemsCache_Create()

Dim Buffer As clsBuffer, itemnum As Long
Dim ItemSize As Long
Dim ItemData() As Byte

    Set Buffer = New clsBuffer

    For itemnum = 1 To MAX_ITEMS 'Re-iteration everytime an item is saved…
        If Len(Trim$(Item(itemnum).Name)) > 0 Then 'Should not send null/empty data.
        ItemSize = LenB(Item(itemnum))
        ReDim ItemData(ItemSize - 1)
        CopyMemory ItemData(0), ByVal VarPtr(Item(itemnum)), ItemSize
        Buffer.WriteLong itemnum
        Buffer.WriteBytes ItemData
        End If
    Next

    Buffer.CompressBuffer
    AllItemsCache.Data = Buffer.ToArray 'Buffers entire cache for its packet sending.
    Set Buffer = Nothing
End Sub
```
I'll follow up and say when you have constants like this:

```

Public Const MAX_ITEMS = 2000
Public Const MAX_NPCS = 1000
Public Const MAX_ANIMATIONS = 500
Public Const MAX_QUESTS = 1000
Public Const MAX_SPELLS = 255
Public Const MAX_BOOKS = 255
Public Const MAX_SHOPS = 255
Public Const MAX_RESOURCES = 255

```
And a Sub JoinGame(index) doing this:

```

SendItems index
SendNpcs index
SendAnimations index
SendQuests index
SendSpells index
SendBooks index
SendShops index
```
And if all or alot of this data is used up (primarily speaking for long term games, such as Ambardia was....)

You'd be sending upto...

**5520 individual packets…**

Caching and compressing turns 5520 individual packets, into 7 packets.
Link to comment
Share on other sites

  • 3 months later...

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
 Share

×
×
  • Create New...