mirror of
https://github.com/HikikoMarmy/Champions-Reborn-Server.git
synced 2026-04-05 00:49:48 -03:00
Reorganized and cleaned up the solution.
This commit is contained in:
76
Source/Game/ChatRoom.cpp
Normal file
76
Source/Game/ChatRoom.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "Game/ChatRoomSession.hpp"
|
||||
#include "Game/RealmUser.hpp"
|
||||
|
||||
ChatRoomSession::ChatRoomSession()
|
||||
{
|
||||
m_type = RoomType::Public;
|
||||
m_index = 0;
|
||||
m_name.clear();
|
||||
}
|
||||
|
||||
ChatRoomSession::~ChatRoomSession()
|
||||
{
|
||||
m_type = RoomType::Public;
|
||||
m_index = 0;
|
||||
m_name.clear();
|
||||
}
|
||||
|
||||
bool ChatRoomSession::AddMember( sptr_user user )
|
||||
{
|
||||
if( !user )
|
||||
return false;
|
||||
|
||||
for( const auto &member : m_members )
|
||||
{
|
||||
if( member.lock() == user )
|
||||
return false; // User already in the room.
|
||||
}
|
||||
|
||||
m_members.push_back( user );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatRoomSession::RemoveMember( sptr_user user )
|
||||
{
|
||||
if( !user )
|
||||
return false;
|
||||
|
||||
auto it = std::remove_if( m_members.begin(), m_members.end(),
|
||||
[ &user ]( const std::weak_ptr< RealmUser > &member )
|
||||
{
|
||||
return member.lock() == user;
|
||||
} );
|
||||
|
||||
if( it == m_members.end() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_members.erase( it, m_members.end() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChatRoomSession::IsMember( sptr_user user )
|
||||
{
|
||||
if( !user )
|
||||
return false;
|
||||
|
||||
for( const auto &member : m_members )
|
||||
{
|
||||
if( member.lock() == user )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChatRoomSession::IsPublic() const
|
||||
{
|
||||
return m_type == RoomType::Public;
|
||||
}
|
||||
|
||||
bool ChatRoomSession::IsPrivate() const
|
||||
{
|
||||
return m_type == RoomType::Private;
|
||||
}
|
||||
Reference in New Issue
Block a user