Beispiel #1
0
 /// <summary>
 ///  ギャザリングを新規作成<br />
 ///    <br />
 ///    Player に指定する自身のプレイヤー情報のユーザIDは省略できます。<br />
 ///    expiresAtを指定することでギャザリングの有効期限を設定することができます。<br />
 ///    有効期限を用いない場合、古いギャザリングが残り続けマッチングが成立したときには、<br />
 ///    ユーザーがゲームから離脱している可能性があります。<br />
 ///    有効期限を用いる場合は、有効期限が来るたびにユーザーにギャザリングの再作成を促す仕組みにしてください。<br />
 /// </summary>
 ///
 /// <returns>IEnumerator</returns>
 /// <param name="callback">コールバックハンドラ</param>
 /// <param name="session">ゲームセッション</param>
 /// <param name="namespaceName">ネームスペース名</param>
 /// <param name="player">自身のプレイヤー情報</param>
 /// <param name="attributeRanges">募集条件</param>
 /// <param name="capacityOfRoles">参加者</param>
 /// <param name="allowUserIds">参加を許可するユーザIDリスト</param>
 /// <param name="expiresAt">ギャザリングの有効期限</param>
 public IEnumerator CreateGathering(
     UnityAction <AsyncResult <EzCreateGatheringResult> > callback,
     GameSession session,
     string namespaceName,
     EzPlayer player,
     List <EzCapacityOfRole> capacityOfRoles,
     List <string> allowUserIds,
     List <EzAttributeRange> attributeRanges = null,
     long?expiresAt = null
     )
 {
     yield return(_profile.Run(
                      callback,
                      session,
                      cb => _client.CreateGathering(
                          new CreateGatheringRequest()
                          .WithNamespaceName(namespaceName)
                          .WithPlayer(player.ToModel())
                          .WithAttributeRanges(attributeRanges != null ? attributeRanges.Select(item => item?.ToModel()).ToList() : new List <AttributeRange>(new AttributeRange[] {}))
                          .WithCapacityOfRoles(capacityOfRoles != null ? capacityOfRoles.Select(item => item?.ToModel()).ToList() : new List <CapacityOfRole>(new CapacityOfRole[] {}))
                          .WithAllowUserIds(allowUserIds)
                          .WithExpiresAt(expiresAt)
                          .WithAccessToken(session.AccessToken.token),
                          r => cb.Invoke(
                              new AsyncResult <EzCreateGatheringResult>(
                                  r.Result == null ? null : new EzCreateGatheringResult(r.Result),
                                  r.Error
                                  )
                              )
                          )
                      ));
 }
Beispiel #2
0
        public void OnLeavePlayer(LeavePlayer packet)
        {
            if (Player == null)
            {
                return;
            }

            lock (Sessions)
            {
                Sessions.Remove(this);

                if (Sessions.Count > 0)
                {
                    Sessions.Broadcast(new LeavePlayer()
                    {
                        RootPlayerId = Sessions.First().Player.PlayerId,

                        Player = Player
                    });
                }

                Console.Title = $"GSF.Ez,  {Sessions.Count} user(s) online";
            }

            var json = JsonConvert.SerializeObject(Player);

            File.WriteAllText("players\\" + Player.PlayerId, json);
            Player = null;
        }
Beispiel #3
0
 /// <summary>
 ///  すでに存在する中で、自分が参加できるギャザリングを探して参加<br />
 ///    <br />
 ///    一定時間 検索を行い、対象が見つからなかったときには `マッチメイキングの状態を保持するトークン` を返す。<br />
 ///    次回 `マッチメイキングの状態を保持するトークン` をつけて再度リクエストを出すことで、前回の続きから検索処理を再開できる。<br />
 ///    すべてのギャザリングを検索したが、参加できるギャザリングが存在しなかった場合はギャザリングもトークンもどちらも `null` が応答される。<br />
 /// </summary>
 ///
 /// <returns>IEnumerator</returns>
 /// <param name="callback">コールバックハンドラ</param>
 /// <param name="session">ゲームセッション</param>
 /// <param name="namespaceName">ネームスペース名</param>
 /// <param name="player">自身のプレイヤー情報</param>
 /// <param name="matchmakingContextToken">検索の再開に使用する マッチメイキングの状態を保持するトークン</param>
 public IEnumerator DoMatchmaking(
     UnityAction <AsyncResult <EzDoMatchmakingResult> > callback,
     GameSession session,
     string namespaceName,
     EzPlayer player,
     string matchmakingContextToken = null
     )
 {
     yield return(_profile.Run(
                      callback,
                      session,
                      cb => _client.DoMatchmaking(
                          new DoMatchmakingRequest()
                          .WithNamespaceName(namespaceName)
                          .WithPlayer(player.ToModel())
                          .WithMatchmakingContextToken(matchmakingContextToken)
                          .WithAccessToken(session.AccessToken.token),
                          r => cb.Invoke(
                              new AsyncResult <EzDoMatchmakingResult>(
                                  r.Result == null ? null : new EzDoMatchmakingResult(r.Result),
                                  r.Error
                                  )
                              )
                          )
                      ));
 }
