Files
ConnectTools/tcp/tcp_server.h
Ayndpa af181bb133 Refactor Steam Networking Components
- Removed SteamMessageHandler class and its implementation files.
- Integrated control packet handling directly into the SteamMessageHandler.
- Updated TCPClient and TCPServer classes to improve connection management and error handling.
- Added SteamNetworkingManager class to manage Steam networking, including lobby creation and connection handling.
- Implemented callbacks for Steam Friends and Matchmaking to handle lobby events.
- Enhanced message forwarding logic between TCP clients and Steam connections.
- Introduced control packet handling for ping responses.
- Improved thread safety with mutexes for shared resources.
2025-11-18 21:03:01 +08:00

44 lines
1.2 KiB
C++

#pragma once
#include <boost/asio.hpp>
#include <memory>
#include <vector>
#include <string>
#include <thread>
#include <mutex>
#include <isteamnetworkingsockets.h>
#include <isteamnetworkingutils.h>
#include <steamnetworkingtypes.h>
class SteamNetworkingManager;
using boost::asio::ip::tcp;
// TCP Server class
class TCPServer {
public:
TCPServer(int port, SteamNetworkingManager* manager);
~TCPServer();
bool start();
void stop();
void sendToAll(const std::string& message, std::shared_ptr<tcp::socket> excludeSocket = nullptr);
void sendToAll(const char* data, size_t size, std::shared_ptr<tcp::socket> excludeSocket = nullptr);
int getClientCount();
private:
void start_accept();
void start_read(std::shared_ptr<tcp::socket> socket);
int port_;
bool running_;
boost::asio::io_context io_context_;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work_;
tcp::acceptor acceptor_;
std::vector<std::shared_ptr<tcp::socket>> clients_;
std::mutex clientsMutex_;
std::thread serverThread_;
bool hasAcceptedConnection_;
SteamNetworkingManager* manager_;
bool forwarding_;
};