summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2006-08-14 08:36:16 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2006-08-14 08:36:16 +0000
commitc79bf8c82f0a38b574b83be2484eb347852cd833 (patch)
treebf13ca5f0ff3f0413bab52f89ba95e705ffce745 /src
parent9e6862623370f53d1b78e4bd167152b840e28884 (diff)
downloadmana-c79bf8c82f0a38b574b83be2484eb347852cd833.tar.gz
mana-c79bf8c82f0a38b574b83be2484eb347852cd833.tar.bz2
mana-c79bf8c82f0a38b574b83be2484eb347852cd833.tar.xz
mana-c79bf8c82f0a38b574b83be2484eb347852cd833.zip
Completed porting of character creation/deletion, fixed some issues with network code.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp2
-rw-r--r--src/being.h4
-rw-r--r--src/gui/char_select.cpp42
-rw-r--r--src/gui/char_select.h1
-rw-r--r--src/gui/playerbox.cpp3
-rw-r--r--src/gui/playerbox.h8
-rw-r--r--src/gui/status.cpp12
-rw-r--r--src/gui/status.h2
-rw-r--r--src/localplayer.cpp1
-rw-r--r--src/localplayer.h2
-rw-r--r--src/main.cpp39
-rw-r--r--src/net/buysellhandler.cpp2
-rw-r--r--src/net/charserverhandler.cpp216
-rw-r--r--src/net/loginhandler.cpp19
-rw-r--r--src/net/loginhandler.h3
-rw-r--r--src/net/messageout.cpp4
-rw-r--r--src/net/messageout.h4
-rw-r--r--src/net/network.cpp8
-rw-r--r--src/net/network.h5
-rw-r--r--src/net/playerhandler.cpp2
-rw-r--r--src/net/protocol.h14
21 files changed, 179 insertions, 214 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 1ca8929a..7755d4e5 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -46,6 +46,7 @@ PATH_NODE::PATH_NODE(Uint16 iX, Uint16 iY):
}
Being::Being(Uint32 id, Uint16 job, Map *map):
+ mSex(2),
mJob(job),
mX(0), mY(0), mDirection(DOWN),
mAction(0),
@@ -58,7 +59,6 @@ Being::Being(Uint32 id, Uint16 job, Map *map):
mWalkSpeed(150),
mMap(NULL),
mHairStyle(0), mHairColor(0),
- mSex(2),
mSpeechTime(0),
mDamageTime(0),
mShowSpeech(false), mShowDamage(false)
diff --git a/src/being.h b/src/being.h
index 0735efe9..055ea0d4 100644
--- a/src/being.h
+++ b/src/being.h
@@ -98,6 +98,8 @@ class Being : public Sprite
static const char UP = 4;
static const char RIGHT = 8;
+ std::string mName; /**< Name of character */
+ Uint8 mSex; /**< Character's gender */
Uint16 mJob; /**< Job (player job, npc, monster, ) */
Uint16 mX, mY; /**< Tile coordinates */
Uint8 mDirection; /**< Facing direction */
@@ -358,14 +360,12 @@ class Being : public Sprite
Uint16 mWeapon; /**< Weapon picture id */
Uint16 mWalkSpeed; /**< Walking speed */
Map *mMap; /**< Map on which this being resides */
- std::string mName; /**< Name of character */
SpriteIterator mSpriteIterator;
Path mPath;
std::string mSpeech;
std::string mDamage;
Uint16 mHairStyle, mHairColor;
- Uint8 mSex;
Uint32 mSpeechTime;
Uint32 mDamageTime;
bool mShowSpeech, mShowDamage;
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 75887b99..775eea24 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -38,6 +38,8 @@
#include "../main.h"
#include "../net/messageout.h"
+#include "../net/network.h"
+#include "../net/protocol.h"
#include "../utils/tostring.h"
@@ -83,7 +85,6 @@ CharSelectDialog::CharSelectDialog(Network *network,
mNameLabel = new gcn::Label("Name");
mLevelLabel = new gcn::Label("Level");
- mJobLevelLabel = new gcn::Label("Job Level");
mMoneyLabel = new gcn::Label("Money");
mPlayerBox = new PlayerBox(0);
@@ -93,7 +94,6 @@ CharSelectDialog::CharSelectDialog(Network *network,
mPlayerBox->setDimension(gcn::Rectangle(5, 5, w - 10, 90));
mNameLabel->setDimension(gcn::Rectangle(10, 100, 128, 16));
mLevelLabel->setDimension(gcn::Rectangle(10, 116, 128, 16));
- mJobLevelLabel->setDimension(gcn::Rectangle(10, 132, 128, 16));
mMoneyLabel->setDimension(gcn::Rectangle(10, 148, 128, 16));
mPreviousButton->setPosition(5, 170);
mNextButton->setPosition(mPreviousButton->getWidth() + 10, 170);
@@ -117,7 +117,6 @@ CharSelectDialog::CharSelectDialog(Network *network,
add(mNextButton);
add(mNameLabel);
add(mLevelLabel);
- add(mJobLevelLabel);
add(mMoneyLabel);
mSelectButton->requestFocus();
@@ -177,8 +176,7 @@ void CharSelectDialog::updatePlayerInfo()
if (pi) {
mNameLabel->setCaption(pi->getName());
mLevelLabel->setCaption("Lvl: " + toString(pi->mLevel));
- mJobLevelLabel->setCaption("Job Lvl: " + toString(pi->mJobLevel));
- mMoneyLabel->setCaption("Gold: " + toString(pi->mGp));
+ mMoneyLabel->setCaption("Money: " + toString(pi->mMoney));
if (!mCharSelected)
{
mNewCharButton->setEnabled(false);
@@ -192,7 +190,6 @@ void CharSelectDialog::updatePlayerInfo()
} else {
mNameLabel->setCaption("Name");
mLevelLabel->setCaption("Level");
- mJobLevelLabel->setCaption("Job Level");
mMoneyLabel->setCaption("Money");
mNewCharButton->setEnabled(true);
mDelCharButton->setEnabled(false);
@@ -207,10 +204,11 @@ void CharSelectDialog::updatePlayerInfo()
void CharSelectDialog::attemptCharDelete()
{
// Request character deletion
- MessageOut outMsg;
- outMsg.writeShort(0x0068);
- outMsg.writeLong(mCharInfo->getEntry()->mCharId);
- outMsg.writeString("a@a.com", 40);
+ MessageOut msg;
+ msg.writeShort(PAMSG_CHAR_DELETE);
+ // TODO: Send the selected slot
+ msg.writeByte(0);
+ network->send(msg);
mCharInfo->lock();
}
@@ -326,15 +324,17 @@ void CharCreateDialog::attemptCharCreate()
{
// Send character infos
MessageOut outMsg;
- outMsg.writeShort(0x0067);
- outMsg.writeString(getName(), 24);
- outMsg.writeByte(5);
- outMsg.writeByte(5);
- outMsg.writeByte(5);
- outMsg.writeByte(5);
- outMsg.writeByte(5);
- outMsg.writeByte(5);
- outMsg.writeByte(mSlot);
- outMsg.writeShort(mPlayerBox->mHairColor + 1);
- outMsg.writeShort(mPlayerBox->mHairStyle + 1);
+ outMsg.writeShort(PAMSG_CHAR_CREATE);
+ outMsg.writeString(getName());
+ outMsg.writeByte(mPlayerBox->mHairStyle + 1);
+ outMsg.writeByte(mPlayerBox->mHairColor + 1);
+ // TODO: send selected sex
+ outMsg.writeByte(0); // Player sex
+ outMsg.writeShort(10); // STR
+ outMsg.writeShort(10); // AGI
+ outMsg.writeShort(10); // VIT
+ outMsg.writeShort(10); // INT
+ outMsg.writeShort(10); // DEX
+ outMsg.writeShort(10); // LUK
+ network->send(outMsg);
}
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index 3bf9911e..e65f400d 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -69,7 +69,6 @@ class CharSelectDialog : public Window, public gcn::ActionListener
gcn::Label *mNameLabel;
gcn::Label *mLevelLabel;
- gcn::Label *mJobLevelLabel;
gcn::Label *mMoneyLabel;
PlayerBox *mPlayerBox;
diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp
index f0ed9b71..d8faff99 100644
--- a/src/gui/playerbox.cpp
+++ b/src/gui/playerbox.cpp
@@ -94,8 +94,7 @@ void PlayerBox::draw(gcn::Graphics *graphics)
playerset[mSex]->get(0), 23, 12);
// Draw his hair
- if (mHairColor >= 0 && mHairStyle >= 0 &&
- mHairColor < NR_HAIR_COLORS && mHairStyle < NR_HAIR_STYLES)
+ if (mHairColor < NR_HAIR_COLORS && mHairStyle < NR_HAIR_STYLES)
{
int hf = 9 * mHairColor;
if (hf >= 0 && hf < (int)hairset[mHairStyle]->size()) {
diff --git a/src/gui/playerbox.h b/src/gui/playerbox.h
index 79f7c2aa..ec04eaf6 100644
--- a/src/gui/playerbox.h
+++ b/src/gui/playerbox.h
@@ -57,10 +57,10 @@ class PlayerBox : public gcn::ScrollArea
*/
void drawBorder(gcn::Graphics *graphics);
- int mHairColor; /**< The hair color index */
- int mHairStyle; /**< The hair style index */
- unsigned char mSex; /**< Sex */
- bool mShowPlayer; /**< Wether to show the player or not */
+ unsigned char mHairColor; /**< The hair color index */
+ unsigned char mHairStyle; /**< The hair style index */
+ unsigned char mSex; /**< Sex */
+ bool mShowPlayer; /**< Wether to show the player or not */
private:
static int instances;
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index bf109460..2b61ed35 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -48,7 +48,7 @@ StatusWindow::StatusWindow(LocalPlayer *player):
// ----------------------
mLvlLabel = new gcn::Label("Level:");
- mGpLabel = new gcn::Label("Money:");
+ mMoneyLabel = new gcn::Label("Money:");
mHpLabel = new gcn::Label("HP:");
mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34);
@@ -71,7 +71,7 @@ StatusWindow::StatusWindow(LocalPlayer *player):
mLvlLabel->setPosition(x, y);
x += mLvlLabel->getWidth() + 40;
- mGpLabel->setPosition(x, y);
+ mMoneyLabel->setPosition(x, y);
y += mLvlLabel->getHeight() + 5; // Next Row
x = 5;
@@ -100,7 +100,7 @@ StatusWindow::StatusWindow(LocalPlayer *player):
mJobValueLabel->setPosition(290, y);
add(mLvlLabel);
- add(mGpLabel);
+ add(mMoneyLabel);
add(mHpLabel);
add(mHpValueLabel);
add(mMpLabel);
@@ -227,8 +227,8 @@ void StatusWindow::update()
mLvlLabel->setCaption("Level: " + toString(mPlayer->mLevel));
mLvlLabel->adjustSize();
- mGpLabel->setCaption("Money: " + toString(mPlayer->mGp) + " GP");
- mGpLabel->adjustSize();
+ mMoneyLabel->setCaption("Money: " + toString(mPlayer->mMoney) + " GP");
+ mMoneyLabel->adjustSize();
mJobXpLabel->setCaption("Job: " + toString(mPlayer->mJobLevel));
mJobXpLabel->adjustSize();
@@ -334,7 +334,7 @@ void StatusWindow::update()
mStatsReflexPoints->adjustSize();
// Update Second column widgets position
- mGpLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20,
+ mMoneyLabel->setPosition(mLvlLabel->getX() + mLvlLabel->getWidth() + 20,
mLvlLabel->getY());
mXpLabel->setPosition(
diff --git a/src/gui/status.h b/src/gui/status.h
index 6b963d24..fe2140e3 100644
--- a/src/gui/status.h
+++ b/src/gui/status.h
@@ -69,7 +69,7 @@ class StatusWindow : public Window, public gcn::ActionListener {
/**
* Status Part
*/
- gcn::Label *mLvlLabel, *mGpLabel, *mHpLabel, *mHpValueLabel;
+ gcn::Label *mLvlLabel, *mMoneyLabel, *mHpLabel, *mHpValueLabel;
gcn::Label *mMpLabel, *mMpValueLabel;
gcn::Label *mXpLabel, *mXpValueLabel, *mJobXpLabel, *mJobValueLabel;
ProgressBar *mHpBar, *mMpBar;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 4a15cba3..83884b6f 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -38,6 +38,7 @@ LocalPlayer *player_node = NULL;
LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
Player(id, job, map),
+ mLevel(1),
mInventory(new Inventory()),
mTarget(NULL), mPickUpTarget(NULL),
mTrading(false), mLastAction(-1)
diff --git a/src/localplayer.h b/src/localplayer.h
index 1f8c836f..fdef6ba1 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -127,7 +127,7 @@ class LocalPlayer : public Player
Uint32 mJobLevel;
Uint32 mXpForNextLevel, mJobXpForNextLevel;
Uint16 mHp, mMaxHp, mMp, mMaxMp;
- Uint32 mGp;
+ Uint32 mMoney;
Uint32 mTotalWeight, mMaxWeight;
diff --git a/src/main.cpp b/src/main.cpp
index a4ef29ee..dc76846e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -407,21 +407,23 @@ LockedArray<LocalPlayer*> charInfo(MAX_SLOT + 1);
MapLoginHandler mapLoginHandler;
// TODO Find some nice place for these functions
-void accountLogin(Network *network, LoginData *loginData)
+void accountLogin(LoginData *loginData)
{
logger->log("Trying to connect to account server...");
logger->log("Username is %s", loginData->username.c_str());
network->connect(loginData->hostname, loginData->port);
network->registerHandler(&loginHandler);
- loginHandler.setCharInfo(&charInfo);
+ network->registerHandler(&charServerHandler);
loginHandler.setLoginData(loginData);
+ charServerHandler.setLoginData(loginData);
+ charServerHandler.setCharInfo(&charInfo);
// Send login infos
- MessageOut *msg = new MessageOut();
- msg->writeShort(PAMSG_LOGIN);
- msg->writeLong(0); // client version
- msg->writeString(loginData->username);
- msg->writeString(loginData->password);
+ MessageOut msg;
+ msg.writeShort(PAMSG_LOGIN);
+ msg.writeLong(0); // client version
+ msg.writeString(loginData->username);
+ msg.writeString(loginData->password);
network->send(msg);
// Clear the password, avoids auto login when returning to login
@@ -436,22 +438,23 @@ void accountLogin(Network *network, LoginData *loginData)
config.setValue("remember", loginData->remember);
}
-void accountRegister(Network *network, LoginData *loginData)
+void accountRegister(LoginData *loginData)
{
logger->log("Trying to connect to account server...");
logger->log("Username is %s", loginData->username.c_str());
network->connect(loginData->hostname, loginData->port);
network->registerHandler(&loginHandler);
- loginHandler.setCharInfo(&charInfo);
loginHandler.setLoginData(loginData);
+ charServerHandler.setLoginData(loginData);
+ charServerHandler.setCharInfo(&charInfo);
// Send login infos
- MessageOut *msg = new MessageOut();
- msg->writeShort(PAMSG_REGISTER);
- msg->writeLong(0); // client version
- msg->writeString(loginData->username);
- msg->writeString(loginData->password);
- msg->writeString(loginData->email);
+ MessageOut msg;
+ msg.writeShort(PAMSG_REGISTER);
+ msg.writeLong(0); // client version
+ msg.writeString(loginData->username);
+ msg.writeString(loginData->password);
+ msg.writeString(loginData->email);
network->send(msg);
}
@@ -544,7 +547,7 @@ int main(int argc, char *argv[])
{
logger->error("An error occurred while initializing ENet.");
}
- Network *network = new Network();
+ network = new Network();
SDL_Event event;
@@ -678,11 +681,11 @@ int main(int argc, char *argv[])
break;
case ACCOUNT_STATE:
- accountLogin(network, &loginData);
+ accountLogin(&loginData);
break;
case REGISTER_ACCOUNT_STATE:
- accountRegister(network, &loginData);
+ accountRegister(&loginData);
break;
default:
diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp
index be636d94..3b5fc87d 100644
--- a/src/net/buysellhandler.cpp
+++ b/src/net/buysellhandler.cpp
@@ -72,7 +72,7 @@ void BuySellHandler::handleMessage(MessageIn *msg)
msg->readShort(); // length
n_items = (msg->getLength() - 4) / 11;
buyDialog->reset();
- buyDialog->setMoney(player_node->mGp);
+ buyDialog->setMoney(player_node->mMoney);
buyDialog->setVisible(true);
for (int k = 0; k < n_items; k++)
diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp
index 36a17acf..e41ca0f3 100644
--- a/src/net/charserverhandler.cpp
+++ b/src/net/charserverhandler.cpp
@@ -38,14 +38,9 @@
CharServerHandler::CharServerHandler()
{
static const Uint16 _messages[] = {
- 0x006b,
- 0x006c,
- 0x006d,
- 0x006e,
- 0x006f,
- 0x0070,
- 0x0071,
- 0x0081,
+ APMSG_CHAR_CREATE_RESPONSE,
+ APMSG_CHAR_DELETE_RESPONSE,
+ APMSG_CHAR_INFO,
0
};
handledMessages = _messages;
@@ -56,145 +51,114 @@ void CharServerHandler::handleMessage(MessageIn *msg)
int slot;
LocalPlayer *tempPlayer;
- logger->log("CharServerHandler: Packet ID: %x, Length: %d",
- msg->getId(), msg->getLength());
switch (msg->getId())
{
- case 0x006b:
- // Derive number of characters from message length
- n_character = (msg->getLength() - 24) / 106;
-
- for (int i = 0; i < n_character; i++)
+ case APMSG_CHAR_CREATE_RESPONSE:
+ int errMsg = msg->readByte();
+ // Character creation successful
+ if (errMsg == ERRMSG_OK)
{
- tempPlayer = readPlayerData(msg, slot);
- mCharInfo->select(slot);
- mCharInfo->setEntry(tempPlayer);
- logger->log("CharServer: Player: %s (%d)",
- tempPlayer->getName().c_str(), slot);
}
-
- state = CHAR_SELECT_STATE;
+ // Character creation failed
+ else
+ {
+ std::string message = "";
+ switch (errMsg)
+ {
+ case ERRMSG_NO_LOGIN:
+ message = "Not logged in";
+ break;
+ case CREATE_TOO_MUCH_CHARACTERS:
+ message = "No empty slot";
+ break;
+ case ERRMSG_INVALID_ARGUMENT:
+ message = "Invalid name";
+ break;
+ case CREATE_EXISTS_NAME:
+ message = "Character's name already exists";
+ break;
+ case CREATE_INVALID_HAIRSTYLE:
+ message = "Invalid hairstyle";
+ break;
+ case CREATE_INVALID_HAIRCOLOR:
+ message = "Invalid hair color";
+ break;
+ case CREATE_INVALID_GENDER:
+ message = "Invalid gender";
+ break;
+ case CREATE_RAW_STATS_TOO_HIGH:
+ message = "Character's stats are too high";
+ break;
+ case CREATE_RAW_STATS_TOO_LOW:
+ message = "Character's stats are too low";
+ break;
+ case CREATE_RAW_STATS_INVALID_DIFF:
+ message = "Character's stats difference is too high";
+ break;
+ case CREATE_RAW_STATS_EQUAL_TO_ZERO:
+ message = "One stat is zero";
+ break;
+ default:
+ message = "Unknown error";
+ break;
+ }
+ new OkDialog("Error", message);
+ }
break;
-
- case 0x006c:
- switch (msg->readByte()) {
- case 0:
- errorMessage = "Access denied";
- break;
- case 1:
- errorMessage = "Cannot use this ID";
- break;
- default:
- errorMessage = "Unknown failure to select character";
- break;
+ case APMSG_CHAR_DELETE_RESPONSE:
+ {
+ int errMsg = msg->readByte();
+ // Character deletion successful
+ if (errMsg == ERRMSG_OK)
+ {
+ delete mCharInfo->getEntry();
+ mCharInfo->setEntry(0);
+ mCharInfo->unlock();
+ n_character--;
+ new OkDialog("Info", "Player deleted");
}
- mCharInfo->unlock();
+ // Character deletion failed
+ else
+ {
+ std::string message = "";
+ switch (errMsg)
+ {
+ case ERRMSG_NO_LOGIN:
+ message = "Not logged in";
+ break;
+ case ERRMSG_INVALID_ARGUMENT:
+ message = "Selection out of range";
+ break;
+ default:
+ message = "Unknown error";
+ }
+ mCharInfo->unlock();
+ new OkDialog("Error", message);
+ }
+ }
break;
-
- case 0x006d:
+ case APMSG_CHAR_INFO:
tempPlayer = readPlayerData(msg, slot);
mCharInfo->unlock();
mCharInfo->select(slot);
mCharInfo->setEntry(tempPlayer);
n_character++;
break;
-
- case 0x006e:
- new OkDialog("Error", "Failed to create character");
- break;
-
- case 0x006f:
- delete mCharInfo->getEntry();
- mCharInfo->setEntry(0);
- mCharInfo->unlock();
- n_character--;
- new OkDialog("Info", "Player deleted");
- break;
-
- case 0x0070:
- mCharInfo->unlock();
- new OkDialog("Error", "Failed to delete character.");
- break;
-
- case 0x0071:
- player_node = mCharInfo->getEntry();
- map_path = msg->readString(16);
- mLoginData->hostname = iptostring(msg->readLong());
- mLoginData->port = msg->readShort();
- mCharInfo->unlock();
- mCharInfo->select(0);
- // Clear unselected players infos
- do
- {
- LocalPlayer *tmp = mCharInfo->getEntry();
- if (tmp != player_node)
- delete tmp;
- mCharInfo->next();
- } while (mCharInfo->getPos());
-
- state = CONNECTING_STATE;
- break;
-
- case 0x0081:
- switch (msg->readByte()) {
- case 1:
- errorMessage = "Map server offline";
- break;
- case 3:
- errorMessage = "Speed hack detected";
- break;
- case 8:
- errorMessage = "Duplicated login";
- break;
- default:
- errorMessage = "Unkown error with 0x0081";
- break;
- }
- mCharInfo->unlock();
- state = ERROR_STATE;
- break;
}
}
LocalPlayer* CharServerHandler::readPlayerData(MessageIn *msg, int &slot)
{
LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL);
- tempPlayer->mCharId = msg->readLong();
- tempPlayer->mTotalWeight = 0;
- tempPlayer->mMaxWeight = 0;
- tempPlayer->mLastAttackTime = 0;
- tempPlayer->mXp = msg->readLong();
- tempPlayer->mGp = msg->readLong();
- tempPlayer->mJobXp = msg->readLong();
- tempPlayer->mJobLevel = msg->readLong();
- msg->readLong(); // option
- msg->readLong(); // karma
- msg->readLong(); // manner
- tempPlayer->mHp = msg->readShort();
- tempPlayer->mMaxHp = msg->readShort();
- tempPlayer->mMp = msg->readShort();
- tempPlayer->mMaxMp = msg->readShort();
- msg->readShort(); // speed
- msg->readShort(); // class
- tempPlayer->setHairStyle(msg->readShort());
- Uint16 weapon = msg->readShort();
- if (weapon == 11)
- weapon = 2;
- tempPlayer->setWeapon(weapon);
- tempPlayer->mLevel = msg->readShort();
- msg->readShort(); // skill point
- tempPlayer->setVisibleEquipment(3, msg->readShort()); // head bottom
- msg->readShort(); // shield
- tempPlayer->setVisibleEquipment(4, msg->readShort()); // head option top
- tempPlayer->setVisibleEquipment(5, msg->readShort()); // head option mid
- tempPlayer->setHairColor(msg->readShort());
- msg->readShort(); // unknown
- tempPlayer->setName(msg->readString(24));
+ slot = msg->readByte(); // character slot
+ tempPlayer->mName = msg->readString();
+ tempPlayer->mSex = msg->readByte();
+ tempPlayer->setHairStyle(msg->readByte());
+ tempPlayer->setHairColor(msg->readByte());
+ tempPlayer->mLevel = msg->readByte();
+ tempPlayer->mMoney = msg->readShort();
for (int i = 0; i < 6; i++) {
tempPlayer->mAttr[i] = msg->readByte();
}
- slot = msg->readByte(); // character slot
- msg->readByte(); // unknown
-
return tempPlayer;
}
diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp
index 324c33cd..27d8eed5 100644
--- a/src/net/loginhandler.cpp
+++ b/src/net/loginhandler.cpp
@@ -27,7 +27,6 @@
#include "network.h"
#include "protocol.h"
-#include "../localplayer.h"
#include "../log.h"
#include "../logindata.h"
#include "../main.h"
@@ -52,21 +51,6 @@ void LoginHandler::handleMessage(MessageIn *msg)
// Successful login
if (errMsg == ERRMSG_OK)
{
- unsigned char charNumber = msg->readByte();
- printf("Account has %i characters:\n", charNumber);
- for (unsigned int i = 0; i < charNumber; i++) {
- // Create a temp empty player to show up in character
- // selection dialog
- LocalPlayer *temp = new LocalPlayer(0, 0, 0);
- temp->setName(msg->readString());
- temp->setSex(msg->readByte());
- temp->setHairStyle(msg->readByte());
- temp->setHairColor(msg->readByte());
- temp->mLevel = msg->readByte();
- temp->mGp = msg->readShort();
- mCharInfo->select(i);
- mCharInfo->setEntry(temp);
- }
state = CHAR_SELECT_STATE;
}
// Login failed
@@ -102,7 +86,8 @@ void LoginHandler::handleMessage(MessageIn *msg)
state = ACCOUNT_STATE;
}
// Registration failed
- else {
+ else
+ {
switch (errMsg) {
case REGISTER_INVALID_VERSION:
errorMessage = "Client has an insufficient version number to login.";
diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h
index 7d5d6f75..1b15b736 100644
--- a/src/net/loginhandler.h
+++ b/src/net/loginhandler.h
@@ -38,13 +38,10 @@ class LoginHandler : public MessageHandler
void handleMessage(MessageIn *msg);
- void setCharInfo(LockedArray<LocalPlayer*> *charInfo) { mCharInfo = charInfo; };
-
void setLoginData(LoginData *loginData) { mLoginData = loginData; };
protected:
LoginData *mLoginData;
- LockedArray<LocalPlayer*> *mCharInfo;
};
#endif
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 5e8a5d72..7f5fadcb 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -104,13 +104,13 @@ MessageOut::writeString(const std::string &string, int length)
}
char*
-MessageOut::getData()
+MessageOut::getData() const
{
return mData;
}
unsigned int
-MessageOut::getDataSize()
+MessageOut::getDataSize() const
{
return mDataSize;
}
diff --git a/src/net/messageout.h b/src/net/messageout.h
index 8431d887..22754f60 100644
--- a/src/net/messageout.h
+++ b/src/net/messageout.h
@@ -55,12 +55,12 @@ class MessageOut
/**
* Returns the content of the message.
*/
- char *getData();
+ char *getData() const;
/**
* Returns the length of the data.
*/
- unsigned int getDataSize();
+ unsigned int getDataSize() const;
private:
/**
diff --git a/src/net/network.cpp b/src/net/network.cpp
index dcfbc8f1..39a632a2 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -29,6 +29,8 @@
#include "../log.h"
+Network *network;
+
Network::Network():
mClient(0), mServer(0),
mAddress(), mPort(0),
@@ -216,7 +218,7 @@ void Network::flush()
}
}
-void Network::send(MessageOut *msg)
+void Network::send(const MessageOut &msg)
{
if (mState == IDLE || mState == NET_ERROR)
{
@@ -225,8 +227,8 @@ void Network::send(MessageOut *msg)
return;
}
- ENetPacket *packet = enet_packet_create(msg->getData(),
- msg->getDataSize(),
+ ENetPacket *packet = enet_packet_create(msg.getData(),
+ msg.getDataSize(),
ENET_PACKET_FLAG_RELIABLE);
mOutgoingPackets.push(packet);
}
diff --git a/src/net/network.h b/src/net/network.h
index 50ee9af7..f91c926b 100644
--- a/src/net/network.h
+++ b/src/net/network.h
@@ -59,7 +59,7 @@ class Network
void dispatchMessages();
void flush();
- void send(MessageOut *msg);
+ void send(const MessageOut &msg);
enum State {
IDLE,
@@ -96,4 +96,7 @@ class Network
/** Convert an address from int format to string */
char *iptostring(int address);
+// TODO: remove this global, just a temp solution.
+extern Network *network;
+
#endif
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index c70eada3..d8ff81f4 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -177,7 +177,7 @@ void PlayerHandler::handleMessage(MessageIn *msg)
player_node->mJobXp = msg->readLong();
break;
case 0x0014:
- player_node->mGp = msg->readLong();
+ player_node->mMoney = msg->readLong();
break;
case 0x0016:
player_node->mXpForNextLevel = msg->readLong();
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 6db3762e..528b2fd5 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -128,7 +128,7 @@ enum {
APMSG_CHAR_CREATE_RESPONSE = 0x0021, // B error
PAMSG_CHAR_DELETE = 0x0022, // B index
APMSG_CHAR_DELETE_RESPONSE = 0x0023, // B error
- PAMSG_CHAR_LIST = 0x0024, // -
+ APMSG_CHAR_INFO = 0x0024, // B index, S name, B gender, B hair style, B hair color, B level, W money, W*6 stats, S mapname, W*2 position
APMSG_CHAR_LIST_RESPONSE = 0x0025, // B number, { B index, S name, B gender, B hair style, B hair color, B level, W money, W*6 stats, S mapname, W*2 position }*
PAMSG_CHAR_SELECT = 0x0026, // B index
APMSG_CHAR_SELECT_RESPONSE = 0x0027, // B error, S mapname, W*2 position
@@ -207,6 +207,18 @@ enum {
REGISTER_EXISTS_EMAIL // there already is an account with this email address
};
+// Character creation specific return values
+enum {
+ CREATE_INVALID_HAIRSTYLE = 0x40,
+ CREATE_INVALID_HAIRCOLOR,
+ CREATE_INVALID_GENDER,
+ CREATE_RAW_STATS_TOO_HIGH,
+ CREATE_RAW_STATS_TOO_LOW,
+ CREATE_RAW_STATS_INVALID_DIFF,
+ CREATE_RAW_STATS_EQUAL_TO_ZERO,
+ CREATE_EXISTS_NAME,
+ CREATE_TOO_MUCH_CHARACTERS
+};
/** Encodes coords and direction in 3 bytes data */
void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction);