summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network.cpp15
-rw-r--r--src/network/network.h25
2 files changed, 25 insertions, 15 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 51b5d6a9f..e1401a403 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -9,11 +9,12 @@
namespace Network {
-static std::shared_ptr<RoomMember> g_room_member; ///< RoomMember (Client) for network games
-static std::shared_ptr<Room> g_room; ///< Room (Server) for network games
-// TODO(B3N30): Put these globals into a networking class
+RoomNetwork::RoomNetwork() {
+ g_room = std::make_shared<Room>();
+ g_room_member = std::make_shared<RoomMember>();
+}
-bool Init() {
+bool RoomNetwork::Init() {
if (enet_initialize() != 0) {
LOG_ERROR(Network, "Error initalizing ENet");
return false;
@@ -24,15 +25,15 @@ bool Init() {
return true;
}
-std::weak_ptr<Room> GetRoom() {
+std::weak_ptr<Room> RoomNetwork::GetRoom() {
return g_room;
}
-std::weak_ptr<RoomMember> GetRoomMember() {
+std::weak_ptr<RoomMember> RoomNetwork::GetRoomMember() {
return g_room_member;
}
-void Shutdown() {
+void RoomNetwork::Shutdown() {
if (g_room_member) {
if (g_room_member->IsConnected())
g_room_member->Leave();
diff --git a/src/network/network.h b/src/network/network.h
index 6d002d693..74eb42bf5 100644
--- a/src/network/network.h
+++ b/src/network/network.h
@@ -10,16 +10,25 @@
namespace Network {
-/// Initializes and registers the network device, the room, and the room member.
-bool Init();
+class RoomNetwork {
+public:
+ RoomNetwork();
-/// Returns a pointer to the room handle
-std::weak_ptr<Room> GetRoom();
+ /// Initializes and registers the network device, the room, and the room member.
+ bool Init();
-/// Returns a pointer to the room member handle
-std::weak_ptr<RoomMember> GetRoomMember();
+ /// Returns a pointer to the room handle
+ std::weak_ptr<Room> GetRoom();
-/// Unregisters the network device, the room, and the room member and shut them down.
-void Shutdown();
+ /// Returns a pointer to the room member handle
+ std::weak_ptr<RoomMember> GetRoomMember();
+
+ /// Unregisters the network device, the room, and the room member and shut them down.
+ void Shutdown();
+
+private:
+ std::shared_ptr<RoomMember> g_room_member; ///< RoomMember (Client) for network games
+ std::shared_ptr<Room> g_room; ///< Room (Server) for network games
+};
} // namespace Network