Ejemplo n.º 1
0
        public NetworkManager(string ipAddress, int port, Type packetHandler, Type fallbackEncryptor, bool isWorldServer) : base(packetHandler, isWorldServer)
        {
            _encryptor = (EncryptorT)Activator.CreateInstance(typeof(EncryptorT));

            if (fallbackEncryptor != null)
            {
                _fallbackEncryptor = (CryptographyBase)Activator.CreateInstance(fallbackEncryptor);
            }

            _server = ScsServerFactory.CreateServer(new ScsTcpEndPoint(ipAddress, port));

            // Register events of the server to be informed about clients
            _server.ClientConnected    += OnServerClientConnected;
            _server.ClientDisconnected += OnServerClientDisconnected;
            _server.WireProtocolFactory = new WireProtocolFactory <EncryptorT>();

            // Start the server
            _server.Start();

            if (port == 4002)
            {
                Console.WriteLine("[Start] Login Server has been started successfully");
                Console.WriteLine($"[Info] Started at: {DateTime.Now}");
            }

            if (isWorldServer)
            {
                Console.WriteLine($"[Start] World Server has been started successfully");
                Console.WriteLine($"[Info] Started at: {DateTime.Now}");
            }
            ;
        }
Ejemplo n.º 2
0
        public NetworkManager(string ipAddress, int port, Type packetHandler, Type fallbackEncryptor, bool isWorldServer) : base(packetHandler, isWorldServer)
        {
            _encryptor = (EncryptorT)Activator.CreateInstance(typeof(EncryptorT));

            if (fallbackEncryptor != null)
            {
                _fallbackEncryptor = (CryptographyBase)Activator.CreateInstance(fallbackEncryptor);
            }

            _server = ScsServerFactory.CreateServer(new ScsTcpEndPoint(ipAddress, port));

            // Register events of the server to be informed about clients
            _server.ClientConnected    += OnServerClientConnected;
            _server.ClientDisconnected += OnServerClientDisconnected;
            _server.WireProtocolFactory = new WireProtocolFactory <EncryptorT>();

            // Start the server
            _server.Start();

            Logger.Info(Language.Instance.GetMessageFromKey("STARTED"), memberName: "NetworkManager");
        }
        private void ExecuteHandler(ClientSession session)
        {
            if (session.HasCurrentMapInstance)
            {
                return;
            }

            AccountDTO account = DAOFactory.AccountDAO.LoadById(session.Account.AccountId);

            if (account == null)
            {
                return;
            }

            if (account.Password.ToLower() == CryptographyBase.Sha512(Password))
            {
                CharacterDTO character =
                    DAOFactory.CharacterDAO.LoadBySlot(account.AccountId, Slot);
                if (character == null)
                {
                    return;
                }

                GameLogger.Instance.LogCharacterDeletion(ServerManager.Instance.ChannelId, session.Account.Name,
                                                         session.Account.AccountId, character);

                // this was removed. propably baguettes idea, idk.
                //DAOFactory.GeneralLogDAO.SetCharIdNull(Convert.ToInt64(character.CharacterId));
                DAOFactory.CharacterDAO.DeleteByPrimaryKey(account.AccountId, Slot);
                EntryPointPacket.HandlePacket(session, string.Empty);
            }
            else
            {
                session.SendPacket($"info {Language.Instance.GetMessageFromKey("BAD_PASSWORD")}");
            }
        }
