public static void HandleCheckUserLimit(Client pClient, Packet pPacket)
        {
            if (pClient.Account.LoggedIn != 1) return;

            byte WorldId = pPacket.ReadByte();

            if (Master.Instance.Worlds[WorldId] == null)
            {
                pClient.Session.Disconnect();
                return;
            }

            int CurrentLoad = Master.Instance.Worlds[WorldId].CurrentLoad;

            if (CurrentLoad >= 100)
            { // TODO: Max players.
                pClient.SendPacket(LoginPacket.UserLimitResult(2));
            }
            else if (CurrentLoad * 2 >= 100)
            {
                pClient.SendPacket(LoginPacket.UserLimitResult(1));
            }
            else
            {
                pClient.SendPacket(LoginPacket.UserLimitResult(0));
            }
        }
Exemple #2
0
        public void OnClientAccepted(object sender, SocketEventArgs e)
        {
            Console.WriteLine("[{0}] Accepted connection from {1}.", "Login", e.Socket.RemoteEndPoint.ToString());
            Client Client = new Client(e.Socket, 0, 0, "Login");

            Client.SessionId = Randomizer.NextLong();

            Client.SendHandshake(Constants.MajorVersion, Constants.MinorVersion, Constants.Locale);

            Clients.Add(Client);
        }
        public static void HandleEnterCS(Client pClient, Packet pPacket)
        {
            int CharacterId = pClient.Character.Id;
            long SessionId = pClient.SessionId;

            pClient.Character.Save();

            Master.Instance.Worlds[pClient.World].AddMigrationRequest(CharacterId, SessionId, true);

            pClient.SendPacket(GeneralPacket.ChangeChannel(pClient, Master.Instance.CashShop.Port));
        }
        public static void HandleCheckNameDuplicate(Client pClient, Packet pPacket)
        {
            if (pClient.Account.LoggedIn != 1) return;

            string Name = pPacket.ReadMapleString();

            if (Master.Instance.Accessor.NameAvailable(Name))
                pClient.SendPacket(LoginPacket.CheckNameResult(Name, false));
            else
                pClient.SendPacket(LoginPacket.CheckNameResult(Name, true));
        }
        public static void HandleChannelChange(Client pClient, Packet pPacket)
        {
            byte ChannelId = pPacket.ReadByte();
            int CharacterId = pClient.Character.Id;
            long SessionId = pClient.SessionId;

            pClient.Character.Save();

            Master.Instance.Worlds[pClient.World].AddMigrationRequest(CharacterId, SessionId, false);

            pClient.SendPacket(GeneralPacket.ChangeChannel(pClient, Master.Instance.Worlds[pClient.World].Channels[ChannelId].Port));
        }
        public static void HandleValidate(Client pClient, Packet pPacket)
        {
            byte Locale = pPacket.ReadByte();
            short Major = pPacket.ReadShort();
            short Minor = pPacket.ReadShort();

            Console.WriteLine("Handshake received, Locale: {0}, Major: {1}, Minor: {2}.", Locale, Major, Minor);

            //if (Locale != 8 || Major != 141 || Minor != 2)
            //{
            //    pClient.Disconnect();
            //}
        }
