the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 151 lines 6.2 kB view raw
1#pragma once 2#include "SQRNetworkManager.h" 3#include <queue> 4 5// This is the lowest level class for handling the concept of a player on Sony platforms. This is managed by SQRNetworkManager. The game shouldn't directly communicate 6// with this class, as it is wrapped by NetworkPlayerSony which is an implementation of a platform-independent interface INetworkPlayer. 7 8class SQRNetworkPlayer 9{ 10#ifdef __ORBIS__ 11 friend class SQRNetworkManager_Orbis; 12 friend class SonyVoiceChat_Orbis; 13#elif defined __PS3__ 14 friend class SQRNetworkManager_PS3; 15#else // __PSVITA__ 16 friend class SQRNetworkManager_Vita; 17 friend class SQRNetworkManager_AdHoc_Vita; 18 friend class SonyVoiceChat_Vita; 19#endif 20 friend class SQRNetworkManager; 21 friend class NetworkPlayerSony; 22 friend class CPlatformNetworkManagerSony; 23 24 int GetSmallId(); 25 wchar_t *GetName(); 26 bool IsRemote(); 27 bool IsHost(); 28 bool IsLocal(); 29 int GetLocalPlayerIndex(); 30 bool IsSameSystem(SQRNetworkPlayer *other); 31 uintptr_t GetCustomDataValue(); 32 void SetCustomDataValue(uintptr_t data); 33 bool HasVoice(); 34 bool IsTalking(); 35 bool IsMutedByLocalUser(int userIndex); 36 37 static const int SNP_FLAG_CONNECTION_COMPLETE = 1; // This player has a fully connected Rudp or other local link established (to a remote player if this is on the host, to the host if this is a client) - or isn't expected to have one 38 static const int SNP_FLAG_SMALLID_ALLOCATED = 2; // This player has a small id allocated 39 static const int SNP_FLAG_SMALLID_CONFIRMED = 4; // This player's small id has been confirmed as received by the client (only relevant for players using network communications, others set at the same time as allocating) 40 static const int SNP_FLAG_READY_MASK = 7; // Mask indicated all bits which must be set in the flags for this player to be considered "ready" 41 42 static const int SNP_MAX_PAYLOAD = 1346; // This is the default RUDP payload size - if we want to change this we'll need to use cellRudpSetOption to set something else & adjust segment size 43 44 typedef enum 45 { 46 SNP_TYPE_HOST, // This player represents the host 47 SNP_TYPE_LOCAL, // On host - this player is a local player that needs communicated with specially not using rudp. On clients - this is a local player, where m_rudpCtx is the context used to communicate from this player to/from the host 48 SNP_TYPE_REMOTE, // On host - this player's m_rupdCtx can be used to communicate from between the host and this player. On clients - this is a remote player that cannot be communicated with 49 } eSQRNetworkPlayerType; 50 51 enum AckFlags 52 { 53 e_flag_AckUnknown, 54 e_flag_AckNotRequested, 55 e_flag_AckRequested, 56 e_flag_AckReturning 57 }; 58 59 class DataPacketHeader 60 { 61 unsigned short m_dataSize; 62 unsigned short m_ackFlags; 63 public: 64 DataPacketHeader() : m_dataSize(0), m_ackFlags(e_flag_AckUnknown) {} 65 DataPacketHeader(int dataSize, AckFlags ackFlags) : m_dataSize(dataSize), m_ackFlags(ackFlags) { } 66 AckFlags GetAckFlags() { return (AckFlags)m_ackFlags;} 67 int GetDataSize() { return m_dataSize; } 68 }; 69 70#ifndef _CONTENT_PACKAGE 71 std::vector<__int64> m_ackStats; 72 int m_minAckTime; 73 int m_maxAckTime; 74 int m_totalAcks; 75 __int64 m_totalAckTime; 76 int m_averageAckTime; 77#endif 78 79 class QueuedSendBlock 80 { 81 public: 82 unsigned char *start; 83 unsigned char *end; 84 unsigned char *current; 85 AckFlags ack; 86 }; 87 88 class InitSendData 89 { 90 public: 91 unsigned char m_smallId; // Id to uniquely and permanently identify this player between machines - assigned by the server 92 PlayerUID m_UID; 93 }; 94 95 SQRNetworkPlayer(SQRNetworkManager *manager, eSQRNetworkPlayerType playerType, bool onHost, SceNpMatching2RoomMemberId roomMemberId, int localPlayerIdx, int rudpCtx, PlayerUID *pUID); 96 ~SQRNetworkPlayer(); 97 98 PlayerUID GetUID(); 99 void SetUID(PlayerUID UID); 100 bool HasConnectionAndSmallId(); 101 bool IsReady(); 102 void ConnectionComplete(); 103 void SmallIdAllocated(unsigned char smallId); 104 void InitialDataReceived(InitSendData *ISD); // Only for remote players as viewed from the host, this is set when the host has received confirmation that the client has received the small id for this player, ie it is now safe to send data to 105 bool HasSmallIdConfirmed(); 106 107 void SendData( SQRNetworkPlayer *pPlayerTarget, const void *data, unsigned int dataSize, bool ack ); 108 109 void ConfirmReady(); 110 void SendInternal(const void *data, unsigned int dataSize, AckFlags ackFlags); 111 void SendMoreInternal(); 112 int GetPacketDataSize(); 113 int ReadDataPacket(void* data, int dataSize); 114 int WriteDataPacket(const void* data, int dataSize, AckFlags ackFlags); 115 void ReadAck(); 116 void WriteAck(); 117 118 int GetOutstandingAckCount(); 119 int GetSendQueueSizeBytes(); 120 int GetSendQueueSizeMessages(); 121 122 int GetTotalOutstandingAckCount(); 123 int GetTotalSendQueueBytes(); 124 int GetTotalSendQueueMessages(); 125 126 127#ifdef __PSVITA__ 128 void SendInternal_VitaAdhoc(const void *data, unsigned int dataSize, EAdhocDataTag tag = e_dataTag_Normal); 129 void SendMoreInternal_VitaAdhoc(); 130#endif 131 void SetNameFromUID(); 132 void SetName(char *name); 133 int GetSessionIndex(); 134 135 eSQRNetworkPlayerType m_type; // The player type 136 bool m_host; // Whether this actual player class is stored on a host (not whether it represents the host, or a player on the host machine) 137 int m_flags; // Flags reflecting current state of this player 138 int m_rudpCtx; // Rudp context that can be used to communicate between this player & the host (see comments for eSQRNetworkPlayerType above) 139 int m_localPlayerIdx; // Index of this player on the machine to which it belongs 140 SceNpMatching2RoomMemberId m_roomMemberId; // The room member id, effectively a per machine id 141 InitSendData m_ISD; // Player UID & ID that get sent together to the host when connection is established 142 SQRNetworkManager *m_manager; // Pointer back to the manager that is managing this player 143 wchar_t m_name[21]; 144 uintptr_t m_customData; 145 CRITICAL_SECTION m_csQueue; 146 CRITICAL_SECTION m_csAcks; 147 std::queue<QueuedSendBlock> m_sendQueue; 148 int m_totalBytesInSendQueue; 149 150 int m_acksOutstanding; 151};