Exemplo n.º 1
0
        public bool InstanceCheck(ClientClass client, uint mapId)
        {
            if (!_clusterServiceLocator.WcNetwork.WorldServer.Worlds.ContainsKey(mapId))
            {
                // We don't create new continents
                if (_clusterServiceLocator.Functions.IsContinentMap((int)mapId))
                {
                    _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.WARNING, "[{0:000000}] Requested Instance Map [{1}] is a continent", client.Index, mapId);
                    client.Send(new PacketClass(Opcodes.SMSG_LOGOUT_COMPLETE));
                    new PacketClass(Opcodes.SMSG_LOGOUT_COMPLETE).Dispose();
                    client.Character.IsInWorld = false;
                    return(false);
                }

                _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.INFORMATION, "[{0:000000}] Requesting Instance Map [{1}]", client.Index, mapId);
                IWorld    parentMap     = default;
                WorldInfo parentMapInfo = null;

                // Check if we got parent map
                if (_clusterServiceLocator.WcNetwork.WorldServer.Worlds.ContainsKey((uint)_clusterServiceLocator.WsDbcDatabase.Maps[(int)mapId].ParentMap) && _clusterServiceLocator.WcNetwork.WorldServer.Worlds[(uint)_clusterServiceLocator.WsDbcDatabase.Maps[(int)mapId].ParentMap].InstanceCanCreate((int)_clusterServiceLocator.WsDbcDatabase.Maps[(int)mapId].Type))
                {
                    parentMap     = _clusterServiceLocator.WcNetwork.WorldServer.Worlds[(uint)_clusterServiceLocator.WsDbcDatabase.Maps[(int)mapId].ParentMap];
                    parentMapInfo = _clusterServiceLocator.WcNetwork.WorldServer.WorldsInfo[(uint)_clusterServiceLocator.WsDbcDatabase.Maps[(int)mapId].ParentMap];
                }
                else if (_clusterServiceLocator.WcNetwork.WorldServer.Worlds.ContainsKey(0U) && _clusterServiceLocator.WcNetwork.WorldServer.Worlds[0U].InstanceCanCreate((int)_clusterServiceLocator.WsDbcDatabase.Maps[(int)mapId].Type))
                {
                    parentMap     = _clusterServiceLocator.WcNetwork.WorldServer.Worlds[0U];
                    parentMapInfo = _clusterServiceLocator.WcNetwork.WorldServer.WorldsInfo[0U];
                }
                else if (_clusterServiceLocator.WcNetwork.WorldServer.Worlds.ContainsKey(1U) && _clusterServiceLocator.WcNetwork.WorldServer.Worlds[1U].InstanceCanCreate((int)_clusterServiceLocator.WsDbcDatabase.Maps[(int)mapId].Type))
                {
                    parentMap     = _clusterServiceLocator.WcNetwork.WorldServer.Worlds[1U];
                    parentMapInfo = _clusterServiceLocator.WcNetwork.WorldServer.WorldsInfo[1U];
                }

                if (parentMap is null)
                {
                    _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.WARNING, "[{0:000000}] Requested Instance Map [{1}] can't be loaded", client.Index, mapId);
                    client.Send(new PacketClass(Opcodes.SMSG_LOGOUT_COMPLETE));
                    new PacketClass(Opcodes.SMSG_LOGOUT_COMPLETE).Dispose();
                    client.Character.IsInWorld = false;
                    return(false);
                }

                if (parentMap.InstanceCreateAsync(mapId) != null)
                {
                    parentMap.InstanceCreateAsync(mapId).Wait();
                }

                lock (((ICollection)Worlds).SyncRoot)
                {
                    _clusterServiceLocator.WcNetwork.WorldServer.Worlds.Add(mapId, parentMap);
                    _clusterServiceLocator.WcNetwork.WorldServer.WorldsInfo.Add(mapId, parentMapInfo);
                }
                return(true);
            }

            return(true);
        }
Exemplo n.º 2
0
        public void OnPacket(PacketClass p)
        {
            if (_socket is null)
            {
                throw new ApplicationException("socket is Null!");
            }

            if (_clusterServiceLocator.WorldCluster.ClienTs is null)
            {
                throw new ApplicationException("Clients doesn't exist!");
            }

            if (_clusterServiceLocator.WorldCluster.GetPacketHandlers() is null)
            {
                throw new ApplicationException("PacketHandler is empty!");
            }

            ClientClass client = this;

            if (configurationProvider.GetConfiguration().PacketLogging)
            {
                ClientClass argclient = this;
                _clusterServiceLocator.Packets.LogPacket(p.Data, false, client);
            }

            if (!_clusterServiceLocator.WorldCluster.GetPacketHandlers().ContainsKey(p.OpCode))
            {
                if (Character is null || !Character.IsInWorld)
                {
                    _socket?.Dispose();
                    _socket?.Close();

                    _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.WARNING, "[{0}:{1}] Unknown Opcode 0x{2:X} [{2}], DataLen={4}", IP, Port, p.OpCode, Environment.NewLine, p.Length);
                    _clusterServiceLocator.Packets.DumpPacket(p.Data, client);
                }
                else
                {
                    try
                    {
                        Character.GetWorld.ClientPacket(Index, p.Data);
                    }
                    catch
                    {
                        _clusterServiceLocator.WcNetwork.WorldServer.Disconnect("NULL", new List <uint> {
                            Character.Map
                        });
                    }
                }
            }
Exemplo n.º 3
0
        public async Task <ITcpClient> CreateTcpClientAsync(Socket clientSocket)
        {
            var client = new Client();

            var clientClass = new ClientClass(
                client,
                clientSocket,
                _clusterServiceLocator,
                configurationProvider);

            await clientClass.OnConnectAsync();

            var clusterTcpClient = new ClusterTcpClient(
                logger,
                client,
                clientClass);

            return(clusterTcpClient);
        }
Exemplo n.º 4
0
 public ClusterTcpClient(ILogger logger, Client client, ClientClass clientClass)
 {
     this.logger      = logger;
     this.client      = client;
     this.clientClass = clientClass;
 }