Exemple #7
0
        public void OnPacketInbound(Client pClient, Packet pPacket)
        {
            byte Header = pPacket.ReadByte();

            PacketHandler Handler = Processor[Header];

            if (Handler != null)
            {
                Console.WriteLine("[{0}] Handling 0x{1:X4} with {2}.", "Login", Header.ToString("X"), Handler.Method.Name);
                Handler(pClient, pPacket);
            }
            else
            {
                Console.WriteLine("[{0}] Unhandled 0x{1:X4} from {2}.", "Login", Header.ToString("X"), pClient.IP);
                Console.WriteLine("Full packet: " + pPacket.ToString());
            }
        }
        public static void HandleMigration(Client pClient, Packet pPacket)
        {
            int CharacterId = pPacket.ReadInt();
            pPacket.Skip(18);
            long SessionId = pPacket.ReadLong();

            if (Master.Instance.Worlds[pClient.World].EligableMigration(CharacterId, SessionId, false))
            {
                pClient.SessionId = SessionId;

                pClient.Character = Master.Instance.Accessor.GetCharacter(CharacterId);
                pClient.Account = Master.Instance.Accessor.GetAccount(pClient.Character.AccountId);

                if (pClient.Character.Id != CharacterId)
                {
                    pClient.Session.Disconnect();
                    return;
                }

                pClient.Character.Client = pClient;

                if (pClient.Account.LoggedIn == 2)
                {
                    pClient.Session.Disconnect();
                    return;
                }

                pClient.Account.LoggedIn = 2;

                if (Master.Instance.Worlds[pClient.World].CashShopMigration(pClient.Character.Id))
                {
                    CashShopHandler.HandleEnter(pClient, pPacket);
                }
                else
                {
                    pClient.SendPacket(MapPacket.EnterFieldNew(pClient.Character));
                    Master.Instance.Worlds[pClient.World].Channels[pClient.Channel].Maps[pClient.Character.MapId].AddPlayer(pClient.Character);
                }
            }
            else
            {
                Console.WriteLine("[{0}] Migration failed.", pClient.Session.IP);
            }
        }
Exemple #9
0
        public void OnClientDisconnected(Client pClient)
        {
            Console.WriteLine("[{0}] Lost connection from {1}.", Constants.WorldNames[this.Id] + " Channel " +this.Id, pClient.IP);

            if (pClient.Character != null)
            {
                if (pClient.Character.CurrentMap.Characters.Contains(pClient.Character))
                    pClient.Character.CurrentMap.RemovePlayer(pClient.Character);

                pClient.Character.Save();
            }

            if (pClient.Account != null)
                pClient.Account.Save();

            Clients.Remove(pClient);
            pClient = null;
        }
        private static void MigrateClient(Client pClient, int pCharacterId)
        {
            int Count = pClient.Account.Characters.Count((Character) => Character.Id == pCharacterId);

            if (Count != 1)
            {
                pClient.Session.Disconnect();
                return;
            }

            byte[] IP = new byte[] { 8, 31, 99, 141 };
            ushort Port = Master.Instance.Worlds[pClient.World].Channels[pClient.Channel].Port;

            Master.Instance.Worlds[pClient.World].AddMigrationRequest(pCharacterId, pClient.SessionId,false);

            pClient.SendPacket(LoginPacket.Migrate(IP, Port, pCharacterId));
        }
        public static void HandleWorldsRequest(Client pClient, Packet pPacket)
        {
            if (pClient.Account.Characters.Count > 0)
            {
                pClient.Account.Characters.Clear();
            }

            foreach (World World in Master.Instance.Worlds)
            {
                var Loads = World.GetChannelLoads();

                pClient.SendPacket(LoginPacket.Worldlist(World, Loads));
            }

            pClient.SendPacket(LoginPacket.WorldlistEnd());
        }
        public static void HandleWorldSelect(Client pClient, Packet pPacket)
        {
            if (pClient.Account.LoggedIn != 1) return;

            pPacket.Skip(1);

            pClient.World = pPacket.ReadByte();
            pClient.Channel = pPacket.ReadByte();

            pClient.Account.WorldId = pClient.World;
            pClient.Account.ChannelId = pClient.Channel;

            if (Master.Instance.Worlds[pClient.World] == null || Master.Instance.Worlds[pClient.World].Channels[pClient.Channel] == null)
            {
                pClient.Session.Disconnect();
                return;
            }

            if (pClient.Account.Characters.Count == 0)
            {
                pClient.Account.LoadCharacters();

                foreach (Character Character in pClient.Account.Characters)
                {
                    if (!Character.Loaded)
                        Character.Load();
                }
            }

            pClient.SendPacket(LoginPacket.WorldSelectResult(pClient));
        }
        public static void HandleStart(Client pClient, Packet pPacket)
        {
            //pClient.Account = new Account();
            //pClient.Account.Username = "******";
            //pClient.Account.LoggedIn = 1;
            //pClient.Account.Load();

            //pClient.SendPacket(LoginPacket.Login(pClient, pClient.SessionId));
        }
        public static void HandleSelectCharacter(Client pClient, Packet pPacket)
        {
            if (pClient.Account.LoggedIn != 1) return;

            int CharacterId = pPacket.ReadInt();

            MigrateClient(pClient, CharacterId);
        }
        public static void HandleLogin(Client pClient, Packet pPacket)
        {
            string Username = pPacket.ReadMapleString().Trim();
            string Password = pPacket.ReadMapleString();

            pClient.Account = new Account();
            pClient.Account.Username = Username;
            pClient.Account.Load();

            if (pClient.Account != null)
            {
                pClient.Account.LoggedIn = 1;
                pClient.SendPacket(LoginPacket.Login(pClient, pClient.SessionId));
            }
            else
            {
                pClient.SendPacket(LoginPacket.LoginStatus(1));
            }
        }