Ejemplo n.º 4
0
        private void ExecuteHandler(ClientSession session)
        {
            string BuildServersPacket(string username, int sessionId, bool ignoreUserName)
            {
                string channelPacket = CommunicationServiceClient.Instance.RetrieveRegisteredWorldServers(username, sessionId, ignoreUserName);

                if (channelPacket?.Contains(':') != true)
                {
                    // no need for this as in release the debug is ignored eitherway
                    //if (ServerManager.Instance.IsDebugMode)
                    Logger.Debug("Could not retrieve Worldserver groups. Please make sure they've already been registered.");

                    // find a new way to display this message
                    //Session.SendPacket($"fail {Language.Instance.GetMessageFromKey("NO_WORLDSERVERS")}");
                    session.SendPacket($"fail {Language.Instance.GetMessageFromKey("IDERROR")}");
                }

                return(channelPacket);
            }

            UserDTO user = new UserDTO
            {
                Name     = Name,
                Password = ConfigurationManager.AppSettings["UseOldCrypto"] == "true" ? CryptographyBase.Sha512(LoginCryptography.GetPassword(Password)).ToUpper() : Password
            };
            AccountDTO loadedAccount = DAOFactory.AccountDAO.LoadByName(user.Name);

            if (loadedAccount?.Password.ToUpper().Equals(user.Password) == true)
            {
                string ipAddress = session.IpAddress;
                DAOFactory.AccountDAO.WriteGeneralLog(loadedAccount.AccountId, ipAddress, null, GeneralLogType.Connection, "LoginServer");

                //check if the account is connected
                if (!CommunicationServiceClient.Instance.IsAccountConnected(loadedAccount.AccountId))
                {
                    AuthorityType type    = loadedAccount.Authority;
                    PenaltyLogDTO penalty = DAOFactory.PenaltyLogDAO.LoadByAccount(loadedAccount.AccountId).FirstOrDefault(s => s.DateEnd > DateTime.UtcNow && s.Penalty == PenaltyType.Banned);
                    if (penalty != null)
                    {
                        // find a new way to display date of ban
                        session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("BANNED"), penalty.Reason, penalty.DateEnd.ToString("yyyy-MM-dd-HH:mm"))}");;
                    }
                    else
                    {
                        switch (type)
                        {
                        case AuthorityType.Unconfirmed:
                        {
                            session.SendPacket($"fail {Language.Instance.GetMessageFromKey("NOTVALIDATE")}");
                        }
                        break;

                        case AuthorityType.Banned:
                        {
                            session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("BANNED"), penalty.Reason, penalty.DateEnd.ToString("yyyy-MM-dd-HH:mm"))}");;
                        }
                        break;

                        case AuthorityType.Closed:
                        {
                            session.SendPacket($"fail {Language.Instance.GetMessageFromKey("IDERROR")}");
                        }
                        break;

                        default:
                        {
                            if (loadedAccount.Authority == AuthorityType.User || loadedAccount.Authority == AuthorityType.BitchNiggerFaggot)
                            {
                                MaintenanceLogDTO maintenanceLog = DAOFactory.MaintenanceLogDAO.LoadFirst();
                                if (maintenanceLog != null)
                                {
                                    // find a new way to display date and reason of maintenance
                                    session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("MAINTENANCE"), maintenanceLog.DateEnd, maintenanceLog.Reason)}");
                                    return;
                                }
                            }

                            int newSessionId = SessionFactory.Instance.GenerateSessionId();
                            Logger.Debug(string.Format(Language.Instance.GetMessageFromKey("CONNECTION"), user.Name, newSessionId));
                            try
                            {
                                ipAddress = ipAddress.Substring(6, ipAddress.LastIndexOf(':') - 6);
                                CommunicationServiceClient.Instance.RegisterAccountLogin(loadedAccount.AccountId, newSessionId, ipAddress);
                            }
                            catch (Exception ex)
                            {
                                Logger.Error("General Error SessionId: " + newSessionId, ex);
                            }
                            string[] clientData     = ClientData.Split('.');
                            bool     ignoreUserName = clientData.Length < 3 ? false : short.TryParse(clientData[3], out short clientVersion) && (clientVersion < 3075 || ConfigurationManager.AppSettings["UseOldCrypto"] == "true");
                            session.SendPacket(BuildServersPacket(user.Name, newSessionId, ignoreUserName));
                        }
                        break;
                        }
                    }
                }
                else
                {
                    session.SendPacket($"fail {Language.Instance.GetMessageFromKey("ALREADY_CONNECTED")}");
                }
            }
            else
            {
                session.SendPacket($"fail {Language.Instance.GetMessageFromKey("IDERROR")}");
            }
        }
