Пример #1
0
        private void MakeProperties(INeutronMatchmaking matchmaking)
        {
            //* Gambiarra
            var props = matchmaking.Properties;

            matchmaking.Properties = props;
        }
Пример #2
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);
        }
Пример #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.
     }
 }
Пример #4
0
 public static void AddCache(int id, int viewId, NeutronStream.IWriter writer, NeutronPlayer player, CacheMode cache, CachedPacket cachedPacket)
 {
     //LogHelper.Error(ThreadHelper.GetThreadID());
     if (cache != CacheMode.None)
     {
         INeutronMatchmaking neutronMatchmaking = player.Matchmaking;
         if (neutronMatchmaking != null)
         {
             NeutronCache dataCache = new NeutronCache(id, writer.ToArray(), player, cachedPacket, cache);
             neutronMatchmaking.Add(dataCache, viewId);
         }
         else
         {
             LogHelper.Error("Cache: Matchmaking not found!");
         }
     }
 }
Пример #5
0
        public void OnNeutronRegister(NeutronPlayer player, bool isServer, Scene scene, MatchmakingMode mode, INeutronMatchmaking matchmaking, Neutron neutron)
        {
            if (!_isOriginalObject)
            {
                return;
            }

            #region Prevent Being Instantiated
            if (_hasMap)
            {
                if (!(mode == _matchmakingMode))
                {
                    return;
                }

                if (matchmaking.Get.ContainsKey(_mapKey))
                {
                    string mapName = matchmaking.Get[_mapKey].ToObject <string>();
                    if (!(mapName == _mapName))
                    {
                        return;
                    }
                    else /*continue;*/ } {
            }
            else
            {
                LogHelper.Info($"This scene object({_mapName} - {matchmaking.Name}) is not linked to a map, it will be instantiated in all scenes of the specified matchmaking.");
            }
        }
Пример #6
0
 public static NeutronPlayer MakeTheServerPlayer(NeutronChannel channel, NeutronRoom room, INeutronMatchmaking matchmaking)
 {
     return(new NeutronPlayer()
     {
         Nickname = "Server",
         Id = 0,
         Channel = channel,
         Room = room,
         Matchmaking = matchmaking,
     });
 }