aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Durango/Network/DQRNetworkPlayer.cpp
blob: e2d82a9025b27abfd020e3a4ade4c1d0d3215f54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "stdafx.h"
#include "DQRNetworkPlayer.h"
#include "ChatIntegrationLayer.h"

DQRNetworkPlayer::DQRNetworkPlayer()
{
}

DQRNetworkPlayer::DQRNetworkPlayer(DQRNetworkManager *manager, eDQRNetworkPlayerType playerType, bool onHost, int localPlayerIdx, unsigned int sessionAddress)
{
	m_localPlayerIdx	= localPlayerIdx;
	m_type				= playerType;
	m_host				= onHost;
	m_manager			= manager;
	m_customData		= 0;
	m_sessionAddress	= sessionAddress;
}

DQRNetworkPlayer::~DQRNetworkPlayer()
{
}

PlayerUID	DQRNetworkPlayer::GetUID()
{
	return m_UID;
}

void	DQRNetworkPlayer::SetUID(PlayerUID UID)
{
	m_UID = UID;
}

int DQRNetworkPlayer::GetLocalPlayerIndex()
{
	return m_localPlayerIdx;
}

uintptr_t	DQRNetworkPlayer::GetCustomDataValue()
{
	return m_customData;
}

void	DQRNetworkPlayer::SetCustomDataValue(uintptr_t data)
{
	m_customData = data;
}

bool DQRNetworkPlayer::IsRemote()
{
	return !IsLocal();
}

bool DQRNetworkPlayer::IsHost()
{
	return (m_type == DNP_TYPE_HOST);
}

bool DQRNetworkPlayer::IsLocal()
{
	// m_host determines whether this *machine* is hosting the game, not this player (which is determined by m_type)
	if( m_host )
	{
		// If we are the hosting machine, then both the host & local players are local to this machine
		return (m_type == DNP_TYPE_HOST) || (m_type == DNP_TYPE_LOCAL);
	}
	else
	{
		// Not hosting, just local players are actually physically local
		return (m_type == DNP_TYPE_LOCAL) ;
	}
}

bool	DQRNetworkPlayer::IsSameSystem(DQRNetworkPlayer *other)
{
	return ( m_sessionAddress == other->m_sessionAddress );
}

bool	DQRNetworkPlayer::IsTalking()
{
	if(m_manager->m_chat == nullptr) return false;
	Microsoft::Xbox::GameChat::ChatUser^ chatUser = m_manager->m_chat->GetChatUserByXboxUserId(ref new Platform::String(m_UID.toString().c_str()));

	if( chatUser == nullptr ) return false;
	if( chatUser->TalkingMode == Microsoft::Xbox::GameChat::ChatUserTalkingMode::NotTalking )
	{
		return false;
	}
	else
	{
		return true;
	}
}

bool	DQRNetworkPlayer::HasVoice()
{
	if(m_manager->m_chat == nullptr) return false;
	Microsoft::Xbox::GameChat::ChatUser^ chatUser = m_manager->m_chat->GetChatUserByXboxUserId(ref new Platform::String(m_UID.toString().c_str()));

	if( chatUser == nullptr ) return false;
	if( ((int)chatUser->ParticipantType) & ((int)Windows::Xbox::Chat::ChatParticipantTypes::Talker) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool	DQRNetworkPlayer::HasCamera()
{
	return false;
}

LPCWSTR	DQRNetworkPlayer::GetGamertag()
{
	return m_name;
}

int	DQRNetworkPlayer::GetSmallId()
{
	return (int)m_smallId;
}

void DQRNetworkPlayer::SetSmallId(unsigned char smallId)
{
	m_smallId = smallId;
}

int DQRNetworkPlayer::GetSessionIndex()
{
	return m_manager->GetSessionIndex(this);
}

// 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
// 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.
void DQRNetworkPlayer::SendData( DQRNetworkPlayer *pPlayerTarget, const void *data, unsigned int dataSize )
{
	// 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.
	// The host can also send to other local players, but this doesn't need to go through Rudp. 
	if( m_host )
	{
		if( ( m_type == DNP_TYPE_HOST ) && ( pPlayerTarget->m_type == DNP_TYPE_REMOTE ) )
		{
			// Rudp communication from host to remote player - handled by remote player instance
			pPlayerTarget->SendInternal(data,dataSize);
		}
		else
		{
			// Can't do any other types of communications
			assert(false);
		}
	}
	else
	{
		if( ( m_type == DNP_TYPE_LOCAL ) && ( pPlayerTarget->m_type == DNP_TYPE_HOST ) )
		{
			// Rudp communication from client to host - handled by this player instace
			SendInternal(data, dataSize);
		}
		else
		{
			// Can't do any other types of communications
			assert(false);
		}
	}
}

void DQRNetworkPlayer::SendInternal(const void *data, unsigned int dataSize)
{
	m_manager->SendBytes(m_smallId, (BYTE *)data, dataSize);
}

int DQRNetworkPlayer::GetSendQueueSizeBytes()
{
	return m_manager->GetQueueSizeBytes();
}

int DQRNetworkPlayer::GetSendQueueSizeMessages()
{
	return m_manager->GetQueueSizeMessages();
}

wchar_t	*DQRNetworkPlayer::GetName()
{
	return m_name;
}

void DQRNetworkPlayer::SetName(const wchar_t *name)
{
	wcscpy_s(m_name, name);
}

// Return display name (if display name is not set, return name instead)
wstring	DQRNetworkPlayer::GetDisplayName()
{
	return (m_displayName == L"") ? m_name : m_displayName;
}

// Set display name
void DQRNetworkPlayer::SetDisplayName(wstring displayName)
{
	m_displayName = displayName;
}