Beispiel #4
0
    private void ProcessModifyPlayerProperty(ModifyPlayerProperty packet)
    {
        if (packet.Player.PlayerId == player.PlayerId)
        {
            return;
        }

        EzPlayer targetPlayer = null;

        lock (players)
            targetPlayer = players.Find(x => x.PlayerId == packet.Player.PlayerId);

        foreach (var pair in packet.Property)
        {
            targetPlayer.Property[pair.Key] = pair.Value;
        }
        if (packet.RemovedKeys != null)
        {
            foreach (var key in packet.RemovedKeys)
            {
                targetPlayer.Property.Remove(key);
            }
        }

        if (onModifyPlayerProperty != null)
        {
            AddTask(() => onModifyPlayerProperty.Invoke(packet));
        }
    }
Beispiel #5
0
        public void OnJoinPlayer(JoinPlayer packet)
        {
            var inputPlayer = packet.Player;

            if (File.Exists("players\\" + packet.Player.PlayerId))
            {
                var json = File.ReadAllText("players\\" + packet.Player.PlayerId);
                packet.Player = JsonConvert.DeserializeObject <EzPlayer>(json);

                foreach (var pair in inputPlayer.Property)
                {
                    packet.Player.Property[pair.Key] = pair.Value;
                }
            }

            lock (Sessions)
            {
                EzPlayer rootPlayer = null;

                if (Sessions.Count > 0)
                {
                    Sessions.Broadcast(packet);
                    rootPlayer = Sessions.First().Player;
                }
                else
                {
                    rootPlayer = packet.Player;
                }

                lock (WorldProperty)
                {
                    SendPacket(new WorldInfo()
                    {
                        RootPlayerId = rootPlayer.PlayerId,

                        Player       = packet.Player,
                        OtherPlayers = Sessions.Select(x => x.Player).ToArray(),
                        Property     = WorldProperty
                    });
                }

                Sessions.Add(this);

                Console.Title = $"GSF.Ez,  {Sessions.Count} user(s) online";
            }

            Player = packet.Player;
        }
Beispiel #6
0
    public void RemoteCall(EzPlayer player, string functionName, object[] args, Action <RespondRemoteCall> callback)
    {
        int packetId = Interlocked.Increment(ref nextPacketId);

        lock (responseCallbacks)
            responseCallbacks[packetId] = (p) => callback.Invoke((RespondRemoteCall)p);

        Send(new RequestRemoteCall()
        {
            PacketId = packetId,
            Player   = new EzPlayer()
            {
                PlayerId = player.PlayerId
            },
            FunctionName = functionName,
            Args         = args
        });
    }
Beispiel #7
0
    private void ProcessWorldInfo(WorldInfo packet)
    {
        rootPlayerId = packet.RootPlayerId;
        isRootPlayer = packet.RootPlayerId == packet.Player.PlayerId;

        players = new List <EzPlayer>(packet.OtherPlayers);
        player  = packet.Player;
        players.Add(player);
        worldProperty = packet.Property;

        if (onWorldInfo != null)
        {
            AddTask(() => onWorldInfo.Invoke(packet));
        }
        if (onDesignatedRootPlayer != null &&
            alreadyDesignated == false && player.PlayerId == rootPlayerId)
        {
            onDesignatedRootPlayer();
            alreadyDesignated = true;
        }
    }
Beispiel #8
0
 public void RemoteCall <T1, T2, T3>(EzPlayer player, string functionName, T1 a, T2 b, T3 c)
 {
     RemoteCall(player, functionName, new object[] { a, b, c });
 }
Beispiel #9
0
 public void RemoteCall <T1>(EzPlayer player, string functionName, T1 a)
 {
     RemoteCall(player, functionName, new object[] { a });
 }
Beispiel #10
0
 public void RemoteCall(EzPlayer player, string functionName, object[] args)
 {
     RemoteCall(player, functionName, args, _ => { });
 }
Beispiel #11
0
 public void RemoteCall <T1, T2, T3>(EzPlayer player, string functionName, T1 a, T2 b, T3 c, Action <RespondRemoteCall> callback)
 {
     RemoteCall(player, functionName, new object[] { a, b, c }, callback);
 }
Beispiel #12
0
 public void RemoteCall <T1>(EzPlayer player, string functionName, T1 a, Action <RespondRemoteCall> callback)
 {
     RemoteCall(player, functionName, new object[] { a }, callback);
 }