Example #1
0
        public void OnUpdateClusterWorldsList(IClusterCoreClient _, INetPacketStream packet)
        {
            int numberOfWorldServers = packet.Read <int>();

            _clusterServer.WorldServers.Clear();

            for (var i = 0; i < numberOfWorldServers; ++i)
            {
                int    serverId        = packet.Read <int>();
                string serverHost      = packet.Read <string>();
                string serverName      = packet.Read <string>();
                int    serverPort      = packet.Read <int>();
                int    parentClusterId = packet.Read <int>();

                if (parentClusterId != _clusterServer.ClusterConfiguration.Id)
                {
                    _logger.LogCritical($"Cannot add server '{serverName}' to current cluster. Ids doesn't match.");
                    continue;
                }

                var worldServer = new WorldServerInfo(serverId, serverName, serverHost, serverPort, parentClusterId);

                _clusterServer.WorldServers.Add(worldServer);
            }
        }
        protected override void Deserialize()
        {
            BinaryPacket.SetPosition(0);
            BinaryPacket.ReadByteArray(7);                                          //Offset
            unk         = BinaryPacket.ReadInt16();                                 //unk
            serverTime  = BinaryPacket.ReadInt64();                                 //Server time
            serverCount = BinaryPacket.ReadInt16();                                 //Channel count
            for (int serverId = 0; serverId < serverCount; ++serverId)
            {
                WorldServerInfo wsi = new WorldServerInfo();
                wsi.ChannelId = BinaryPacket.ReadInt16();                           //Channel ID
                wsi.Id        = BinaryPacket.ReadInt16();                           //Server ID
                Int16 unkValue = BinaryPacket.ReadInt16();                          //unk
                wsi.ChannelName = BinaryPacket.ReadString(62, Encoding.Unicode);    //Channel name
                wsi.ServerName  = BinaryPacket.ReadString(62, Encoding.Unicode);    //Server name

                BinaryPacket.ReadByte();                                            //unk
                wsi.ServerIp = BinaryPacket.ReadString(16, Encoding.ASCII);         //IP address
                BinaryPacket.ReadByte();                                            //unk
                BinaryPacket.ReadByteArray(84);                                     //unk
                wsi.ServerPort       = BinaryPacket.ReadInt16();                    //Server port
                wsi.PopulationStatus = BinaryPacket.ReadByte();                     //Population status (light, crowded, etc)
                wsi.IsPublic         = BinaryPacket.ReadByte();                     //Is publicly joinable
                BinaryPacket.ReadByte();                                            //unk
                wsi.CharacterCount       = BinaryPacket.ReadByte();                 //Number of character own by the player on this channel
                wsi.CharacterDeleteCount = BinaryPacket.ReadByte();                 //Number of character in delete state on this channel
                BinaryPacket.ReadInt16();                                           //unk
                wsi.RelogingDelayTime = BinaryPacket.ReadInt64();                   //Reloging time allowed
                wsi.LastLoginTime     = BinaryPacket.ReadInt64();                   //Last login time
                wsi.XpDropBonus       = BinaryPacket.ReadByte();                    //Wp ordrop bonus available
                BinaryPacket.ReadByteArray(13);                                     //unk
                wsi.Medal = BinaryPacket.ReadByte();                                //Medal
            }
        }
Example #3
0
        public WorldSocket(IGame program, WorldServerInfo serverInfo)
        {
            Game       = program;
            ServerInfo = serverInfo;

            SendLock = new object();
        }
