示例#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);
        }
示例#2
0
            public static NeutronPlayer[] GetPlayersByMatchmakingTo(NeutronPlayer player, MatchmakingTo matchmakingTo)
            {
                switch (matchmakingTo)
                {
                case MatchmakingTo.Me:
                    return(null);

                case MatchmakingTo.Server:
                {
                    return(Neutron.Server.PlayersBySocket.Values.ToArray());
                }

                case MatchmakingTo.Channel:
                {
                    if (player.IsInChannel())
                    {
                        return(player.Channel.Players());
                    }
                    else
                    {
                        LogHelper.Error("Failed to direct packet, channel not found. Join a channel before sending the packet.");
                    }
                    return(default);
                }