From 69a7f6d7e982d97a52f25436cd9063be9e1ddb78 Mon Sep 17 00:00:00 2001 From: MER Date: Sun, 27 Apr 2014 00:44:13 -0300 Subject: [PATCH 01/46] added Dumb and DumbNoMore packet classes --- .../com/ao/network/ServerPacketsManager.java | 6 ++-- .../packet/outgoing/DumbNoMorePacket.java | 34 ++++++++++++++++++ .../network/packet/outgoing/DumbPacket.java | 35 +++++++++++++++++++ .../packet/outgoing/UpdateStrengthPacket.java | 2 +- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbNoMorePacket.java create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java index 7d28125..65a1ec8 100755 --- a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java @@ -37,6 +37,8 @@ import com.ao.network.packet.outgoing.UpdateStrengthPacket; import com.ao.network.packet.outgoing.UserCharacterIndexInServerPacket; import com.ao.network.packet.outgoing.UserIndexInServer; +import com.ao.network.packet.outgoing.DumbPacket; +import com.ao.network.packet.outgoing.DumbNoMorePacket; /** * Manager for server-side packets. @@ -104,7 +106,7 @@ private enum ServerPackets { REST_OK(null), ERROR_MESSAGE(ErrorMessagePacket.class), BLIND(null), - DUMB(null), + DUMB(DumbPacket.class), SHOW_SIGNAL(null), CHANGE_NPC_INVENTORY_SLOT(null), UPDATE_HUNGER_AND_THRIST(null), @@ -117,7 +119,7 @@ private enum ServerPackets { ROLL_DICE(DiceRollPacket.class), MEDITATE_TOGGLE(null), BLIND_NO_MORE(null), - DUMB_NO_MORE(null), + DUMB_NO_MORE(DumbNoMorePacket.class), SEND_SKILLS(null), TRAINER_CREATURE_LIST(null), GUILD_NEWS(null), diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbNoMorePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbNoMorePacket.java new file mode 100644 index 0000000..a3e4ba7 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbNoMorePacket.java @@ -0,0 +1,34 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + + +/** + * Packet to tell the client the user is no longer dumb. + */ +public class DumbNoMorePacket implements OutgoingPacket{ + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} +} diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbPacket.java new file mode 100644 index 0000000..0de4e6e --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbPacket.java @@ -0,0 +1,35 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + + +/** + * Packet to tell the client the user is now dumb. + */ +public class DumbPacket implements OutgoingPacket{ + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + +} diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateStrengthPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateStrengthPacket.java index 0c9d8b4..dfde114 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateStrengthPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateStrengthPacket.java @@ -27,10 +27,10 @@ * @author mvanotti */ public class UpdateStrengthPacket implements OutgoingPacket { + protected byte strength; - /** * Creates a new UpdateStrength packet * From 8f0e0dce7a297d4c73f01c694781439177c5124f Mon Sep 17 00:00:00 2001 From: MER Date: Sun, 27 Apr 2014 03:36:08 -0300 Subject: [PATCH 02/46] Added SendSkillsPacket class --- .../java/com/ao/model/character/Skill.java | 27 +++++---- .../com/ao/model/character/UserCharacter.java | 57 +++++++++++++------ .../java/com/ao/model/user/LoggedUser.java | 29 ++++++++-- .../com/ao/network/ServerPacketsManager.java | 3 +- .../packet/outgoing/SendSkillsPacket.java | 55 ++++++++++++++++++ 5 files changed, 135 insertions(+), 36 deletions(-) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java diff --git a/aoxp-server/src/main/java/com/ao/model/character/Skill.java b/aoxp-server/src/main/java/com/ao/model/character/Skill.java index cb62574..e24ee2c 100755 --- a/aoxp-server/src/main/java/com/ao/model/character/Skill.java +++ b/aoxp-server/src/main/java/com/ao/model/character/Skill.java @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -*/ + */ package com.ao.model.character; @@ -22,28 +22,28 @@ * Defines available skills. */ public enum Skill { - LUCK, + MAGIC, - STEAL, + STEALING, COMBAT_TACTICS, HAND_TO_HAND_COMBAT, - MEDITATE, - STAB, + MEDITATION, + STABBING, HIDING, - SURVIVE, + SURVIVAL, LUMBER, TRADE, - DEFENSE, + SHIELD_DEFENSE, FISHING, MINING, - WOODWORK, - IRONWORK, + WOODWORKING, + SMITHING, LEADERSHIP, - TAME, - PROJECTILES, + TAMMING, + RANGED_COMBAT, WRESTLING, SAILING; - + /** * The amount of existing skills. * @@ -51,4 +51,7 @@ public enum Skill { */ public static final int AMOUNT = Skill.values().length; public static final Skill[] VALUES = Skill.values(); + + /** Maximum amount of points a character can earn for any given skill*/ + public static final int MAX_SKILL_POINT= 100; } diff --git a/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java b/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java index 4d57ec1..655ebb7 100755 --- a/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java +++ b/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -*/ + */ package com.ao.model.character; @@ -28,67 +28,88 @@ public interface UserCharacter extends Character { * @return The amount of skill points. */ int getSkill(Skill skill); - + + /** + * Retrieves the experience needed to level up the skill. + * @param skill The skill. + * @return the experience needed to level up the skill. + */ + int getSkillELU(Skill skill); // ELU stands for Experience Level Up + + /** + * Retrieves the skill's accumulated experience. + * @param skill The skill. + * @return the skill's progress. + */ + int getSkillExp(Skill skill); + /** * Adds points to the given user's skill. * @param skill The skill to add points. * @param points The points to add. */ void addToSkill(Skill skill, byte points); - + + /** + * Adds experience points to this skill. + * @param skill The skill. + * @param points the experience points to add. + */ + void addToSkillExp(Skill skill, byte points); + /** - * Checks if the user is doing some work. - * @return True if the user is working, false other wise. + * Checks if the user is working. + * @return True if the user is working, false otherwise. */ boolean isWorking(); - + /** * Sets the user to work. */ void work(); - + /** * Retrieves the user's guild name. * @return The user's guild name. */ String getGuildName(); - + /** * Sets the user's guild name. - * @param name The guild name to be setted. + * @param name The guild name to be set. */ void setGuildName(String name); - + /** * Retrieves the user's party id. * @return The user's party id if the user belongs to one, -1 otherwise. */ int getPartyId(); - + /** * Sets the user's party id. - * @param id The party id to be setted. + * @param id The party id to be set. */ void setPartyId(int id); - + /** * Retrieves the user's race. * @return The user's race. */ Race getRace(); - + /** * Retrieves the user's gender. * @return The user's gender. */ Gender getGender(); - + /** * Retrieves the user's archetype. * @return The user's archetype. */ Archetype getArchetype(); - + /** * Retrieves the user's stamina. * @return The user's stamina. @@ -112,10 +133,10 @@ public interface UserCharacter extends Character { * @param maxStamina The max stamina. */ public void setMaxStamina(int maxStamina); - + /** * Checks if the user is meditating. - * @return True if the user is meditating, false other wise. + * @return True if the user is meditating, false otherwise. */ boolean isMeditating(); diff --git a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java index e1bd8e5..d82a01b 100644 --- a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java +++ b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java @@ -125,11 +125,6 @@ public LoggedUser(Reputation reputation, Race race, Gender gender, this.description = description; } - @Override - public void addToSkill(Skill skill, byte points) { - // TODO Auto-generated method stub - - } @Override public Archetype getArchetype() { @@ -163,6 +158,18 @@ public int getSkill(Skill skill) { // TODO Auto-generated method stub return 0; } + + @Override + public int getSkillELU(Skill skill) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getSkillExp(Skill skill) { + // TODO Auto-generated method stub + return 0; + } @Override public boolean isWorking() { @@ -239,7 +246,19 @@ public void addToThirstiness(int points) { } } + + @Override + public void addToSkill(Skill skill, byte points) { + // TODO Auto-generated method stub + + } + + @Override + public void addToSkillExp(Skill skill, byte points) { + // TODO Auto-generated method stub + } + @Override public void attack(Character character) { // TODO Auto-generated method stub diff --git a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java index 65a1ec8..df0357c 100755 --- a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java @@ -32,6 +32,7 @@ import com.ao.network.packet.outgoing.ObjectCreatePacket; import com.ao.network.packet.outgoing.PlayMidiPacket; import com.ao.network.packet.outgoing.PlayWavePacket; +import com.ao.network.packet.outgoing.SendSkillsPacket; import com.ao.network.packet.outgoing.UpdateDexterityPacket; import com.ao.network.packet.outgoing.UpdateStrengthAndDexterityPacket; import com.ao.network.packet.outgoing.UpdateStrengthPacket; @@ -120,7 +121,7 @@ private enum ServerPackets { MEDITATE_TOGGLE(null), BLIND_NO_MORE(null), DUMB_NO_MORE(DumbNoMorePacket.class), - SEND_SKILLS(null), + SEND_SKILLS(SendSkillsPacket.class), TRAINER_CREATURE_LIST(null), GUILD_NEWS(null), OFFER_DETAILS(null), diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java new file mode 100644 index 0000000..36fc764 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java @@ -0,0 +1,55 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; +import com.ao.model.character.Skill; +import com.ao.model.character.UserCharacter; + +/** + * Packet to send user skill points and progress to the client + */ +public class SendSkillsPacket implements OutgoingPacket { + + private UserCharacter user; + + + public SendSkillsPacket(UserCharacter user) { + + super(); + this.user= user; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + for (Skill skill : Skill.VALUES) { + + buffer.put((byte)user.getSkill(skill)); + + if (user.getSkill(skill) < Skill.MAX_SKILL_POINT) + buffer.put( (byte) ( user.getSkillExp(skill) * 100 / user.getSkillELU(skill) ) ); + else + buffer.put((byte)0); + } + } + +} From aabebef681e94c9f51d9b734de92ac6b83baa5a4 Mon Sep 17 00:00:00 2001 From: MER Date: Sun, 27 Apr 2014 20:41:14 -0300 Subject: [PATCH 03/46] Added a getter method to the Skill enum --- .../model/builder/UserCharacterBuilder.java | 4 ++-- .../java/com/ao/model/character/Gender.java | 4 ++-- .../java/com/ao/model/character/Skill.java | 19 +++++++++++++++++-- .../com/ao/model/character/UserCharacter.java | 3 ++- .../packet/outgoing/SendSkillsPacket.java | 3 +-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java b/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java index 2c1d199..7b83156 100644 --- a/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java +++ b/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -*/ + */ package com.ao.model.builder; import java.util.Map; @@ -238,7 +238,7 @@ public UserCharacterBuilder withMana(int minMana, int maxMana) { public UserCharacterBuilder withSkills(Map skills) throws InvalidAttributeValueException { Preconditions.checkContentsNotNull(skills.values()); - for (Skill skill : Skill.VALUES) { + for (Skill skill : Skill.values()) { if (!skills.containsKey(skill)) { throw new InvalidAttributeValueException(); } diff --git a/aoxp-server/src/main/java/com/ao/model/character/Gender.java b/aoxp-server/src/main/java/com/ao/model/character/Gender.java index a6f6857..8e08109 100755 --- a/aoxp-server/src/main/java/com/ao/model/character/Gender.java +++ b/aoxp-server/src/main/java/com/ao/model/character/Gender.java @@ -28,7 +28,7 @@ public enum Gender { /** * Enum values. */ - private static Gender[] values = Gender.values(); + private static final Gender[] VALUES = Gender.values(); /** * Retrieves the gender with the given index. @@ -36,6 +36,6 @@ public enum Gender { * @return The gender. */ public static Gender get(byte index) { - return values[index]; + return VALUES[index]; } } diff --git a/aoxp-server/src/main/java/com/ao/model/character/Skill.java b/aoxp-server/src/main/java/com/ao/model/character/Skill.java index e24ee2c..99fe20c 100755 --- a/aoxp-server/src/main/java/com/ao/model/character/Skill.java +++ b/aoxp-server/src/main/java/com/ao/model/character/Skill.java @@ -23,6 +23,7 @@ */ public enum Skill { + //LUCK //no existe más MAGIC, STEALING, COMBAT_TACTICS, @@ -50,8 +51,22 @@ public enum Skill { * TODO: I don't really like this...any better alternative? */ public static final int AMOUNT = Skill.values().length; - public static final Skill[] VALUES = Skill.values(); + private static final Skill[] VALUES = Skill.values(); - /** Maximum amount of points a character can earn for any given skill*/ + /** + * Maximum amount of points a character can earn for any given skill + */ public static final int MAX_SKILL_POINT= 100; + + /** + * Retrieves the skill for the given index + * @param index the index + * @return the skill at the given index + */ + public Skill get(byte index) { + //TODO: must ensure index ranges between 0 and AMOUNT(not included) + return VALUES[index]; + } + + } diff --git a/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java b/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java index 655ebb7..2919094 100755 --- a/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java +++ b/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java @@ -31,10 +31,11 @@ public interface UserCharacter extends Character { /** * Retrieves the experience needed to level up the skill. + * ELU stands for Experience Level Up. * @param skill The skill. * @return the experience needed to level up the skill. */ - int getSkillELU(Skill skill); // ELU stands for Experience Level Up + int getSkillELU(Skill skill); /** * Retrieves the skill's accumulated experience. diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java index 36fc764..477fe22 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java @@ -41,7 +41,7 @@ public SendSkillsPacket(UserCharacter user) { @Override public void write(DataBuffer buffer) throws UnsupportedEncodingException { - for (Skill skill : Skill.VALUES) { + for (Skill skill : Skill.values()) { buffer.put((byte)user.getSkill(skill)); @@ -51,5 +51,4 @@ public void write(DataBuffer buffer) throws UnsupportedEncodingException { buffer.put((byte)0); } } - } From b95662a7ddda201a7191212a956d43c0d6f4ad2d Mon Sep 17 00:00:00 2001 From: MER Date: Mon, 28 Apr 2014 01:52:02 -0300 Subject: [PATCH 04/46] Added CommerceEndPacket, DisconnectPacket, LoggedPacket, NavigateTogglePacket, RemoveAllDialogsPacket, and UserCommerceInitPacket classes --- .../com/ao/network/ServerPacketsManager.java | 21 +++++---- .../packet/outgoing/CommerceEndPacket.java | 35 ++++++++++++++ .../packet/outgoing/DisconnectPacket.java | 35 ++++++++++++++ .../network/packet/outgoing/LoggedPacket.java | 47 +++++++++++++++++++ .../packet/outgoing/NavigateTogglePacket.java | 35 ++++++++++++++ .../outgoing/RemoveAllDialogsPacket.java | 35 ++++++++++++++ .../outgoing/UserCommerceInitPacket.java | 47 +++++++++++++++++++ 7 files changed, 247 insertions(+), 8 deletions(-) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceEndPacket.java create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/DisconnectPacket.java create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/NavigateTogglePacket.java create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveAllDialogsPacket.java create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java index df0357c..f45b786 100755 --- a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java @@ -25,22 +25,27 @@ import com.ao.network.packet.OutgoingPacket; import com.ao.network.packet.outgoing.ChangeMapPacket; import com.ao.network.packet.outgoing.CharacterCreatePacket; +import com.ao.network.packet.outgoing.CommerceEndPacket; import com.ao.network.packet.outgoing.ConsoleMessagePacket; import com.ao.network.packet.outgoing.DiceRollPacket; +import com.ao.network.packet.outgoing.DisconnectPacket; import com.ao.network.packet.outgoing.ErrorMessagePacket; import com.ao.network.packet.outgoing.GuildChatPacket; +import com.ao.network.packet.outgoing.NavigateTogglePacket; import com.ao.network.packet.outgoing.ObjectCreatePacket; import com.ao.network.packet.outgoing.PlayMidiPacket; import com.ao.network.packet.outgoing.PlayWavePacket; +import com.ao.network.packet.outgoing.RemoveAllDialogsPacket; import com.ao.network.packet.outgoing.SendSkillsPacket; import com.ao.network.packet.outgoing.UpdateDexterityPacket; import com.ao.network.packet.outgoing.UpdateStrengthAndDexterityPacket; import com.ao.network.packet.outgoing.UpdateStrengthPacket; import com.ao.network.packet.outgoing.UserCharacterIndexInServerPacket; +import com.ao.network.packet.outgoing.UserCommerceInitPacket; import com.ao.network.packet.outgoing.UserIndexInServer; import com.ao.network.packet.outgoing.DumbPacket; import com.ao.network.packet.outgoing.DumbNoMorePacket; - +import com.ao.network.packet.outgoing.LoggedPacket; /** * Manager for server-side packets. */ @@ -50,16 +55,16 @@ public class ServerPacketsManager { * Enumerates server packets. */ private enum ServerPackets { - LOGGED(null), - REMOVE_ALL_DIALOGS(null), - REMOVE_CHR_DIALOG(null), - TOGGLE_NAVIGATE(null), - DISCONNECT(null), - COMMERCE_END(null), + LOGGED(LoggedPacket.class), + REMOVE_ALL_DIALOGS(RemoveAllDialogsPacket.class), + REMOVE_CHAR_DIALOG(null), + TOGGLE_NAVIGATE(NavigateTogglePacket.class), + DISCONNECT(DisconnectPacket.class), + COMMERCE_END(CommerceEndPacket.class), BANKING_END(null), COMMERCE_INIT(null), BANK_INIT(null), - USER_COMMERCE_INIT(null), + USER_COMMERCE_INIT(UserCommerceInitPacket.class), USER_COMMERCE_END(null), USER_OFFER_CONFIRM(null), COMMERCE_CHAT(null), diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceEndPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceEndPacket.java new file mode 100644 index 0000000..2f96bac --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceEndPacket.java @@ -0,0 +1,35 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet to tell the client to close trade window. + */ +public class CommerceEndPacket implements OutgoingPacket{ + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + +} diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DisconnectPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DisconnectPacket.java new file mode 100644 index 0000000..7c5be94 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DisconnectPacket.java @@ -0,0 +1,35 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet to tell the client to disconnect the user. + */ +public class DisconnectPacket implements OutgoingPacket{ + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + +} diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java new file mode 100644 index 0000000..9dde45a --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java @@ -0,0 +1,47 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.character.UserCharacter; +import com.ao.model.character.archetype.UserArchetype; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet to tell the client to proceed with user login. + */ +public class LoggedPacket implements OutgoingPacket{ + + private UserCharacter user; + + + public LoggedPacket(UserCharacter user) { + + this.user= user; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.put((byte)UserArchetype.valueOf(user.getArchetype()).ordinal()); + } + +} diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/NavigateTogglePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/NavigateTogglePacket.java new file mode 100644 index 0000000..b63f352 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/NavigateTogglePacket.java @@ -0,0 +1,35 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet to tell the client the user sailed. + */ +public class NavigateTogglePacket implements OutgoingPacket{ + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + +} diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveAllDialogsPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveAllDialogsPacket.java new file mode 100644 index 0000000..c425418 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveAllDialogsPacket.java @@ -0,0 +1,35 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet to tell the client to remove all dialogs + */ +public class RemoveAllDialogsPacket implements OutgoingPacket{ + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + +} diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java new file mode 100644 index 0000000..a34bf9e --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java @@ -0,0 +1,47 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.character.UserCharacter; +import com.ao.model.user.LoggedUser; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet to tell the client to open user-to-user trade window. + */ +public class UserCommerceInitPacket implements OutgoingPacket{ + + private LoggedUser trader; + + + public UserCommerceInitPacket (LoggedUser trader) { + + this.trader= trader; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putASCIIString(trader.getName()); + } + +} From 16a53d52275cda62126fafec90d027e5d136662c Mon Sep 17 00:00:00 2001 From: MER Date: Mon, 28 Apr 2014 02:57:33 -0300 Subject: [PATCH 05/46] Replaced tabs with spaces. --- .../java/com/ao/model/character/Skill.java | 82 ++--- .../com/ao/model/character/UserCharacter.java | 248 ++++++++-------- .../com/ao/network/ServerPacketsManager.java | 280 +++++++++--------- .../packet/outgoing/CommerceEndPacket.java | 6 +- .../packet/outgoing/DisconnectPacket.java | 8 +- .../packet/outgoing/DumbNoMorePacket.java | 6 +- .../network/packet/outgoing/DumbPacket.java | 10 +- .../network/packet/outgoing/LoggedPacket.java | 16 +- .../packet/outgoing/NavigateTogglePacket.java | 6 +- .../outgoing/RemoveAllDialogsPacket.java | 6 +- .../packet/outgoing/SendSkillsPacket.java | 30 +- .../outgoing/UserCommerceInitPacket.java | 16 +- 12 files changed, 357 insertions(+), 357 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/model/character/Skill.java b/aoxp-server/src/main/java/com/ao/model/character/Skill.java index 99fe20c..9588606 100755 --- a/aoxp-server/src/main/java/com/ao/model/character/Skill.java +++ b/aoxp-server/src/main/java/com/ao/model/character/Skill.java @@ -23,50 +23,50 @@ */ public enum Skill { - //LUCK //no existe más - MAGIC, - STEALING, - COMBAT_TACTICS, - HAND_TO_HAND_COMBAT, - MEDITATION, - STABBING, - HIDING, - SURVIVAL, - LUMBER, - TRADE, - SHIELD_DEFENSE, - FISHING, - MINING, - WOODWORKING, - SMITHING, - LEADERSHIP, - TAMMING, - RANGED_COMBAT, - WRESTLING, - SAILING; + //LUCK //no existe más + MAGIC, + STEALING, + COMBAT_TACTICS, + HAND_TO_HAND_COMBAT, + MEDITATION, + STABBING, + HIDING, + SURVIVAL, + LUMBER, + TRADE, + SHIELD_DEFENSE, + FISHING, + MINING, + WOODWORKING, + SMITHING, + LEADERSHIP, + TAMMING, + RANGED_COMBAT, + WRESTLING, + SAILING; - /** - * The amount of existing skills. - * - * TODO: I don't really like this...any better alternative? - */ - public static final int AMOUNT = Skill.values().length; - private static final Skill[] VALUES = Skill.values(); + /** + * The amount of existing skills. + * + * TODO: I don't really like this...any better alternative? + */ + public static final int AMOUNT = Skill.values().length; + private static final Skill[] VALUES = Skill.values(); - /** - * Maximum amount of points a character can earn for any given skill - */ - public static final int MAX_SKILL_POINT= 100; + /** + * Maximum amount of points a character can earn for any given skill + */ + public static final int MAX_SKILL_POINT= 100; - /** - * Retrieves the skill for the given index - * @param index the index - * @return the skill at the given index - */ - public Skill get(byte index) { - //TODO: must ensure index ranges between 0 and AMOUNT(not included) - return VALUES[index]; - } + /** + * Retrieves the skill for the given index + * @param index the index + * @return the skill at the given index + */ + public Skill get(byte index) { + //TODO: must ensure index ranges between 0 and AMOUNT(not included) + return VALUES[index]; + } } diff --git a/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java b/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java index 2919094..3834457 100755 --- a/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java +++ b/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java @@ -22,128 +22,128 @@ public interface UserCharacter extends Character { - /** - * Retrieves the user's requested skill points. - * @param skill The skill. - * @return The amount of skill points. - */ - int getSkill(Skill skill); - - /** - * Retrieves the experience needed to level up the skill. - * ELU stands for Experience Level Up. - * @param skill The skill. - * @return the experience needed to level up the skill. - */ - int getSkillELU(Skill skill); - - /** - * Retrieves the skill's accumulated experience. - * @param skill The skill. - * @return the skill's progress. - */ - int getSkillExp(Skill skill); - - /** - * Adds points to the given user's skill. - * @param skill The skill to add points. - * @param points The points to add. - */ - void addToSkill(Skill skill, byte points); - - /** - * Adds experience points to this skill. - * @param skill The skill. - * @param points the experience points to add. - */ - void addToSkillExp(Skill skill, byte points); - - /** - * Checks if the user is working. - * @return True if the user is working, false otherwise. - */ - boolean isWorking(); - - /** - * Sets the user to work. - */ - void work(); - - /** - * Retrieves the user's guild name. - * @return The user's guild name. - */ - String getGuildName(); - - /** - * Sets the user's guild name. - * @param name The guild name to be set. - */ - void setGuildName(String name); - - /** - * Retrieves the user's party id. - * @return The user's party id if the user belongs to one, -1 otherwise. - */ - int getPartyId(); - - /** - * Sets the user's party id. - * @param id The party id to be set. - */ - void setPartyId(int id); - - /** - * Retrieves the user's race. - * @return The user's race. - */ - Race getRace(); - - /** - * Retrieves the user's gender. - * @return The user's gender. - */ - Gender getGender(); - - /** - * Retrieves the user's archetype. - * @return The user's archetype. - */ - Archetype getArchetype(); - - /** - * Retrieves the user's stamina. - * @return The user's stamina. - */ - public int getStamina(); - - /** - * Sets the user's stamina. - * @param stamina The stamina - */ - public void setStamina(int stamina); - - /** - * Retrieves the user's max stamina. - * @return The user's max stamina. - */ - public int getMaxStamina(); - - /** - * Sets the user's max stamina. - * @param maxStamina The max stamina. - */ - public void setMaxStamina(int maxStamina); - - /** - * Checks if the user is meditating. - * @return True if the user is meditating, false otherwise. - */ - boolean isMeditating(); - - /** - * Sets the user to meditate. - * @param meditating The boolean value. - */ - void setMeditate(boolean meditating); + /** + * Retrieves the user's requested skill points. + * @param skill The skill. + * @return The amount of skill points. + */ + int getSkill(Skill skill); + + /** + * Retrieves the experience needed to level up the skill. + * ELU stands for Experience Level Up. + * @param skill The skill. + * @return the experience needed to level up the skill. + */ + int getSkillELU(Skill skill); + + /** + * Retrieves the skill's accumulated experience. + * @param skill The skill. + * @return the skill's progress. + */ + int getSkillExp(Skill skill); + + /** + * Adds points to the given user's skill. + * @param skill The skill to add points. + * @param points The points to add. + */ + void addToSkill(Skill skill, byte points); + + /** + * Adds experience points to this skill. + * @param skill The skill. + * @param points the experience points to add. + */ + void addToSkillExp(Skill skill, byte points); + + /** + * Checks if the user is working. + * @return True if the user is working, false otherwise. + */ + boolean isWorking(); + + /** + * Sets the user to work. + */ + void work(); + + /** + * Retrieves the user's guild name. + * @return The user's guild name. + */ + String getGuildName(); + + /** + * Sets the user's guild name. + * @param name The guild name to be set. + */ + void setGuildName(String name); + + /** + * Retrieves the user's party id. + * @return The user's party id if the user belongs to one, -1 otherwise. + */ + int getPartyId(); + + /** + * Sets the user's party id. + * @param id The party id to be set. + */ + void setPartyId(int id); + + /** + * Retrieves the user's race. + * @return The user's race. + */ + Race getRace(); + + /** + * Retrieves the user's gender. + * @return The user's gender. + */ + Gender getGender(); + + /** + * Retrieves the user's archetype. + * @return The user's archetype. + */ + Archetype getArchetype(); + + /** + * Retrieves the user's stamina. + * @return The user's stamina. + */ + public int getStamina(); + + /** + * Sets the user's stamina. + * @param stamina The stamina + */ + public void setStamina(int stamina); + + /** + * Retrieves the user's max stamina. + * @return The user's max stamina. + */ + public int getMaxStamina(); + + /** + * Sets the user's max stamina. + * @param maxStamina The max stamina. + */ + public void setMaxStamina(int maxStamina); + + /** + * Checks if the user is meditating. + * @return True if the user is meditating, false otherwise. + */ + boolean isMeditating(); + + /** + * Sets the user to meditate. + * @param meditating The boolean value. + */ + void setMeditate(boolean meditating); } diff --git a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java index f45b786..953162c 100755 --- a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java @@ -51,151 +51,151 @@ */ public class ServerPacketsManager { - /** - * Enumerates server packets. - */ - private enum ServerPackets { - LOGGED(LoggedPacket.class), - REMOVE_ALL_DIALOGS(RemoveAllDialogsPacket.class), - REMOVE_CHAR_DIALOG(null), - TOGGLE_NAVIGATE(NavigateTogglePacket.class), - DISCONNECT(DisconnectPacket.class), - COMMERCE_END(CommerceEndPacket.class), - BANKING_END(null), - COMMERCE_INIT(null), - BANK_INIT(null), - USER_COMMERCE_INIT(UserCommerceInitPacket.class), - USER_COMMERCE_END(null), - USER_OFFER_CONFIRM(null), - COMMERCE_CHAT(null), - SHOW_BLACKSMITH_FORM(null), - SHOW_CARPENTER_FORM(null), - UPDATE_STAMINA(null), - UPDATE_MANA(null), - UPDATE_HP(null), - UPDATE_GOLD(null), - UPDATE_BANK_GOLD(null), - UPDATE_EXP(null), - CHANGE_MAP(ChangeMapPacket.class), - POSITION_UPDATE(null), - CHAT_OVER_HEAD(null), - CONSOLE_MESSAGE(ConsoleMessagePacket.class), - GUILD_CHAT(GuildChatPacket.class), - SHOW_MESSAGE_BOX(null), - USER_INDEX_IN_SERVER(UserIndexInServer.class), - USER_CHARACTER_INDEX_IN_SERVER(UserCharacterIndexInServerPacket.class), - CHARACTER_CREATE(CharacterCreatePacket.class), - CHARACTER_REMOVE(null), - CHARACTER_CHANGE_NICKNAME(null), - CHARACTER_MOVE(null), - CHARACTER_FORCE_MOVE(null), - CHARACTER_CHANGE(null), - OBJECT_CREATE(ObjectCreatePacket.class), - OBJECT_DEETE(null), - BLOCK_POSITION(null), - PLAY_MIDI(PlayMidiPacket.class), - PLAY_WAVE(PlayWavePacket.class), - GUILD_LIST(null), - AREA_CHANGED(null), - TOGGLE_PAUSE(null), - TOGGLE_RAIN(null), - CREATE_FX(null), - UPDATE_USER_STATS(null), - WORK_REQUEST_TARGET(null), - CHANGE_INVENTORY_SLOT(null), - CHANGE_BANK_SLOT(null), - CHANGE_SPELL_SLOT(ChangeSpellSlotPacket.class), - ATTRIBUTES(null), - BLACKSMITH_WEAPONS(null), - BLACKSMITH_ARMORS(null), - CARPENTER_OBJECTS(null), - REST_OK(null), - ERROR_MESSAGE(ErrorMessagePacket.class), - BLIND(null), - DUMB(DumbPacket.class), - SHOW_SIGNAL(null), - CHANGE_NPC_INVENTORY_SLOT(null), - UPDATE_HUNGER_AND_THRIST(null), - FAME(null), - MINI_STATS(null), - LEVEL_UP(null), - ADD_FORUM_MESAGE(null), - SHOW_FORUM_MESSAGE(null), - SET_INVISIBLE(null), - ROLL_DICE(DiceRollPacket.class), - MEDITATE_TOGGLE(null), - BLIND_NO_MORE(null), - DUMB_NO_MORE(DumbNoMorePacket.class), - SEND_SKILLS(SendSkillsPacket.class), - TRAINER_CREATURE_LIST(null), - GUILD_NEWS(null), - OFFER_DETAILS(null), - ALIANCE_PROPOSALS_LIST(null), - PEACE_PROPOSALS_LIST(null), - CHARACTER_INFO(null), - GUILD_LEADER_INFO(null), - GUILD_MEMBER_INFO(null), - GUILD_DETAILS(null), - SHOW_GUILD_FUNDATION_FORM(null), - PARALIZE_OK(null), - SHOW_USER_REQUEST(null), - TRADE_OK(null), - BANK_OK(null), - CHANGE_USER_TRADE_SLOT(null), - SEND_NIGHT(null), - PONG(null), - UPDATE_TAG_AND_STATUS(null), - SPAWN_LIST(null), - SHOW_SOS_FORM(null), - SHOW_MOTD_EDITION_FORM(null), - SHOW_GM_PANEL_FORM(null), - USER_NAME_LIST(null), - SHOW_DENOUNCES(null), - RECORD_LIST(null), - RECORD_DETAILS(null), - SHOW_GUILD_ALIGN(null), - SHOW_PARTY_FORM(null), - UPDATE_STRENGHT_AND_DEXTERITY(UpdateStrengthAndDexterityPacket.class), - UPDATE_STRENGHT(UpdateStrengthPacket.class), - UPDATE_DEXTERITY(UpdateDexterityPacket.class), - ADD_SLOTS(null), - MULTI_MESSAGE(null), - STOP_WORKING(null), - CANCEL_OFFER_ITEM(null); + /** + * Enumerates server packets. + */ + private enum ServerPackets { + LOGGED(LoggedPacket.class), + REMOVE_ALL_DIALOGS(RemoveAllDialogsPacket.class), + REMOVE_CHAR_DIALOG(null), + TOGGLE_NAVIGATE(NavigateTogglePacket.class), + DISCONNECT(DisconnectPacket.class), + COMMERCE_END(CommerceEndPacket.class), + BANKING_END(null), + COMMERCE_INIT(null), + BANK_INIT(null), + USER_COMMERCE_INIT(UserCommerceInitPacket.class), + USER_COMMERCE_END(null), + USER_OFFER_CONFIRM(null), + COMMERCE_CHAT(null), + SHOW_BLACKSMITH_FORM(null), + SHOW_CARPENTER_FORM(null), + UPDATE_STAMINA(null), + UPDATE_MANA(null), + UPDATE_HP(null), + UPDATE_GOLD(null), + UPDATE_BANK_GOLD(null), + UPDATE_EXP(null), + CHANGE_MAP(ChangeMapPacket.class), + POSITION_UPDATE(null), + CHAT_OVER_HEAD(null), + CONSOLE_MESSAGE(ConsoleMessagePacket.class), + GUILD_CHAT(GuildChatPacket.class), + SHOW_MESSAGE_BOX(null), + USER_INDEX_IN_SERVER(UserIndexInServer.class), + USER_CHARACTER_INDEX_IN_SERVER(UserCharacterIndexInServerPacket.class), + CHARACTER_CREATE(CharacterCreatePacket.class), + CHARACTER_REMOVE(null), + CHARACTER_CHANGE_NICKNAME(null), + CHARACTER_MOVE(null), + CHARACTER_FORCE_MOVE(null), + CHARACTER_CHANGE(null), + OBJECT_CREATE(ObjectCreatePacket.class), + OBJECT_DEETE(null), + BLOCK_POSITION(null), + PLAY_MIDI(PlayMidiPacket.class), + PLAY_WAVE(PlayWavePacket.class), + GUILD_LIST(null), + AREA_CHANGED(null), + TOGGLE_PAUSE(null), + TOGGLE_RAIN(null), + CREATE_FX(null), + UPDATE_USER_STATS(null), + WORK_REQUEST_TARGET(null), + CHANGE_INVENTORY_SLOT(null), + CHANGE_BANK_SLOT(null), + CHANGE_SPELL_SLOT(ChangeSpellSlotPacket.class), + ATTRIBUTES(null), + BLACKSMITH_WEAPONS(null), + BLACKSMITH_ARMORS(null), + CARPENTER_OBJECTS(null), + REST_OK(null), + ERROR_MESSAGE(ErrorMessagePacket.class), + BLIND(null), + DUMB(DumbPacket.class), + SHOW_SIGNAL(null), + CHANGE_NPC_INVENTORY_SLOT(null), + UPDATE_HUNGER_AND_THRIST(null), + FAME(null), + MINI_STATS(null), + LEVEL_UP(null), + ADD_FORUM_MESAGE(null), + SHOW_FORUM_MESSAGE(null), + SET_INVISIBLE(null), + ROLL_DICE(DiceRollPacket.class), + MEDITATE_TOGGLE(null), + BLIND_NO_MORE(null), + DUMB_NO_MORE(DumbNoMorePacket.class), + SEND_SKILLS(SendSkillsPacket.class), + TRAINER_CREATURE_LIST(null), + GUILD_NEWS(null), + OFFER_DETAILS(null), + ALIANCE_PROPOSALS_LIST(null), + PEACE_PROPOSALS_LIST(null), + CHARACTER_INFO(null), + GUILD_LEADER_INFO(null), + GUILD_MEMBER_INFO(null), + GUILD_DETAILS(null), + SHOW_GUILD_FUNDATION_FORM(null), + PARALIZE_OK(null), + SHOW_USER_REQUEST(null), + TRADE_OK(null), + BANK_OK(null), + CHANGE_USER_TRADE_SLOT(null), + SEND_NIGHT(null), + PONG(null), + UPDATE_TAG_AND_STATUS(null), + SPAWN_LIST(null), + SHOW_SOS_FORM(null), + SHOW_MOTD_EDITION_FORM(null), + SHOW_GM_PANEL_FORM(null), + USER_NAME_LIST(null), + SHOW_DENOUNCES(null), + RECORD_LIST(null), + RECORD_DETAILS(null), + SHOW_GUILD_ALIGN(null), + SHOW_PARTY_FORM(null), + UPDATE_STRENGHT_AND_DEXTERITY(UpdateStrengthAndDexterityPacket.class), + UPDATE_STRENGHT(UpdateStrengthPacket.class), + UPDATE_DEXTERITY(UpdateDexterityPacket.class), + ADD_SLOTS(null), + MULTI_MESSAGE(null), + STOP_WORKING(null), + CANCEL_OFFER_ITEM(null); - protected Class packetClass; + protected Class packetClass; - private ServerPackets(Class packet) { - packetClass = packet; - } - } + private ServerPackets(Class packet) { + packetClass = packet; + } + } - /** - * Maps packets ids to their classes. - */ - protected static final ServerPackets[] packets = ServerPackets.values(); + /** + * Maps packets ids to their classes. + */ + protected static final ServerPackets[] packets = ServerPackets.values(); - /** - * Maps packets classes to their ids. - */ - protected static final Map, Integer> packetsMap = new HashMap, Integer>(); + /** + * Maps packets classes to their ids. + */ + protected static final Map, Integer> packetsMap = new HashMap, Integer>(); - static { - for (ServerPackets packet : packets) { - packetsMap.put(packet.packetClass, packet.ordinal()); - } - } + static { + for (ServerPackets packet : packets) { + packetsMap.put(packet.packetClass, packet.ordinal()); + } + } - /** - * Writes the given packet in the given buffer. - * @param packet The packet to write. - * @param buffer The buffer where to write the packet. - * @throws UnsupportedEncodingException - */ - public static void write(OutgoingPacket packet, DataBuffer buffer) throws UnsupportedEncodingException { + /** + * Writes the given packet in the given buffer. + * @param packet The packet to write. + * @param buffer The buffer where to write the packet. + * @throws UnsupportedEncodingException + */ + public static void write(OutgoingPacket packet, DataBuffer buffer) throws UnsupportedEncodingException { - // Put the packet id before the packet itself. - buffer.put(packetsMap.get(packet.getClass()).byteValue()); - packet.write(buffer); - } + // Put the packet id before the packet itself. + buffer.put(packetsMap.get(packet.getClass()).byteValue()); + packet.write(buffer); + } } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceEndPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceEndPacket.java index 2f96bac..02786f4 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceEndPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceEndPacket.java @@ -28,8 +28,8 @@ */ public class CommerceEndPacket implements OutgoingPacket{ - - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DisconnectPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DisconnectPacket.java index 7c5be94..e5356c2 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DisconnectPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DisconnectPacket.java @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -*/ + */ package com.ao.network.packet.outgoing; @@ -28,8 +28,8 @@ */ public class DisconnectPacket implements OutgoingPacket{ - - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbNoMorePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbNoMorePacket.java index a3e4ba7..c74a13e 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbNoMorePacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbNoMorePacket.java @@ -28,7 +28,7 @@ */ public class DumbNoMorePacket implements OutgoingPacket{ - - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbPacket.java index 0de4e6e..5e091ff 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/DumbPacket.java @@ -27,9 +27,9 @@ * Packet to tell the client the user is now dumb. */ public class DumbPacket implements OutgoingPacket{ - - - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException {} - + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java index 9dde45a..a9c7ac1 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java @@ -30,18 +30,18 @@ */ public class LoggedPacket implements OutgoingPacket{ - private UserCharacter user; + private UserCharacter user; - public LoggedPacket(UserCharacter user) { + public LoggedPacket(UserCharacter user) { - this.user= user; - } + this.user= user; + } - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException { + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { - buffer.put((byte)UserArchetype.valueOf(user.getArchetype()).ordinal()); - } + buffer.put((byte)UserArchetype.valueOf(user.getArchetype()).ordinal()); + } } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/NavigateTogglePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/NavigateTogglePacket.java index b63f352..8d6a947 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/NavigateTogglePacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/NavigateTogglePacket.java @@ -28,8 +28,8 @@ */ public class NavigateTogglePacket implements OutgoingPacket{ - - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveAllDialogsPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveAllDialogsPacket.java index c425418..ea515db 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveAllDialogsPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveAllDialogsPacket.java @@ -28,8 +28,8 @@ */ public class RemoveAllDialogsPacket implements OutgoingPacket{ - - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java index 477fe22..471e324 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/SendSkillsPacket.java @@ -29,26 +29,26 @@ */ public class SendSkillsPacket implements OutgoingPacket { - private UserCharacter user; + private UserCharacter user; - public SendSkillsPacket(UserCharacter user) { + public SendSkillsPacket(UserCharacter user) { - super(); - this.user= user; - } + super(); + this.user= user; + } - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException { + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { - for (Skill skill : Skill.values()) { + for (Skill skill : Skill.values()) { - buffer.put((byte)user.getSkill(skill)); + buffer.put((byte)user.getSkill(skill)); - if (user.getSkill(skill) < Skill.MAX_SKILL_POINT) - buffer.put( (byte) ( user.getSkillExp(skill) * 100 / user.getSkillELU(skill) ) ); - else - buffer.put((byte)0); - } - } + if (user.getSkill(skill) < Skill.MAX_SKILL_POINT) + buffer.put( (byte) ( user.getSkillExp(skill) * 100 / user.getSkillELU(skill) ) ); + else + buffer.put((byte)0); + } + } } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java index a34bf9e..8e7d9a5 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java @@ -30,18 +30,18 @@ */ public class UserCommerceInitPacket implements OutgoingPacket{ - private LoggedUser trader; + private LoggedUser trader; - public UserCommerceInitPacket (LoggedUser trader) { + public UserCommerceInitPacket (LoggedUser trader) { - this.trader= trader; - } + this.trader= trader; + } - @Override - public void write(DataBuffer buffer) throws UnsupportedEncodingException { + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { - buffer.putASCIIString(trader.getName()); - } + buffer.putASCIIString(trader.getName()); + } } From 18d9f3e5581544d8c66d704cc16111509c704f2a Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:28:33 -0300 Subject: [PATCH 06/46] Updated ServerPacketsManager --- .../com/ao/network/ServerPacketsManager.java | 94 ++++++++++++------- 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java index 953162c..527933c 100755 --- a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java @@ -23,29 +23,51 @@ import java.util.Map; import com.ao.network.packet.OutgoingPacket; +import com.ao.network.packet.outgoing.AreaChangedPacket; +import com.ao.network.packet.outgoing.BlockPositionPacket; +import com.ao.network.packet.outgoing.ChangeInventorySlotPacket; import com.ao.network.packet.outgoing.ChangeMapPacket; +import com.ao.network.packet.outgoing.CharacterChangeNickNamePacket; +import com.ao.network.packet.outgoing.CharacterChangePacket; import com.ao.network.packet.outgoing.CharacterCreatePacket; +import com.ao.network.packet.outgoing.CharacterForceMovePacket; +import com.ao.network.packet.outgoing.CharacterMovePacket; +import com.ao.network.packet.outgoing.CharacterRemovePacket; +import com.ao.network.packet.outgoing.ChatOverHeadPacket; +import com.ao.network.packet.outgoing.CommerceChatPacket; import com.ao.network.packet.outgoing.CommerceEndPacket; import com.ao.network.packet.outgoing.ConsoleMessagePacket; +import com.ao.network.packet.outgoing.CreateFXPacket; import com.ao.network.packet.outgoing.DiceRollPacket; import com.ao.network.packet.outgoing.DisconnectPacket; import com.ao.network.packet.outgoing.ErrorMessagePacket; import com.ao.network.packet.outgoing.GuildChatPacket; import com.ao.network.packet.outgoing.NavigateTogglePacket; import com.ao.network.packet.outgoing.ObjectCreatePacket; +import com.ao.network.packet.outgoing.ObjectDeletePacket; import com.ao.network.packet.outgoing.PlayMidiPacket; import com.ao.network.packet.outgoing.PlayWavePacket; import com.ao.network.packet.outgoing.RemoveAllDialogsPacket; +import com.ao.network.packet.outgoing.RemoveCharDialogPacket; import com.ao.network.packet.outgoing.SendSkillsPacket; +import com.ao.network.packet.outgoing.ShowMessageBoxPacket; import com.ao.network.packet.outgoing.UpdateDexterityPacket; +import com.ao.network.packet.outgoing.UpdateExperiencePacket; +import com.ao.network.packet.outgoing.UpdateGoldPacket; +import com.ao.network.packet.outgoing.UpdateHPPacket; +import com.ao.network.packet.outgoing.UpdateManaPacket; +import com.ao.network.packet.outgoing.UpdatePositionPacket; +import com.ao.network.packet.outgoing.UpdateStaminaPacket; import com.ao.network.packet.outgoing.UpdateStrengthAndDexterityPacket; import com.ao.network.packet.outgoing.UpdateStrengthPacket; +import com.ao.network.packet.outgoing.UpdateUserStatsPacket; import com.ao.network.packet.outgoing.UserCharacterIndexInServerPacket; import com.ao.network.packet.outgoing.UserCommerceInitPacket; import com.ao.network.packet.outgoing.UserIndexInServer; import com.ao.network.packet.outgoing.DumbPacket; import com.ao.network.packet.outgoing.DumbNoMorePacket; import com.ao.network.packet.outgoing.LoggedPacket; +import com.ao.network.packet.outgoing.WorkRequestTargetPacket; /** * Manager for server-side packets. */ @@ -56,53 +78,53 @@ public class ServerPacketsManager { */ private enum ServerPackets { LOGGED(LoggedPacket.class), - REMOVE_ALL_DIALOGS(RemoveAllDialogsPacket.class), - REMOVE_CHAR_DIALOG(null), - TOGGLE_NAVIGATE(NavigateTogglePacket.class), - DISCONNECT(DisconnectPacket.class), - COMMERCE_END(CommerceEndPacket.class), - BANKING_END(null), - COMMERCE_INIT(null), - BANK_INIT(null), + REMOVE_ALL_DIALOGS(RemoveAllDialogsPacket.class), //sends no data + REMOVE_CHAR_DIALOG(RemoveCharDialogPacket.class), + TOGGLE_NAVIGATE(NavigateTogglePacket.class), //sends no data + DISCONNECT(DisconnectPacket.class), //sends no data + COMMERCE_END(CommerceEndPacket.class), //sends no data + BANKING_END(null), //sends no data + COMMERCE_INIT(null), //sends no data + BANK_INIT(null), //CANNOT BE DONE UNTIL VAULT GETTERS ARE DEFINED USER_COMMERCE_INIT(UserCommerceInitPacket.class), - USER_COMMERCE_END(null), - USER_OFFER_CONFIRM(null), - COMMERCE_CHAT(null), - SHOW_BLACKSMITH_FORM(null), - SHOW_CARPENTER_FORM(null), - UPDATE_STAMINA(null), - UPDATE_MANA(null), - UPDATE_HP(null), - UPDATE_GOLD(null), - UPDATE_BANK_GOLD(null), - UPDATE_EXP(null), + USER_COMMERCE_END(null), //sends no data + USER_OFFER_CONFIRM(null), //sends no data + COMMERCE_CHAT(CommerceChatPacket.class), + SHOW_BLACKSMITH_FORM(null), //sends no data + SHOW_CARPENTER_FORM(null), //sends no data + UPDATE_STAMINA(UpdateStaminaPacket.class), + UPDATE_MANA(UpdateManaPacket.class), + UPDATE_HP(UpdateHPPacket.class), + UPDATE_GOLD(UpdateGoldPacket.class), + UPDATE_BANK_GOLD(null), //CANNOT BE DONE UNTIL A GOLD-IN-BANK GETTER IS DEFINED + UPDATE_EXP(UpdateExperiencePacket.class), CHANGE_MAP(ChangeMapPacket.class), - POSITION_UPDATE(null), - CHAT_OVER_HEAD(null), + POSITION_UPDATE(UpdatePositionPacket.class), + CHAT_OVER_HEAD(ChatOverHeadPacket.class), CONSOLE_MESSAGE(ConsoleMessagePacket.class), GUILD_CHAT(GuildChatPacket.class), - SHOW_MESSAGE_BOX(null), + SHOW_MESSAGE_BOX(ShowMessageBoxPacket.class), USER_INDEX_IN_SERVER(UserIndexInServer.class), USER_CHARACTER_INDEX_IN_SERVER(UserCharacterIndexInServerPacket.class), CHARACTER_CREATE(CharacterCreatePacket.class), - CHARACTER_REMOVE(null), - CHARACTER_CHANGE_NICKNAME(null), - CHARACTER_MOVE(null), - CHARACTER_FORCE_MOVE(null), - CHARACTER_CHANGE(null), + CHARACTER_REMOVE(CharacterRemovePacket.class), + CHARACTER_CHANGE_NICKNAME(CharacterChangeNickNamePacket.class), + CHARACTER_MOVE(CharacterMovePacket.class), + CHARACTER_FORCE_MOVE(CharacterForceMovePacket.class), + CHARACTER_CHANGE(CharacterChangePacket.class), OBJECT_CREATE(ObjectCreatePacket.class), - OBJECT_DEETE(null), - BLOCK_POSITION(null), + OBJECT_DELETE(ObjectDeletePacket.class), + BLOCK_POSITION(BlockPositionPacket.class), PLAY_MIDI(PlayMidiPacket.class), PLAY_WAVE(PlayWavePacket.class), - GUILD_LIST(null), + GUILD_LIST(null), //CAN'T BE DONE YET AREA_CHANGED(null), - TOGGLE_PAUSE(null), - TOGGLE_RAIN(null), - CREATE_FX(null), - UPDATE_USER_STATS(null), - WORK_REQUEST_TARGET(null), - CHANGE_INVENTORY_SLOT(null), + TOGGLE_PAUSE(null), //sends no data + TOGGLE_RAIN(null), //sends no data + CREATE_FX(CreateFXPacket.class), + UPDATE_USER_STATS(UpdateUserStatsPacket.class), + WORK_REQUEST_TARGET(WorkRequestTargetPacket.class), + CHANGE_INVENTORY_SLOT(ChangeInventorySlotPacket.class), CHANGE_BANK_SLOT(null), CHANGE_SPELL_SLOT(ChangeSpellSlotPacket.class), ATTRIBUTES(null), From 28adac0c3dc46edc34e054ca63582e332fd66753 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:29:31 -0300 Subject: [PATCH 07/46] Fixed comment in Font class --- aoxp-server/src/main/java/com/ao/model/fonts/Font.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aoxp-server/src/main/java/com/ao/model/fonts/Font.java b/aoxp-server/src/main/java/com/ao/model/fonts/Font.java index df49c3c..cce6e5b 100755 --- a/aoxp-server/src/main/java/com/ao/model/fonts/Font.java +++ b/aoxp-server/src/main/java/com/ao/model/fonts/Font.java @@ -19,7 +19,7 @@ package com.ao.model.fonts; /** - * Defines available skills. + * Defines available fonts. */ public enum Font { TALK, From 3ef25334faeed1562dd7bfe7ebd3d7c120b784f7 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:30:03 -0300 Subject: [PATCH 08/46] Added WorkRequestTargetPacket --- .../outgoing/WorkRequestTargetPacket.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/WorkRequestTargetPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/WorkRequestTargetPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/WorkRequestTargetPacket.java new file mode 100644 index 0000000..56d50f9 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/WorkRequestTargetPacket.java @@ -0,0 +1,49 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.character.Skill; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that sends the client the data needed to properly prompt the user according to the tool being used. + */ +public class WorkRequestTargetPacket implements OutgoingPacket{ + + private Skill skill; + + /** + * Creates the packet. + * @param skill the skill representing the activity the user intends to perform + */ + public WorkRequestTargetPacket(Skill skill) { + + this.skill= skill; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.put((byte) skill.ordinal()); + } + +} From b3011a245d39f210dca699252cf1a20721793dba Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:31:03 -0300 Subject: [PATCH 09/46] Added UserCommerceInitPacket --- .../network/packet/outgoing/UserCommerceInitPacket.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java index 8e7d9a5..d92f683 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UserCommerceInitPacket.java @@ -20,19 +20,21 @@ import java.io.UnsupportedEncodingException; -import com.ao.model.character.UserCharacter; import com.ao.model.user.LoggedUser; import com.ao.network.DataBuffer; import com.ao.network.packet.OutgoingPacket; /** - * Packet to tell the client to open user-to-user trade window. + * Packet that prompts the client to initiate user-to-user trade console. */ public class UserCommerceInitPacket implements OutgoingPacket{ private LoggedUser trader; - + /** + * Creates the packet. + * @param trader the character with which the trade begins + */ public UserCommerceInitPacket (LoggedUser trader) { this.trader= trader; From d3441e8d8b96866c9efafc0c05dbbecd8bdfc5f4 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:31:24 -0300 Subject: [PATCH 10/46] Added UpdateStaminaPacket --- .../packet/outgoing/UpdateStaminaPacket.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateStaminaPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateStaminaPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateStaminaPacket.java new file mode 100644 index 0000000..f0ab23c --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateStaminaPacket.java @@ -0,0 +1,52 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.user.LoggedUser; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports an update in character's stamina. + * */ +public class UpdateStaminaPacket implements OutgoingPacket{ + + private LoggedUser character; + + + /** + * Creates the packet. + * @param character the character whose stamina was updated. + */ + public UpdateStaminaPacket(LoggedUser character) { + + this.character= character; + } + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getStamina()); + } + + +} From a17ac6c036727704247b163c199e115a5464ab65 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:31:49 -0300 Subject: [PATCH 11/46] Added UpdatePositionPacket --- .../packet/outgoing/UpdatePositionPacket.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdatePositionPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdatePositionPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdatePositionPacket.java new file mode 100644 index 0000000..7ce613b --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdatePositionPacket.java @@ -0,0 +1,52 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.user.LoggedUser; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports an update in character's position. + */ +public class UpdatePositionPacket implements OutgoingPacket{ + + private LoggedUser character; + + /** + * Creates the packet. + * @param character the character whose position was updated. + */ + public UpdatePositionPacket (LoggedUser character) { + + this.character= character; + } + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.put(character.getPosition().getX()); + buffer.put(character.getPosition().getY()); + } + + +} From 687b9df3fb7524de9df54335d2f58b5cd029620e Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:32:06 -0300 Subject: [PATCH 12/46] Added UpdateManaPacket --- .../packet/outgoing/UpdateManaPacket.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateManaPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateManaPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateManaPacket.java new file mode 100644 index 0000000..236612b --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateManaPacket.java @@ -0,0 +1,49 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.user.LoggedUser; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports an update in character's mana. + */ +public class UpdateManaPacket implements OutgoingPacket{ + + private LoggedUser character; + + /** + * Creates the packet. + * @param character the character whose mana was updated. + */ + public UpdateManaPacket(LoggedUser character) { + + this.character= character; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getMana()); + } + +} From 996d767038ea99ea587a504b6bb532503a9df44e Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:32:24 -0300 Subject: [PATCH 13/46] Added UpdateHPPacket --- .../packet/outgoing/UpdateHPPacket.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateHPPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateHPPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateHPPacket.java new file mode 100644 index 0000000..ff1dd38 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateHPPacket.java @@ -0,0 +1,49 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.user.LoggedUser; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports an update in character's HP. + */ +public class UpdateHPPacket implements OutgoingPacket{ + + private LoggedUser character; + + /** + * Creates the packet. + * @param character the character whose HP was updated. + */ + public UpdateHPPacket (LoggedUser character) { + + this.character= character; + } + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getHitPoints()); + } +} From f1f5dca54e18da242e9d648546b3b456e489b229 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:32:57 -0300 Subject: [PATCH 14/46] Added UpdateGoldPacket --- .../packet/outgoing/UpdateGoldPacket.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateGoldPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateGoldPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateGoldPacket.java new file mode 100644 index 0000000..88fab21 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateGoldPacket.java @@ -0,0 +1,52 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.user.LoggedUser; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that informs about an update in character's amount of gold. + */ +public class UpdateGoldPacket implements OutgoingPacket{ + + private LoggedUser character; + + /** + * Creates the packet. + * @param character the character whose amount of gold was updated. + */ + public UpdateGoldPacket (LoggedUser character) { + + this.character= character; + } + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putInt(character.getMoney()); + + } + + +} From 3adb23b94f8909797e66158d1d1e32e55a367b9a Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:33:19 -0300 Subject: [PATCH 15/46] Added UpdateExperiencePacket --- .../outgoing/UpdateExperiencePacket.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateExperiencePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateExperiencePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateExperiencePacket.java new file mode 100644 index 0000000..ac23d55 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/UpdateExperiencePacket.java @@ -0,0 +1,50 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.user.LoggedUser; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that informs about an update in character's experience. + */ +public class UpdateExperiencePacket implements OutgoingPacket{ + + private LoggedUser character; + + /** + * Creates the packet. + * @param character the character whose experience was updated. + */ + public UpdateExperiencePacket (LoggedUser character) { + + this.character= character; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putInt(character.getExperience()); + } + + +} From b34fe7e6a21eb83d579cf129b4327fbfc0c28ffe Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:34:06 -0300 Subject: [PATCH 16/46] Added ShowMessageBoxPacket --- .../packet/outgoing/ShowMessageBoxPacket.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/ShowMessageBoxPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ShowMessageBoxPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ShowMessageBoxPacket.java new file mode 100644 index 0000000..5a7a79b --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ShowMessageBoxPacket.java @@ -0,0 +1,49 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that sends a message to display in a message box. + */ +public class ShowMessageBoxPacket implements OutgoingPacket{ + + private String message; + + + /** + * Creates the packet. + * @param message the message to display + */ + public ShowMessageBoxPacket(String message) { + + this.message= message; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putASCIIString(message); + } + +} From 4b0d7be2f9109efea50ea481ca8487ef82d00a66 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:34:35 -0300 Subject: [PATCH 17/46] Added RemoveCharDialogPacket --- .../outgoing/RemoveCharDialogPacket.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveCharDialogPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveCharDialogPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveCharDialogPacket.java new file mode 100644 index 0000000..398b23f --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/RemoveCharDialogPacket.java @@ -0,0 +1,53 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.character.Character; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet to tell the client to remove a character's dialog. + */ +public class RemoveCharDialogPacket implements OutgoingPacket{ + + private Character character; + + /** + * Creates the packet. + * @param character the character who's dialog will be removed. + */ + public RemoveCharDialogPacket (Character character) { + + this.character= character; + } + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getCharIndex()); + + } + + + +} From b92044349c7de6512b1ec9451ffafec1acd83534 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:34:58 -0300 Subject: [PATCH 18/46] Added ObjectDeletePacket --- .../packet/outgoing/ObjectDeletePacket.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/ObjectDeletePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ObjectDeletePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ObjectDeletePacket.java new file mode 100644 index 0000000..60c2a88 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ObjectDeletePacket.java @@ -0,0 +1,50 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.map.Position; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports the deletion of an object. + */ +public class ObjectDeletePacket implements OutgoingPacket{ + + private Position position; + + /** + * Creates the packet + * @param position the object's position + */ + public ObjectDeletePacket(Position position) { + + this.position= position; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.put(position.getX()); + buffer.put(position.getY()); + } + +} From 2266b3a27c3230af6b9f8ce9c375489fd1167440 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:35:30 -0300 Subject: [PATCH 19/46] Added LoggedPacket --- .../ao/network/packet/outgoing/LoggedPacket.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java index a9c7ac1..d880ac7 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/LoggedPacket.java @@ -20,8 +20,8 @@ import java.io.UnsupportedEncodingException; -import com.ao.model.character.UserCharacter; import com.ao.model.character.archetype.UserArchetype; +import com.ao.model.user.LoggedUser; import com.ao.network.DataBuffer; import com.ao.network.packet.OutgoingPacket; @@ -30,18 +30,22 @@ */ public class LoggedPacket implements OutgoingPacket{ - private UserCharacter user; + private LoggedUser character; - public LoggedPacket(UserCharacter user) { + /** + * Creates the packet. + * @param character the character that logged in + */ + public LoggedPacket(LoggedUser character) { - this.user= user; + this.character= character; } @Override public void write(DataBuffer buffer) throws UnsupportedEncodingException { - buffer.put((byte)UserArchetype.valueOf(user.getArchetype()).ordinal()); + buffer.put((byte)UserArchetype.valueOf(character.getArchetype()).ordinal()); } } From dcc3dd80ed0d0a3aceb5569c4fc28f5d4df92bd9 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:35:54 -0300 Subject: [PATCH 20/46] Added CreateFXPacket --- .../packet/outgoing/CreateFXPacket.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/CreateFXPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CreateFXPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CreateFXPacket.java new file mode 100644 index 0000000..42d485e --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CreateFXPacket.java @@ -0,0 +1,52 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.character.Character; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports an FX to be displayed over a character + */ +public class CreateFXPacket implements OutgoingPacket{ + + private Character character; + + + /** + * Creates the packet + * @param character the character the FX will be displayed over + */ + public CreateFXPacket(Character character) { + + this.character= character; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getCharIndex()); + buffer.putShort((short) character.getFx().getId()); + buffer.putShort((short) character.getFx().getLoops()); + } + +} From 984cd89d212cae02d8a25a3745e21ae3d9717d54 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:36:47 -0300 Subject: [PATCH 21/46] Added CommerceChatPacket --- .../packet/outgoing/CommerceChatPacket.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceChatPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceChatPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceChatPacket.java new file mode 100644 index 0000000..ffd7b80 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CommerceChatPacket.java @@ -0,0 +1,56 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + + +import com.ao.model.fonts.Font; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that sends a message to display on the commerce console chat. + */ +public class CommerceChatPacket implements OutgoingPacket{ + + private String chatMessage; + private Font font; + + /** + * Creates the packet. + * @param chatMessage the message to display + * @param font the font for the chatMessage + */ + public CommerceChatPacket (String chatMessage, Font font) { + + this.chatMessage= chatMessage; + this.font= font; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putASCIIString(chatMessage); + + buffer.put( (byte) font.ordinal() ); + } + + +} From fa292c688755e2f1737a3b579325dc3bccb0da7c Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:37:04 -0300 Subject: [PATCH 22/46] Added ChatOverHeadPacket --- .../packet/outgoing/ChatOverHeadPacket.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/ChatOverHeadPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ChatOverHeadPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ChatOverHeadPacket.java new file mode 100644 index 0000000..041777c --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/ChatOverHeadPacket.java @@ -0,0 +1,62 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.awt.Color; +import java.io.UnsupportedEncodingException; + +import com.ao.model.character.Character; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that sends to client a message to display over a talking character's head. + */ +public class ChatOverHeadPacket implements OutgoingPacket{ + + private Character character; + private String text; + private Color color; + + + /** + * Creates the packet. + * @param character the character that spoke + * @param text what the character said + * @param color font color used to display the message + * */ + public ChatOverHeadPacket (Character character, String text, Color color) { + + this.character= character; + this.text= text; + this.color= color; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putASCIIString(text); + buffer.putShort((short) character.getCharIndex()); + + buffer.put( (byte) color.getRed() ); + buffer.put( (byte) color.getGreen() ); + buffer.put( (byte) color.getBlue() ); + } + +} From 3ed8b0c0477494212d7b5c385f75a27a73b4664c Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:37:34 -0300 Subject: [PATCH 23/46] Added CharacterRemovePacket --- .../outgoing/CharacterRemovePacket.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterRemovePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterRemovePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterRemovePacket.java new file mode 100644 index 0000000..03db600 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterRemovePacket.java @@ -0,0 +1,49 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.character.Character; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports a character removal. + */ +public class CharacterRemovePacket implements OutgoingPacket{ + + private Character character; + + /** + *Creates the packet. + *@param character the character to remove + */ + public CharacterRemovePacket (Character character) { + + this.character= character; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getCharIndex()); + } + +} From 1a7100afa47a5a96c88dcea5e66f1903cdcc158e Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:39:11 -0300 Subject: [PATCH 24/46] Added CharacterMovePacket --- .../packet/outgoing/CharacterMovePacket.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterMovePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterMovePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterMovePacket.java new file mode 100644 index 0000000..1f8f06a --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterMovePacket.java @@ -0,0 +1,52 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; +import com.ao.model.character.Character; + +/** + * Packet that reports a change in a character's position. + */ +public class CharacterMovePacket implements OutgoingPacket{ + + private Character character; + + /** + * Creates the packet + * @param character the character that moved + */ + public CharacterMovePacket(Character character) { + + this.character= character; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getCharIndex()); + + buffer.put(character.getPosition().getX()); + buffer.put(character.getPosition().getY()); + } + +} From 4f4f8f48c4f4d2d0d4cbcca997315fd1dee40083 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:39:38 -0300 Subject: [PATCH 25/46] Added CharacterForceMovePacket --- .../outgoing/CharacterForceMovePacket.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterForceMovePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterForceMovePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterForceMovePacket.java new file mode 100644 index 0000000..8e44e2c --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterForceMovePacket.java @@ -0,0 +1,49 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.map.Heading; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports about a character's forced move + */ +public class CharacterForceMovePacket implements OutgoingPacket{ + + private Heading direction; + + /** + * Creates the packet + * @param direction the direction in which the character was forced to move + */ + public CharacterForceMovePacket(Heading direction) { + + this.direction= direction; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.put( (byte) direction.ordinal() ); + } + +} From 9db68416ca8937470cb8cd34e9f3a525675a5d10 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:40:25 -0300 Subject: [PATCH 26/46] Added CharacterChangePacket --- .../outgoing/CharacterChangePacket.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterChangePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterChangePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterChangePacket.java new file mode 100644 index 0000000..94a34b7 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterChangePacket.java @@ -0,0 +1,57 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.character.Character; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports about a character's change. + */ +public class CharacterChangePacket implements OutgoingPacket{ + + private Character character; + + /** + * Creates the packet + * @param character the character being changed + */ + public CharacterChangePacket(Character character) { + + this.character= character; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getCharIndex()); + buffer.putShort((short) character.getBody()); + buffer.putShort((short) character.getHead()); + buffer.put((byte) character.getHeading().ordinal() ); + buffer.putShort((short) character.getWeapon().getId()); + buffer.putShort((short) character.getShield().getId()); + buffer.putShort((short) character.getHelmet().getId()); + buffer.putShort((short) character.getFx().getId()); + buffer.putShort((short) character.getFx().getLoops()); + } + +} From 6f9ba6e110fba9a25f4bca0fb3ffd34172efdfe1 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:40:54 -0300 Subject: [PATCH 27/46] Added CharacterChangeNickNamePacket --- .../CharacterChangeNickNamePacket.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterChangeNickNamePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterChangeNickNamePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterChangeNickNamePacket.java new file mode 100644 index 0000000..a0e65b3 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/CharacterChangeNickNamePacket.java @@ -0,0 +1,53 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.user.LoggedUser; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports a nickname change to client. + */ +public class CharacterChangeNickNamePacket implements OutgoingPacket{ + + private LoggedUser character; + private String newNick; + + /** + *Creates the packet + *@param character character whose nickname was changed + *@param newNick character's new nickname + */ + public CharacterChangeNickNamePacket(LoggedUser character, String newNick) { + + this.character= character; + this.newNick= newNick; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.putShort((short) character.getCharIndex()); + buffer.putASCIIString(newNick); + } + +} From b7ed101d49378cddcf98e24298cacf3cab2ea73d Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:41:24 -0300 Subject: [PATCH 28/46] Added BlockPositionPacket --- .../packet/outgoing/BlockPositionPacket.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/BlockPositionPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/BlockPositionPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/BlockPositionPacket.java new file mode 100644 index 0000000..e39c67b --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/BlockPositionPacket.java @@ -0,0 +1,55 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.map.Position; +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet that reports a given position being blocked or unblocked + */ +public class BlockPositionPacket implements OutgoingPacket{ + + private Position position; + + private boolean blocked; + + /** + * Creates the packet + * @param position the position to block/unblock + * @param blocked true if the position is blocked, false if it's unblocked + */ + public BlockPositionPacket(Position position, boolean blocked) { + + this.position= position; + this.blocked= blocked; + } + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException { + + buffer.put(position.getX()); + buffer.put(position.getY()); + buffer.putBoolean(blocked); + } + +} From 7733c8d6e618f2a6e4787bc4f09c3ace97172526 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 1 May 2014 22:44:57 -0300 Subject: [PATCH 29/46] Deleted a non-existent class import from ServerPacketsManager --- .../src/main/java/com/ao/network/ServerPacketsManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java index 527933c..bf5bd4d 100755 --- a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java @@ -23,7 +23,6 @@ import java.util.Map; import com.ao.network.packet.OutgoingPacket; -import com.ao.network.packet.outgoing.AreaChangedPacket; import com.ao.network.packet.outgoing.BlockPositionPacket; import com.ao.network.packet.outgoing.ChangeInventorySlotPacket; import com.ao.network.packet.outgoing.ChangeMapPacket; From 016782e44555b6c025bd7502c75ca43c23393a5e Mon Sep 17 00:00:00 2001 From: MER Date: Mon, 5 May 2014 21:55:06 -0300 Subject: [PATCH 30/46] Completed WalkPacket with some checks concerning moving while meditating. Added MeditateTogglePacket in order to do so --- .../com/ao/network/ServerPacketsManager.java | 3 +- .../network/packet/incoming/WalkPacket.java | 16 +++++---- .../packet/outgoing/MeditateTogglePacket.java | 35 +++++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/outgoing/MeditateTogglePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java index bf5bd4d..f9519a5 100755 --- a/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ServerPacketsManager.java @@ -41,6 +41,7 @@ import com.ao.network.packet.outgoing.DisconnectPacket; import com.ao.network.packet.outgoing.ErrorMessagePacket; import com.ao.network.packet.outgoing.GuildChatPacket; +import com.ao.network.packet.outgoing.MeditateTogglePacket; import com.ao.network.packet.outgoing.NavigateTogglePacket; import com.ao.network.packet.outgoing.ObjectCreatePacket; import com.ao.network.packet.outgoing.ObjectDeletePacket; @@ -144,7 +145,7 @@ private enum ServerPackets { SHOW_FORUM_MESSAGE(null), SET_INVISIBLE(null), ROLL_DICE(DiceRollPacket.class), - MEDITATE_TOGGLE(null), + MEDITATE_TOGGLE(MeditateTogglePacket.class), //sends no data (was needed to continue implementing WalkPacket) BLIND_NO_MORE(null), DUMB_NO_MORE(DumbNoMorePacket.class), SEND_SKILLS(SendSkillsPacket.class), diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java index 84ac62a..e33a6b4 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java @@ -11,6 +11,8 @@ import com.ao.network.DataBuffer; import com.ao.network.packet.IncomingPacket; import com.ao.network.packet.outgoing.ConsoleMessagePacket; +import com.ao.network.packet.outgoing.CreateFXPacket; +import com.ao.network.packet.outgoing.MeditateTogglePacket; import com.ao.service.MapService; public class WalkPacket implements IncomingPacket { @@ -37,12 +39,14 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO new ConsoleMessagePacket("Dejas de meditar.", Font.INFO) ); - /* TODO - * .Char.FX = 0 - * .Char.loops = 0 - * Call WriteMeditateToggle(UserIndex) - * Call SendData(SendTa rget.ToPCArea, UserIndex, PrepareMessageCreateFX(.Char.CharIndex, 0, 0)) - */ + user.getFx().setId(0); + user.getFx().setLoops(0); + + connection.send( + new MeditateTogglePacket()); + + connection.send( + new CreateFXPacket(user)); } else { Heading heading = Heading.get(buffer.get()); diff --git a/aoxp-server/src/main/java/com/ao/network/packet/outgoing/MeditateTogglePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/MeditateTogglePacket.java new file mode 100644 index 0000000..a267301 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/outgoing/MeditateTogglePacket.java @@ -0,0 +1,35 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.outgoing; + +import java.io.UnsupportedEncodingException; + +import com.ao.network.DataBuffer; +import com.ao.network.packet.OutgoingPacket; + +/** + * Packet to tell the client the user began or halted his meditation. + */ +public class MeditateTogglePacket implements OutgoingPacket{ + + + @Override + public void write(DataBuffer buffer) throws UnsupportedEncodingException {} + +} \ No newline at end of file From 43b6d94ad8a42c702310d47b9df8a743ed0a4b03 Mon Sep 17 00:00:00 2001 From: MER Date: Wed, 7 May 2014 01:40:52 -0300 Subject: [PATCH 31/46] Completed some methods to achieve character movement (haven't tested any of them yet) --- .../java/com/ao/model/user/LoggedUser.java | 18 ++++++----- .../network/packet/incoming/WalkPacket.java | 31 ++++++++++++++++--- .../com/ao/service/map/MapServiceImpl.java | 14 ++++++--- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java index d82a01b..ab9c40d 100644 --- a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java +++ b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java @@ -72,6 +72,7 @@ public class LoggedUser extends ConnectedUser implements UserCharacter { private boolean hidden; private boolean meditating; private boolean sailing; + private boolean homecoming; /* * AdminFlags @@ -94,6 +95,8 @@ public class LoggedUser extends ConnectedUser implements UserCharacter { private byte level; private String name; private String description; + private Position position; + private Heading heading; public LoggedUser(Reputation reputation, Race race, Gender gender, Archetype archetype, boolean poisoned, boolean paralyzed, @@ -403,8 +406,7 @@ public int getOriginalHead() { @Override public Position getPosition() { - // TODO Auto-generated method stub - return null; + return position; } @Override @@ -462,6 +464,10 @@ public boolean isParalyzed() { public boolean isPoisoned() { return poisoned; } + + public boolean isHomecoming() { + return homecoming; + } @Override public void setBody(int body) { @@ -521,8 +527,7 @@ public void setPoisoned(boolean poisoned) { @Override public void setPosition(Position pos) { - // TODO Auto-generated method stub - + position= pos; } @Override @@ -563,13 +568,12 @@ public int getMoney() { @Override public Heading getHeading() { - // TODO Auto-generated method stub - return Heading.EAST; + return heading; } @Override public void setHeading(Heading heading) { - + this.heading= heading; } @Override diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java index e33a6b4..34f12ba 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java @@ -10,6 +10,8 @@ import com.ao.network.Connection; import com.ao.network.DataBuffer; import com.ao.network.packet.IncomingPacket; +import com.ao.network.packet.outgoing.CharacterChangePacket; +import com.ao.network.packet.outgoing.CharacterMovePacket; import com.ao.network.packet.outgoing.ConsoleMessagePacket; import com.ao.network.packet.outgoing.CreateFXPacket; import com.ao.network.packet.outgoing.MeditateTogglePacket; @@ -17,7 +19,7 @@ public class WalkPacket implements IncomingPacket { - private MapService marService = ApplicationContext.getInstance(MapService.class); + private MapService mapService = ApplicationContext.getInstance(MapService.class); @Override public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutOfBoundsException, UnsupportedEncodingException { @@ -30,7 +32,7 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO //TODO check security issues - if (! user.isParalyzed()) { + if ( !( user.isParalyzed() || user.isImmobilized() ) ) { if (user.isMeditating()) { // Stop meditating, next action will start movement. user.setMeditate(false); @@ -46,16 +48,21 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO new MeditateTogglePacket()); connection.send( - new CreateFXPacket(user)); + new CreateFXPacket(user)); // Halts meditation FX with a no-effect FX - } else { + } else if (!user.isHomecoming()){ + Heading heading = Heading.get(buffer.get()); + if (heading != null) { // Move user - marService.moveCharacterTo(user, heading); + mapService.moveCharacterTo(user, heading); //TODO Stop resting if needed + + connection.send( + new CharacterMovePacket(user)); } else { return true; @@ -65,6 +72,20 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO } else { //if paralized //TODO set last message flag //TODO aplicar seguridad contra SH + + Heading heading = Heading.get(buffer.get()); + + if (heading != null) { + + user.setHeading(heading); + + /* client updates character's heading without + * server notification (doesn't it?) so no need to send anything. + * */ + + } else { + return true; + } } // Check if hidden and can move while hidden diff --git a/aoxp-server/src/main/java/com/ao/service/map/MapServiceImpl.java b/aoxp-server/src/main/java/com/ao/service/map/MapServiceImpl.java index 03dc5f4..cd230d7 100644 --- a/aoxp-server/src/main/java/com/ao/service/map/MapServiceImpl.java +++ b/aoxp-server/src/main/java/com/ao/service/map/MapServiceImpl.java @@ -77,12 +77,11 @@ public City getCity(byte id) { @Override public void putCharacterAtPos(Character chara, Position pos) { pos.getMap().putCharacterAtPos(chara, pos.getX(), pos.getY()); - //TODO Seteamos aca la nueva position en el character? } @Override public void moveCharacterTo(Character chara, Heading heading) { - //FIXME Metodo getPosition() de loggedUser no está implementado. + byte x = chara.getPosition().getX(); byte y = chara.getPosition().getY(); @@ -104,8 +103,15 @@ public void moveCharacterTo(Character chara, Heading heading) { x--; break; } + + // How much of this has to be done in Character.moveTo(Heading) method? + + Position newPos= new Position(x, y, chara.getPosition().getMap()); - putCharacterAtPos(chara, new Position(x, y, chara.getPosition().getMap())); + putCharacterAtPos(chara, newPos); + + chara.setPosition(newPos); + chara.setHeading(heading); } -} \ No newline at end of file +} From a9d5dd23f58188cdc058d2661b760858feb02bd7 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 8 May 2014 07:49:20 -0300 Subject: [PATCH 32/46] Fixed awful implementation from previous commit --- .../java/com/ao/model/user/LoggedUser.java | 11 ++- .../network/packet/incoming/PickUpPacket.java | 70 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java diff --git a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java index ab9c40d..20d98d4 100644 --- a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java +++ b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java @@ -728,7 +728,16 @@ public boolean isSailing() { public void setSailing(boolean sailing) { this.sailing = sailing; } - + + /** + * Picks up a given item. + * @param item the Item to pick up + * @return true if item was successfully added to inventory, false otherwise. + */ + public boolean pickUp(Item item) { + return false; //TODO to complete + } + @Override public void moveTo(Heading heading) { // TODO Auto-generated method stub diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java new file mode 100644 index 0000000..ae0b9be --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java @@ -0,0 +1,70 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.incoming; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.fonts.Font; +import com.ao.model.map.Tile; +import com.ao.model.user.LoggedUser; +import com.ao.model.worldobject.Item; +import com.ao.model.worldobject.WorldObject; +import com.ao.network.Connection; +import com.ao.network.DataBuffer; +import com.ao.network.packet.IncomingPacket; +import com.ao.network.packet.outgoing.ConsoleMessagePacket; +import com.ao.network.packet.outgoing.ObjectDeletePacket; + +public class PickUpPacket implements IncomingPacket{ + + + @Override + public boolean handle(DataBuffer buffer, Connection connection) + throws IndexOutOfBoundsException, UnsupportedEncodingException { + + LoggedUser user = ((LoggedUser)connection.getUser()); + + Tile tile = user.getPosition().getMap().getTile(user.getPosition().getX(), user.getPosition().getY()); + + WorldObject object = tile.getWorldObject(); + + if(object == null/*TODO or user is dead or user is trading*/) + return true; + + if (user.getPrivileges().isCouncelor()) { + + connection.send( + new ConsoleMessagePacket("No puedes tomar ningún objeto.", Font.INFO) ); + + return true; + } + + if (object instanceof Item) { + + if( user.pickUp((Item)object) ) { + + tile.setWorldObject(null); + + connection.send( new ObjectDeletePacket(user.getPosition()) ); + } + } + return true; + } + +} From bb43eecf5ab7a71f6031bc5ebb04be86f1f63f42 Mon Sep 17 00:00:00 2001 From: MER Date: Thu, 8 May 2014 16:32:27 -0300 Subject: [PATCH 33/46] Updated MapServiceImpl so it removes the user from the tile it was in before moving --- .../com/ao/network/ClientPacketsManager.java | 4 +++- .../network/packet/incoming/WalkPacket.java | 23 ++++++++++++++++--- .../com/ao/service/map/MapServiceImpl.java | 17 ++++++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java index 760100e..f4b81ee 100755 --- a/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java @@ -23,6 +23,7 @@ import com.ao.network.packet.IncomingPacket; import com.ao.network.packet.incoming.LoginExistingCharacterPacket; import com.ao.network.packet.incoming.LoginNewCharacterPacket; +import com.ao.network.packet.incoming.PickUpPacket; import com.ao.network.packet.incoming.ThrowDicesPacket; import com.ao.network.packet.incoming.WalkPacket; @@ -41,7 +42,8 @@ private enum ClientPackets { TALK(null), YELL(null), WHISPER(null), - WALK(WalkPacket.class); + WALK(WalkPacket.class), + PICK_UP(PickUpPacket.class); //TODO Is this the right place for it? protected IncomingPacket handler; diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java index 34f12ba..9498db9 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java @@ -1,3 +1,21 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + package com.ao.network.packet.incoming; import java.io.UnsupportedEncodingException; @@ -10,7 +28,6 @@ import com.ao.network.Connection; import com.ao.network.DataBuffer; import com.ao.network.packet.IncomingPacket; -import com.ao.network.packet.outgoing.CharacterChangePacket; import com.ao.network.packet.outgoing.CharacterMovePacket; import com.ao.network.packet.outgoing.ConsoleMessagePacket; import com.ao.network.packet.outgoing.CreateFXPacket; @@ -28,7 +45,7 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO return false; } - LoggedUser user = ((LoggedUser)connection.getUser()); + LoggedUser user = (LoggedUser) connection.getUser(); //TODO check security issues @@ -79,7 +96,7 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO user.setHeading(heading); - /* client updates character's heading without + /* TODO client updates character's heading without * server notification (doesn't it?) so no need to send anything. * */ diff --git a/aoxp-server/src/main/java/com/ao/service/map/MapServiceImpl.java b/aoxp-server/src/main/java/com/ao/service/map/MapServiceImpl.java index cd230d7..7986053 100644 --- a/aoxp-server/src/main/java/com/ao/service/map/MapServiceImpl.java +++ b/aoxp-server/src/main/java/com/ao/service/map/MapServiceImpl.java @@ -104,14 +104,23 @@ public void moveCharacterTo(Character chara, Heading heading) { break; } - // How much of this has to be done in Character.moveTo(Heading) method? + //TODO How much of all this has to be done in Character.moveTo(Heading) method? + //TODO This doesn't take into account map crossing because it always use char current map. Position newPos= new Position(x, y, chara.getPosition().getMap()); - putCharacterAtPos(chara, newPos); + //Checks whether the destination tile is blocked or not. + if (!newPos.getMap().getTile(x, y).isBlocked()) { + + putCharacterAtPos(chara, newPos); //puts character at his new tile in the map. + + chara.getPosition().getMap().getTile( //deletes character from the tile it was at before. + chara.getPosition().getX(), chara.getPosition().getY()).setCharacter(null); + + chara.setPosition(newPos); //updates character's position + } - chara.setPosition(newPos); - chara.setHeading(heading); + chara.setHeading(heading); //heading is updated regardless of blocked tiles. } } From 117560c28c2a3b0a0c680eb5da74dbf35018c62b Mon Sep 17 00:00:00 2001 From: MER Date: Sat, 10 May 2014 01:34:14 -0300 Subject: [PATCH 34/46] Added some functionality so the newly created character can be logged in --- .../model/builder/UserCharacterBuilder.java | 1 + .../incoming/LoginNewCharacterPacket.java | 4 ++ .../ao/service/login/LoginServiceImpl.java | 38 ++++++++++--------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java b/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java index 7b83156..464af30 100644 --- a/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java +++ b/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java @@ -44,6 +44,7 @@ */ public class UserCharacterBuilder implements Builder { + //TODO we should mention what constitutes a valid name in this message. public static final String INVALID_NAME_ERROR = "El nombre ingresado no es válido."; public static final String INVALID_EMAIL_ERROR = "La dirección de e-mail ingresada no es válida."; diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java index 401759a..2faea8f 100755 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java @@ -22,9 +22,11 @@ import com.ao.context.ApplicationContext; import com.ao.model.user.ConnectedUser; +import com.ao.model.user.LoggedUser; import com.ao.network.Connection; import com.ao.network.DataBuffer; import com.ao.network.packet.IncomingPacket; +import com.ao.network.packet.outgoing.CharacterCreatePacket; import com.ao.network.packet.outgoing.ErrorMessagePacket; import com.ao.security.SecurityManager; import com.ao.service.LoginService; @@ -66,6 +68,8 @@ public boolean handle(DataBuffer buffer, Connection connection) throws ArrayInde } catch (LoginErrorException e) { loginError(connection, e.getMessage()); } + + connection.send( new CharacterCreatePacket((LoggedUser) connection.getUser()) ); return true; } diff --git a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java index c5c6c10..28111c0 100644 --- a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java +++ b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java @@ -33,6 +33,7 @@ import com.ao.model.map.City; import com.ao.model.user.Account; import com.ao.model.user.ConnectedUser; +import com.ao.model.user.LoggedUser; import com.ao.security.SecurityManager; import com.ao.service.CharacterBodyService; import com.ao.service.LoginService; @@ -54,7 +55,7 @@ public class LoginServiceImpl implements LoginService { public static final String CORRUPTED_CLIENT_ERROR = "El cliente está dañado, por favor descárguelo nuevamente desde http://www.argentumonline.com.ar/"; public static final String BANNED_CHARACTER_ERROR = "Se te ha prohibido la entrada a Argentum debido a tu mal comportamiento. Puedes consultar el reglamento y el sistema de soporte desde www.argentumonline.com.ar"; public static final String INCORRECT_PASSWORD_ERROR = "Contraseña incorrecta."; - public static final String CHARACTER_CREATION_DISABLED_ERROR = "La creación de personajes en este servidor se ha deshabilitado."; + public static final String CHARACTER_CREATION_DISABLED_ERROR = "La creación de personajes en este servidor se ha deshabilitado momentaneamente."; public static final String ONLY_ADMINS_ERROR = "Servidor restringido a administradores. Consulte la página oficial o el foro oficial para más información."; public static final String MUST_THROW_DICES_BEFORE_ERROR = "Debe tirar los dados antes de poder crear un personaje."; public static final String INVALID_RACE_ERROR = "La raza seleccionada no es válida."; @@ -170,10 +171,8 @@ public void connectNewCharacter(ConnectedUser user, String username, String pass // First, we have to create the new account. - Account acc; - try { - acc = accDAO.create(username, password, mail); + Account acc = accDAO.create(username, password, mail); } catch(NameAlreadyTakenException e) { throw new LoginErrorException(ACCOUNT_NAME_TAKEN_ERROR); @@ -184,25 +183,21 @@ public void connectNewCharacter(ConnectedUser user, String username, String pass } - // Once we have the account, lets create the character itself! + // Once we have the account, lets create the character itself! try { - UserCharacter chara = charDAO.create(username, race, gender, archetype, - head, homeland, user.getAttribute(Attribute.STRENGTH), + charDAO.create(username, race, gender, archetype, + head, homeland, user.getAttribute(Attribute.STRENGTH), user.getAttribute(Attribute.AGILITY), user.getAttribute(Attribute.INTELLIGENCE), user.getAttribute(Attribute.CHARISMA), user.getAttribute(Attribute.CONSTITUTION), initialAvailableSkills, body); + } catch (DAOException e) { accDAO.delete(username); throw new LoginErrorException(e.getMessage()); } - - // Everything it's okay, associate the character with the account and the account with the user. - acc.addCharacter(username); - user.setAccount(acc); - - // TODO: Put it in the world! - + + connectExistingCharacter(user, username, password, version, clientHash); } @Override @@ -251,9 +246,18 @@ public void connectExistingCharacter(ConnectedUser user, String name, String pas // TODO : send all data! - user.setAccount(acc); - - userService.logIn(user); + user.setAccount(acc); //associates the account with the user + + try { + character= (LoggedUser) charDAO.load(name); // loads the character. + + } catch (DAOException e) { + throw new LoginErrorException(e.getMessage()); + } + + userService.logIn(user); //logs the character in. + + mapService.putCharacterAtPos(character, character.getPosition()); //places character in the world. } /** From 1d16c5d630aea1ef38718c7e4dbdf357f203690c Mon Sep 17 00:00:00 2001 From: MER Date: Sun, 11 May 2014 00:15:47 -0300 Subject: [PATCH 35/46] Added functionality for the user to be able to drop items --- .../com/ao/network/ClientPacketsManager.java | 4 +- .../network/packet/incoming/DropPacket.java | 80 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/incoming/DropPacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java index f4b81ee..ad97da3 100755 --- a/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java @@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException; import com.ao.network.packet.IncomingPacket; +import com.ao.network.packet.incoming.DropPacket; import com.ao.network.packet.incoming.LoginExistingCharacterPacket; import com.ao.network.packet.incoming.LoginNewCharacterPacket; import com.ao.network.packet.incoming.PickUpPacket; @@ -43,7 +44,8 @@ private enum ClientPackets { YELL(null), WHISPER(null), WALK(WalkPacket.class), - PICK_UP(PickUpPacket.class); //TODO Is this the right place for it? + PICK_UP(PickUpPacket.class), //TODO Is this the right place for it? + DROP(DropPacket.class); //TODO Is this the right place for it? protected IncomingPacket handler; diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/DropPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/DropPacket.java new file mode 100644 index 0000000..fdffa1d --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/DropPacket.java @@ -0,0 +1,80 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.incoming; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.fonts.Font; +import com.ao.model.map.Tile; +import com.ao.model.user.LoggedUser; +import com.ao.model.worldobject.AbstractItem; +import com.ao.model.worldobject.Item; +import com.ao.network.Connection; +import com.ao.network.DataBuffer; +import com.ao.network.packet.IncomingPacket; +import com.ao.network.packet.outgoing.ConsoleMessagePacket; +import com.ao.network.packet.outgoing.ObjectCreatePacket; + +public class DropPacket implements IncomingPacket{ + + @Override + public boolean handle(DataBuffer buffer, Connection connection) + throws IndexOutOfBoundsException, UnsupportedEncodingException { + + if (buffer.getReadableBytes() < 3) + return false; + + LoggedUser user= (LoggedUser) connection.getUser(); + + //TODO should we send a message to a counselor trying to pick up an item? + if (user.getPrivileges().isCouncelor() || user.isSailing()/*TODO or dead, or trading*/) + return true; + + int amount = buffer.getInt(); + + if (amount > 0) { + + byte slot= buffer.get(); + Tile tile= user.getPosition().getMap().getTile(user.getPosition().getX(), user.getPosition().getY()); + + if (tile.getWorldObject() == null) { + + tile.setWorldObject( user.getInventory().removeItem(slot, amount) ); + connection.send( new ObjectCreatePacket(tile.getWorldObject(), user.getPosition()) ); + + return true; + } + + if ( tile.getWorldObject().getId() == user.getInventory().getItem(slot).getId() && + ((Item) tile.getWorldObject()).getAmount() + amount <= AbstractItem.MAX_STACKED_ITEMS ) { + + user.getInventory().removeItem(slot, amount); + + ( (Item) tile.getWorldObject() ).addAmount(amount); + + return true; + } + + connection.send (new ConsoleMessagePacket("No hay espacio en el piso", Font.INFO)); + } + + return true; + } + +} From d1221a6d9ca1f32c146a51458a2b3723f80c860d Mon Sep 17 00:00:00 2001 From: MER Date: Sun, 11 May 2014 01:28:42 -0300 Subject: [PATCH 36/46] Listed all ClientPacketsManager packets --- .../com/ao/network/ClientPacketsManager.java | 125 +++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java index ad97da3..ff2d5bf 100755 --- a/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java @@ -44,9 +44,130 @@ private enum ClientPackets { YELL(null), WHISPER(null), WALK(WalkPacket.class), + REQUEST_POSITION_UPDATE(null), + ATTACK(null), PICK_UP(PickUpPacket.class), //TODO Is this the right place for it? - DROP(DropPacket.class); //TODO Is this the right place for it? - + SAFE_TOGGLE(null), + RESUCITATION_SAFE_TOGGLE(null), //RESURRECTION + REQUEST_GUILD_LEADER_INFO(null), + REQUEST_ATRIBUTES(null), + REQUEST_FAME(null), + REQUEST_SKILLS(null), + REQUEST_MINI_STATS(null), + COMMERCE_END(null), + USER_COMMERCE_END(null), + USER_COMMERCE_CONFIRM(null), + COMMERCE_CHAT(null), + BANK_END(null), + USER_COMMERCE_OK(null), + USER_COMMERCE_REJECT(null), + DROP(DropPacket.class), //TODO Is this the right place for it? + CAST_SPELL(null), + LEFT_CLICK(null), + DOUBLE_CLICK(null), + WORK(null), + USE_SPELL_MACRO(null), + USE_ITEM(null), + CRAFT_BLACKSMITH(null), + CRAFT_CARPENTER(null), + WORK_LEFT_CLICK(null), + CREATE_NEW_GUILD(null), + SPELL_INFO(null), + EQUIP_ITEM(null), //RIG OUT + CHANGE_HEADING(null), + MODIFY_SKILLS(null), + TRAIN(null), + COMMERCE_BUY(null), + BANK_EXTRACT_ITEM(null), //WITHDRAW + COMMERCE_SELL(null), + BANK_DEPOSIT(null), + FORUM_POST(null), + MOVE_SPELL(null), + MOVE_BANK(null), + CLAN_CODEX_UPDATE(null), + USER_COMMERCE_OFFER(null), + GUILD_ACCEPT_PEACE(null), + GUILD_REJECT_ALLIANCE(null), + GUILD_REJECT_PEACE(null), + GUILD_ACCEPT_ALLIANCE(null), + GUILD_OFFER_PEACE(null), + GUILD_OFFER_ALLIANCE(null), + GUILD_ALLIANCE_DETAILS(null), + GUILD_PEACE_DETAILS(null), + GUILD_REQUEST_JOINER_INFO(null), //APPLICANT + GUILD_ALLIANCE_PROPOSAL_LIST(null), + GUILD_PEACE_PROPOSAL_LIST(null), + GUILD_DECLARE_WAR(null), + GUILD_NEW_WEBSITE(null), + GUILD_ACCEPT_NEW_MEMBER(null), + GUILD_REJECT_NEW_MEMBER(null), + GUILD_KICK_MEMBER(null), + GUILD_UPDATE_NEWS(null), + GUILD_MEMBER_INFO(null), + GUILD_OPEN_ELECTIONS(null), + GUILD_REQUEST_MEMBERSHIP(null), + GUILD_REQUEST_DETAILS(null), + ONLINE(null), + QUIT(null), + GUILD_LEAVE(null), + REQUEST_ACCOUNT_STATE(null), + PET_STAND(null), + PET_FOLLOW(null), + RELEASE_PET(null), + TRAIN_LIST(null), + REST(null), + MEDITATE(null), + RESUCITATE(null), + HEAL(null), + HELP(null), + REQUEST_STATS(null), + COMMERCE_START(null), + BANK_START(null), + ENLIST(null), + INFORMATION(null), + REWARD(null), + REQUEST_MOTD(null), //MOTD stands for 'message of the day' + UPTIME(null), + PARTY_LEAVE(null), + PARTY_CREATE(null), + PARTY_JOIN(null), + INQUIRY(null), + GUILD_MESSAGE(null), + PARTY_MESSAGE(null), + CENTINEL_REPORT(null), + GUILD_ONLINE(null), + PARTY_ONLINE(null), + COUNCIL_MESSAGE(null), + ROLEMASTER_REQUEST(null), + GM_REQUEST(null), + BUG_REPORT(null), + CHANGE_DESCRIPTION(null), + GUILD_VOTE(null), + PUNISHMENTS(null), + CHANGE_PASSWORD(null), + GAMBLE(null), //BET + INQUIRY_VOTE(null), + LEAVE_FACTION(null), + BANK_EXTRACT_GOLD(null), //WITHDRAW + BANK_DEPOSIT_GOLD(null), + DENOUNCE(null), + GUILD_FUNDATE(null), + GUILD_FUNDATION(null), + PARTY_KICK(null), + PARTY_SET_LEADER(null), + PARTY_ACCEPT_MEMBER(null), + PING(null), + REQUEST_PARTY_FORM(null), + ITEM_UPGRADE(null), + GM_COMMANDS(null), + INITIATE_CRAFTING(null), + HOME(null), + SHOW_GUILD_NEWS(null), + SHARE_NPC(null), + STOP_SHARING_NPC(null), + CONSULTATION(null), + MOVE_ITEM(null); + protected IncomingPacket handler; private ClientPackets(Class handler) { From ea0309ff35c51b4a62197c77dda1999c4f9c075e Mon Sep 17 00:00:00 2001 From: MER Date: Sun, 11 May 2014 04:26:21 -0300 Subject: [PATCH 37/46] Possible solution to error found by junit test --- .../packet/incoming/LoginNewCharacterPacket.java | 12 ++++++++---- .../src/main/java/com/ao/service/LoginService.java | 5 +++-- .../java/com/ao/service/login/LoginServiceImpl.java | 10 ++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java index 2faea8f..ff8297e 100755 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java @@ -21,8 +21,9 @@ import java.io.UnsupportedEncodingException; import com.ao.context.ApplicationContext; + +import com.ao.model.character.UserCharacter; import com.ao.model.user.ConnectedUser; -import com.ao.model.user.LoggedUser; import com.ao.network.Connection; import com.ao.network.DataBuffer; import com.ao.network.packet.IncomingPacket; @@ -59,17 +60,20 @@ public boolean handle(DataBuffer buffer, Connection connection) throws ArrayInde int head = buffer.get(); String mail = buffer.getASCIIString(); byte homeland = buffer.get(); + + UserCharacter loggedChar; try { - service.connectNewCharacter((ConnectedUser) connection.getUser(), + loggedChar= service.connectNewCharacter((ConnectedUser) connection.getUser(), nick, password, race, gender, archetype, head, mail, homeland, clientHash, version); } catch (LoginErrorException e) { + loggedChar= null; //If I don't do this compiler complains about it not being initialized. loginError(connection, e.getMessage()); - } + } - connection.send( new CharacterCreatePacket((LoggedUser) connection.getUser()) ); + connection.send( new CharacterCreatePacket(loggedChar) ); return true; } diff --git a/aoxp-server/src/main/java/com/ao/service/LoginService.java b/aoxp-server/src/main/java/com/ao/service/LoginService.java index fb63d10..ce133e8 100644 --- a/aoxp-server/src/main/java/com/ao/service/LoginService.java +++ b/aoxp-server/src/main/java/com/ao/service/LoginService.java @@ -19,6 +19,7 @@ package com.ao.service; import com.ao.model.user.ConnectedUser; +import com.ao.model.user.LoggedUser; import com.ao.service.login.LoginErrorException; public interface LoginService { @@ -33,7 +34,7 @@ public interface LoginService { * @param clientHash The client's integrity check hash. * @throws LoginErrorException */ - void connectExistingCharacter(ConnectedUser user, String name, String password, String version, + LoggedUser connectExistingCharacter(ConnectedUser user, String name, String password, String version, String clientHash) throws LoginErrorException; /** @@ -53,7 +54,7 @@ void connectExistingCharacter(ConnectedUser user, String name, String password, * @return * @throws LoginErrorException */ - void connectNewCharacter(ConnectedUser user, String username, String password, byte race, + LoggedUser connectNewCharacter(ConnectedUser user, String username, String password, byte race, byte gender, byte archetype, int head, String mail, byte homeland, String clientHash, String version) throws LoginErrorException; diff --git a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java index 28111c0..c1c59f1 100644 --- a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java +++ b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java @@ -95,7 +95,7 @@ public LoginServiceImpl(AccountDAO accDAO, UserCharacterDAO charDAO, } @Override - public void connectNewCharacter(ConnectedUser user, String username, String password, byte bRace, + public LoggedUser connectNewCharacter(ConnectedUser user, String username, String password, byte bRace, byte bGender, byte bArchetype, int head, String mail, byte bHomeland, String clientHash, String version) throws LoginErrorException { @@ -197,11 +197,11 @@ public void connectNewCharacter(ConnectedUser user, String username, String pass throw new LoginErrorException(e.getMessage()); } - connectExistingCharacter(user, username, password, version, clientHash); + return connectExistingCharacter(user, username, password, version, clientHash); } @Override - public void connectExistingCharacter(ConnectedUser user, String name, String password, String version, + public LoggedUser connectExistingCharacter(ConnectedUser user, String name, String password, String version, String clientHash) throws LoginErrorException { checkClient(clientHash, version); @@ -257,7 +257,9 @@ public void connectExistingCharacter(ConnectedUser user, String name, String pas userService.logIn(user); //logs the character in. - mapService.putCharacterAtPos(character, character.getPosition()); //places character in the world. + mapService.putCharacterAtPos(character, character.getPosition()); //places character in the world. + + return (LoggedUser)character; } /** From 12f699afc60ca2f0570e13d6cbca096fb8cce8e3 Mon Sep 17 00:00:00 2001 From: MER Date: Sun, 11 May 2014 16:42:23 -0300 Subject: [PATCH 38/46] Added class to handle position update requests --- .../com/ao/network/ClientPacketsManager.java | 7 +-- .../incoming/RequestPositionUpdatePacket.java | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 aoxp-server/src/main/java/com/ao/network/packet/incoming/RequestPositionUpdatePacket.java diff --git a/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java b/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java index ff2d5bf..ab95c17 100755 --- a/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java +++ b/aoxp-server/src/main/java/com/ao/network/ClientPacketsManager.java @@ -25,6 +25,7 @@ import com.ao.network.packet.incoming.LoginExistingCharacterPacket; import com.ao.network.packet.incoming.LoginNewCharacterPacket; import com.ao.network.packet.incoming.PickUpPacket; +import com.ao.network.packet.incoming.RequestPositionUpdatePacket; import com.ao.network.packet.incoming.ThrowDicesPacket; import com.ao.network.packet.incoming.WalkPacket; @@ -44,9 +45,9 @@ private enum ClientPackets { YELL(null), WHISPER(null), WALK(WalkPacket.class), - REQUEST_POSITION_UPDATE(null), + REQUEST_POSITION_UPDATE(RequestPositionUpdatePacket.class), ATTACK(null), - PICK_UP(PickUpPacket.class), //TODO Is this the right place for it? + PICK_UP(PickUpPacket.class), SAFE_TOGGLE(null), RESUCITATION_SAFE_TOGGLE(null), //RESURRECTION REQUEST_GUILD_LEADER_INFO(null), @@ -61,7 +62,7 @@ private enum ClientPackets { BANK_END(null), USER_COMMERCE_OK(null), USER_COMMERCE_REJECT(null), - DROP(DropPacket.class), //TODO Is this the right place for it? + DROP(DropPacket.class), CAST_SPELL(null), LEFT_CLICK(null), DOUBLE_CLICK(null), diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/RequestPositionUpdatePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/RequestPositionUpdatePacket.java new file mode 100644 index 0000000..cf4a004 --- /dev/null +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/RequestPositionUpdatePacket.java @@ -0,0 +1,43 @@ +/* + AO-XP Server (XP stands for Cross Platform) is a Java implementation of Argentum Online's server + Copyright (C) 2009 Juan Martín Sotuyo Dodero. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package com.ao.network.packet.incoming; + +import java.io.UnsupportedEncodingException; + +import com.ao.model.user.LoggedUser; +import com.ao.network.Connection; +import com.ao.network.DataBuffer; +import com.ao.network.packet.IncomingPacket; +import com.ao.network.packet.outgoing.UpdatePositionPacket; + +/** + * Class to handle position update requests from client. + */ +public class RequestPositionUpdatePacket implements IncomingPacket{ + + @Override + public boolean handle(DataBuffer buffer, Connection connection) + throws IndexOutOfBoundsException, UnsupportedEncodingException { + + connection.send( new UpdatePositionPacket( (LoggedUser)connection.getUser() )); + + return true; + } + +} From 04230a2fd7817ea6a32dde06d05d08d4ddecf3b1 Mon Sep 17 00:00:00 2001 From: MER Date: Mon, 12 May 2014 18:54:28 -0300 Subject: [PATCH 39/46] fixed typos --- .../src/main/java/com/ao/model/map/City.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/model/map/City.java b/aoxp-server/src/main/java/com/ao/model/map/City.java index ba9f342..385f32a 100644 --- a/aoxp-server/src/main/java/com/ao/model/map/City.java +++ b/aoxp-server/src/main/java/com/ao/model/map/City.java @@ -29,9 +29,9 @@ public class City{ /** * Creates a new city instance. - * @param map The city map. - * @param x The city x co-ordinate for users spawn. - * @param y The city y co-ordinate for users spawn. + * @param map The city's map id. + * @param x City's x coordinate for users spawn. + * @param y City's y coordinate for users spawn. */ public City(int map, byte x, byte y){ this.map = map; @@ -40,24 +40,24 @@ public City(int map, byte x, byte y){ } /** - * Retrieves the city map. - * @return The city map. + * Retrieves the city's map id. + * @return The city's map id. */ public int getMap() { return map; } /** - * Retrieves the city x co-ordinate for users spawn. - * @return The city x co-ordinate for users spawn. + * Retrieves city's X coordinate for users spawn. + * @return city's X coordinate for users spawn. */ public byte getX() { return x; } /** - * Retrieves the city y co-ordinate for users spawn. - * @return The city y co-ordinate for users spawn. + * Retrieves city's Y coordinate for users spawn. + * @return city's Y coordinate for users spawn. */ public byte getY() { return y; From a60ace495e38abe212833f1de2ab098b2e07344a Mon Sep 17 00:00:00 2001 From: MER Date: Mon, 12 May 2014 19:04:56 -0300 Subject: [PATCH 40/46] Added some fields and methods to LoggedUser and its implemented interface UserCharacter in order to achieve character's login. For the same purpose made some changes and completions to several classes involved in a newly created character's first login --- .../java/com/ao/data/dao/ini/UserDAOIni.java | 6 ++-- .../model/builder/UserCharacterBuilder.java | 9 +++++- .../com/ao/model/character/UserCharacter.java | 12 ++++++++ .../java/com/ao/model/user/LoggedUser.java | 13 ++++++++- .../ao/model/worldobject/AbstractItem.java | 2 +- .../java/com/ao/service/LoginService.java | 3 +- .../ao/service/login/LoginServiceImpl.java | 28 +++++++++++++++---- 7 files changed, 59 insertions(+), 14 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/data/dao/ini/UserDAOIni.java b/aoxp-server/src/main/java/com/ao/data/dao/ini/UserDAOIni.java index d3729fa..04bb000 100755 --- a/aoxp-server/src/main/java/com/ao/data/dao/ini/UserDAOIni.java +++ b/aoxp-server/src/main/java/com/ao/data/dao/ini/UserDAOIni.java @@ -381,7 +381,7 @@ public UserCharacter create(String name, Race race, Gender gender, // TODO: Update this when hp, mana and hit points get updated! return new LoggedUser(rep, race, gender, archetype.getArchetype(), - false, false, false, false, false, false, 0, 0, 0, 0, + false, false, false, false, false, false, false, 0, 0, 0, 0, 100, 0, 100, 0, (byte) 1, name, ""); } @@ -450,9 +450,7 @@ public UserCharacter load(String username) throws DAOException { String description = ""; // TODO : Validate character - /* UserCharacter userCharacter = new LoggedUser(reputation, race, gender, archetype, poisoned, paralyzed, immobilized, invisible, mimetized, dumbed, hidden, maxMana, maxHitPoints, mana, hitpoints, thirstiness, hunger, lvl, username, description); */ - - return null; + return new LoggedUser(reputation, race, gender, archetype, poisoned, paralyzed, immobilized, invisible, mimetized, dumbed, hidden, maxMana, mana, maxHitPoints, hitpoints, 100, thirstiness, 100, hunger, lvl, username, description); } private Ini readCharFile(String username) throws DAOException { diff --git a/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java b/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java index 464af30..28292f3 100644 --- a/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java +++ b/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java @@ -71,6 +71,7 @@ public class UserCharacterBuilder implements Builder { protected boolean hidden = false; protected boolean immobilized = false; protected boolean invisible = false; + protected boolean mimetized = false; protected byte lvl = 1; protected boolean poisoned = false; protected Guild guild; @@ -123,6 +124,12 @@ public UserCharacterBuilder withInvisible(boolean invisible) { return this; } + + public UserCharacterBuilder withMimetized(boolean mimetized) { + this.mimetized= mimetized; + + return this; + } public UserCharacterBuilder withDumbed(boolean dumbed) { this.dumbed = dumbed; @@ -326,7 +333,7 @@ public UserCharacter build() { Preconditions.checkNotNull(position); LoggedUser user = new LoggedUser(reputation, race, gender, archetype.getArchetype(), poisoned, - paralyzed, immobilized, invisible, dumbed, hidden, maxMana, minMana, maxHp, minHp, + paralyzed, immobilized, invisible, mimetized, dumbed, hidden, maxMana, minMana, maxHp, minHp, maxThirstiness, minThirstiness, maxHunger, minHunger, lvl, name, description); //TODO: Set everything! diff --git a/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java b/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java index 3834457..f72e42b 100755 --- a/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java +++ b/aoxp-server/src/main/java/com/ao/model/character/UserCharacter.java @@ -19,6 +19,7 @@ package com.ao.model.character; import com.ao.model.character.archetype.Archetype; +import com.ao.model.map.City; public interface UserCharacter extends Character { @@ -111,6 +112,17 @@ public interface UserCharacter extends Character { */ Archetype getArchetype(); + /** + * Retrieves the user's homeland. + * @return the user's homeland. + */ + City getHomeland(); + + /** + * Sets user's new homeland. + * @param homeland the new homeland. + */ + void setHomeland(City homeland); /** * Retrieves the user's stamina. * @return The user's stamina. diff --git a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java index 20d98d4..d24bd69 100644 --- a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java +++ b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java @@ -28,6 +28,7 @@ import com.ao.model.character.UserCharacter; import com.ao.model.character.archetype.Archetype; import com.ao.model.inventory.Inventory; +import com.ao.model.map.City; import com.ao.model.map.Heading; import com.ao.model.map.Position; import com.ao.model.spell.Spell; @@ -53,6 +54,7 @@ public class LoggedUser extends ConnectedUser implements UserCharacter { private Race race; private Gender gender; private Archetype archetype; + private City homeland; private Weapon weapon; private Helmet helmet; @@ -100,7 +102,7 @@ public class LoggedUser extends ConnectedUser implements UserCharacter { public LoggedUser(Reputation reputation, Race race, Gender gender, Archetype archetype, boolean poisoned, boolean paralyzed, - boolean immobilized, boolean invisible, boolean dumbed, boolean hidden, int maxMana, int minMana, int maxHp, + boolean immobilized, boolean invisible, boolean mimetized, boolean dumbed, boolean hidden, int maxMana, int minMana, int maxHp, int minHp, int maxThirstiness, int minThirstiness , int maxHunger, int minHunger, byte lvl, String name, String description) { @@ -113,6 +115,7 @@ public LoggedUser(Reputation reputation, Race race, Gender gender, this.paralyzed = paralyzed; this.immobilized = immobilized; this.invisible = invisible; + this.mimetized= mimetized; this.dumbed = dumbed; this.hidden = hidden; this.maxMana = maxMana; @@ -403,6 +406,14 @@ public int getOriginalHead() { // TODO Auto-generated method stub return 0; } + + public City getHomeland() { + return homeland; + } + + public void setHomeland(City homeland) { + this.homeland= homeland; + } @Override public Position getPosition() { diff --git a/aoxp-server/src/main/java/com/ao/model/worldobject/AbstractItem.java b/aoxp-server/src/main/java/com/ao/model/worldobject/AbstractItem.java index 8381b25..be53cc9 100644 --- a/aoxp-server/src/main/java/com/ao/model/worldobject/AbstractItem.java +++ b/aoxp-server/src/main/java/com/ao/model/worldobject/AbstractItem.java @@ -31,7 +31,7 @@ */ public abstract class AbstractItem extends AbstractWorldObject implements Item { - protected static final int MAX_STACKED_ITEMS = 10000; + public static final int MAX_STACKED_ITEMS = 10000; //TODO Why was this protected? protected int amount; diff --git a/aoxp-server/src/main/java/com/ao/service/LoginService.java b/aoxp-server/src/main/java/com/ao/service/LoginService.java index ce133e8..6d6b5b3 100644 --- a/aoxp-server/src/main/java/com/ao/service/LoginService.java +++ b/aoxp-server/src/main/java/com/ao/service/LoginService.java @@ -32,6 +32,7 @@ public interface LoginService { * @param password The character's password. * @param version The client's version. * @param clientHash The client's integrity check hash. + * @return the loggedUser that was successfully connected. * @throws LoginErrorException */ LoggedUser connectExistingCharacter(ConnectedUser user, String name, String password, String version, @@ -51,7 +52,7 @@ LoggedUser connectExistingCharacter(ConnectedUser user, String name, String pass * @param homeland The character's homeland. * @param clientHash The client's integrity check hash. * @param version The client's version. - * @return + * @return the loggedUser that was successfully connected. * @throws LoginErrorException */ LoggedUser connectNewCharacter(ConnectedUser user, String username, String password, byte race, diff --git a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java index c1c59f1..b35232e 100644 --- a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java +++ b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java @@ -31,6 +31,7 @@ import com.ao.model.character.UserCharacter; import com.ao.model.character.archetype.UserArchetype; import com.ao.model.map.City; +import com.ao.model.map.Position; import com.ao.model.user.Account; import com.ao.model.user.ConnectedUser; import com.ao.model.user.LoggedUser; @@ -171,8 +172,10 @@ public LoggedUser connectNewCharacter(ConnectedUser user, String username, Strin // First, we have to create the new account. + Account acc; + try { - Account acc = accDAO.create(username, password, mail); + acc = accDAO.create(username, password, mail); } catch(NameAlreadyTakenException e) { throw new LoginErrorException(ACCOUNT_NAME_TAKEN_ERROR); @@ -183,9 +186,11 @@ public LoggedUser connectNewCharacter(ConnectedUser user, String username, Strin } - // Once we have the account, lets create the character itself! + // Once we have the account, lets create the character itself! + UserCharacter chara; + try { - charDAO.create(username, race, gender, archetype, + chara= charDAO.create(username, race, gender, archetype, head, homeland, user.getAttribute(Attribute.STRENGTH), user.getAttribute(Attribute.AGILITY), user.getAttribute(Attribute.INTELLIGENCE), user.getAttribute(Attribute.CHARISMA), user.getAttribute(Attribute.CONSTITUTION), @@ -197,7 +202,18 @@ public LoggedUser connectNewCharacter(ConnectedUser user, String username, Strin throw new LoginErrorException(e.getMessage()); } - return connectExistingCharacter(user, username, password, version, clientHash); + acc.addCharacter(username); + user.setAccount(acc); + + + userService.logIn(user); //logs the character in. + + //TODO Does this belong here? + chara.setPosition(new Position(homeland.getX(), homeland.getY(), mapService.getMap((byte)homeland.getMap()))); + + mapService.putCharacterAtPos(chara, chara.getPosition()); //places character in the world. + + return (LoggedUser)chara; } @Override @@ -242,7 +258,7 @@ public LoggedUser connectExistingCharacter(ConnectedUser user, String name, Stri // TODO : Do something with the account!!! - UserCharacter character = acc.getCharacter(name); + UserCharacter character; // TODO : send all data! @@ -255,7 +271,7 @@ public LoggedUser connectExistingCharacter(ConnectedUser user, String name, Stri throw new LoginErrorException(e.getMessage()); } - userService.logIn(user); //logs the character in. + userService.logIn(user); //adds character to list of logged characters. mapService.putCharacterAtPos(character, character.getPosition()); //places character in the world. From 30a60af5669700fa4128d2350b5fc3802a89adda Mon Sep 17 00:00:00 2001 From: MER Date: Tue, 13 May 2014 08:42:43 -0300 Subject: [PATCH 41/46] Completed LoginExistingCharacterPacket and changed catch statement in LoginNewCharacterPacket --- .../incoming/LoginExistingCharacterPacket.java | 12 ++++++++++-- .../packet/incoming/LoginNewCharacterPacket.java | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginExistingCharacterPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginExistingCharacterPacket.java index 92982d3..f7cd001 100755 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginExistingCharacterPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginExistingCharacterPacket.java @@ -21,10 +21,12 @@ import java.io.UnsupportedEncodingException; import com.ao.context.ApplicationContext; +import com.ao.model.character.UserCharacter; import com.ao.model.user.ConnectedUser; import com.ao.network.Connection; import com.ao.network.DataBuffer; import com.ao.network.packet.IncomingPacket; +import com.ao.network.packet.outgoing.CharacterCreatePacket; import com.ao.network.packet.outgoing.ErrorMessagePacket; import com.ao.security.SecurityManager; import com.ao.service.LoginService; @@ -48,11 +50,17 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO String version = buffer.get() + "." + buffer.get() + "." + buffer.get(); String clientHash = buffer.getASCIIStringFixed(security.getClientHashLength()); + UserCharacter loggedChar; try { - loginService.connectExistingCharacter((ConnectedUser) connection.getUser(), username, password, version, clientHash); + loggedChar= loginService.connectExistingCharacter((ConnectedUser) connection.getUser(), username, password, version, clientHash); + } catch (LoginErrorException e) { - loginError(connection, e.getMessage()); + + loginError(connection, e.getMessage()); + return true; } + + connection.send( new CharacterCreatePacket(loggedChar)); return true; } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java index ff8297e..8ef31bd 100755 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java @@ -69,8 +69,9 @@ public boolean handle(DataBuffer buffer, Connection connection) throws ArrayInde homeland, clientHash, version); } catch (LoginErrorException e) { - loggedChar= null; //If I don't do this compiler complains about it not being initialized. + loginError(connection, e.getMessage()); + return true; } connection.send( new CharacterCreatePacket(loggedChar) ); From e3a9ea1e4e700d553366ba3d2dc2bfe39b112bdb Mon Sep 17 00:00:00 2001 From: MER Date: Tue, 13 May 2014 09:39:14 -0300 Subject: [PATCH 42/46] aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java --- .../java/com/ao/network/packet/incoming/PickUpPacket.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java index ae0b9be..ee8adbc 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/PickUpPacket.java @@ -44,8 +44,12 @@ public boolean handle(DataBuffer buffer, Connection connection) WorldObject object = tile.getWorldObject(); - if(object == null/*TODO or user is dead or user is trading*/) + /*TODO if (user is dead or user is trading) return true*/ + if(object == null) { + + connection.send(new ConsoleMessagePacket("No hay nada aquí.", Font.INFO)); return true; + } if (user.getPrivileges().isCouncelor()) { From a812e41b22fe855c75244147a8b66cc8f954ec5a Mon Sep 17 00:00:00 2001 From: MER Date: Tue, 13 May 2014 16:46:01 -0300 Subject: [PATCH 43/46] Fixed javadoc typos --- aoxp-server/src/main/java/com/ao/model/user/Account.java | 4 ++-- aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/model/user/Account.java b/aoxp-server/src/main/java/com/ao/model/user/Account.java index 4154b2e..cb77d2b 100755 --- a/aoxp-server/src/main/java/com/ao/model/user/Account.java +++ b/aoxp-server/src/main/java/com/ao/model/user/Account.java @@ -47,7 +47,7 @@ public interface Account { boolean hasCharacter(String name); /** - * Checks wether the account is banned or not. + * Checks whether the account is banned or not. * @return True if the account is banned, false otherwise. */ boolean isBanned(); @@ -68,7 +68,7 @@ public interface Account { /** * Try to authenticate the account with the given password. * @param password The password used to authenticate. - * @return True if the password matchs the account password, false otherwise. + * @return True if the password matches the account password, false otherwise. */ boolean authenticate(String password); diff --git a/aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java b/aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java index 0b0840e..cf8498f 100755 --- a/aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java +++ b/aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java @@ -42,7 +42,7 @@ public class AccountImpl implements Account { * @param password The account's password. * @param mail The account's email. * @param characters The account's characters. - * @param banned Wether the account is banned or not. + * @param banned Whether the account is banned or not. */ public AccountImpl(String name, String password, String mail, Set characters, boolean banned) { this.name = name; From 0c819f6949d8b0101c6f83985bae8cb4d7a3172c Mon Sep 17 00:00:00 2001 From: MER Date: Tue, 13 May 2014 19:04:13 -0300 Subject: [PATCH 44/46] Added a LoggedUser field to AccountImpl representing the character that's currently logged in, if any. Couldn't find another way to gain access to the actual character (Connection's User is not the logged character)from incoming packet's classes. Now I can call connection.getUser().getAccount.getLoggedCharacter() and work with it from within the IncomingPacket.handle method. Updated only LoginNewCharacterPacket and LoginExistingCharacterPacket to suit these changes(Have to do so with the other IncomingPackets too). --- .../main/java/com/ao/model/user/Account.java | 12 ++++++++++ .../java/com/ao/model/user/AccountImpl.java | 21 ++++++++++++++++++ .../LoginExistingCharacterPacket.java | 9 ++++---- .../incoming/LoginNewCharacterPacket.java | 15 +++++-------- .../java/com/ao/service/LoginService.java | 6 ++--- .../ao/service/login/LoginServiceImpl.java | 22 +++++++++---------- 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/model/user/Account.java b/aoxp-server/src/main/java/com/ao/model/user/Account.java index cb77d2b..2de1ff2 100755 --- a/aoxp-server/src/main/java/com/ao/model/user/Account.java +++ b/aoxp-server/src/main/java/com/ao/model/user/Account.java @@ -65,6 +65,18 @@ public interface Account { */ UserCharacter getCharacter(String name); + /** + * Retrieves this account's logged character. + * @return account's currently logged character. + */ + LoggedUser getLoggedCharacter(); + + /** + * Sets this account's logged character. + * @param the logged character. + */ + void setLoggedCharacter(LoggedUser loggedChar); + /** * Try to authenticate the account with the given password. * @param password The password used to authenticate. diff --git a/aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java b/aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java index cf8498f..b8113b9 100755 --- a/aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java +++ b/aoxp-server/src/main/java/com/ao/model/user/AccountImpl.java @@ -36,6 +36,8 @@ public class AccountImpl implements Account { protected Set characters; private boolean banned; + private LoggedUser currentLoggedChar; + /** * Creates a new account instance. * @param name The name of the account. @@ -108,6 +110,25 @@ public UserCharacter getCharacter(String name) { return ApplicationContext.getInstance(UserService.class).getCharacter(name); } + /* (non-Javadoc) + * @see com.ao.model.user.Account#getLoggedCharacter() + */ + public LoggedUser getLoggedCharacter() { + //TODO many NPEs may arise as a result of this method being called when no character is logged. + return this.currentLoggedChar; + } + + /* (non-Javadoc) + * @see com.ao.model.user.Account#setLoggedCharacter(com.ao.model.user.LoggedUser) + */ + public void setLoggedCharacter(LoggedUser loggedChar) { + + if (this.hasCharacter( loggedChar.getName()) ) + this.currentLoggedChar= loggedChar; + else + this.currentLoggedChar= null; + } + /* (non-Javadoc) * @see com.ao.model.user.Account#authenticate(java.lang.String) */ diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginExistingCharacterPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginExistingCharacterPacket.java index f7cd001..4ee3d6a 100755 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginExistingCharacterPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginExistingCharacterPacket.java @@ -21,7 +21,6 @@ import java.io.UnsupportedEncodingException; import com.ao.context.ApplicationContext; -import com.ao.model.character.UserCharacter; import com.ao.model.user.ConnectedUser; import com.ao.network.Connection; import com.ao.network.DataBuffer; @@ -50,9 +49,11 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO String version = buffer.get() + "." + buffer.get() + "." + buffer.get(); String clientHash = buffer.getASCIIStringFixed(security.getClientHashLength()); - UserCharacter loggedChar; + + ConnectedUser user= (ConnectedUser) connection.getUser(); + try { - loggedChar= loginService.connectExistingCharacter((ConnectedUser) connection.getUser(), username, password, version, clientHash); + loginService.connectExistingCharacter(user, username, password, version, clientHash); } catch (LoginErrorException e) { @@ -60,7 +61,7 @@ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutO return true; } - connection.send( new CharacterCreatePacket(loggedChar)); + connection.send( new CharacterCreatePacket(user.getAccount().getLoggedCharacter())); return true; } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java index 8ef31bd..59f598e 100755 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/LoginNewCharacterPacket.java @@ -21,8 +21,6 @@ import java.io.UnsupportedEncodingException; import com.ao.context.ApplicationContext; - -import com.ao.model.character.UserCharacter; import com.ao.model.user.ConnectedUser; import com.ao.network.Connection; import com.ao.network.DataBuffer; @@ -60,21 +58,20 @@ public boolean handle(DataBuffer buffer, Connection connection) throws ArrayInde int head = buffer.get(); String mail = buffer.getASCIIString(); byte homeland = buffer.get(); - - UserCharacter loggedChar; + + ConnectedUser user= (ConnectedUser) connection.getUser(); try { - loggedChar= service.connectNewCharacter((ConnectedUser) connection.getUser(), - nick, password, race, gender, archetype, head, mail, - homeland, clientHash, version); + service.connectNewCharacter(user, nick, password, race, gender, + archetype, head, mail, homeland, clientHash, version); } catch (LoginErrorException e) { loginError(connection, e.getMessage()); return true; - } + } - connection.send( new CharacterCreatePacket(loggedChar) ); + connection.send( new CharacterCreatePacket( user.getAccount().getLoggedCharacter() )); return true; } diff --git a/aoxp-server/src/main/java/com/ao/service/LoginService.java b/aoxp-server/src/main/java/com/ao/service/LoginService.java index 6d6b5b3..3298342 100644 --- a/aoxp-server/src/main/java/com/ao/service/LoginService.java +++ b/aoxp-server/src/main/java/com/ao/service/LoginService.java @@ -32,10 +32,9 @@ public interface LoginService { * @param password The character's password. * @param version The client's version. * @param clientHash The client's integrity check hash. - * @return the loggedUser that was successfully connected. * @throws LoginErrorException */ - LoggedUser connectExistingCharacter(ConnectedUser user, String name, String password, String version, + void connectExistingCharacter(ConnectedUser user, String name, String password, String version, String clientHash) throws LoginErrorException; /** @@ -52,10 +51,9 @@ LoggedUser connectExistingCharacter(ConnectedUser user, String name, String pass * @param homeland The character's homeland. * @param clientHash The client's integrity check hash. * @param version The client's version. - * @return the loggedUser that was successfully connected. * @throws LoginErrorException */ - LoggedUser connectNewCharacter(ConnectedUser user, String username, String password, byte race, + void connectNewCharacter(ConnectedUser user, String username, String password, byte race, byte gender, byte archetype, int head, String mail, byte homeland, String clientHash, String version) throws LoginErrorException; diff --git a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java index b35232e..026e6df 100644 --- a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java +++ b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java @@ -96,7 +96,7 @@ public LoginServiceImpl(AccountDAO accDAO, UserCharacterDAO charDAO, } @Override - public LoggedUser connectNewCharacter(ConnectedUser user, String username, String password, byte bRace, + public void connectNewCharacter(ConnectedUser user, String username, String password, byte bRace, byte bGender, byte bArchetype, int head, String mail, byte bHomeland, String clientHash, String version) throws LoginErrorException { @@ -203,21 +203,19 @@ public LoggedUser connectNewCharacter(ConnectedUser user, String username, Strin } acc.addCharacter(username); - user.setAccount(acc); - + user.setAccount(acc); + acc.setLoggedCharacter((LoggedUser)chara); userService.logIn(user); //logs the character in. - //TODO Does this belong here? + //TODO Is this the right place to set up char's initial position? chara.setPosition(new Position(homeland.getX(), homeland.getY(), mapService.getMap((byte)homeland.getMap()))); mapService.putCharacterAtPos(chara, chara.getPosition()); //places character in the world. - - return (LoggedUser)chara; } @Override - public LoggedUser connectExistingCharacter(ConnectedUser user, String name, String password, String version, + public void connectExistingCharacter(ConnectedUser user, String name, String password, String version, String clientHash) throws LoginErrorException { checkClient(clientHash, version); @@ -258,24 +256,24 @@ public LoggedUser connectExistingCharacter(ConnectedUser user, String name, Stri // TODO : Do something with the account!!! - UserCharacter character; + UserCharacter chara; // TODO : send all data! user.setAccount(acc); //associates the account with the user try { - character= (LoggedUser) charDAO.load(name); // loads the character. + chara= (LoggedUser) charDAO.load(name); // loads the character. } catch (DAOException e) { throw new LoginErrorException(e.getMessage()); } + + acc.setLoggedCharacter((LoggedUser)chara); userService.logIn(user); //adds character to list of logged characters. - mapService.putCharacterAtPos(character, character.getPosition()); //places character in the world. - - return (LoggedUser)character; + mapService.putCharacterAtPos(chara, chara.getPosition()); //places character in the world. } /** From f44354261425d5a4c17f0fa22ed0b283fd960f5e Mon Sep 17 00:00:00 2001 From: MER Date: Sat, 17 May 2014 16:02:47 -0300 Subject: [PATCH 45/46] Now LoggedUser's constructor asks for homeland and position parameters. Now LoginNewCharacterPacketTest loads the maps. Now UserDAOIni sets user position both at create and load methods. --- .../java/com/ao/data/dao/ini/UserDAOIni.java | 28 +++++++++++++++++-- .../com/ao/data/dao/map/WorldMapDAOImpl.java | 7 ++++- .../model/builder/UserCharacterBuilder.java | 2 +- .../java/com/ao/model/user/LoggedUser.java | 4 ++- .../ao/service/login/LoginServiceImpl.java | 6 ++-- .../incoming/LoginNewCharacterPacketTest.java | 1 + 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/data/dao/ini/UserDAOIni.java b/aoxp-server/src/main/java/com/ao/data/dao/ini/UserDAOIni.java index 04bb000..f77c6a4 100755 --- a/aoxp-server/src/main/java/com/ao/data/dao/ini/UserDAOIni.java +++ b/aoxp-server/src/main/java/com/ao/data/dao/ini/UserDAOIni.java @@ -33,6 +33,7 @@ import org.apache.log4j.Logger; import org.ini4j.Ini; +import com.ao.context.ApplicationContext; import com.ao.data.dao.AccountDAO; import com.ao.data.dao.UserCharacterDAO; import com.ao.data.dao.exception.DAOException; @@ -48,9 +49,11 @@ import com.ao.model.character.archetype.UserArchetype; import com.ao.model.map.City; import com.ao.model.map.Heading; +import com.ao.model.map.Position; import com.ao.model.user.Account; import com.ao.model.user.AccountImpl; import com.ao.model.user.LoggedUser; +import com.ao.service.MapService; import com.google.inject.Inject; import com.google.inject.name.Named; @@ -191,7 +194,11 @@ public class UserDAOIni implements AccountDAO, UserCharacterDAO { protected static final int INITIAL_NOBLE_POINTS = 1000; private static final Logger logger = Logger.getLogger(UserDAOIni.class); - + + /*---------FIXME awful workaround to be able to set char's position-----------*/ + private MapService mapService = ApplicationContext.getInstance(MapService.class); + /*----------------------------------------------------------------------------*/ + private String charfilesPath; @Inject @@ -285,6 +292,9 @@ public UserCharacter create(String name, Race race, Gender gender, String positionKey = homeland.getMap() + "-" + homeland.getX() + "-" + homeland.getY(); chara.put(INIT_HEADER, POSITION_KEY, positionKey ); + + Position position= new Position(homeland.getX(), homeland.getY(), mapService.getMap(homeland.getMap())); + // TODO: Save last ip? chara.put(FLAGS_HEADER, BANNED_KEY, 0); @@ -380,7 +390,7 @@ public UserCharacter create(String name, Race race, Gender gender, } // TODO: Update this when hp, mana and hit points get updated! - return new LoggedUser(rep, race, gender, archetype.getArchetype(), + return new LoggedUser(rep, race, gender, archetype.getArchetype(), homeland, position, false, false, false, false, false, false, false, 0, 0, 0, 0, 100, 0, 100, 0, (byte) 1, name, ""); } @@ -423,6 +433,18 @@ public UserCharacter load(String username) throws DAOException { Archetype archetype = UserArchetype.get(Byte.parseByte(chara.get(INIT_HEADER, ARCHETYPE_KEY))).getArchetype(); + int homeId= Integer.parseInt(chara.get(INIT_HEADER, HOMELAND_KEY)); + + City homeland= new City( homeId, mapService.getCity((byte)homeId).getX() , mapService.getCity((byte)homeId).getY()); + + String[] stringPos= chara.get(INIT_HEADER, POSITION_KEY).split("-"); + + Position position= new Position ( + Byte.parseByte(stringPos[1]), + Byte.parseByte(stringPos[2]), + mapService.getMap(Integer.parseInt(stringPos[0])) + ); + boolean poisoned = chara.get(FLAGS_HEADER, POISONED_KEY).equals("1"); boolean paralyzed = chara.get(FLAGS_HEADER, PARALYZED_KEY).equals("1"); @@ -450,7 +472,7 @@ public UserCharacter load(String username) throws DAOException { String description = ""; // TODO : Validate character - return new LoggedUser(reputation, race, gender, archetype, poisoned, paralyzed, immobilized, invisible, mimetized, dumbed, hidden, maxMana, mana, maxHitPoints, hitpoints, 100, thirstiness, 100, hunger, lvl, username, description); + return new LoggedUser(reputation, race, gender, archetype, homeland, position, poisoned, paralyzed, immobilized, invisible, mimetized, dumbed, hidden, maxMana, mana, maxHitPoints, hitpoints, 100, thirstiness, 100, hunger, lvl, username, description); } private Ini readCharFile(String username) throws DAOException { diff --git a/aoxp-server/src/main/java/com/ao/data/dao/map/WorldMapDAOImpl.java b/aoxp-server/src/main/java/com/ao/data/dao/map/WorldMapDAOImpl.java index 20c15fb..c8a01c0 100644 --- a/aoxp-server/src/main/java/com/ao/data/dao/map/WorldMapDAOImpl.java +++ b/aoxp-server/src/main/java/com/ao/data/dao/map/WorldMapDAOImpl.java @@ -112,7 +112,12 @@ private void loadMap(int id, WorldMap[] maps) { logger.error("Map " + id + " loading failed!", e); throw new RuntimeException(e); } - + try { + dataInf.close(); + dataMap.close(); + + } catch (IOException e) {} + ByteBuffer infBuffer = ByteBuffer.wrap(bufInf); ByteBuffer mapBuffer = ByteBuffer.wrap(bufMap); diff --git a/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java b/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java index 28292f3..3dfb853 100644 --- a/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java +++ b/aoxp-server/src/main/java/com/ao/model/builder/UserCharacterBuilder.java @@ -332,7 +332,7 @@ public UserCharacter build() { Preconditions.checkNotNull(reputation); Preconditions.checkNotNull(position); - LoggedUser user = new LoggedUser(reputation, race, gender, archetype.getArchetype(), poisoned, + LoggedUser user = new LoggedUser(reputation, race, gender, archetype.getArchetype(), homeland, position, poisoned, paralyzed, immobilized, invisible, mimetized, dumbed, hidden, maxMana, minMana, maxHp, minHp, maxThirstiness, minThirstiness, maxHunger, minHunger, lvl, name, description); diff --git a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java index d24bd69..52ce045 100644 --- a/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java +++ b/aoxp-server/src/main/java/com/ao/model/user/LoggedUser.java @@ -101,7 +101,7 @@ public class LoggedUser extends ConnectedUser implements UserCharacter { private Heading heading; public LoggedUser(Reputation reputation, Race race, Gender gender, - Archetype archetype, boolean poisoned, boolean paralyzed, + Archetype archetype, City homeland, Position position, boolean poisoned, boolean paralyzed, boolean immobilized, boolean invisible, boolean mimetized, boolean dumbed, boolean hidden, int maxMana, int minMana, int maxHp, int minHp, int maxThirstiness, int minThirstiness , int maxHunger, int minHunger, byte lvl, String name, String description) { @@ -111,6 +111,8 @@ public LoggedUser(Reputation reputation, Race race, Gender gender, this.race = race; this.gender = gender; this.archetype = archetype; + this.homeland = homeland; + this.position = position; this.poisoned = poisoned; this.paralyzed = paralyzed; this.immobilized = immobilized; diff --git a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java index 026e6df..433e577 100644 --- a/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java +++ b/aoxp-server/src/main/java/com/ao/service/login/LoginServiceImpl.java @@ -31,7 +31,6 @@ import com.ao.model.character.UserCharacter; import com.ao.model.character.archetype.UserArchetype; import com.ao.model.map.City; -import com.ao.model.map.Position; import com.ao.model.user.Account; import com.ao.model.user.ConnectedUser; import com.ao.model.user.LoggedUser; @@ -208,8 +207,9 @@ public void connectNewCharacter(ConnectedUser user, String username, String pass userService.logIn(user); //logs the character in. - //TODO Is this the right place to set up char's initial position? - chara.setPosition(new Position(homeland.getX(), homeland.getY(), mapService.getMap((byte)homeland.getMap()))); + + +// setPosition(new Position(homeland.getX(), homeland.getY(), mapService.getMap((byte)homeland.getMap()))); mapService.putCharacterAtPos(chara, chara.getPosition()); //places character in the world. } diff --git a/aoxp-server/src/test/java/com/ao/network/packet/incoming/LoginNewCharacterPacketTest.java b/aoxp-server/src/test/java/com/ao/network/packet/incoming/LoginNewCharacterPacketTest.java index daebcc3..41a5342 100644 --- a/aoxp-server/src/test/java/com/ao/network/packet/incoming/LoginNewCharacterPacketTest.java +++ b/aoxp-server/src/test/java/com/ao/network/packet/incoming/LoginNewCharacterPacketTest.java @@ -90,6 +90,7 @@ public void setUp() throws Exception { mapService = ApplicationContext.getInstance(MapService.class); mapService.loadCities(); + mapService.loadMaps(); config.setRestrictedToAdmins(false); config.setCharacterCreationEnabled(true); From ff19b382daea6a8035b62b431d7993142419bf7d Mon Sep 17 00:00:00 2001 From: MER Date: Sat, 17 May 2014 16:18:07 -0300 Subject: [PATCH 46/46] Updated DropPacket, RequestPositioUpdatePacket and WalkPacket to figure out user's LoggedUser propperly. --- .../network/packet/incoming/DropPacket.java | 3 +- .../incoming/RequestPositionUpdatePacket.java | 4 +- .../network/packet/incoming/WalkPacket.java | 151 ++++++++---------- 3 files changed, 74 insertions(+), 84 deletions(-) diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/DropPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/DropPacket.java index fdffa1d..8fd7a9a 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/DropPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/DropPacket.java @@ -22,6 +22,7 @@ import com.ao.model.fonts.Font; import com.ao.model.map.Tile; +import com.ao.model.user.ConnectedUser; import com.ao.model.user.LoggedUser; import com.ao.model.worldobject.AbstractItem; import com.ao.model.worldobject.Item; @@ -40,7 +41,7 @@ public boolean handle(DataBuffer buffer, Connection connection) if (buffer.getReadableBytes() < 3) return false; - LoggedUser user= (LoggedUser) connection.getUser(); + LoggedUser user= ((ConnectedUser)connection.getUser()).getAccount().getLoggedCharacter(); //TODO should we send a message to a counselor trying to pick up an item? if (user.getPrivileges().isCouncelor() || user.isSailing()/*TODO or dead, or trading*/) diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/RequestPositionUpdatePacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/RequestPositionUpdatePacket.java index cf4a004..6aed963 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/RequestPositionUpdatePacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/RequestPositionUpdatePacket.java @@ -20,6 +20,7 @@ import java.io.UnsupportedEncodingException; +import com.ao.model.user.ConnectedUser; import com.ao.model.user.LoggedUser; import com.ao.network.Connection; import com.ao.network.DataBuffer; @@ -35,7 +36,8 @@ public class RequestPositionUpdatePacket implements IncomingPacket{ public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutOfBoundsException, UnsupportedEncodingException { - connection.send( new UpdatePositionPacket( (LoggedUser)connection.getUser() )); + LoggedUser user= ((ConnectedUser) connection.getUser()).getAccount().getLoggedCharacter(); + connection.send( new UpdatePositionPacket(user) ); return true; } diff --git a/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java b/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java index 9498db9..f54c36c 100644 --- a/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java +++ b/aoxp-server/src/main/java/com/ao/network/packet/incoming/WalkPacket.java @@ -14,128 +14,115 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -*/ + */ package com.ao.network.packet.incoming; import java.io.UnsupportedEncodingException; import com.ao.context.ApplicationContext; -import com.ao.model.character.archetype.PirateArchetype; import com.ao.model.fonts.Font; import com.ao.model.map.Heading; +import com.ao.model.user.ConnectedUser; import com.ao.model.user.LoggedUser; import com.ao.network.Connection; import com.ao.network.DataBuffer; import com.ao.network.packet.IncomingPacket; +import com.ao.network.packet.outgoing.CharacterChangePacket; import com.ao.network.packet.outgoing.CharacterMovePacket; import com.ao.network.packet.outgoing.ConsoleMessagePacket; import com.ao.network.packet.outgoing.CreateFXPacket; import com.ao.network.packet.outgoing.MeditateTogglePacket; +import com.ao.network.packet.outgoing.SetInvisiblePacket; import com.ao.service.MapService; public class WalkPacket implements IncomingPacket { - private MapService mapService = ApplicationContext.getInstance(MapService.class); + private MapService mapService = ApplicationContext.getInstance(MapService.class); - @Override - public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutOfBoundsException, UnsupportedEncodingException { + @Override + public boolean handle(DataBuffer buffer, Connection connection) throws IndexOutOfBoundsException, UnsupportedEncodingException { - if (buffer.getReadableBytes() < 1) { - return false; - } + if (buffer.getReadableBytes() < 1) { + return false; + } - LoggedUser user = (LoggedUser) connection.getUser(); + LoggedUser user = ( (ConnectedUser)connection.getUser() ).getAccount().getLoggedCharacter(); - //TODO check security issues + //TODO check security issues - if ( !( user.isParalyzed() || user.isImmobilized() ) ) { - if (user.isMeditating()) { - // Stop meditating, next action will start movement. - user.setMeditate(false); + Heading heading = Heading.get(buffer.get()); - connection.send( - new ConsoleMessagePacket("Dejas de meditar.", Font.INFO) - ); + if (heading != null) { - user.getFx().setId(0); - user.getFx().setLoops(0); - - connection.send( - new MeditateTogglePacket()); - - connection.send( - new CreateFXPacket(user)); // Halts meditation FX with a no-effect FX + if ( !(user.isParalyzed() || user.isImmobilized()) ) { - } else if (!user.isHomecoming()){ - - Heading heading = Heading.get(buffer.get()); - - if (heading != null) { + if (user.isMeditating()) { + // Stop meditating, next action will start movement. + user.setMeditate(false); - // Move user - mapService.moveCharacterTo(user, heading); + connection.send( + new ConsoleMessagePacket("Dejas de meditar.", Font.INFO) + ); + + user.getFx().setId(0); + user.getFx().setLoops(0); + + connection.send( + new MeditateTogglePacket()); - //TODO Stop resting if needed - connection.send( - new CharacterMovePacket(user)); + new CreateFXPacket(user)); // Halts meditation FX with a no-effect FX + + } else if (!user.isHomecoming()) { - } else { - return true; - } + mapService.moveCharacterTo(user, heading); // Move user - } - } else { //if paralized - //TODO set last message flag - //TODO aplicar seguridad contra SH - - Heading heading = Heading.get(buffer.get()); + //TODO Stop resting if needed - if (heading != null) { + connection.send(new CharacterMovePacket(user)); + } + } else { //if paralyzed + //TODO set last message flag + //TODO aplicar seguridad contra SH user.setHeading(heading); /* TODO client updates character's heading without * server notification (doesn't it?) so no need to send anything. * */ - - } else { - return true; } - } - - // Check if hidden and can move while hidden - if (user.isHidden() && !user.isAdminHidden() && !user.getArchetype().canWalkHidden()) { - user.setHidden(false); - - if (user.isSailing()) { - // TODO : Find a nicer way to do this... - if (user.getArchetype() instanceof PirateArchetype) { - -// ' Pierde la apariencia de fragata fantasmal -// Call ToggleBoatBody(UserIndex) - - connection.send( - new ConsoleMessagePacket("¡Has recuperado tu apariencia normal!", Font.INFO) - ); -// Call WriteConsoleMsg(UserIndex, "¡Has recuperado tu apariencia normal!", FontTypeNames.FONTTYPE_INFO) - -// Call ChangeUserChar(UserIndex, .Char.body, .Char.Head, .Char.heading, NingunArma, _ -// NingunEscudo, NingunCasco) - } - - } else if (user.isInvisible()) { - - // If not under a spell effect, show character - connection.send( - new ConsoleMessagePacket("Has vuelto a ser visible.", Font.INFO) - ); -// Call UsUaRiOs.SetInvisible(UserIndex, .Char.CharIndex, False) - } - } - - return true; - } + // Check if hidden and can move while hidden + if (user.isHidden() && !user.isAdminHidden() && !user.getArchetype().canWalkHidden()) { + user.setHidden(false); + + if (user.isSailing()) { + //No need to check for pirate since any character hidden while sailing MUST be a pirate. + connection.send( + new ConsoleMessagePacket("¡Has recuperado tu apariencia normal!", Font.INFO) + ); + + connection.send( + new CharacterChangePacket(user) + ); + + + } else if (!user.isInvisible()) { + // If not under a spell effect, show character + connection.send( + new ConsoleMessagePacket("Has vuelto a ser visible.", Font.INFO) + ); + + user.setHidden(false); + + connection.send( + new SetInvisiblePacket(user, false) + ); + } + } + } + + return true; + } }