From 025eac9062787d2edc065626842c4e4acbdc17b5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 Mar 2017 09:07:33 -0400 Subject: [PATCH 1/2] NetPlayClient: const correctness --- Source/Core/Core/NetPlayClient.cpp | 6 +++--- Source/Core/Core/NetPlayClient.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 37eaa12531..9389f66cd7 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -560,7 +560,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) return 0; } -void NetPlayClient::Send(sf::Packet& packet) +void NetPlayClient::Send(const sf::Packet& packet) { ENetPacket* epac = enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE); @@ -1150,7 +1150,7 @@ int NetPlayClient::NumLocalPads() const })); } -int NetPlayClient::InGamePadToLocalPad(int ingame_pad) +int NetPlayClient::InGamePadToLocalPad(int ingame_pad) const { // not our pad if (m_pad_map[ingame_pad] != m_local_player->pid) @@ -1168,7 +1168,7 @@ int NetPlayClient::InGamePadToLocalPad(int ingame_pad) return local_pad; } -int NetPlayClient::LocalPadToInGamePad(int local_pad) +int NetPlayClient::LocalPadToInGamePad(int local_pad) const { // Figure out which in-game pad maps to which local pad. // The logic we have here is that the local slots always diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 5b9907319a..79545a6d35 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -93,8 +93,8 @@ public: bool IsFirstInGamePad(int ingame_pad) const; int NumLocalPads() const; - int InGamePadToLocalPad(int ingame_pad); - int LocalPadToInGamePad(int localPad); + int InGamePadToLocalPad(int ingame_pad) const; + int LocalPadToInGamePad(int localPad) const; static void SendTimeBase(); bool DoAllPlayersHaveGame(); @@ -156,7 +156,7 @@ private: void SendPadState(int in_game_pad, const GCPadStatus& np); void SendWiimoteState(int in_game_pad, const NetWiimote& nw); unsigned int OnData(sf::Packet& packet); - void Send(sf::Packet& packet); + void Send(const sf::Packet& packet); void Disconnect(); bool Connect(); void ComputeMD5(const std::string& file_identifier); From 35c230a4182a36252a75cff0a9a0d405fdc4bcbe Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 Mar 2017 09:14:03 -0400 Subject: [PATCH 2/2] NetPlayServer: const correctness --- Source/Core/Core/NetPlayServer.cpp | 14 +++++++------- Source/Core/Core/NetPlayServer.h | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index c5da53ca94..700558541c 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -342,7 +342,7 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket) } // called from ---NETPLAY--- thread -unsigned int NetPlayServer::OnDisconnect(Client& player) +unsigned int NetPlayServer::OnDisconnect(const Client& player) { PlayerId pid = player.pid; @@ -823,7 +823,7 @@ bool NetPlayServer::StartGame() } // called from multiple threads -void NetPlayServer::SendToClients(sf::Packet& packet, const PlayerId skip_pid) +void NetPlayServer::SendToClients(const sf::Packet& packet, const PlayerId skip_pid) { for (auto& p : m_players) { @@ -834,7 +834,7 @@ void NetPlayServer::SendToClients(sf::Packet& packet, const PlayerId skip_pid) } } -void NetPlayServer::Send(ENetPeer* socket, sf::Packet& packet) +void NetPlayServer::Send(ENetPeer* socket, const sf::Packet& packet) { ENetPacket* epac = enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE); @@ -853,7 +853,7 @@ void NetPlayServer::KickPlayer(PlayerId player) } } -u16 NetPlayServer::GetPort() +u16 NetPlayServer::GetPort() const { return m_server->address.port; } @@ -864,7 +864,7 @@ void NetPlayServer::SetNetPlayUI(NetPlayUI* dialog) } // called from ---GUI--- thread -std::unordered_set NetPlayServer::GetInterfaceSet() +std::unordered_set NetPlayServer::GetInterfaceSet() const { std::unordered_set result; auto lst = GetInterfaceListInternal(); @@ -874,7 +874,7 @@ std::unordered_set NetPlayServer::GetInterfaceSet() } // called from ---GUI--- thread -std::string NetPlayServer::GetInterfaceHost(const std::string& inter) +std::string NetPlayServer::GetInterfaceHost(const std::string& inter) const { char buf[16]; sprintf(buf, ":%d", GetPort()); @@ -890,7 +890,7 @@ std::string NetPlayServer::GetInterfaceHost(const std::string& inter) } // called from ---GUI--- thread -std::vector> NetPlayServer::GetInterfaceListInternal() +std::vector> NetPlayServer::GetInterfaceListInternal() const { std::vector> result; #if defined(_WIN32) diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index 33829d5669..e741990800 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -50,11 +50,11 @@ public: void KickPlayer(PlayerId player); - u16 GetPort(); + u16 GetPort() const; void SetNetPlayUI(NetPlayUI* dialog); - std::unordered_set GetInterfaceSet(); - std::string GetInterfaceHost(const std::string& inter); + std::unordered_set GetInterfaceSet() const; + std::string GetInterfaceHost(const std::string& inter) const; bool is_connected = false; @@ -78,10 +78,10 @@ private: bool operator==(const Client& other) const { return this == &other; } }; - void SendToClients(sf::Packet& packet, const PlayerId skip_pid = 0); - void Send(ENetPeer* socket, sf::Packet& packet); + void SendToClients(const sf::Packet& packet, const PlayerId skip_pid = 0); + void Send(ENetPeer* socket, const sf::Packet& packet); unsigned int OnConnect(ENetPeer* socket); - unsigned int OnDisconnect(Client& player); + unsigned int OnDisconnect(const Client& player); unsigned int OnData(sf::Packet& packet, Client& player); void OnTraversalStateChanged() override; @@ -89,7 +89,7 @@ private: void OnConnectFailed(u8) override {} void UpdatePadMapping(); void UpdateWiimoteMapping(); - std::vector> GetInterfaceListInternal(); + std::vector> GetInterfaceListInternal() const; NetSettings m_settings;