the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 204 lines 4.8 kB view raw
1#include "stdafx.h" 2#include "DQRNetworkPlayer.h" 3#include "ChatIntegrationLayer.h" 4 5DQRNetworkPlayer::DQRNetworkPlayer() 6{ 7} 8 9DQRNetworkPlayer::DQRNetworkPlayer(DQRNetworkManager *manager, eDQRNetworkPlayerType playerType, bool onHost, int localPlayerIdx, unsigned int sessionAddress) 10{ 11 m_localPlayerIdx = localPlayerIdx; 12 m_type = playerType; 13 m_host = onHost; 14 m_manager = manager; 15 m_customData = 0; 16 m_sessionAddress = sessionAddress; 17} 18 19DQRNetworkPlayer::~DQRNetworkPlayer() 20{ 21} 22 23PlayerUID DQRNetworkPlayer::GetUID() 24{ 25 return m_UID; 26} 27 28void DQRNetworkPlayer::SetUID(PlayerUID UID) 29{ 30 m_UID = UID; 31} 32 33int DQRNetworkPlayer::GetLocalPlayerIndex() 34{ 35 return m_localPlayerIdx; 36} 37 38uintptr_t DQRNetworkPlayer::GetCustomDataValue() 39{ 40 return m_customData; 41} 42 43void DQRNetworkPlayer::SetCustomDataValue(uintptr_t data) 44{ 45 m_customData = data; 46} 47 48bool DQRNetworkPlayer::IsRemote() 49{ 50 return !IsLocal(); 51} 52 53bool DQRNetworkPlayer::IsHost() 54{ 55 return (m_type == DNP_TYPE_HOST); 56} 57 58bool DQRNetworkPlayer::IsLocal() 59{ 60 // m_host determines whether this *machine* is hosting the game, not this player (which is determined by m_type) 61 if( m_host ) 62 { 63 // If we are the hosting machine, then both the host & local players are local to this machine 64 return (m_type == DNP_TYPE_HOST) || (m_type == DNP_TYPE_LOCAL); 65 } 66 else 67 { 68 // Not hosting, just local players are actually physically local 69 return (m_type == DNP_TYPE_LOCAL) ; 70 } 71} 72 73bool DQRNetworkPlayer::IsSameSystem(DQRNetworkPlayer *other) 74{ 75 return ( m_sessionAddress == other->m_sessionAddress ); 76} 77 78bool DQRNetworkPlayer::IsTalking() 79{ 80 if(m_manager->m_chat == nullptr) return false; 81 Microsoft::Xbox::GameChat::ChatUser^ chatUser = m_manager->m_chat->GetChatUserByXboxUserId(ref new Platform::String(m_UID.toString().c_str())); 82 83 if( chatUser == nullptr ) return false; 84 if( chatUser->TalkingMode == Microsoft::Xbox::GameChat::ChatUserTalkingMode::NotTalking ) 85 { 86 return false; 87 } 88 else 89 { 90 return true; 91 } 92} 93 94bool DQRNetworkPlayer::HasVoice() 95{ 96 if(m_manager->m_chat == nullptr) return false; 97 Microsoft::Xbox::GameChat::ChatUser^ chatUser = m_manager->m_chat->GetChatUserByXboxUserId(ref new Platform::String(m_UID.toString().c_str())); 98 99 if( chatUser == nullptr ) return false; 100 if( ((int)chatUser->ParticipantType) & ((int)Windows::Xbox::Chat::ChatParticipantTypes::Talker) ) 101 { 102 return true; 103 } 104 else 105 { 106 return false; 107 } 108} 109 110bool DQRNetworkPlayer::HasCamera() 111{ 112 return false; 113} 114 115LPCWSTR DQRNetworkPlayer::GetGamertag() 116{ 117 return m_name; 118} 119 120int DQRNetworkPlayer::GetSmallId() 121{ 122 return (int)m_smallId; 123} 124 125void DQRNetworkPlayer::SetSmallId(unsigned char smallId) 126{ 127 m_smallId = smallId; 128} 129 130int DQRNetworkPlayer::GetSessionIndex() 131{ 132 return m_manager->GetSessionIndex(this); 133} 134 135// Attempt to send data, of any size, from this player to that specified by pPlayerTarget. This may not be possible depending on the two players, due to 136// our star shaped network connectivity. Data may be any size, and is copied so on returning from this method it does not need to be preserved. 137void DQRNetworkPlayer::SendData( DQRNetworkPlayer *pPlayerTarget, const void *data, unsigned int dataSize ) 138{ 139 // Our network is connected as a star. If we are the host, then we can send to any remote player. If we're a client, we can send only to the host. 140 // The host can also send to other local players, but this doesn't need to go through Rudp. 141 if( m_host ) 142 { 143 if( ( m_type == DNP_TYPE_HOST ) && ( pPlayerTarget->m_type == DNP_TYPE_REMOTE ) ) 144 { 145 // Rudp communication from host to remote player - handled by remote player instance 146 pPlayerTarget->SendInternal(data,dataSize); 147 } 148 else 149 { 150 // Can't do any other types of communications 151 assert(false); 152 } 153 } 154 else 155 { 156 if( ( m_type == DNP_TYPE_LOCAL ) && ( pPlayerTarget->m_type == DNP_TYPE_HOST ) ) 157 { 158 // Rudp communication from client to host - handled by this player instace 159 SendInternal(data, dataSize); 160 } 161 else 162 { 163 // Can't do any other types of communications 164 assert(false); 165 } 166 } 167} 168 169void DQRNetworkPlayer::SendInternal(const void *data, unsigned int dataSize) 170{ 171 m_manager->SendBytes(m_smallId, (BYTE *)data, dataSize); 172} 173 174int DQRNetworkPlayer::GetSendQueueSizeBytes() 175{ 176 return m_manager->GetQueueSizeBytes(); 177} 178 179int DQRNetworkPlayer::GetSendQueueSizeMessages() 180{ 181 return m_manager->GetQueueSizeMessages(); 182} 183 184wchar_t *DQRNetworkPlayer::GetName() 185{ 186 return m_name; 187} 188 189void DQRNetworkPlayer::SetName(const wchar_t *name) 190{ 191 wcscpy_s(m_name, name); 192} 193 194// Return display name (if display name is not set, return name instead) 195wstring DQRNetworkPlayer::GetDisplayName() 196{ 197 return (m_displayName == L"") ? m_name : m_displayName; 198} 199 200// Set display name 201void DQRNetworkPlayer::SetDisplayName(wstring displayName) 202{ 203 m_displayName = displayName; 204}