Support Removal of Friends and Ignores
This commit is contained in:
56
Network/Event/RequestRemoveFriend.cpp
Normal file
56
Network/Event/RequestRemoveFriend.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "RequestRemoveFriend.h"
|
||||
|
||||
#include "../../Game/RealmUserManager.h"
|
||||
#include "../../Database/Database.h"
|
||||
#include "../../logging.h"
|
||||
|
||||
void RequestRemoveFriend::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
m_chatHandle = stream->read_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestRemoveFriend::ProcessRequest( sptr_socket socket, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
auto user = UserManager::Get().FindUserBySocket( socket );
|
||||
if( user == nullptr )
|
||||
{
|
||||
return std::make_shared< ResultRemoveFriend >( this, FATAL_ERROR );
|
||||
}
|
||||
|
||||
if( !user->IsFriend( m_chatHandle ) )
|
||||
{
|
||||
return std::make_shared< ResultRemoveFriend >( this, FRIEND_INVALID );
|
||||
}
|
||||
|
||||
if( !Database::Get().RemoveFriend( user->m_accountId, m_chatHandle ) )
|
||||
{
|
||||
return std::make_shared< ResultRemoveFriend >( this, DATABASE_ERROR );
|
||||
}
|
||||
|
||||
const auto iter = std::find( user->m_friendList.begin(), user->m_friendList.end(), m_chatHandle );
|
||||
if( iter == user->m_friendList.end() )
|
||||
{
|
||||
return std::make_shared< ResultRemoveFriend >( this, FRIEND_INVALID );
|
||||
}
|
||||
|
||||
user->m_friendList.erase( iter );
|
||||
|
||||
return std::make_shared< ResultRemoveFriend >( this, SUCCESS );
|
||||
}
|
||||
|
||||
ResultRemoveFriend::ResultRemoveFriend( GenericRequest *request, int32_t reply ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
}
|
||||
|
||||
void ResultRemoveFriend::Serialize( ByteBuffer &out ) const
|
||||
{
|
||||
out.write_u16( m_packetId );
|
||||
out.write_u32( m_trackId );
|
||||
out.write_u32( m_reply );
|
||||
}
|
||||
40
Network/Event/RequestRemoveFriend.h
Normal file
40
Network/Event/RequestRemoveFriend.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "../GenericNetRequest.h"
|
||||
#include "../GenericNetResponse.h"
|
||||
|
||||
class RequestRemoveFriend : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
std::wstring m_chatHandle;
|
||||
|
||||
enum ERROR_CODE {
|
||||
SUCCESS = 0,
|
||||
FATAL_ERROR,
|
||||
DATABASE_ERROR = 2,
|
||||
FRIEND_IGNORING = 19,
|
||||
FRIEND_INVALID = 20,
|
||||
FRIEND_DUPLICATE = 21,
|
||||
};
|
||||
public:
|
||||
static std::unique_ptr< RequestRemoveFriend > Create()
|
||||
{
|
||||
return std::make_unique< RequestRemoveFriend >();
|
||||
}
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_socket socket, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultRemoveFriend : public GenericResponse {
|
||||
private:
|
||||
int32_t m_reply;
|
||||
|
||||
public:
|
||||
ResultRemoveFriend( GenericRequest *request, int32_t reply );
|
||||
void Serialize( ByteBuffer &out ) const;
|
||||
};
|
||||
56
Network/Event/RequestRemoveIgnore.cpp
Normal file
56
Network/Event/RequestRemoveIgnore.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "RequestRemoveIgnore.h"
|
||||
|
||||
#include "../../Game/RealmUserManager.h"
|
||||
#include "../../Database/Database.h"
|
||||
#include "../../logging.h"
|
||||
|
||||
void RequestRemoveIgnore::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
m_chatHandle = stream->read_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestRemoveIgnore::ProcessRequest( sptr_socket socket, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
auto user = UserManager::Get().FindUserBySocket( socket );
|
||||
if( user == nullptr )
|
||||
{
|
||||
return std::make_shared< ResultRemoveIgnore >( this, FATAL_ERROR );
|
||||
}
|
||||
|
||||
if( !user->IsIgnored( m_chatHandle ) )
|
||||
{
|
||||
return std::make_shared< ResultRemoveIgnore >( this, IGNORE_INVALID );
|
||||
}
|
||||
|
||||
if( !Database::Get().RemoveIgnore( user->m_accountId, m_chatHandle ) )
|
||||
{
|
||||
return std::make_shared< ResultRemoveIgnore >( this, DATABASE_ERROR );
|
||||
}
|
||||
|
||||
const auto iter = std::find( user->m_ignoreList.begin(), user->m_ignoreList.end(), m_chatHandle );
|
||||
if( iter == user->m_ignoreList.end() )
|
||||
{
|
||||
return std::make_shared< ResultRemoveIgnore >( this, IGNORE_INVALID );
|
||||
}
|
||||
|
||||
user->m_ignoreList.erase( iter );
|
||||
|
||||
return std::make_shared< ResultRemoveIgnore >( this, SUCCESS );
|
||||
}
|
||||
|
||||
ResultRemoveIgnore::ResultRemoveIgnore( GenericRequest *request, int32_t reply ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
}
|
||||
|
||||
void ResultRemoveIgnore::Serialize( ByteBuffer &out ) const
|
||||
{
|
||||
out.write_u16( m_packetId );
|
||||
out.write_u32( m_trackId );
|
||||
out.write_u32( m_reply );
|
||||
}
|
||||
41
Network/Event/RequestRemoveIgnore.h
Normal file
41
Network/Event/RequestRemoveIgnore.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "../GenericNetRequest.h"
|
||||
#include "../GenericNetResponse.h"
|
||||
|
||||
class RequestRemoveIgnore : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
std::wstring m_chatHandle;
|
||||
|
||||
enum ERROR_CODE {
|
||||
SUCCESS = 0,
|
||||
FATAL_ERROR,
|
||||
DATABASE_ERROR = 2,
|
||||
IGNORE_INVALID = 20,
|
||||
IGNORE_FRIEND = 24,
|
||||
IGNORE_DUPLICATE = 25,
|
||||
};
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestRemoveIgnore > Create()
|
||||
{
|
||||
return std::make_unique< RequestRemoveIgnore >();
|
||||
}
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_socket socket, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultRemoveIgnore : public GenericResponse {
|
||||
private:
|
||||
int32_t m_reply;
|
||||
|
||||
public:
|
||||
ResultRemoveIgnore( GenericRequest *request, int32_t reply );
|
||||
void Serialize( ByteBuffer &out ) const;
|
||||
};
|
||||
Reference in New Issue
Block a user