Ejemplo n.º 5
0
 public void Initialize(CryptographyBase encryptor) => _encryptor = encryptor;
        private void ExecuteHandler(ClientSession session, string packet)
        {
            string[] loginPacketParts   = packet.Split(' ');
            bool     isCrossServerLogin = false;

            // Load account by given SessionId
            if (session.Account == null)
            {
                bool       hasRegisteredAccountLogin = true;
                AccountDTO account = null;
                if (loginPacketParts.Length > 4)
                {
                    if (loginPacketParts.Length > 7 && loginPacketParts[4] == "DAC" &&
                        loginPacketParts[8] == "CrossServerAuthenticate")
                    {
                        isCrossServerLogin = true;
                        account            = DAOFactory.AccountDAO.LoadByName(loginPacketParts[5]);
                    }
                    else
                    {
                        account = DAOFactory.AccountDAO.LoadByName(loginPacketParts[4]);
                    }
                }

                try
                {
                    if (account != null)
                    {
                        if (isCrossServerLogin)
                        {
                            hasRegisteredAccountLogin =
                                CommunicationServiceClient.Instance.IsCrossServerLoginPermitted(account.AccountId,
                                                                                                session.SessionId);
                        }
                        else
                        {
                            hasRegisteredAccountLogin =
                                CommunicationServiceClient.Instance.IsLoginPermitted(account.AccountId,
                                                                                     session.SessionId);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("MS Communication Failed.", ex);
                    session.Disconnect();
                    return;
                }

                if (loginPacketParts.Length > 4 && hasRegisteredAccountLogin)
                {
                    if (account != null)
                    {
                        if (account.Password.ToLower().Equals(CryptographyBase.Sha512(loginPacketParts[6])) ||
                            isCrossServerLogin)
                        {
                            session.InitializeAccount(new Account(account), isCrossServerLogin);
                            ServerManager.Instance.CharacterScreenSessions[session.Account.AccountId] = session;
                        }
                        else
                        {
                            Logger.Debug($"Client {session.ClientId} forced Disconnection, invalid Password.");
                            session.Disconnect();
                            return;
                        }
                    }
                    else
                    {
                        Logger.Debug($"Client {session.ClientId} forced Disconnection, invalid AccountName.");
                        session.Disconnect();
                        return;
                    }
                }
                else
                {
                    Logger.Debug($"Client {session.ClientId} forced Disconnection, login has not been registered or Account is already logged in.");
                    session.Disconnect();
                    return;
                }
            }

            if (isCrossServerLogin)
            {
                if (byte.TryParse(loginPacketParts[6], out byte slot))
                {
                    SelectPacket.HandlePacket(session, $"1 select {slot}");
                }
            }
            else
            {
                IEnumerable <CharacterDTO> characters = DAOFactory.CharacterDAO.LoadByAccount(session.Account.AccountId);
                Logger.Info(string.Format(Language.Instance.GetMessageFromKey("ACCOUNT_ARRIVED"), session.SessionId));

                // load characterlist packet for each character in CharacterDTO
                session.SendPacket("clist_start 0");
                foreach (CharacterDTO character in characters)
                {
                    IEnumerable <ItemInstanceDTO> inventory =
                        DAOFactory.ItemInstanceDAO.LoadByType(character.CharacterId, InventoryType.Wear);

                    ItemInstance[] equipment = new ItemInstance[16];
                    foreach (ItemInstanceDTO equipmentEntry in inventory)
                    {
                        // explicit load of iteminstance
                        ItemInstance currentInstance = new ItemInstance(equipmentEntry);
                        if (currentInstance != null)
                        {
                            equipment[(short)currentInstance.Item.EquipmentSlot] = currentInstance;
                        }
                    }

                    string         petlist = string.Empty;
                    List <MateDTO> mates   = DAOFactory.MateDAO.LoadByCharacterId(character.CharacterId).ToList();
                    for (int i = 0; i < 26; i++)
                    {
                        //0.2105.1102.319.0.632.0.333.0.318.0.317.0.9.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1
                        petlist += (i != 0 ? "." : string.Empty) + (mates.Count > i ? $"{mates[i].Skin}.{mates[i].NpcMonsterVNum}" : "-1");
                    }

                    // 1 1 before long string of -1.-1 = act completion
                    session.SendPacket($"clist {character.Slot} {character.Name} 0 {(byte)character.Gender} {(byte)character.HairStyle} {(byte)character.HairColor} 0 {(byte)character.Class} {character.Level} {character.HeroLevel} {equipment[(byte)EquipmentType.Hat]?.ItemVNum ?? -1}.{equipment[(byte)EquipmentType.Armor]?.ItemVNum ?? -1}.{equipment[(byte)EquipmentType.WeaponSkin]?.ItemVNum ?? (equipment[(byte)EquipmentType.MainWeapon]?.ItemVNum ?? -1)}.{equipment[(byte)EquipmentType.SecondaryWeapon]?.ItemVNum ?? -1}.{equipment[(byte)EquipmentType.Mask]?.ItemVNum ?? -1}.{equipment[(byte)EquipmentType.Fairy]?.ItemVNum ?? -1}.{equipment[(byte)EquipmentType.CostumeSuit]?.ItemVNum ?? -1}.{equipment[(byte)EquipmentType.CostumeHat]?.ItemVNum ?? -1} {character.JobLevel}  1 1 {petlist} {(equipment[(byte)EquipmentType.Hat]?.Item.IsColored == true ? equipment[(byte)EquipmentType.Hat].Design : 0)} 0");
                }

                session.SendPacket("clist_end");
            }
        }