Exemple #16
0
 public void OnClientDisconnected(Client pClient)
 {
     Console.WriteLine("[{0}] Lost connection from {1}.", "Login", pClient.IP);
     Clients.Remove(pClient);
     pClient = null;
 }
Exemple #17
0
 public bool Contains(Client pClient)
 {
     return Clients.Contains(pClient);
 }
Exemple #18
0
        private void OnClientAccepted(object sender, SocketEventArgs e)
        {
            Console.WriteLine("[{0}] Accepted connection from {1}.", Constants.WorldNames[this.Id] + " Channel " + this.Id, e.Socket.RemoteEndPoint.ToString());
            Client Client = new Client(e.Socket, WorldId, Id, "Channel");

            Client.SendHandshake(Constants.MajorVersion, Constants.MinorVersion, Constants.Locale);

            Clients.Add(Client);
        }
Exemple #19
0
        public void OnPacketInbound(Client pClient, Packet pPacket)
        {
            byte Header = pPacket.ReadByte();

            PacketHandler Handler = Processor[Header];

            if (Handler != null)
            {
                Console.WriteLine("[{0}] Handling 0x{1:X4} with {2}.", Constants.WorldNames[WorldId] + " Channel " + this.Id, Header.ToString("X"), Handler.Method.Name);
                Handler(pClient, pPacket);
            }
            else
            {
                Console.WriteLine("[{0}] Unhandled 0x{1:X4} from {2}.", Constants.WorldNames[WorldId] + " Channel " + this.Id, Header.ToString("X"), pClient.IP);
            }
        }
        public static void HandleCreateCharacter(Client pClient, Packet pPacket)
        {
            if (pClient.Account.LoggedIn != 1) { return; }

            List<Equip> equips = new List<Equip>();

            string name = pPacket.ReadMapleString();
            pPacket.ReadInt();

            int startMap = 0;

            int jobType = pPacket.ReadInt();
            short jobSubtype = pPacket.ReadShort();
            byte gender = pPacket.ReadByte();
            byte skin = pPacket.ReadByte();
            pPacket.ReadByte();
            int face = pPacket.ReadInt();
            int hair = pPacket.ReadInt();
            int hairColor = -1, faceMark = -1, topId, bottomId = -1, capeId = -1, shoesId, weaponId, shieldId = -1;

            if (Constants.CharacterCreation.hasHairColor(jobType))
                hairColor = pPacket.ReadInt();
            if (Constants.CharacterCreation.hasSkinColor(jobType))
                pPacket.ReadInt();
            if (Constants.CharacterCreation.hasFaceMark(jobType))
                faceMark = pPacket.ReadInt();
            if (Constants.CharacterCreation.hasHat(jobType))
            {
                int capId = pPacket.ReadInt();
                Equip cap = new Equip();
                cap.ItemID = capId;
                cap.GiveStats(false);
                cap.InventorySlot = -1;

                equips.Add(cap);
            }
            topId = pPacket.ReadInt();
            Equip top = new Equip();
            top.ItemID = topId;
            top.GiveStats(false);
            top.InventorySlot = -5;

            equips.Add(top);
            if (Constants.CharacterCreation.hasBottom(jobType))
            {
                bottomId = pPacket.ReadInt();
                Equip bottom = new Equip();
                bottom.ItemID = bottomId;
                bottom.GiveStats(false);
                bottom.InventorySlot = -6;

                equips.Add(bottom);
            }
            if (Constants.CharacterCreation.hasCape(jobType))
            {
                capeId = pPacket.ReadInt();
                Equip cape = new Equip();
                cape.ItemID = capeId;
                cape.GiveStats(false);
                cape.InventorySlot = -9;

                equips.Add(cape);
            }
            shoesId = pPacket.ReadInt();
            Equip shoes = new Equip();
            shoes.ItemID = shoesId;
            shoes.GiveStats(false);
            shoes.InventorySlot = -7;

            equips.Add(shoes);
            weaponId = pPacket.ReadInt();
            Equip weapon = new Equip();
            weapon.ItemID = weaponId;
            weapon.GiveStats(false);
            weapon.InventorySlot = -11;

            equips.Add(weapon);
            if (jobType == (int)Constants.CharacterCreation.CreateTypes.Demon)
            {
                shieldId = pPacket.ReadInt();
                Equip shield = new Equip();
                shield.ItemID = shieldId;
                shield.GiveStats(false);
                shield.InventorySlot = -10;

                equips.Add(shield);
            }
            Character newChr = new Character();

            newChr.Client = pClient;
            newChr.AccountId = pClient.Account.Id;
            newChr.WorldId = pClient.World;

            newChr.Name = name;

            newChr.MapId = Constants.CharacterCreation.GetMapByType(jobType);
            if (hairColor < 0) hairColor = 0;
            if (jobType != (short)Constants.CharacterCreation.CreateTypes.Mihile)
            {
                hair += hairColor;
            }
            newChr.HairId = hair;
            newChr.FaceId = face;
            newChr.SkinColor = (byte)skin;
            newChr.Gender = gender;
            if (faceMark < 0) faceMark = 0;
            newChr.FaceMarking = faceMark;

            newChr.Job = Constants.CharacterCreation.GetJobByType(jobType);
            newChr.Level = 1;
            newChr.HP = 50;
            newChr.MaxHP = 50;
            newChr.MP = 50;
            newChr.MaxMP = 50;
            newChr.Str = 4;
            newChr.Dex = 4;
            newChr.Int = 4;
            newChr.Luk = 4;

            newChr.ApHp = 0;

            newChr.MapId = startMap;

            pClient.Account.Characters.Add(newChr);

            try
            {
                newChr.Create();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating character for {0}, Exception: {1}.", pClient.Session.IP, ex.Message);
                pClient.Session.Disconnect();
                return;
            }

            newChr.Id = Master.Instance.Accessor.GetLastId();

            Master.Instance.Accessor.AppendInventories(newChr, true);
            Master.Instance.Accessor.LoadInventoriesId(newChr);
            Master.Instance.Accessor.CreateEquips(newChr, equips);

            foreach (KeyValuePair<InventoryType, Inventory> inv in newChr.Inventory)
                inv.Value.Save();

            //TODO: Check for forbidden names and stuff like so.
            pClient.SendPacket(LoginPacket.CreateCharacterResult(newChr, true));
        }
        public static void HandleHeartbeat(Client pClient, Packet pPacket)
        {
            int Request = pPacket.ReadInt();

            pClient.SendPacket(GeneralPacket.HeartbeatResponse(Request));
        }