mirror of
https://github.com/HikikoMarmy/Champions-Reborn-Server.git
synced 2026-04-05 08:59:54 -03:00
Support Removal of Friends and Ignores
This commit is contained in:
@@ -256,6 +256,8 @@
|
||||
<ClInclude Include="Network\Event\RequestMatchGame.h" />
|
||||
<ClInclude Include="Network\Event\RequestMatchGame_RTA.h" />
|
||||
<ClInclude Include="Network\Event\RequestCreateNewCharacter_RTA.h" />
|
||||
<ClInclude Include="Network\Event\RequestRemoveFriend.h" />
|
||||
<ClInclude Include="Network\Event\RequestRemoveIgnore.h" />
|
||||
<ClInclude Include="Network\Event\RequestSaveCharacter_RTA.h" />
|
||||
<ClInclude Include="Network\Event\RequestSendInstantMessage.h" />
|
||||
<ClInclude Include="Network\Event\RequestSendRoomMessage.h" />
|
||||
@@ -332,6 +334,8 @@
|
||||
<ClCompile Include="Network\Event\RequestLogout.cpp" />
|
||||
<ClCompile Include="Network\Event\RequestMatchGame.cpp" />
|
||||
<ClCompile Include="Network\Event\RequestCreateNewCharacter_RTA.cpp" />
|
||||
<ClCompile Include="Network\Event\RequestRemoveFriend.cpp" />
|
||||
<ClCompile Include="Network\Event\RequestRemoveIgnore.cpp" />
|
||||
<ClCompile Include="Network\Event\RequestSaveCharacter_RTA.cpp" />
|
||||
<ClCompile Include="Network\Event\RequestSendInstantMessage.cpp" />
|
||||
<ClCompile Include="Network\Event\RequestSendRoomMessage.cpp" />
|
||||
|
||||
@@ -308,6 +308,12 @@
|
||||
<ClInclude Include="Network\Event\NotifyInstantMessage.h">
|
||||
<Filter>Header Files\Network\Event</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Network\Event\RequestRemoveFriend.h">
|
||||
<Filter>Header Files\Network\Event</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Network\Event\RequestRemoveIgnore.h">
|
||||
<Filter>Header Files\Network\Event</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
@@ -529,6 +535,12 @@
|
||||
<ClCompile Include="Network\Event\NotifyInstantMessage.cpp">
|
||||
<Filter>Source Files\Network\Event</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Network\Event\RequestRemoveFriend.cpp">
|
||||
<Filter>Source Files\Network\Event</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Network\Event\RequestRemoveIgnore.cpp">
|
||||
<Filter>Source Files\Network\Event</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Champions Server.rc" />
|
||||
|
||||
@@ -98,12 +98,18 @@ void Database::PrepareStatements()
|
||||
{ QueryID::SaveFriend,
|
||||
"INSERT OR IGNORE INTO UserFriendList ( account_id, friend_handle ) VALUES ( ?, ? );" },
|
||||
|
||||
{ QueryID::RemoveFriend,
|
||||
"DELETE FROM UserFriendList WHERE account_id = ? AND friend_handle = ?;" },
|
||||
|
||||
{ QueryID::LoadFriendList,
|
||||
"SELECT friend_handle FROM UserFriendList WHERE account_id = ?;" },
|
||||
|
||||
{ QueryID::SaveIgnore,
|
||||
"INSERT OR IGNORE INTO UserIgnoredList ( account_id, ignore_handle ) VALUES ( ?, ? );" },
|
||||
|
||||
{ QueryID::RemoveIgnore,
|
||||
"DELETE FROM UserIgnoredList WHERE account_id = ? AND ignore_handle = ?;" },
|
||||
|
||||
{ QueryID::LoadIgnoreList,
|
||||
"SELECT ignore_handle FROM UserIgnoredList WHERE account_id = ?;" }
|
||||
};
|
||||
@@ -453,6 +459,39 @@ bool Database::SaveFriend( const int64_t account_id, const std::wstring &friend_
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Database::RemoveFriend( const int64_t account_id, const std::wstring &friend_handle )
|
||||
{
|
||||
if( account_id <= 0 || friend_handle.empty() )
|
||||
{
|
||||
Log::Error( "Invalid parameters for RemoveFriend" );
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto stmt = m_statements[ QueryID::RemoveFriend ];
|
||||
auto friendHandle = Util::WideToUTF8( friend_handle );
|
||||
|
||||
sqlite3_reset( stmt );
|
||||
sqlite3_clear_bindings( stmt );
|
||||
sqlite3_bind_int64( stmt, 1, account_id );
|
||||
sqlite3_bind_text( stmt, 2, friendHandle.c_str(), -1, SQLITE_TRANSIENT );
|
||||
|
||||
if( sqlite3_step( stmt ) != SQLITE_DONE )
|
||||
{
|
||||
Log::Error( "SQLite delete failed: {}", sqlite3_errmsg( m_db ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( const std::exception &e )
|
||||
{
|
||||
Log::Error( "Database error: {}", std::string( e.what() ) );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> Database::LoadFriends( const int64_t account_id )
|
||||
{
|
||||
std::vector<std::wstring> friend_list;
|
||||
@@ -517,6 +556,39 @@ bool Database::SaveIgnore( const int64_t account_id, const std::wstring &ignore_
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Database::RemoveIgnore( const int64_t account_id, const std::wstring &ignore_handle )
|
||||
{
|
||||
if( account_id <= 0 || ignore_handle.empty() )
|
||||
{
|
||||
Log::Error( "Invalid parameters for RemoveIgnore" );
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto stmt = m_statements[ QueryID::RemoveIgnore ];
|
||||
auto ignoreHandle = Util::WideToUTF8( ignore_handle );
|
||||
|
||||
sqlite3_reset( stmt );
|
||||
sqlite3_clear_bindings( stmt );
|
||||
sqlite3_bind_int64( stmt, 1, account_id );
|
||||
sqlite3_bind_text( stmt, 2, ignoreHandle.c_str(), -1, SQLITE_TRANSIENT );
|
||||
|
||||
if( sqlite3_step( stmt ) != SQLITE_DONE )
|
||||
{
|
||||
Log::Error( "SQLite delete failed: {}", sqlite3_errmsg( m_db ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( const std::exception &e )
|
||||
{
|
||||
Log::Error( "Database error: {}", std::string( e.what() ) );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::wstring> Database::LoadIgnores( const int64_t account_id )
|
||||
{
|
||||
std::vector<std::wstring> ignore_list;
|
||||
|
||||
@@ -23,9 +23,11 @@ enum class QueryID {
|
||||
LoadCharacter,
|
||||
|
||||
SaveFriend,
|
||||
RemoveFriend,
|
||||
LoadFriendList,
|
||||
|
||||
SaveIgnore,
|
||||
RemoveIgnore,
|
||||
LoadIgnoreList,
|
||||
};
|
||||
|
||||
@@ -78,9 +80,11 @@ public:
|
||||
sptr_realm_character LoadCharacterData( const int64_t account_id, const int32_t character_id );
|
||||
|
||||
bool SaveFriend( const int64_t account_id, const std::wstring &friend_handle );
|
||||
bool RemoveFriend( const int64_t account_id, const std::wstring &friend_handle );
|
||||
std::vector< std::wstring > LoadFriends( const int64_t account_id );
|
||||
|
||||
bool SaveIgnore( const int64_t account_id, const std::wstring &ignore_handle );
|
||||
bool RemoveIgnore( const int64_t account_id, const std::wstring &ignore_handle );
|
||||
std::vector< std::wstring > LoadIgnores( const int64_t account_id );
|
||||
|
||||
private:
|
||||
|
||||
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