Example #4
0
        public void OnGetPlayerList(IClusterClient client, GetPlayerListPacket packet)
        {
            WorldServerInfo selectedWorldServer = _clusterServer.GetWorldServerById(packet.ServerId);

            if (selectedWorldServer == null)
            {
                _logger.LogWarning($"Unable to get characters list for user '{packet.Username}' from {client.Socket.RemoteEndPoint}. " +
                                   "Reason: client requested the list on a not connected World server.");
                client.Disconnect();
                return;
            }

            DbUser dbUser = _database.Users.FirstOrDefault(x => x.Username == packet.Username);

            if (dbUser == null)
            {
                _logger.LogWarning($"[SECURITY] Unable to load character list for user '{packet.Username}' from {client.Socket.RemoteEndPoint}. " +
                                   "Reason: bad presented credentials compared to the database.");
                client.Disconnect();
                return;
            }

            IEnumerable <DbCharacter> userCharacters = GetCharacters(dbUser.Id);

            _clusterPacketFactory.SendPlayerList(client, packet.AuthenticationKey, userCharacters);
            _clusterPacketFactory.SendWorldAddress(client, selectedWorldServer.Host);

            if (_clusterServer.ClusterConfiguration.EnableLoginProtect)
            {
                _clusterPacketFactory.SendLoginNumPad(client, client.LoginProtectValue);
            }
        }
Example #5
0
 public void SetWordServerInfo(WorldServerInfo worldServerInfo)
 {
     if (this.WorldServerInfo != null)
     {
         throw new InvalidOperationException("Client world server info already set.");
     }
     this.WorldServerInfo = worldServerInfo;
 }
Example #6
0
        public AuthenticateServerPacket(IPacketStream packet)
        {
            byte id = 1;

            byte[] host           = packet.Read <byte>(4);
            string name           = packet.ReadString(32);
            int    buildVersion   = packet.Read <int>();
            ushort maxConnections = packet.Read <ushort>();

            WorldServerInfo = new WorldServerInfo(id, host, name, buildVersion, maxConnections);
        }
Example #7
0
        public void WorldServerConnected(WorldConfiguration config)
        {
            var worldInfo = new WorldServerInfo(
                (byte)_interServer.WorldServers.Count,
                IPAddress.Parse(config.Host).GetAddressBytes(),
                config.Name,
                config.BuildVersion,
                (ushort)config.MaximumNumberOfConnections);

            _interServer.AddWorldServer(worldInfo);
        }
Example #8
0
        public static void OnAuthenticateServer(ISClient client, IPacketStream packet)
        {
            byte id = 1;

            byte[] host           = packet.Read <byte>(4);
            string name           = packet.ReadString(32);
            int    buildVersion   = packet.Read <int>();
            ushort maxConnections = packet.Read <ushort>();

            WorldServerInfo world = new WorldServerInfo(id, host, name, buildVersion, maxConnections);

            client.SetWordServerInfo(world);
        }
Example #9
0
        public void PresentRealmList(WorldServerList worldServerList)
        {
            WorldServerInfo selectedServer = null;

            if (worldServerList.Count == 1)
            {
                selectedServer = worldServerList[0];
            }
            else
            {
                LogLine("\n\tName\tType\tPopulation");

                int index = 0;
                foreach (WorldServerInfo server in worldServerList)
                {
                    LogLine
                    (
                        string.Format("{0}\t{1}\t{2}\t{3}",
                                      index++,
                                      server.Name,
                                      server.Type,
                                      server.Population
                                      )
                    );
                }


                index = Settings.Default.RealmID;

                if (index == -1) // select a realm - default to the first realm if there is only one
                {
                    index = worldServerList.Count == 1 ? 0 : -1;
                }

                while (index > worldServerList.Count || index < 0)
                {
                    Log("Choose a realm:  ");
                    if (!int.TryParse(Console.ReadLine(), out index))
                    {
                        LogLine();
                    }
                }
                selectedServer = worldServerList[index];
            }

            Game.ConnectTo(selectedServer);
        }
