2024-12-21 10:04:04 +08:00
|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
|
#include "DNChatRoom.h"
|
|
|
|
|
|
#include "DNGameRoom.h"
|
|
|
|
|
|
#include "DNUserSession.h"
|
|
|
|
|
|
#include "DNFriend.h"
|
|
|
|
|
|
|
|
|
|
|
|
CDNChatRoom::CDNChatRoom(UINT nChatRoomID, WCHAR * pwzRoomName, BYTE nRoomType, USHORT uRoomAllow, WCHAR * pwzPassword,
|
|
|
|
|
|
WCHAR * pwzPRLine1, WCHAR * pwzPRLine2, WCHAR * pwzPRLine3 )
|
|
|
|
|
|
{
|
|
|
|
|
|
memset(m_nChatRoomMemberArray, 0, sizeof(m_nChatRoomMemberArray));
|
|
|
|
|
|
m_nLeaderSessionID = 0;
|
|
|
|
|
|
|
|
|
|
|
|
m_nChatRoomID = nChatRoomID;
|
|
|
|
|
|
|
|
|
|
|
|
m_nChatRoomType = nRoomType;
|
|
|
|
|
|
m_nChatRoomAllow = uRoomAllow;
|
|
|
|
|
|
|
|
|
|
|
|
m_wstrChatRoomName = pwzRoomName;
|
|
|
|
|
|
m_wstrChatRoomPW = pwzPassword;
|
|
|
|
|
|
|
|
|
|
|
|
m_wstrChatRoomPRLine1 = pwzPRLine1;
|
|
|
|
|
|
m_wstrChatRoomPRLine2 = pwzPRLine2;
|
|
|
|
|
|
m_wstrChatRoomPRLine3 = pwzPRLine3;
|
|
|
|
|
|
|
|
|
|
|
|
m_VecKickedList.clear();
|
|
|
|
|
|
|
|
|
|
|
|
m_pGameRoom = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CDNChatRoom::~CDNChatRoom()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_VecKickedList.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UINT CDNChatRoom::GetMemberAIDFromIndex( int nIndex )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( nIndex < 0 || nIndex >= CHATROOMMAX ) return 0;
|
|
|
|
|
|
|
|
|
|
|
|
return m_nChatRoomMemberArray[ nIndex ];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CDNChatRoom::GetUserCount()
|
|
|
|
|
|
{
|
|
|
|
|
|
int nUserCount = 0;
|
|
|
|
|
|
for( int i=0; i<CHATROOMMAX; i++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_nChatRoomMemberArray[i] <= 0 ) continue;
|
|
|
|
|
|
|
|
|
|
|
|
nUserCount++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nUserCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CDNChatRoom::IsLeader( UINT nUserAID )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_nLeaderSessionID <= 0 ) return false;
|
|
|
|
|
|
if( nUserAID != m_nLeaderSessionID ) return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CDNChatRoom::LeaveUser( UINT nUserAID, int nReason )
|
|
|
|
|
|
{
|
|
|
|
|
|
int idx = _FindUserFromAID( nUserAID );
|
|
|
|
|
|
if(idx < 0 ) return ERROR_CHATROOM_UNKNOWNUSER; // <20>濡 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>̴<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
|
|
if( nReason == CHATROOMLEAVE_FOREVERKICKED )
|
|
|
|
|
|
{
|
|
|
|
|
|
m_VecKickedList.push_back( nUserAID );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_nChatRoomMemberArray[idx] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// <20>ο<EFBFBD><CEBF><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> <20>ٽ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
for( int i=idx; i < CHATROOMMAX-1; i++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
m_nChatRoomMemberArray[i] = m_nChatRoomMemberArray[i+1];
|
|
|
|
|
|
}
|
|
|
|
|
|
m_nChatRoomMemberArray[CHATROOMMAX-1] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ä<>ù<EFBFBD>ID<49><44> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>쿡<EFBFBD><ECBFA1> <20><><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ִ<EFBFBD>.
|
|
|
|
|
|
CDNUserSession * pUser = m_pGameRoom->GetUserSession(nUserAID);
|
|
|
|
|
|
if( pUser != NULL )
|
|
|
|
|
|
{
|
|
|
|
|
|
pUser->m_nChatRoomID = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ERROR_NONE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CDNChatRoom::EnterRoom( UINT nUserAID, WCHAR * pwzPassword, bool bLeader )
|
|
|
|
|
|
{
|
|
|
|
|
|
CDNUserSession * pUser = m_pGameRoom->GetUserSession(nUserAID);
|
|
|
|
|
|
if( pUser == NULL ) return ERROR_GENERIC_USER_NOT_FOUND;
|
|
|
|
|
|
|
|
|
|
|
|
int nCanEnter = 0;
|
|
|
|
|
|
if((nCanEnter = _CanEnterRoom( nUserAID, pwzPassword, bLeader )) != ERROR_NONE ) return nCanEnter;
|
|
|
|
|
|
|
|
|
|
|
|
int nEmptyIndex = _FindEmptyIndex();
|
|
|
|
|
|
if( nEmptyIndex < 0 ) return ERROR_CHATROOM_NOMORESPACE; // <20><><EFBFBD><EFBFBD> <20><> á<><C3A1>
|
|
|
|
|
|
|
|
|
|
|
|
m_nChatRoomMemberArray[nEmptyIndex] = nUserAID;
|
|
|
|
|
|
if( bLeader )
|
|
|
|
|
|
m_nLeaderSessionID = nUserAID;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ä<>ù<EFBFBD>ID<49><44> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
|
|
|
|
|
pUser->m_nChatRoomID = m_nChatRoomID;
|
|
|
|
|
|
|
|
|
|
|
|
return ERROR_NONE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDNChatRoom::ChangeRoomOption( WCHAR * pwzRoomName, BYTE nRoomType, USHORT nRoomAllow, WCHAR * pwzPassword,
|
|
|
|
|
|
WCHAR * pwzPRLine1, WCHAR * pwzPRLine2, WCHAR * pwzPRLine3 )
|
|
|
|
|
|
{
|
|
|
|
|
|
m_wstrChatRoomName = pwzRoomName;
|
|
|
|
|
|
m_nChatRoomType = nRoomType;
|
|
|
|
|
|
m_nChatRoomAllow = nRoomAllow;
|
|
|
|
|
|
m_wstrChatRoomPW = pwzPassword;
|
|
|
|
|
|
m_wstrChatRoomPRLine1 = pwzPRLine1;
|
|
|
|
|
|
m_wstrChatRoomPRLine2 = pwzPRLine2;
|
|
|
|
|
|
m_wstrChatRoomPRLine3 = pwzPRLine3;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDNChatRoom::SendChatMessageToAll( int cLen, const WCHAR *pwszCharacterName, const WCHAR *pwszChatMsg )
|
|
|
|
|
|
{
|
|
|
|
|
|
for( int i=0; i<CHATROOMMAX; i++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_nChatRoomMemberArray[i] <= 0 ) continue;
|
|
|
|
|
|
CDNUserSession * pUser = m_pGameRoom->GetUserSession(m_nChatRoomMemberArray[i]);
|
|
|
|
|
|
if( pUser == NULL ) continue;
|
|
|
|
|
|
|
|
|
|
|
|
pUser->SendChat( CHATTYPE_CHATROOM, cLen, pwszCharacterName, pwszChatMsg );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CDNChatRoom::SendProfileToAll( int nSessionID, TProfile & profile )
|
|
|
|
|
|
{
|
|
|
|
|
|
for( int i=0; i<CHATROOMMAX; i++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_nChatRoomMemberArray[i] <= 0 ) continue;
|
|
|
|
|
|
CDNUserSession * pUser = m_pGameRoom->GetUserSession(m_nChatRoomMemberArray[i]);
|
|
|
|
|
|
if( pUser == NULL ) continue;
|
|
|
|
|
|
|
|
|
|
|
|
pUser->SendDisplayProfile( nSessionID, profile );
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CDNChatRoom::_CanEnterRoom( UINT nUserAID, WCHAR * pwzPassword, bool bLeader )
|
|
|
|
|
|
{
|
|
|
|
|
|
CDNUserSession * pUser = m_pGameRoom->GetUserSession(nUserAID);
|
|
|
|
|
|
if( pUser == NULL ) return ERROR_CHATROOM_CANNOTENTER;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1. <20>Ϲ<EFBFBD><CFB9><EFBFBD><EFBFBD><EFBFBD> üũ
|
|
|
|
|
|
// 1.1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> üũ
|
|
|
|
|
|
int nEmptyIndex = _FindEmptyIndex();
|
|
|
|
|
|
if( nEmptyIndex < 0 ) return ERROR_CHATROOM_NOMORESPACE; // <20><><EFBFBD><EFBFBD> <20><> á<><C3A1>
|
|
|
|
|
|
|
|
|
|
|
|
// 1.2 <20>濡 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΰ<EFBFBD>?
|
|
|
|
|
|
int nMyIndex = _FindUserFromAID( nUserAID );
|
|
|
|
|
|
if( nMyIndex >= 0 ) return ERROR_CHATROOM_ALREADYINROOM; // <20>̹<EFBFBD> <20>濡 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̴<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
|
|
// 1.3 <20><><EFBFBD><EFBFBD>ű<EFBFBD><C5B1><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ°<CFB4>?
|
|
|
|
|
|
for( UINT i=0; i<m_VecKickedList.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_VecKickedList[i] == nUserAID )
|
|
|
|
|
|
return ERROR_CHATROOM_KICKEDFOREVER;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> üũ
|
|
|
|
|
|
bool bCanEnterRoom = true;
|
|
|
|
|
|
|
|
|
|
|
|
// 2.1 <20>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if( m_wstrChatRoomPW.length() > 0 && m_wstrChatRoomPW != pwzPassword ) return ERROR_CHATROOM_WRONGPASSWORD;
|
|
|
|
|
|
|
|
|
|
|
|
// 2.2 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> üũ
|
|
|
|
|
|
if( bLeader == false ) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ѿ<EFBFBD> <20>ɸ<EFBFBD><C9B8><EFBFBD> <20>ʴ´<CAB4>.
|
|
|
|
|
|
{
|
|
|
|
|
|
CDNUserSession * pLeader = m_pGameRoom->GetUserSession(m_nLeaderSessionID);
|
|
|
|
|
|
if( pLeader == NULL ) return ERROR_CHATROOM_UNKNOWNUSER;
|
|
|
|
|
|
|
|
|
|
|
|
bool bFriend = pLeader->GetFriend()->HasFriend( pUser->GetCharacterDBID() );
|
|
|
|
|
|
bool bSameGuild = pLeader->GetGuildUID().IsSet() && pUser->GetGuildUID().IsSet() && pLeader->GetGuildUID() == pUser->GetGuildUID();
|
|
|
|
|
|
|
|
|
|
|
|
switch( m_nChatRoomAllow )
|
|
|
|
|
|
{
|
|
|
|
|
|
case CHATROOMALLOW_ALL:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CHATROOMALLOW_FRIEND:
|
|
|
|
|
|
if( bFriend == false ) return ERROR_CHATROOM_CANNOTENTER;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CHATROOMALLOW_GUILD:
|
|
|
|
|
|
if( bSameGuild == false ) return ERROR_CHATROOM_CANNOTENTER;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CHATROOMALLOW_FRIENDANDGUILD:
|
|
|
|
|
|
if((bFriend || bSameGuild) == false ) return ERROR_CHATROOM_CANNOTENTER;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ERROR_NONE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CDNChatRoom::_FindUserFromAID( UINT nUserAID )
|
|
|
|
|
|
{
|
|
|
|
|
|
for( int i=0; i < CHATROOMMAX; i++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_nChatRoomMemberArray[i] == nUserAID )
|
|
|
|
|
|
{
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CDNChatRoom::_FindEmptyIndex()
|
|
|
|
|
|
{
|
|
|
|
|
|
for( int i=0; i < CHATROOMMAX; i++ )
|
|
|
|
|
|
{
|
|
|
|
|
|
if( m_nChatRoomMemberArray[i] <= 0 )
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|