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 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(); }
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 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 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); }
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); }
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 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); }
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 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 static void Disconnect(Client pClient, Packet pPacket) { if (pClient.Account == null) pClient.Disconnect(); }
public static void PlayerNameCheck(Client pClient, Packet pPacket) { string name; if (!pPacket.ReadString(out name)) { pClient.Disconnect(); return; } bool unusable = name.Length < 4 || name.Length > 16 || (long)Database.Scalar("SELECT COUNT(*) FROM player WHERE name=@name", new MySqlParameter("@name", name)) != 0; SendPlayerNameCheck(pClient, name, unusable); }
public static void PlayerDelete(Client pClient, Packet pPacket) { int identifier; if (!pPacket.ReadSkip(4) || !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; } Database.Execute("DELETE FROM player WHERE identifier=@identifier", new MySqlParameter("@identifier", identifier)); SendPlayerDelete(pClient, identifier); }
public static void PlayerCreate(Client pClient, Packet pPacket) { string name; int eyesIdentifier; int hairIdentifier; int hairColor; int skin; int shirtIdentifier; int pantsIdentifier; int shoesIdentifier; int weaponIdentifier; byte gender; if (!pPacket.ReadString(out name) || !pPacket.ReadInt(out eyesIdentifier) || !pPacket.ReadInt(out hairIdentifier) || !pPacket.ReadInt(out hairColor) || !pPacket.ReadInt(out skin) || !pPacket.ReadInt(out shirtIdentifier) || !pPacket.ReadInt(out pantsIdentifier) || !pPacket.ReadInt(out shoesIdentifier) || !pPacket.ReadInt(out weaponIdentifier) || !pPacket.ReadByte(out gender)) { pClient.Disconnect(); return; } bool unusable = name.Length < 4 || name.Length > 16 || (long)Database.Scalar("SELECT COUNT(*) FROM player WHERE name=@name", new MySqlParameter("@name", name)) != 0; if (unusable) { SendPlayerNameCheck(pClient, name, true); return; } hairIdentifier += hairColor; int identifier = Database.InsertAndReturnIdentifier("INSERT INTO player(account_identifier,name,gender,skin,eyes_identifier,hair_identifier) " + "VALUES(@account_identifier,@name,@gender,@skin,@eyes_identifier,@hair_identifier)", new MySqlParameter("@account_identifier", pClient.Account.Identifier), new MySqlParameter("@name", name), new MySqlParameter("@gender", gender), new MySqlParameter("@skin", skin), new MySqlParameter("@eyes_identifier", eyesIdentifier), new MySqlParameter("@hair_identifier", hairIdentifier)); Database.Execute("INSERT INTO player_keymap(player_identifier) VALUES(@player_identifier)", new MySqlParameter("@player_identifier", identifier)); Database.Execute("INSERT INTO player_item(player_identifier,inventory_type,inventory_slot,item_identifier,weapon_defense) " + "VALUES(@player_identifier,@inventory_type,-5,@item_identifier,3)", new MySqlParameter("@player_identifier", identifier), new MySqlParameter("@inventory_type", EInventoryType.Equipment), new MySqlParameter("@item_identifier", shirtIdentifier)); Database.Execute("INSERT INTO player_item(player_identifier,inventory_type,inventory_slot,item_identifier,weapon_defense) " + "VALUES(@player_identifier,@inventory_type,-6,@item_identifier,2)", new MySqlParameter("@player_identifier", identifier), new MySqlParameter("@inventory_type", EInventoryType.Equipment), new MySqlParameter("@item_identifier", pantsIdentifier)); Database.Execute("INSERT INTO player_item(player_identifier,inventory_type,inventory_slot,item_identifier,unused_scroll_slots,weapon_defense) " + "VALUES(@player_identifier,@inventory_type,-7,@item_identifier,5,3)", new MySqlParameter("@player_identifier", identifier), new MySqlParameter("@inventory_type", EInventoryType.Equipment), new MySqlParameter("@item_identifier", shoesIdentifier)); Database.Execute("INSERT INTO player_item(player_identifier,inventory_type,inventory_slot,item_identifier,weapon_attack) " + "VALUES(@player_identifier,@inventory_type,-11,@item_identifier,17)", new MySqlParameter("@player_identifier", identifier), new MySqlParameter("@inventory_type", EInventoryType.Equipment), new MySqlParameter("@item_identifier", weaponIdentifier)); Database.Execute("INSERT INTO player_item(player_identifier,inventory_type,inventory_slot,item_identifier) VALUES(@player_identifier,@inventory_type,1,4161001)", new MySqlParameter("@player_identifier", identifier), new MySqlParameter("@inventory_type", EInventoryType.Etc)); using (DatabaseQuery query = Database.Query("SELECT * FROM player WHERE identifier=@identifier", new MySqlParameter("@identifier", identifier))) { query.NextRow(); SendPlayerCreate(pClient, query); } }