Example #10
0
        public static void OnGetPlayerList(ClusterClient client, INetPacketStream packet)
        {
            var             pak                  = new GetPlayerListPacket(packet);
            var             clusterServer        = DependencyContainer.Instance.Resolve <IClusterServer>();
            var             clusterConfiguration = DependencyContainer.Instance.Resolve <ClusterConfiguration>();
            WorldServerInfo selectedWorldServer  = clusterServer.GetWorldServerById(pak.ServerId);

            // Check if asked World server is still connected.
            if (selectedWorldServer == null)
            {
                Logger.LogWarning($"Unable to get characters list for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                  "Reason: client requested the list on a not connected World server.");
                client.Disconnect();
                return;
            }

            DbUser dbUser = null;

            using (var database = DependencyContainer.Instance.Resolve <IDatabase>())
            {
                dbUser = database.Users.Get(x => x.Username.Equals(pak.Username, StringComparison.OrdinalIgnoreCase));
            }

            // Check if user exist.
            if (dbUser == null)
            {
                Logger.LogWarning($"[SECURITY] Unable to create new character for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                  "Reason: bad presented credentials compared to the database.");
                client.Disconnect();
                return;
            }

            Logger.LogDebug($"Send character list to user '{pak.Username}' from {client.RemoteEndPoint}.");

            IEnumerable <DbCharacter> userCharacters = dbUser.Characters.Where(x => !x.IsDeleted);

            ClusterPacketFactory.SendPlayerList(client, pak.AuthenticationKey, userCharacters);
            ClusterPacketFactory.SendWorldAddress(client, selectedWorldServer.Host);

            if (clusterConfiguration.EnableLoginProtect)
            {
                ClusterPacketFactory.SendLoginNumPad(client, client.LoginProtectValue);
            }
        }
Example #11
0
        public void ConnectTo(WorldServerInfo server)
        {
            if (socket is AuthSocket)
            {
                Key = ((AuthSocket)socket).Key;
            }

            socket.Dispose();

            socket = new WorldSocket(this, server);
            socket.InitHandlers();

            if (socket.Connect())
            {
                socket.Start();
            }
            else
            {
                Exit().Wait();
            }
        }
Example #12
0
        private void OnUpdateWorldServerList(NetPacketBase packet)
        {
            var worldServerCount = packet.Read <int>();

            for (int i = 0; i < worldServerCount; ++i)
            {
                var worldId               = packet.Read <int>();
                var worldIp               = packet.Read <string>();
                var worldName             = packet.Read <string>();
                var worldCapacity         = packet.Read <int>();
                var worldConnectedPlayers = packet.Read <int>();
                var worldServer           = new WorldServerInfo(
                    worldId,
                    this.clusterServer.ClusterConfiguration.ClusterId,
                    worldCapacity,
                    worldIp,
                    worldName,
                    worldConnectedPlayers);

                this.clusterServer.ConnectedWorldServers.Add(worldServer);
            }
        }
Example #13
0
 public void AddWorldServer(WorldServerInfo info)
 {
     _worlds.Add(info);
     _logger.LogInformation($"New world server {info.Name} connected.");
 }
Example #14
0
 public WorldSocket(IGame program, WorldServerInfo serverInfo)
 {
     Game       = program;
     ServerInfo = serverInfo;
 }
Example #15
0
        protected override void ChannelRead0(IChannelHandlerContext ctx, string msg)
        {
            if (msg == null)
            {
                throw new ArgumentNullException(nameof(msg));
            }

            Channel msgChannel;

            try
            {
                msgChannel = JsonConvert.DeserializeObject <Channel>(msg);
            }
            catch (Exception ex)
            {
                Logger.Log.Error(
                    string.Format(LogLanguage.Instance.GetMessageFromKey(LanguageKey.UNRECOGNIZED_MASTER_PACKET), ex));
                return;
            }

            if (!IsAuthenticated)
            {
                if (msgChannel.Password == Password)
                {
                    IsAuthenticated = true;
                    Logger.Log.Debug(string.Format(
                                         LogLanguage.Instance.GetMessageFromKey(LanguageKey.AUTHENTICATED_SUCCESS), _id.ToString()));

                    if (MasterClientListSingleton.Instance.WorldServers == null)
                    {
                        MasterClientListSingleton.Instance.WorldServers = new List <WorldServerInfo>();
                    }

                    try
                    {
                        _id = MasterClientListSingleton.Instance.WorldServers.Select(s => s.Id).Max() + 1;
                    }
                    catch
                    {
                        _id = 0;
                    }

                    var servtype = (ServerType)Enum.Parse(typeof(ServerType), msgChannel.ClientType.ToString());
                    if (servtype == ServerType.WorldServer)
                    {
                        var serv = new WorldServerInfo
                        {
                            Name = msgChannel.ClientName,
                            Host = msgChannel.Host,
                            Port = msgChannel.Port,
                            Id   = _id,
                            ConnectedAccountsLimit = msgChannel.ConnectedAccountsLimit,
                            WebApi = msgChannel.WebApi
                        };

                        MasterClientListSingleton.Instance.WorldServers.Add(serv);
                        msgChannel.ChannelId = _id;
                        WriteAsync(ctx, msgChannel);
                    }

                    ctx.Flush();
                }
                else
                {
                    ctx.CloseAsync();
                    Logger.Log.Error(
                        string.Format(LogLanguage.Instance.GetMessageFromKey(LanguageKey.AUTHENTICATED_ERROR)));
                }
            }
        }
Example #16
0
        public void OnAuthenticate(CoreServerClient client, INetPacketStream packet)
        {
            var id   = packet.Read <int>();
            var name = packet.Read <string>();
            var host = packet.Read <string>();
            var port = packet.Read <int>();
            var type = (ServerType)packet.Read <byte>();

            if (type == ServerType.Cluster)
            {
                if (_coreServer.HasCluster(id))
                {
                    _logger.LogWarning($"Cluster Server '{name}' incoming connection from {client.Socket.RemoteEndPoint} refused. Reason: An other Cluster server with id '{id}' is already connected.");
                    _corePacketFactory.SendAuthenticationResult(client, CoreAuthenticationResultType.FailedClusterExists);
                    _coreServer.DisconnectClient(client.Id);
                    return;
                }

                client.ServerInfo = new ClusterServerInfo(id, name, host, port);
                _logger.LogInformation($"Cluster server '{name}' connected to ISC server from {client.Socket.RemoteEndPoint}.");
            }
            else if (type == ServerType.World)
            {
                var parentClusterId = packet.Read <int>();

                CoreServerClient parentClusterServer = _coreServer.GetClusterServer(parentClusterId);

                if (parentClusterServer == null)
                {
                    _logger.LogWarning($"World server '{name}' incoming connection from {client.Socket.RemoteEndPoint} refused. Reason: Cluster server with id '{parentClusterId}' is not connected.");

                    _corePacketFactory.SendAuthenticationResult(client, CoreAuthenticationResultType.FailedNoCluster);
                    _coreServer.DisconnectClient(client.Id);
                    return;
                }

                if (_coreServer.HasWorld(parentClusterId, id))
                {
                    _logger.LogWarning($"World server '{name}' incoming connection from {client.Socket.RemoteEndPoint} refused. Reason: An other World server with id '{id}' is already connected to Cluster Server '{parentClusterServer.ServerInfo.Name}'.");
                    _corePacketFactory.SendAuthenticationResult(client, CoreAuthenticationResultType.FailedWorldExists);
                    _coreServer.DisconnectClient(client.Id);
                    return;
                }

                var cluster = parentClusterServer.ServerInfo as ClusterServerInfo;
                if (cluster is null)
                {
                    _logger.LogWarning($"World server '{name}' incoming connection from {client.Socket.RemoteEndPoint} refused. Reason: Parent cluster server is not a cluster server.");
                    return;
                }

                var worldInfo = new WorldServerInfo(id, name, host, port, parentClusterId);

                cluster.Worlds.Add(worldInfo);
                client.ServerInfo = worldInfo;
                _corePacketFactory.SendUpdateWorldList(parentClusterServer, cluster.Worlds);
                _logger.LogInformation($"World server '{name}' join cluster '{cluster.Name}' and is connected to ISC server from {client.Socket.RemoteEndPoint}.");
            }
            else
            {
                _logger.LogWarning($"Incoming core connection from {client.Socket.RemoteEndPoint} refused. Reason: server type is unknown.");
                _corePacketFactory.SendAuthenticationResult(client, CoreAuthenticationResultType.FailedUnknownServer);
                _coreServer.DisconnectClient(client.Id);
                return;
            }

            _corePacketFactory.SendAuthenticationResult(client, CoreAuthenticationResultType.Success);
        }
 public bool Compare(WorldServerInfo info)
 {
     return base.Compare(info) && Maps.Compare(info.Maps);
 }