-
-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
netplay: pass compression algorithm to
IClientConnection:s
externally
Make `IClientConnection` agnostic on the compression algorithm in use. Introduce a global singleton `WzCompressionProvider`, which currently is only able to create `ZlibCompressionAdapter:s`. Although, in the future we would want to pass extra configuration info to it so that users can globally specify the compression algorithm to use. Signed-off-by: Pavel Solodovnikov <pavel.al.solodovnikov@gmail.com>
- Loading branch information
Showing
11 changed files
with
147 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
/* | ||
This file is part of Warzone 2100. | ||
Copyright (C) 2025 Warzone 2100 Project | ||
Warzone 2100 is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
Warzone 2100 is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Warzone 2100; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include "listen_socket.h" | ||
|
||
IListenSocket::IListenSocket(WzCompressionProvider& compressionProvider) | ||
: compressionProvider_(&compressionProvider) | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
/* | ||
This file is part of Warzone 2100. | ||
Copyright (C) 2025 Warzone 2100 Project | ||
Warzone 2100 is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
Warzone 2100 is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Warzone 2100; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include "wz_compression_provider.h" | ||
|
||
#include "lib/netplay/zlib_compression_adapter.h" | ||
|
||
WzCompressionProvider& WzCompressionProvider::Instance() | ||
{ | ||
static WzCompressionProvider instance; | ||
return instance; | ||
} | ||
|
||
std::unique_ptr<ICompressionAdapter> WzCompressionProvider::newCompressionAdapter() | ||
{ | ||
// Only support Zlib for the time being. | ||
// TODO: in the future, we might want to support more compression algorithms, e.g. Zstd. | ||
// In this case, we would need to somehow configure `WzCompressionAdapter` from | ||
// the global WZ config to specify compression algorithm to use. | ||
return std::make_unique<ZlibCompressionAdapter>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
/* | ||
This file is part of Warzone 2100. | ||
Copyright (C) 2025 Warzone 2100 Project | ||
Warzone 2100 is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
Warzone 2100 is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Warzone 2100; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
class ICompressionAdapter; | ||
|
||
/// <summary> | ||
/// This class provides is responsible for creating `ICompressionAdapter:s`, | ||
/// which are thin wrappers over some compression algorithm, intended for | ||
/// use in `IClientConnection` to provide compression over raw net messages. | ||
/// </summary> | ||
class WzCompressionProvider | ||
{ | ||
public: | ||
|
||
static WzCompressionProvider& Instance(); | ||
|
||
std::unique_ptr<ICompressionAdapter> newCompressionAdapter(); | ||
|
||
private: | ||
|
||
WzCompressionProvider() = default; | ||
WzCompressionProvider(const WzCompressionProvider&) = delete; | ||
WzCompressionProvider(WzCompressionProvider&&) = delete; | ||
}; |