internal void WriteUpdate(Packet pPacket, EBuddyUpdateType pType) { pPacket.WriteByte((byte)pType); pPacket.WriteByte((byte)mBuddies.Count); foreach (PlayerBuddy buddy in mBuddies) buddy.WriteGeneral(pPacket); foreach (PlayerBuddy buddy in mBuddies) pPacket.WriteUInt(0); }
public static void Load(Client pClient, Packet pPacket) { int accountIdentifier; int playerIdentifier; if (!pPacket.ReadInt(out playerIdentifier) || (accountIdentifier = Server.ValidatePlayerLogin(playerIdentifier, pClient.Host)) == 0) { pClient.Disconnect(); return; } using (DatabaseQuery query = Database.Query("SELECT * FROM account WHERE identifier=@identifier", new MySqlParameter("@identifier", accountIdentifier))) { query.NextRow(); pClient.Account = new Account(query); } using (DatabaseQuery query = Database.Query("SELECT * FROM player WHERE identifier=@identifier", new MySqlParameter("@identifier", playerIdentifier))) { query.NextRow(); pClient.Player = new Player(pClient, query); } pClient.Player.Map.AddPlayer(pClient.Player); Server.UnregisterPlayerLogin(playerIdentifier); Log.WriteLine(ELogLevel.Info, "[{0}] Loaded {1}", pClient.Host, pClient.Player.Name); pClient.Player.SendInitialMapChange(); pClient.Player.SendKeymap(); pClient.Player.SendBuddyUpdate(EBuddyUpdateType.Add); pClient.Player.SendMacroList(); pClient.Player.SendMessage(EMessageType.ErrorText, "Welcome to Chronicle {0}", Server.Version); pClient.Player.EnterMap(); }
internal void WriteGeneral(Packet pPacket) { pPacket.WriteInt(mBuddyIdentifier); pPacket.WritePaddedString(mName, 13); pPacket.WriteByte(mStatus); pPacket.WriteInt(0); pPacket.WritePaddedString("Default Group", 17); }
internal void WriteInitial(Packet pPacket) { for (byte index = 0; index < MAX_KEYS; ++index) { pPacket.WriteByte(mTypes[index]); pPacket.WriteUInt(mActions[index]); } }
internal void WriteInitial(Packet pPacket) { pPacket.WriteUInt(0); pPacket.WriteByte(0x00); pPacket.WriteUShort((ushort)mCards.Count); foreach (PlayerCard card in mCards.Values) { pPacket.WriteUShort(ItemData.ReduceCardIdentifier(card.CardIdentifier)); pPacket.WriteByte(card.Level); } }
internal void WriteInitial(Packet pPacket) { pPacket.WriteUShort((ushort)mSkills.Count); foreach (PlayerSkill skill in mSkills.Values) skill.WriteGeneral(pPacket); List<PlayerSkill> cooldowns = new List<PlayerSkill>(mSkills.Values); cooldowns.RemoveAll(s => s.Cooldown == 0); pPacket.WriteUShort((ushort)cooldowns.Count); foreach (PlayerSkill cooldown in cooldowns) { pPacket.WriteInt(cooldown.SkillIdentifier); pPacket.WriteUShort(cooldown.Cooldown); } }
public static void Emote(Client pClient, Packet pPacket) { int emote; if (!pPacket.ReadInt(out emote)) { pClient.Disconnect(); return; } Packet packet = new Packet(EOpcode.SMSG_PLAYER_EMOTE); packet.WriteInt(pClient.Player.Identifier); packet.WriteInt(emote); pClient.Player.Map.SendPacketToAllExcept(packet, pClient.Player); }
public static void Action(Client pClient, Packet pPacket) { int uniqueIdentifier; short moveIdentifier; bool isUsingAbility; byte usingAbility; Coordinates projectileTarget; if (!pPacket.ReadInt(out uniqueIdentifier) || !pPacket.ReadShort(out moveIdentifier) || !pPacket.ReadBool(out isUsingAbility) || !pPacket.ReadByte(out usingAbility) || !pPacket.ReadCoordinates(out projectileTarget) || !pPacket.ReadSkip(5)) { pClient.Disconnect(); return; } Mob mob = pClient.Player.Map.GetMob(uniqueIdentifier); if (mob == null || mob.Controller != pClient.Player) return; int rewindOffset = pPacket.Cursor; Coordinates unknownPosition; if (!pPacket.ReadCoordinates(out unknownPosition) || !pClient.Player.Map.ReadMovement(mob, pPacket)) { pClient.Disconnect(); return; } Packet packet = new Packet(EOpcode.SMSG_MOB_ACTION_CONFIRM); packet.WriteInt(uniqueIdentifier); packet.WriteShort(moveIdentifier); packet.WriteBool(isUsingAbility); packet.WriteUShort((ushort)mob.Mana); packet.WriteByte(0x00); // Ability Identifier packet.WriteByte(0x00); // Ability Level pClient.SendPacket(packet); pPacket.Rewind(rewindOffset); packet = new Packet(EOpcode.SMSG_MOB_ACTION); packet.WriteInt(uniqueIdentifier); packet.WriteBool(isUsingAbility); packet.WriteByte(usingAbility); packet.WriteCoordinates(projectileTarget); packet.WriteBytes(pPacket.InnerBuffer, pPacket.Cursor, pPacket.Remaining); pClient.Player.Map.SendPacketToAllExcept(packet, pClient.Player); pClient.Player.Map.UpdateMobControllers(true); }
public static void AllPlayerConnect(Client pClient, Packet pPacket) { int identifier; if (!pPacket.ReadInt(out identifier) || (long)Database.Scalar("SELECT COUNT(*) FROM player WHERE identifier=@identifier AND account_identifier=@account_identifier", new MySqlParameter("@identifier", identifier), new MySqlParameter("@account_identifier", pClient.Account.Identifier)) == 0) { pClient.Disconnect(); return; } Server.RegisterPlayerLogin(pClient.Account.Identifier, identifier, pClient.Host); SendChannelConnect(pClient, identifier); }
public static void Chat(Client pClient, Packet pPacket) { string message; bool bubble; if (!pPacket.ReadString(out message) || !pPacket.ReadBool(out bubble)) { pClient.Disconnect(); return; } Packet packet = new Packet(EOpcode.SMSG_PLAYER_CHAT); packet.WriteInt(pClient.Player.Identifier); packet.WriteBool(pClient.Account.Level > 0); packet.WriteString(message); packet.WriteBool(bubble); pClient.Player.Map.SendPacketToAll(packet); }
internal void WriteEquipment(Packet pPacket) { for (byte index = 0; index < (byte)EEquipmentSlot.Count; ++index) { if (mEquipped[index] == null && mCashEquipped[index] == null) continue; if (index == (byte)EEquipmentSlot.Weapon && mEquipped[index] != null) pPacket.WriteInt(mEquipped[index].ItemIdentifier); else if (mCashEquipped[index] != null) pPacket.WriteInt(mCashEquipped[index].ItemIdentifier); else if (mEquipped[index] != null) pPacket.WriteInt(mEquipped[index].ItemIdentifier); } pPacket.WriteByte(0xFF); for (byte index = 0; index < (byte)EEquipmentSlot.Count; ++index) { if (index == (byte)EEquipmentSlot.Weapon || mEquipped[index] == null || mCashEquipped[index] == null) continue; pPacket.WriteInt(mEquipped[index].ItemIdentifier); } pPacket.WriteByte(0xFF); pPacket.WriteInt(mCashEquipped[(byte)EEquipmentSlot.Weapon] == null ? 0 : mCashEquipped[(byte)EEquipmentSlot.Weapon].ItemIdentifier); }
internal void WriteInitial(Packet pPacket) { List<PlayerQuest> active = new List<PlayerQuest>(mQuests.Values); active.RemoveAll(q => q.Completed != 0); pPacket.WriteUShort((ushort)active.Count); foreach (PlayerQuest quest in active) { pPacket.WriteUShort(quest.QuestIdentifier); pPacket.WriteString(quest.State); } List<PlayerQuest> completed = new List<PlayerQuest>(mQuests.Values); completed.RemoveAll(q => q.Completed == 0); pPacket.WriteUShort((ushort)completed.Count); foreach (PlayerQuest quest in completed) { pPacket.WriteInt(quest.QuestIdentifier); pPacket.WriteLong(quest.Completed); } }
internal void WriteInitial(Packet pPacket) { pPacket.WriteInt(mMesos); Array.ForEach(mItems, a => pPacket.WriteByte((byte)a.Length)); Array.ForEach(mEquipped, i => { if (i != null) i.WriteGeneral(pPacket, false); }); pPacket.WriteByte(0x00); Array.ForEach(mCashEquipped, i => { if (i != null) i.WriteGeneral(pPacket, false); }); pPacket.WriteByte(0x00); Array.ForEach(mItems[(byte)EInventoryType.Equipment], i => { if (i != null) i.WriteGeneral(pPacket, false); }); pPacket.WriteByte(0x00); Array.ForEach(mItems[(byte)EInventoryType.Use], i => { if (i != null) i.WriteGeneral(pPacket, false); }); pPacket.WriteByte(0x00); Array.ForEach(mItems[(byte)EInventoryType.Setup], i => { if (i != null) i.WriteGeneral(pPacket, false); }); pPacket.WriteByte(0x00); Array.ForEach(mItems[(byte)EInventoryType.Etc], i => { if (i != null) i.WriteGeneral(pPacket, false); }); pPacket.WriteByte(0x00); Array.ForEach(mItems[(byte)EInventoryType.Cash], i => { if (i != null) i.WriteGeneral(pPacket, false); }); pPacket.WriteByte(0x00); }
public static void Action(Client pClient, Packet pPacket) { int firstUnknown; short secondUnknown; if (!pPacket.ReadInt(out firstUnknown) || !pPacket.ReadShort(out secondUnknown)) { pClient.Disconnect(); return; } Packet packet = new Packet(EOpcode.SMSG_NPC_ACTION); byte thirdUnknown; if (!pPacket.ReadByte(out thirdUnknown)) { packet.WriteInt(firstUnknown); packet.WriteShort(secondUnknown); } else packet.WriteBytes(pPacket.InnerBuffer, pPacket.Cursor, pPacket.Remaining); pClient.SendPacket(packet); }
public static void ScriptTrigger(Client pClient, Packet pPacket) { string name; if (!pPacket.ReadSkip(1) || !pPacket.ReadString(out name)) { pClient.Disconnect(); return; } Portal portal = pClient.Player.Map.GetPortal(name); if (portal == null || portal.Script == null) { Log.WriteLine(ELogLevel.Debug, "[{0}] Portal Script Blocked {1}", pClient.Host, name); pClient.Player.SendPortalBlocked(); return; } Log.WriteLine(ELogLevel.Info, "[{0}] Portal Script Triggered {1}", pClient.Host, portal.Script.GetType().FullName); portal.Script.Execute(pClient.Player, portal); }
internal void WriteInitial(Packet pPacket) { pPacket.WriteByte((byte)mMacros.Length); Array.ForEach(mMacros, m => { if (m != null) { pPacket.WriteString(m.Name); pPacket.WriteBool(m.Shout); pPacket.WriteInt(m.FirstSkillIdentifier); pPacket.WriteInt(m.SecondSkillIdentifier); pPacket.WriteInt(m.ThirdSkillIdentifier); } else { pPacket.WriteString(""); pPacket.WriteBool(false); pPacket.WriteInt(0); pPacket.WriteInt(0); pPacket.WriteInt(0); } }); }
public static void Authentication(Client pClient, Packet pPacket) { string username; string password; byte[] macBytes = new byte[6]; if (!pPacket.ReadString(out username) || !pPacket.ReadString(out password) || !pPacket.ReadBytes(macBytes)) { pClient.Disconnect(); return; } Account account = null; using (DatabaseQuery query = Database.Query("SELECT * FROM account WHERE username=@username", new MySqlParameter("@username", username))) { if (!query.NextRow()) { SendAuthentication(pClient, EAuthenticationResult.Invalid); return; } account = new Account(query); } if (password != account.Password) { SendAuthentication(pClient, EAuthenticationResult.Incorrect); return; } if (Server.IsAccountOnline(account.Identifier) || Server.IsPendingPlayerLogin(account.Identifier)) { SendAuthentication(pClient, EAuthenticationResult.Online); return; } pClient.Account = account; Log.WriteLine(ELogLevel.Info, "[{0}] Authenticated {1}", pClient.Host, pClient.Account.Username); SendAuthentication(pClient, EAuthenticationResult.Ok); }
internal void WriteStatus(Packet pPacket) { pPacket.WriteInt(0); }
internal void SendControl(bool pTakeControl) { if (mController != null) { Packet packet = new Packet(EOpcode.SMSG_MOB_CONTROL); packet.WriteBool(pTakeControl); packet.WriteInt(UniqueIdentifier); if (pTakeControl) { packet.WriteByte(0x05); packet.WriteInt(mData.MobIdentifier); WriteStatus(packet); packet.WriteCoordinates(mPosition); packet.WriteByte((byte)(0x02 | (FacingLeft ? 0x01 : 0x00))); packet.WriteUShort(mFoothold); packet.WriteUShort(mData.Foothold); packet.WriteBool(false); packet.WriteByte(0xFF); packet.WriteInt(0); } mController.SendPacket(packet); } }
private static void SendWorldStatus(Client pClient) { int population = Server.Population; Packet packet = new Packet(EOpcode.SMSG_WORLD_STATUS); if (population >= Config.Instance.Channel.MaxPopulation) packet.WriteByte(0x02); else if (population >= (Config.Instance.Channel.MaxPopulation * 0.9)) packet.WriteByte(0x01); else packet.WriteByte(0x00); packet.WriteByte(0); pClient.SendPacket(packet); }
internal void WriteInitial(Packet pPacket) { Array.ForEach(mTeleports, t => pPacket.WriteInt(t == null ? MapData.INVALID_MAP_IDENTIFIER : t.MapIdentifier)); }
private static void WritePlayer(Packet pPacket, DatabaseQuery pQuery) { pPacket.WriteInt((int)pQuery["identifier"]); pPacket.WritePaddedString((string)pQuery["name"], 13); pPacket.WriteByte((byte)pQuery["gender"]); pPacket.WriteByte((byte)pQuery["skin"]); pPacket.WriteInt((int)pQuery["eyes_identifier"]); pPacket.WriteInt((int)pQuery["hair_identifier"]); pPacket.WriteSkip(24); pPacket.WriteByte((byte)pQuery["level"]); pPacket.WriteUShort((ushort)pQuery["job"]); pPacket.WriteUShort((ushort)pQuery["strength"]); pPacket.WriteUShort((ushort)pQuery["dexterity"]); pPacket.WriteUShort((ushort)pQuery["intellect"]); pPacket.WriteUShort((ushort)pQuery["luck"]); pPacket.WriteUShort((ushort)pQuery["health"]); pPacket.WriteUShort((ushort)pQuery["max_health"]); pPacket.WriteUShort((ushort)pQuery["mana"]); pPacket.WriteUShort((ushort)pQuery["max_mana"]); pPacket.WriteUShort((ushort)pQuery["ability_points"]); pPacket.WriteUShort((ushort)pQuery["skill_points"]); pPacket.WriteInt((int)pQuery["experience"]); pPacket.WriteUShort((ushort)pQuery["fame"]); pPacket.WriteSkip(4); pPacket.WriteInt((int)pQuery["map_identifier"]); pPacket.WriteByte((byte)pQuery["map_spawn"]); pPacket.WriteSkip(4); pPacket.WriteByte((byte)pQuery["gender"]); pPacket.WriteByte((byte)pQuery["skin"]); pPacket.WriteInt((int)pQuery["eyes_identifier"]); pPacket.WriteBool(true); pPacket.WriteInt((int)pQuery["hair_identifier"]); SortedDictionary<byte, Doublet<int, int>> equipment = new SortedDictionary<byte, Doublet<int, int>>(); using (DatabaseQuery queryEquipment = Database.Query("SELECT inventory_slot,item_identifier FROM player_item WHERE player_identifier=@player_identifier AND inventory_type=0 AND inventory_slot<0", new MySqlParameter("@player_identifier", (int)pQuery["identifier"]))) { while (queryEquipment.NextRow()) { short slot = (short)(-((short)queryEquipment["inventory_slot"])); if (slot > 100) slot -= 100; Doublet<int, int> pair = equipment.GetOrDefault((byte)slot, null); if (pair == null) { pair = new Doublet<int, int>((int)queryEquipment["item_identifier"], 0); equipment.Add((byte)slot, pair); } else if ((short)queryEquipment["inventory_slot"] < -100) { pair.Second = pair.First; pair.First = (int)queryEquipment["item_identifier"]; } else pair.Second = (int)queryEquipment["item_identifier"]; } } foreach (KeyValuePair<byte, Doublet<int, int>> pair in equipment) { pPacket.WriteByte(pair.Key); if (pair.Key == 11 && pair.Value.Second > 0) pPacket.WriteInt(pair.Value.Second); else pPacket.WriteInt(pair.Value.First); } pPacket.WriteByte(0xFF); foreach (KeyValuePair<byte, Doublet<int, int>> pair in equipment) { if (pair.Key != 11 && pair.Value.Second > 0) { pPacket.WriteByte(pair.Key); pPacket.WriteInt(pair.Value.Second); } } pPacket.WriteByte(0xFF); Doublet<int, int> cashWeapon = equipment.GetOrDefault((byte)11, null); pPacket.WriteInt(cashWeapon == null ? 0 : cashWeapon.First); pPacket.WriteSkip(12); pPacket.WriteBool(false); }
public static void AllPlayerList(Client pClient, Packet pPacket) { SendAllPlayerList(pClient); }
public static void Move(Client pClient, Packet pPacket) { if (!pPacket.ReadSkip(9)) { pClient.Disconnect(); return; } int rewindOffset = pPacket.Cursor; pClient.Player.Map.ReadMovement(pClient.Player, pPacket); pPacket.Rewind(rewindOffset); Packet packet = new Packet(EOpcode.SMSG_PLAYER_MOVE); packet.WriteInt(pClient.Player.Identifier); packet.WriteInt(0); packet.WriteBytes(pPacket.InnerBuffer, pPacket.Cursor, pPacket.Remaining); pClient.Player.Map.SendPacketToAllExcept(packet, pClient.Player); if (pClient.Player.Foothold == 0) { } else pClient.Player.FallCount = 0; pClient.Player.Map.UpdateMobControllers(true); }
public static void Disconnect(Client pClient, Packet pPacket) { if (pClient.Account == null) pClient.Disconnect(); }
public static void Pin(Client pClient, Packet pPacket) { SendPin(pClient); }
public static void Teleport(Client pClient, Packet pPacket) { int mapIdentifier; if (!pPacket.ReadSkip(1) || !pPacket.ReadInt(out mapIdentifier)) { pClient.Disconnect(); return; } if (mapIdentifier == -1) { string portalName; if (!pPacket.ReadString(out portalName)) { pClient.Disconnect(); return; } Portal portal = pClient.Player.Map.GetPortal(portalName); if (portal == null) { Log.WriteLine(ELogLevel.Debug, "[{0}] Portal Blocked {1}", pClient.Host, portalName); pClient.Player.SendPortalBlocked(); return; } Map mapDestination = Server.GetActiveMap(portal.Data.ToMapIdentifier); if (mapDestination == null) { Log.WriteLine(ELogLevel.Debug, "[{0}] Portal Blocked {1}", pClient.Host, portalName); pClient.Player.SendPortalBlocked(); return; } Portal portalDestination = mapDestination.GetPortal(portal.Data.ToName); if (portalDestination == null) { Log.WriteLine(ELogLevel.Debug, "[{0}] Portal Blocked {1}", pClient.Host, portalName); pClient.Player.SendPortalBlocked(); return; } Log.WriteLine(ELogLevel.Info, "[{0}] Portal Triggered {1}", pClient.Host, portal.Data.Name); pClient.Player.Map.RemovePlayer(pClient.Player); pClient.Player.Map = mapDestination; pClient.Player.Map.AddPlayer(pClient.Player); pClient.Player.Spawn = portalDestination.Index; pClient.Player.Position.X = portalDestination.Data.X; pClient.Player.Position.Y = portalDestination.Data.Y; pClient.Player.Stance = 0; pClient.Player.Foothold = 0; pClient.Player.FallCount = 0; pClient.Player.SendMapChange(); pClient.Player.EnterMap(); } }
public void SendPacket(Packet pPacket) { if (mDisconnected != 0) return; byte[] buffer = new byte[pPacket.Length + 4]; mSendCrypto.GenerateHeader(buffer); Buffer.BlockCopy(pPacket.InnerBuffer, 0, buffer, 4, pPacket.Length); mSendCrypto.Encrypt(buffer, 4, pPacket.Length); Send(buffer); }
private void EndReceive(SocketAsyncEventArgs pArguments) { if (mDisconnected != 0) return; if (pArguments.BytesTransferred <= 0) { if (pArguments.SocketError != SocketError.Success && pArguments.SocketError != SocketError.ConnectionReset) Log.WriteLine(ELogLevel.Error, "[{0}] Receive Error: {1}", Host, pArguments.SocketError); Disconnect(); return; } mReceiveLength += pArguments.BytesTransferred; while (mReceiveLength > 4) { if (mReceivingPacketLength == 0) { if (!mReceiveCrypto.ConfirmHeader(mReceiveBuffer, mReceiveStart)) { Log.WriteLine(ELogLevel.Error, "[{0}] Invalid Packet Header", Host); Disconnect(); return; } mReceivingPacketLength = mReceiveCrypto.GetHeaderLength(mReceiveBuffer, mReceiveStart); } if (mReceivingPacketLength > 0 && mReceiveLength >= mReceivingPacketLength + 4) { mReceiveCrypto.Decrypt(mReceiveBuffer, mReceiveStart + 4, mReceivingPacketLength); Packet packet = new Packet(mReceiveBuffer, mReceiveStart + 4, mReceivingPacketLength); PacketHandlerAttribute handler = sHandlers.GetOrDefault(packet.Opcode, null); if (handler != null) Server.AddCallback(() => handler.Processor(this, packet)); else { Log.WriteLine(ELogLevel.Debug, "[{0}] Receiving 0x{1}, {2} Bytes", Host, ((ushort)packet.Opcode).ToString("X4"), packet.Length); packet.Dump(); } mReceiveStart += mReceivingPacketLength + 4; mReceiveLength -= mReceivingPacketLength + 4; mReceivingPacketLength = 0; mReceiveLast = DateTime.Now; } } if (mReceiveLength == 0) mReceiveStart = 0; else if (mReceiveStart > 0 && (mReceiveStart + mReceiveLength) >= mReceiveBuffer.Length) { Buffer.BlockCopy(mReceiveBuffer, mReceiveStart, mReceiveBuffer, 0, mReceiveLength); mReceiveStart = 0; } if (mReceiveLength == mReceiveBuffer.Length) { Log.WriteLine(ELogLevel.Error, "[{0}] Receive Overflow", Host); Disconnect(); } else BeginReceive(); }
internal void WriteGeneral(Packet pPacket) { pPacket.WriteInt(mSkillIdentifier); pPacket.WriteUInt(mLevel); if (SkillData.IsFourthJobRelated(mSkillIdentifier)) pPacket.WriteUInt(mMaxLevel); }