Monobit Unity Networking ver.2.8.0 Server API Reference (C++)
MunRoomPlayerInfo.hpp
Go to the documentation of this file.
1 
7 #ifndef __MUN_ROOM_PLAYER_INFO_HPP__
8 #define __MUN_ROOM_PLAYER_INFO_HPP__
9 
10 #include <mrs.hpp>
11 #include <stream/MunStream.hpp>
12 #include <log/MunLogger.hpp>
13 
18 {
19 protected:
21  MrsConnection m_Connection;
22 
24  int32 m_Id;
25 
27  std::string m_Name;
28 
31 
34 
37 
40 
42  uint64 m_RoomId;
43 
44  uint16 m_GroupWriteRecordOptions;
45 
46  uint16 m_GroupWriteRecordPayloadType;
47 
48  uint32 m_GroupWriteRecordCount;
49 
50  MunBuffer m_GroupWriteRecordBuffer;
51 
52 public:
57  MrsConnection GetConnection() { return m_Connection; }
58 
63  int32 GetId() { return m_Id; }
64 
69  std::string GetName() { return m_Name; }
70 
75  void SetName(std::string name) { m_Name = name; }
76 
82 
87  uint16 GetParametersLen() { return m_ParametersLen; }
88 
94  void SetParameters( STREAM::KeyValue* pParameters, uint16 parametersLen ){
95  m_ParametersLen = parametersLen;
96  for ( uint16 i = 0; i < m_ParametersLen; ++i ){
97  m_Parameters[ i ] = pParameters[ i ];
98  }
99  }
100 
106  void UpdateParameters( STREAM::KeyValue* pParameters, uint16 parametersLen ){
107  std::map<std::string, STREAM::Union> parameters;
108  for ( uint16 i = 0; i < m_ParametersLen; ++i ){
109  parameters.insert( std::pair<std::string, STREAM::Union>( m_Parameters[ i ].key.text, m_Parameters[ i ].value ) );
110  }
111  for ( uint16 i = 0; i < parametersLen; ++i ){
112  std::map<std::string, STREAM::Union>::iterator itr = parameters.find( pParameters[ i ].key.text );
113  if ( parameters.end() == itr ){
114  parameters.insert( std::pair<std::string, STREAM::Union>( pParameters[ i ].key.text, pParameters[ i ].value ) );
115  }else{
116  itr->second = pParameters[ i ].value;
117  }
118  }
119  if ( STREAM::PLAYER_PARAMETERS_MAX < parameters.size() ) return;
120 
121  m_ParametersLen = (uint16)parameters.size();
122  uint16 i = 0;
123  for ( std::map<std::string, STREAM::Union>::iterator itr = parameters.begin(); parameters.end() != itr; ++itr ){
124  STREAM::Text key = STREAM::Text( itr->first );
125  m_Parameters[ i++ ] = STREAM::KeyValue( key, itr->second );
126  }
127  }
128 
134 
140 
145  uint64 GetRoomId() { return m_RoomId; }
146 
147 public:
158  MunRoomPlayerInfo( MrsConnection connection = NULL, int32 id = 0, std::string name = "", uint32 clientUidForMasterServer = 0, uint64 clientUidForProxyServer = 0, uint64 roomId = 0, STREAM::KeyValue* pParameters = NULL, uint16 parametersLen = 0 ) {
159  m_Connection = connection;
160  m_Id = id;
161  m_Name = name;
162  m_clientUidForMasterServer = clientUidForMasterServer;
163  m_clientUidForProxyServer = clientUidForProxyServer;
164  m_RoomId = roomId;
165  SetParameters( pParameters, parametersLen );
166 
167  m_GroupWriteRecordOptions = 0;
168  m_GroupWriteRecordPayloadType = 0;
169  m_GroupWriteRecordCount = 0;
170  }
171 
175  virtual ~MunRoomPlayerInfo() {}
176 
177  void FlushGroupWriteRecord(){
178  if ( 0 == m_GroupWriteRecordPayloadType ) return;
179 
180 // MRSEXT_LOG_INFO( "FlushGroupWriteRecord id=%d options=%u payload_type=%u payload_len=%u count=%u", m_Id, m_GroupWriteRecordOptions, m_GroupWriteRecordPayloadType, m_GroupWriteRecordBuffer.GetDataLen(), m_GroupWriteRecordCount );
181  mrs_write_record( m_Connection, m_GroupWriteRecordOptions, m_GroupWriteRecordPayloadType, m_GroupWriteRecordBuffer.GetData(), m_GroupWriteRecordBuffer.GetDataLen() );
182 
183  m_GroupWriteRecordOptions = 0;
184  m_GroupWriteRecordPayloadType = 0;
185  m_GroupWriteRecordCount = 0;
186  m_GroupWriteRecordBuffer.Unread( 0xFFFFFFFF );
187  m_GroupWriteRecordBuffer.Unwrite( 0xFFFFFFFF );
188  }
189 
190  void GroupWriteRecord( uint16 options, uint16 payload_type, const void* payload, uint32 payload_len, bool is_group ){
191  if ( is_group ){
192  if ( ( m_GroupWriteRecordOptions != options ) || ( m_GroupWriteRecordPayloadType != payload_type ) ){
193  FlushGroupWriteRecord();
194  m_GroupWriteRecordOptions = options;
195  m_GroupWriteRecordPayloadType = payload_type;
196  }
197 
198  m_GroupWriteRecordBuffer.Write( payload, payload_len );
199  ++m_GroupWriteRecordCount;
200  }else{
201  FlushGroupWriteRecord();
202  mrs_write_record( m_Connection, options, payload_type, payload, payload_len );
203  }
204  }
205 
206  void Update(){
207  FlushGroupWriteRecord();
208  }
209 };
210 
211 #endif /* __MUN_ROOM_PLAYER_INFO_HPP__ */
std::string GetName()
プレイヤーIDの取得.
Definition: MunRoomPlayerInfo.hpp:69
mrs::Buffer の拡張クラス.
Definition: MunBuffer.hpp:17
void SetParameters(STREAM::KeyValue *pParameters, uint16 parametersLen)
プレイヤーパラメータの設定.
Definition: MunRoomPlayerInfo.hpp:94
MrsConnection m_Connection
MUNクライアントの接続情報.
Definition: MunRoomPlayerInfo.hpp:21
uint16 m_ParametersLen
プレイヤーパラメータの登録数.
Definition: MunRoomPlayerInfo.hpp:33
void SetName(std::string name)
プレイヤーIDの設定.
Definition: MunRoomPlayerInfo.hpp:75
virtual ~MunRoomPlayerInfo()
デストラクタ.
Definition: MunRoomPlayerInfo.hpp:175
int32 GetId()
プレイヤーIDの取得.
Definition: MunRoomPlayerInfo.hpp:63
uint64 GetClientIdForProxyServer()
mun_proxyサーバ上のクライアント識別用ユニークIDの取得.
Definition: MunRoomPlayerInfo.hpp:139
MUNにおける通信データ情報.
MrsConnection GetConnection()
MUNクライアントの接続情報の取得.
Definition: MunRoomPlayerInfo.hpp:57
任意のKey-Valueペア.
Definition: MunStream.hpp:602
STREAM::KeyValue m_Parameters[STREAM::PLAYER_PARAMETERS_MAX]
プレイヤーパラメータ.
Definition: MunRoomPlayerInfo.hpp:30
uint32 m_clientUidForMasterServer
mun_masterサーバ上のクライアント識別用ユニークID.
Definition: MunRoomPlayerInfo.hpp:36
uint64 GetRoomId()
所属するルームIDの取得.
Definition: MunRoomPlayerInfo.hpp:145
STREAM::KeyValue * GetParameters()
プレイヤーパラメータの取得.
Definition: MunRoomPlayerInfo.hpp:81
Union value
値情報.
Definition: MunStream.hpp:608
MunRoomPlayerInfo(MrsConnection connection=NULL, int32 id=0, std::string name="", uint32 clientUidForMasterServer=0, uint64 clientUidForProxyServer=0, uint64 roomId=0, STREAM::KeyValue *pParameters=NULL, uint16 parametersLen=0)
コンストラクタ.
Definition: MunRoomPlayerInfo.hpp:158
ログ管理.
int32 m_Id
プレイヤーID.
Definition: MunRoomPlayerInfo.hpp:24
uint64 m_RoomId
所属するルームID.
Definition: MunRoomPlayerInfo.hpp:42
void UpdateParameters(STREAM::KeyValue *pParameters, uint16 parametersLen)
プレイヤーパラメータの更新.
Definition: MunRoomPlayerInfo.hpp:106
std::string m_Name
プレイヤー名.
Definition: MunRoomPlayerInfo.hpp:27
uint64 m_clientUidForProxyServer
mun_proxyサーバ上のクライアント識別用ユニークID.
Definition: MunRoomPlayerInfo.hpp:39
uint32 GetClientIdForMasterServer()
mun_masterサーバ上のクライアント識別用ユニークIDの取得.
Definition: MunRoomPlayerInfo.hpp:133
1つのプレイヤーに対して設定可能な、プレイヤーカスタムパラメータの最大数.
Definition: MunStream.hpp:272
可変長テキスト.
Definition: MunStream.hpp:331
ルーム内プレイヤー情報クラス.
Definition: MunRoomPlayerInfo.hpp:17
uint16 GetParametersLen()
プレイヤーパラメータの登録数の取得.
Definition: MunRoomPlayerInfo.hpp:87