public static void ReloadBuffs(string[] split, MapleClient c) { c.Account.Character.SendBlueMessage("Reloading buffs..."); foreach (var skillKVP in DataBuffer.CharacterSkillBuffer) { foreach (var effectKVP in skillKVP.Value.SkillEffects) { if (skillKVP.Value.IsBuff || effectKVP.Value.Info.ContainsKey(CharacterSkillStat.time)) { effectKVP.Value.LoadBuffStats(); if (!skillKVP.Value.IsBuff && effectKVP.Value.BuffInfo.Count > 0) { skillKVP.Value.IsBuff = true; } } } } c.Account.Character.SendBlueMessage("Done!"); }
public void KilledMob(MapleClient c, int mobId) { int currentKills; if (MonsterKills.TryGetValue(mobId, out currentKills)) { int requiredKills = GetRequiredMobKillAmount(mobId); if (currentKills < requiredKills) { currentKills++; MonsterKills[mobId] = currentKills; c.SendPacket(UpdateMobKillProgress()); if (currentKills == requiredKills) { c.SendPacket(ShowQuestCompleteNotice(QuestInfo.Id)); } } } }
private static void SendInit(MapleClient c) { SendInventory(c); SendTokens(c); PacketWriter pw = new PacketWriter(); pw.WriteHeader(SendHeader.CashShopInit); pw.WriteShort(CashShopOperation + 3); pw.WriteZeroBytes(3); c.SendPacket(pw); pw = new PacketWriter(); pw.WriteHeader(SendHeader.CashShopInit); pw.WriteShort(CashShopOperation + 5); pw.WriteByte(0); c.SendPacket(pw); }
private static void ShowLinkImage(MapleClient c) { PacketWriter pw = new PacketWriter(); pw.WriteHeader(SendHeader.CashShopInfo); pw.WriteByte(4); //Type pw.WriteBool(true); //Unk List <Item> Items = GetItemsWithImage(); pw.WriteByte((byte)Items.Count); //Count foreach (Item Item in Items) { ShowCashItem(pw, Item, c.Account.Id); } c.SendPacket(pw); }
public static void OnMigrateIn(MapleClient c, InPacket p) { int charId = p.ReadInt(); c.Character = Database.Instance.GetCharacter(charId); c.Account = Database.Instance.GetAccount(c.Character.AccountId); c.LoggedIn = true; using (OutPacket packet = new OutPacket(SendOps.SetField)) { packet.WriteInt(c.Channel); packet.WriteByte(); //pcount packet.WriteBool(true); //new channel for (int i = 0; i < 3; i++) //rand seeds { packet.WriteInt(Randomizer.Generate()); } packet.WriteInt(); packet.WriteShort(-1); // Flags (contains everything: 0xFFFF) PacketCreator.Helper.AddCharacterData(packet, c.Character); packet.WriteByte(20); //Buddylist PacketCreator.Helper.AddInventory(packet, c.Character); packet.WriteShort(); //skills packet.WriteShort(); //quests packet.WriteShort(); //rps packet.WriteShort(); //rings foreach (int rock in c.Character.TeleportRock) { packet.WriteInt(rock); } packet.WriteLong(64); //padding c.Send(packet); } }
public static OutPacket GetCharList(MapleClient mc) { using (var packet = new OutPacket(SendOpcodes.Charlist)) { packet.WriteByte(0x00); packet.WriteInt(0); packet.WriteByte((byte)(mc.Account.Characters?.Count ?? 0)); if (mc.Account.Characters != null) { foreach (var chr in mc.Account.Characters) { AddCharEntry(packet, new MapleCharacter(chr.Id, mc, false)); } } packet.WriteShort(3); packet.WriteInt(ServerSettings.MaxCharacterCouldCreate); return(packet); } }
public static void OnlinePlayers(string[] split, MapleClient c) { Dictionary <int, List <string> > playersPerChannel = new Dictionary <int, List <string> >(); foreach (MapleClient client in Program.Clients.Values.ToList()) { if (client.Account?.Character != null) { string name = client.Account.Character.Name; byte channel = client.Channel; List <string> names; if (playersPerChannel.TryGetValue(channel, out names)) { names.Add(name); } else { playersPerChannel.Add(channel, new List <string>() { name }); } } } MapleCharacter chr = c.Account.Character; chr.SendBlueMessage("Online Players: "); int totalPlayers = 0; foreach (var ppc in playersPerChannel) { totalPlayers += ppc.Value.Count; string show = String.Format("Channel {0}: {1} -", ppc.Key, totalPlayers); foreach (string name in ppc.Value) { show += " " + name + " "; } chr.SendBlueMessage(show); } chr.SendBlueMessage(String.Format("Total: {0}", totalPlayers)); }
public void Buy(MapleClient c, int itemId, short quantity) { if (quantity <= 0) { Console.WriteLine($"{c.Player.Name} is buying an invalid amount: { quantity } of itemid: { itemId}"); c.Close(); return; } MapleShopItem item = FindByItemId(itemId); MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; if (item != null && item.Price > 0 && c.Player.Meso.Value >= item.Price * quantity) { if (MapleInventoryManipulator.CheckSpace(c, itemId, quantity, "")) { if (itemId >= 5000000 && itemId <= 5000100) { if (quantity > 1) { quantity = 1; } int petId = MaplePet.Create(itemId); MapleInventoryManipulator.AddById(c, itemId, quantity, "Pet was purchased.", null, petId); } else if (ii.IsRechargable(itemId)) { short rechquantity = ii.GetSlotMax(c, item.ItemId); MapleInventoryManipulator.AddById(c, itemId, rechquantity, "Rechargable item purchased.", null, -1); } else { MapleInventoryManipulator.AddById(c, itemId, quantity, c.Player.Name + " bought " + quantity + " for " + item.Price * quantity + " from shop " + ShopId); } c.Player.GainMeso(-(item.Price * quantity), false); c.Send(PacketCreator.ConfirmShopTransaction(0)); } else { c.Send(PacketCreator.ConfirmShopTransaction(3)); } } }
public static void Handle(MapleClient c, PacketReader pr) { if (pr.Available > 8) { short type = pr.ReadShort(); string typeString = "Unknown"; if (type == 0x01) { typeString = "SendBackupPacket"; } else if (type == 0x02) { typeString = "Crash Report"; } else if (type == 0x03) { typeString = "Exception"; } int errorType = pr.ReadInt(); //if (errorType == 0) //Usually some bounceback to login //return; short dataLength = pr.ReadShort(); pr.Skip(4); int header = pr.ReadShort(); string headerName = Enum.GetName(typeof(SendHeader), header) + String.Format(" : {0}", header.ToString("X")); string accountName = c.Account.Name; string playerName = "N/A (not logged in yet)"; if (c.Account.Character != null) { playerName = c.Account.Character.Name; //TODO: map id } string remainingBytes = pr.ToString(true); string errorString = String.Format("Error Type: {0}\r\nData Length: {1}\r\nError for player:{2} - account: {3}\r\nHeader: {4}\r\nData: {5}", typeString, dataLength, playerName, accountName, headerName, remainingBytes); FileLogging.Log("ErrorCodes.txt", errorString); ServerConsole.Warning("Error 38 caused by: " + headerName); } }
public static void LevelUp(string[] split, MapleClient c) { MapleCharacter chr = c.Account.Character; int times = 1; if (split.Length > 1) { if (int.TryParse(split[1], out times)) { for (int i = 0; i < times; i++) { chr.LevelUp(); } } } else { chr.LevelUp(); } }
private static void SetItemFav(MapleClient c, int SN, bool enable) { PacketWriter pw = new PacketWriter(); pw.WriteHeader(SendHeader.CashShopItemAction); if (enable) { pw.WriteByte(0x0E); pw.WriteByte(1); pw.WriteInt(SN); } else { pw.WriteByte(0x10); pw.WriteByte(1); pw.WriteInt(SN); pw.WriteByte(1); } c.SendPacket(pw); }
public static void UpdateQuest(string[] split, MapleClient c) { string data = split[2]; ushort questId; if (ushort.TryParse(split[1], out questId)) { MapleQuest quest = c.Account.Character.GetQuest(questId); if (quest != null) { quest.Data = data; c.SendPacket(quest.Update()); } else { quest = new MapleQuest(DataBuffer.GetQuestById(questId), MapleQuestStatus.InProgress, data); c.Account.Character.AddQuest(quest, questId); } } }
private static void AddLike(MapleClient c, int SN) { /*using (LeattyContext DBContext = new LeattyContext()) * { * int cId = c.Account.Character.Id; * CashshopItem ItemToLike = DBContext.CashshopItems.SingleOrDefault(x => x.Id == SN); * int count = DBContext.CashshopLikes.Count(x => x.CharacterId == cId && x.CsId == SN); * if (count == 0 && ItemToLike != null) * { * CashshopLike InsertLike = new CashshopLike(); * InsertLike.CharacterId = cId; * InsertLike.CsId = SN; * DBContext.CashshopLikes.Add(InsertLike); * Item Liked = DbToNormalItem(DataBuffer.CSItems.Single(x => x.Id == SN)); * Liked.Likes += 1; * ItemToLike.Likes = Liked.Likes; * DBContext.SaveChanges(); * } * }*/ }
public static void OnMove(MapleClient client, InPacket iPacket) { Movements movements = Movements.Decode(iPacket); // TODO: Validate movements. Movement lastMovement = movements[movements.Count - 1]; client.Character.Position = lastMovement.Position; client.Character.Foothold = lastMovement.Foothold; client.Character.Stance = lastMovement.Stance; using (OutPacket oPacket = new OutPacket(SendOps.UserMove)) { oPacket.WriteInt(client.Character.ID); movements.Encode(oPacket); client.Character.Map.Broadcast(oPacket, client.Character); } }
private static void AddFav(MapleClient c, int SN) { /*using (LeattyContext DBContext = new LeattyContext()) * { * bool bIsItemFav = IsItemFav(c.Account.Id, SN); * CashshopItem ItemToFav = DBContext.CashshopItems.SingleOrDefault(x => x.Id == SN); * if (!bIsItemFav) * { * CashshopFavorite InsertFav = new CashshopFavorite(); * InsertFav.ItemId = SN; * InsertFav.AccountId = c.Account.Id; * DBContext.CashshopFavorites.Add(InsertFav); * } * else * DBContext.CashshopFavorites.RemoveRange(DBContext.CashshopFavorites.Where(x => x.ItemId == SN && x.AccountId == c.Account.Id)); * * DBContext.SaveChanges(); * SetItemFav(c, SN, !bIsItemFav); * }*/ }
public static void Handle(MapleClient c, PacketReader pr) { MapleCharacter chr = c.Account.Character; if (chr.ActionState == ActionState.Enabled) { int doorOwnerId = pr.ReadInt(); bool back = pr.ReadBool(); //return to source door if used in a town SpecialPortal door = chr.Map.GetDoor(doorOwnerId); if (door != null) { if (!door.IsPartyObject || (doorOwnerId == chr.Id || (chr.Party != null && chr.Party.Id == door.PartyId))) { door.Warp(chr); return; } } chr.EnableActions(); } }
public static void ClearInventory(string[] split, MapleClient c) { if (split.Length < 2) { c.Account.Character.SendBlueMessage("clearinv usage: !clearinv [equip/use/setup/etc/cash]"); return; } MapleInventoryType invType; switch (split[1]) { case "equipped": invType = MapleInventoryType.Equipped; break; case "eq": invType = MapleInventoryType.Equip; break; case "use": invType = MapleInventoryType.Use; break; case "setup": invType = MapleInventoryType.Setup; break; case "etc": invType = MapleInventoryType.Etc; break; case "cash": invType = MapleInventoryType.Cash; break; default: c.Account.Character.SendBlueMessage("clearinv usage: !clearinv [equipped/eq/use/setup/etc/cash]"); return; } c.Account.Character.Inventory.ClearInventory(invType, c); }
public static void HandleMelee(MapleClient c, PacketReader pr, RecvHeader type) { pr.Skip(1); byte attackByte = pr.ReadByte(); byte attacks = (byte)(attackByte & 0x0F); byte targets = (byte)((attackByte >> 4) & 0x0F); int skillId = pr.ReadInt(); byte skillLevel = pr.ReadByte(); pr.Skip(6); //melee //ranged pr.Skip(7); //magic pr.Skip(5); int charge = 0; SkillEffect effect = null; int fixedDamage = -1; double skillDamage = 1; if (skillId > 0) { if (skillLevel < 1 || skillLevel != c.Account.Character.GetSkillLevel(skillId)) { ServerConsole.Warning("Character skill level invalid " + skillLevel); return; } CheckChargeAndDamage(skillId, skillLevel, pr, out charge, out fixedDamage, out effect, out skillDamage); } byte unk = pr.ReadByte(); short display = pr.ReadShort(); pr.Skip(5); byte speed = pr.ReadByte(); int tickCount = pr.ReadInt(); pr.Skip(8); AttackInfo attackInfo = CreateAttackInfo(pr, attackByte, targets, attacks, skillId, skillLevel, charge, speed, display, fixedDamage, c.Account.Character.Stats, skillDamage); if (attackInfo != null) { HandleAttackInfo(c, attackInfo, SendHeader.MeleeAttack, effect); } }
public static void HandleChooseSkill(MapleClient c, PacketReader pr) { //Equip : [E9 39 6E 01] [EB 0C 3D 00] //Unequip: [E9 39 6E 01] [00 00 00 00] MapleCharacter chr = c.Account.Character; PhantomSystem resource = chr.Resource as PhantomSystem; if (!chr.IsPhantom || resource == null) { return; } int skillBase = pr.ReadInt(); int skillId = pr.ReadInt(); if (skillId > 0) //choose new { if (!resource.HasSkill(skillId)) { return; } int jobNum = JobConstants.GetJobNumber(skillId / 10000); if (jobNum != PhantomSystem.GetJobIndexByImpeccableMemory(skillBase)) { return; } if (jobNum > 0 && jobNum < 5) { resource.ChosenSkills[jobNum - 1] = skillId; c.SendPacket(UpdateChosenSkill(skillBase, skillId)); } } else //Unequip chosen skill { int jobNum = JobConstants.GetJobNumber(skillBase); if (jobNum > 0 && jobNum < 5) { resource.ChosenSkills[jobNum - 1] = 0; c.SendPacket(UpdateChosenSkill(skillBase, 0)); } } }
public static LoginResultCode Login(MapleClient c, string username, string password) { var state = LoginResultCode.Unfind; using (var db = new NeoMapleStoryDatabase()) { db.Configuration.LazyLoadingEnabled = false; var model = db.Accounts.Where(x => x.Username == username).Select(x => x).Include(x => x.Characters).FirstOrDefault(); if (model == null) { return(state); } c.Account = model; if (model.LoginState != LoginStateType.NotLogin) { state = LoginResultCode.IsLogged; } else if (model.Password != Sha256.Get(password, model.PasswordSalt)) { state = LoginResultCode.IncorrectPassword; } else if (model.IsPermanentBan || model.TempBanDate != null) { state = LoginResultCode.Banned; } else if (model.Gender == null) { state = LoginResultCode.GenderNeeded; } else { db.SaveChanges(); state = LoginResultCode.Success; } } return(state); }
public CClientSocket(MapleClient pClient, Socket sock) { socket = sock; socketbuffer = new byte[1024]; host = ((IPEndPoint)socket.RemoteEndPoint).Address.ToString(); port = ((IPEndPoint)socket.LocalEndPoint).Port; dispose_Sync = new object(); client = pClient; Crypto = new CipherHelper(ServerConstants.Version); Crypto.PacketFinished += (data) => { pClient.RecvPacket(new PacketReader(data)); }; WaitForData(); }
public static void Handle(MapleClient c, PacketReader pr) { MapleCharacter chr = c.Account.Character; if (!chr.DisableActions()) { return; } int tickCount = pr.ReadInt(); int skillId = pr.ReadInt(); byte skillLevel = pr.ReadByte(); if (skillId != Constants.Cleric.HEAL && skillId != Constants.Bishop.ANGEL_RAY) // Heal is already handled through MagicAttack { SkillEffect.CheckAndApplySkillEffect(c.Account.Character, skillId, DataBuffer.GetCharacterSkillById(skillId)); } else { chr.EnableActions(); } }
public Character(int id = 0, MapleClient client = null) { this.ID = id; this.Client = client; if (this.Client != null) { this.User = this.Client.User; } this.Inventory = new CharacterInventory(this); this.Statistics = new CharacterStatistics(this); this.Skills = new CharacterSkills(this); this.Quests = new CharacterQuests(this); this.SavedLocations = new CharacterSavedLocations(this); this.ControlledMobs = new ControlledMobs(this); this.ControlledNpcs = new ControlledNpcs(this); this.Position = new Position(0, 0); }
public static void RemoveAllById(MapleClient c, int itemId, bool checkEquipped) { var type = MapleItemInformationProvider.Instance.GetInventoryType(itemId); foreach (var item in c.Player.Inventorys[type.Value].ListById(itemId)) { if (item != null) { RemoveFromSlot(c, type, item.Position, item.Quantity, true); } } if (checkEquipped) { var ii = c.Player.Inventorys[type.Value].FindById(itemId); if (ii != null) { c.Player.Inventorys[MapleInventoryType.Equipped.Value].RemoveItem(ii.Position); //c.Character.equipChanged(); } } }
public static void Handle(MapleClient c, PacketReader pw) { MapleCharacter chr = c.Account.Character; if (!chr.DisableActions()) { return; } int tickCount = pw.ReadInt(); int mesos = pw.ReadInt(); if (mesos > 50000 || mesos < 10 || chr.Inventory.Mesos < mesos) { return; } chr.Inventory.RemoveMesos(mesos, false); Point targetPosition = chr.Map.GetDropPositionBelow(new Point(chr.Position.X, chr.Position.Y - 50), chr.Position); chr.Map.SpawnMesoMapItem(mesos, chr.Position, targetPosition, true, MapleDropType.Unk, chr); chr.EnableActions(false); }
public static void HandleItemSort(MapleClient c, PacketReader pr) { MapleCharacter chr = c.Account.Character; if (!chr.DisableActions()) { return; } int tickCount = pr.ReadInt(); byte inventory = pr.ReadByte(); if (inventory < 1 || inventory > 5) { return; } MapleInventoryType type = (MapleInventoryType)inventory; chr.Inventory.SortItems(type, c); chr.EnableActions(false); c.SendPacket(Packets.ItemSortResponse(type)); }
public static void HandlePotentialScroll(MapleClient c, PacketReader pr) { MapleCharacter chr = c.Account.Character; if (!chr.DisableActions()) { return; } int tickCount = pr.ReadInt(); short useSlot = pr.ReadShort(); short equipSlot = pr.ReadShort(); MapleEquip equip; MapleItem scroll; if (GetAndCheckItemsFromInventory(chr.Inventory, equipSlot, useSlot, out equip, out scroll)) { MapleEquipEnhancer.UsePotentialScroll(equip, scroll, chr); } chr.EnableActions(false); }
public NpcEngine(MapleClient c, int id) { Client = c; NpcId = id; Type npcT; if (DataBuffer.NpcScripts.TryGetValue(NpcId, out npcT) && npcT != null) { ScriptInstance = ScriptActivator.CreateScriptInstance(npcT, npcT.ToString(), c.Account.Character) as NpcScript; if (ScriptInstance == null) { string error = string.Format("Error loading {0} {1}", "NpcScript", npcT.ToString()); ServerConsole.Error(error); FileLogging.Log("Npc scripts", error); return; } if (ScriptInstance.IsShop) { IsShop = true; } else { ScriptInstance.SendOk = new Action <string>(SendOk); ScriptInstance.SendNext = new Action <string>(SendNext); ScriptInstance.SendPrev = new Action <string>(SendPrev); ScriptInstance.SendNextPrev = new Action <string>(SendNextPrev); ScriptInstance.SendSimple = new Action <string>(SendSimple); ScriptInstance.EndChat = new Action(Dispose); ScriptInstance.SendYesNo = new Action <string>(SendYesNo); ScriptInstance.SendAskText = new Action <string, int, int, string>(SendAskText); } } else { SendOk(string.Format(@"An error has occured in my script. Please report this as a bug\r\nNpcId: {0}", NpcId)); ServerConsole.Debug(string.Format(@"Missing script for NPC: {0}", NpcId)); ScriptInstance = null; c.Account.Character.EnableActions(); } }
private void OnClientAccepted(Socket socket) { MapleClient client = new MapleClient(socket, mProcessor, mClients.Remove); this.SetClientAttributes(client); mClients.Add(client); using (OutPacket oPacket = new OutPacket(14, 16)) { oPacket .WriteShort(Constants.Version) .WriteMapleString(Constants.Patch) .WriteBytes(Constants.RIV) .WriteBytes(Constants.SIV) .WriteByte(Constants.Locale); client.SendRaw(oPacket.ToArray()); } Logger.Write(LogLevel.Info, "[{0}] Accepted client from {1}.", mLabel, client.Host); }
private static void MigrateClient(MapleClient client, int characterID) { ChannelServer destination = MasterServer.Instance.Worlds[client.World].Channels[client.Channel]; destination.Migrations.Add(client.Host, client.Account.ID, characterID); using (OutPacket oPacket = new OutPacket(SendOps.SelectCharacterResult)) { oPacket .WriteByte() .WriteByte() .WriteBytes(new byte[4] { 127, 0, 0, 1 }) .WriteShort(destination.Port) .WriteInt(characterID) .WriteInt() .WriteByte(); client.Send(oPacket); } }