/**
* Copyright 2018 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Nakama
{
using System;
using System.Runtime.Serialization;
///
/// Some game state update in a match.
///
public interface IMatchState
{
///
/// The unique match identifier.
///
string MatchId { get; }
///
/// The operation code for the state change.
///
///
/// This value can be used to mark the type of the contents of the state.
///
long OpCode { get; }
///
/// The byte contents of the state change.
///
byte[] State { get; }
///
/// Information on the user who sent the state change.
///
IUserPresence UserPresence { get; }
}
///
internal class MatchState : IMatchState
{
[DataMember(Name="match_id")]
public string MatchId { get; set; }
public long OpCode => System.Convert.ToInt64(_opCode);
[DataMember(Name="op_code")]
public string _opCode { get; set; }
public byte[] State => Convert.FromBase64String(_state);
[DataMember(Name="data")]
public string _state { get; set; }
public IUserPresence UserPresence => _userPresence;
[DataMember(Name="presence")]
public UserPresence _userPresence { get; set; }
///
public override string ToString()
{
var presences = string.Join(", ", UserPresence);
return $"MatchState(MatchId={MatchId}, OpCode={OpCode}, State={State}, UserPresence={presences})";
}
}
}