summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/char_server.cpp125
-rw-r--r--src/gui/char_server.h68
-rw-r--r--src/main.cpp41
-rw-r--r--src/net/loginhandler.cpp18
-rw-r--r--src/net/loginhandler.h8
5 files changed, 22 insertions, 238 deletions
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
deleted file mode 100644
index ad0df223..00000000
--- a/src/gui/char_server.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * The Mana World
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World 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 2 of the License, or
- * any later version.
- *
- * The Mana World 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 The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#include "char_server.h"
-
-#include "button.h"
-#include "listbox.h"
-#include "scrollarea.h"
-
-#include "../logindata.h"
-#include "../main.h"
-#include "../serverinfo.h"
-
-#include "../net/network.h" // TODO this is just for iptostring, move that?
-
-#include "../utils/tostring.h"
-
-extern SERVER_INFO **server_info;
-
-/**
- * The list model for the server list.
- */
-class ServerListModel : public gcn::ListModel {
- public:
- virtual ~ServerListModel() {};
-
- int getNumberOfElements();
- std::string getElementAt(int i);
-};
-
-ServerSelectDialog::ServerSelectDialog(LoginData *loginData):
- Window("Select Server"), mLoginData(loginData)
-{
- mServerListModel = new ServerListModel();
- mServerList = new ListBox(mServerListModel);
- ScrollArea *mScrollArea = new ScrollArea(mServerList);
- mOkButton = new Button("OK", "ok", this);
- Button *mCancelButton = new Button("Cancel", "cancel", this);
-
- setContentSize(200, 100);
-
- mCancelButton->setPosition(
- 200 - mCancelButton->getWidth() - 5,
- 100 - mCancelButton->getHeight() - 5);
- mOkButton->setPosition(
- mCancelButton->getX() - mOkButton->getWidth() - 5,
- 100 - mOkButton->getHeight() - 5);
- mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mScrollArea->setDimension(gcn::Rectangle(
- 5, 5, 200 - 2 * 5,
- 100 - 3 * 5 - mCancelButton->getHeight() -
- mScrollArea->getBorderSize()));
-
- mServerList->setEventId("ok");
-
- //mServerList->addActionListener(this);
-
- add(mScrollArea);
- add(mOkButton);
- add(mCancelButton);
-
- if (n_server == 0) {
- // Disable Ok button
- mOkButton->setEnabled(false);
- } else {
- // Select first server
- mServerList->setSelected(1);
- }
-
- mOkButton->requestFocus();
- setLocationRelativeTo(getParent());
-}
-
-ServerSelectDialog::~ServerSelectDialog()
-{
- delete mServerListModel;
-}
-
-void
-ServerSelectDialog::action(const std::string& eventId)
-{
- if (eventId == "ok") {
- mOkButton->setEnabled(false);
- const SERVER_INFO *si = server_info[mServerList->getSelected()];
- mLoginData->hostname = iptostring(si->address);
- mLoginData->port = si->port;
- state = CHAR_CONNECT_STATE;
- }
- else if (eventId == "cancel") {
- state = LOGIN_STATE;
- }
-}
-
-int
-ServerListModel::getNumberOfElements()
-{
- return n_server;
-}
-
-std::string
-ServerListModel::getElementAt(int i)
-{
- const SERVER_INFO *si = server_info[i];
- return si->name + " (" + toString(si->online_users) + ")";
-}
diff --git a/src/gui/char_server.h b/src/gui/char_server.h
deleted file mode 100644
index 85ae2408..00000000
--- a/src/gui/char_server.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * The Mana World
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World 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 2 of the License, or
- * any later version.
- *
- * The Mana World 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 The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#ifndef _CHAR_SEL_SERVER_H
-#define _CHAR_SEL_SERVER_H
-
-#include <guichan/actionlistener.hpp>
-#include <guichan/listmodel.hpp>
-
-#include "window.h"
-
-#include "../guichanfwd.h"
-
-class LoginData;
-class ServerListModel;
-
-/**
- * The server select dialog.
- *
- * \ingroup Interface
- */
-class ServerSelectDialog : public Window, public gcn::ActionListener {
- public:
- /**
- * Constructor
- *
- * @see Window::Window
- */
- ServerSelectDialog(LoginData *loginData);
-
- /**
- * Destructor.
- */
- ~ServerSelectDialog();
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const std::string& eventId);
-
- private:
- LoginData *mLoginData;
- ServerListModel *mServerListModel;
- gcn::ListBox *mServerList;
- gcn::Button *mOkButton;
-};
-
-#endif
diff --git a/src/main.cpp b/src/main.cpp
index ca70b0dc..deca661c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -56,7 +56,6 @@
#endif
#include "sound.h"
-#include "gui/char_server.h"
#include "gui/char_select.h"
#include "gui/connection.h"
#include "gui/gui.h"
@@ -81,16 +80,12 @@
#include "utils/tostring.h"
// Account infos
-char n_server, n_character;
+char n_character;
std::vector<Spriteset *> hairset;
Spriteset *playerset[2];
Graphics *graphics;
-// TODO Anyone knows a good location for this? Or a way to make it non-global?
-class SERVER_INFO;
-SERVER_INFO **server_info;
-
unsigned char state;
std::string errorMessage;
std::string homeDir;
@@ -429,6 +424,7 @@ void accountLogin(Network *network, LoginData *loginData)
logger->log("Username is %s", loginData->username.c_str());
network->connect(loginData->hostname, loginData->port);
network->registerHandler(&loginHandler);
+ loginHandler.setCharInfo(&charInfo);
loginHandler.setLoginData(loginData);
// Send login infos
@@ -451,24 +447,6 @@ void accountLogin(Network *network, LoginData *loginData)
config.setValue("remember", loginData->remember);
}
-void charLogin(Network *network, LoginData *loginData)
-{
- logger->log("Trying to connect to char server...");
- network->connect(loginData->hostname, loginData->port);
- network->registerHandler(&charServerHandler);
- charServerHandler.setCharInfo(&charInfo);
- charServerHandler.setLoginData(loginData);
-
- // Send login infos
- MessageOut outMsg;
- outMsg.writeShort(0x0065);
- outMsg.writeLong(loginData->account_ID);
- outMsg.writeLong(loginData->session_ID1);
- outMsg.writeLong(loginData->session_ID2);
- outMsg.writeShort(0); // unknown
- outMsg.writeByte(loginData->sex);
-}
-
void mapLogin(Network *network, LoginData *loginData)
{
MessageOut outMsg;
@@ -617,7 +595,6 @@ int main(int argc, char *argv[])
// Those states don't cause a network disconnect
case ACCOUNT_STATE:
- case CHAR_CONNECT_STATE:
case CONNECTING_STATE:
break;
@@ -649,14 +626,6 @@ int main(int argc, char *argv[])
currentDialog = new RegisterDialog(&loginData);
break;
- case CHAR_SERVER_STATE:
- logger->log("State: CHAR_SERVER");
- currentDialog = new ServerSelectDialog(&loginData);
- if (options.chooseDefault) {
- ((ServerSelectDialog*)currentDialog)->action("ok");
- }
- break;
-
case CHAR_SELECT_STATE:
logger->log("State: CHAR_SELECT");
currentDialog = new CharSelectDialog(network, &charInfo,
@@ -700,11 +669,6 @@ int main(int argc, char *argv[])
currentDialog = new ConnectionDialog();
break;
- case CHAR_CONNECT_STATE:
- printf("Char: %i\n", loginData.sex);
- charLogin(network, &loginData);
- break;
-
case ACCOUNT_STATE:
printf("Account: %i\n", loginData.sex);
accountLogin(network, &loginData);
@@ -717,7 +681,6 @@ int main(int argc, char *argv[])
}
}
- network->disconnect();
delete network;
enet_deinitialize();
diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp
index d65f7001..5b8fbd1f 100644
--- a/src/net/loginhandler.cpp
+++ b/src/net/loginhandler.cpp
@@ -27,12 +27,10 @@
#include "network.h"
#include "protocol.h"
+#include "../localplayer.h"
#include "../log.h"
#include "../logindata.h"
#include "../main.h"
-#include "../serverinfo.h"
-
-extern SERVER_INFO **server_info;
LoginHandler::LoginHandler()
{
@@ -56,9 +54,19 @@ void LoginHandler::handleMessage(MessageIn *msg)
charNumber = msg->readByte();
printf("Account has %i characters:\n", charNumber);
for (unsigned int i = 0; i < charNumber; i++) {
- printf("%i) %s\n", i, msg->readString().c_str());
+ // 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_SERVER_STATE;
+ state = CHAR_SELECT_STATE;
}
// Login failed
else
diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h
index 52014559..7d5d6f75 100644
--- a/src/net/loginhandler.h
+++ b/src/net/loginhandler.h
@@ -26,7 +26,10 @@
#include "messagehandler.h"
-struct LoginData;
+#include "../lockedarray.h"
+
+class LocalPlayer;
+class LoginData;
class LoginHandler : public MessageHandler
{
@@ -35,10 +38,13 @@ 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