Exemplo n.º 1
0
        //* sabe deus.
        public static bool RemovePlayerFromServer(NeutronPlayer player)
        {
            bool tryRemove = Neutron.Server.PlayersBySocket.TryRemove(player.TcpClient, out NeutronPlayer __) &&
                             Neutron.Server.PlayersById.TryRemove(player.Id, out NeutronPlayer _);

            if (tryRemove)
            {
                Neutron.Server._pooledIds.Push(player.Id);
                string addr = player.StateObject.TcpRemoteEndPoint.Address.ToString();
                if (Neutron.Server.RegisteredConnectionsByIp.TryGetValue(addr, out int value))
                {
                    Neutron.Server.RegisteredConnectionsByIp[addr] = --value;
                }
                MatchmakingHelper.Destroy(player);
                PlayerHelper.Disconnect(player, "Exited");
                if (player.IsInRoom())
                {
                    INeutronMatchmaking matchmaking = player.Matchmaking;
                    if (matchmaking != null)
                    {
                        //* Sai da sala.
                        if (matchmaking.Remove(player))
                        {
                            MatchmakingHelper.Internal.Leave(player, MatchmakingMode.Room);
                        }
                        //* Sai do canal.
                        if (player.IsInChannel())
                        {
                            matchmaking = player.Matchmaking;
                            if (matchmaking.Remove(player))
                            {
                                MatchmakingHelper.Internal.Leave(player, MatchmakingMode.Channel);
                            }
                        }
                    }
                    else
                    {
                        LogHelper.Error("Leave: Matchmaking not found!");
                    }
                }
                else
                {
                    //* Sai do canal.
                    INeutronMatchmaking matchmaking = player.Matchmaking;
                    if (matchmaking != null)
                    {
                        if (matchmaking.Remove(player))
                        {
                            MatchmakingHelper.Internal.Leave(player, MatchmakingMode.Channel);
                        }
                    }
                }
                Interlocked.Decrement(ref Neutron.Server._playerCount);
            }
            else
            {
                LogHelper.Error("Failed to remove player from server!");
            }
            return(tryRemove);
        }
Exemplo n.º 2
0
        private CreateMatchmakingTicketRequest GetCreateRequest(MatchmakingPlayerAttributes attributes)
        {
            var request = new CreateMatchmakingTicketRequest
            {
                Creator               = MatchmakingHelper.GetMatchmakingPlayer(Player, attributes),
                GiveUpAfterSeconds    = QueueConfiguration.GiveUpAfterSeconds,
                QueueName             = QueueConfiguration.QueueName,
                AuthenticationContext = PlayFabAuthenticationContext
            };

            return(request);
        }
Exemplo n.º 3
0
 private void MakeVirtualOwner(INeutronMatchmaking matchmaking, NeutronChannel channel, NeutronRoom room)
 {
     if (matchmaking.Owner != null)
     {
         LogHelper.Error("Matchmaking already has an owner!");
     }
     else
     {
         //* Não pode aproveitar o Neutron.Server.Player? não, não podemos compartilhar a mesma instância pra vários matchmaking, um jogador só pode está em um Matchmaking ao mesmo tempo.
         NeutronPlayer player = PlayerHelper.MakeTheServerPlayer();
         player.Channel     = channel;
         player.Room        = room;
         player.Matchmaking = MatchmakingHelper.Matchmaking(player);
         matchmaking.Owner  = player; //! reforço: um jogador só pode está em um Matchmaking ao mesmo tempo.
     }
 }