summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/buy.cpp10
-rw-r--r--src/gui/buysell.cpp8
-rw-r--r--src/gui/char_select.cpp213
-rw-r--r--src/gui/char_server.cpp123
-rw-r--r--src/gui/chargedialog.cpp11
-rw-r--r--src/gui/chat.cpp10
-rw-r--r--src/gui/inventorywindow.cpp3
-rw-r--r--src/gui/login.cpp246
-rw-r--r--src/gui/npc.cpp38
-rw-r--r--src/gui/npc.h17
-rw-r--r--src/gui/npc_text.cpp18
-rw-r--r--src/gui/npc_text.h12
-rw-r--r--src/gui/popupmenu.cpp46
-rw-r--r--src/gui/requesttrade.cpp16
-rw-r--r--src/gui/requesttrade.h8
-rw-r--r--src/gui/sell.cpp10
-rw-r--r--src/gui/skill.cpp9
-rw-r--r--src/gui/stats.cpp58
-rw-r--r--src/gui/status.cpp28
-rw-r--r--src/gui/status.h8
-rw-r--r--src/gui/trade.cpp41
21 files changed, 522 insertions, 411 deletions
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 926f478e..3a32824a 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -235,11 +235,11 @@ void BuyDialog::action(const std::string& eventId)
// there a better way to ensure this fails in an _obivous_ way in C++?
else if (eventId == "buy" && (m_amountItems > 0 &&
m_amountItems <= m_maxItems)) {
- WFIFOW(0) = net_w_value(0x00c8);
- WFIFOW(2) = net_w_value(8);
- WFIFOW(4) = net_w_value(m_amountItems);
- WFIFOW(6) = net_w_value(shopInventory[selectedItem].id);
- WFIFOSET(8);
+ writeWord(0, 0x00c8);
+ writeWord(2, 8);
+ writeWord(4, m_amountItems);
+ writeWord(6, shopInventory[selectedItem].id);
+ writeSet(8);
// update money !
m_money -= m_amountItems * shopInventory[selectedItem].price;
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index c81744dc..6a56e67f 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -77,10 +77,10 @@ void BuySellDialog::action(const std::string& eventId)
current_npc = 0;
}
if (actionId > -1) {
- WFIFOW(0) = net_w_value(0x00c5);
- WFIFOL(2) = net_l_value(current_npc);
- WFIFOB(6) = net_b_value(actionId);
- WFIFOSET(7);
+ writeWord(0, 0x00c5);
+ writeLong(2, current_npc);
+ writeByte(6, actionId);
+ writeSet(7);
}
setVisible(false);
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 6389f5b0..071708b8 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -33,13 +33,11 @@
#include "playerbox.h"
#include "textfield.h"
#include "windowcontainer.h"
-
#include "../being.h"
#include "../game.h"
#include "../log.h"
#include "../main.h"
#include "../playerinfo.h"
-
#include "../net/network.h"
#include "../net/protocol.h"
@@ -134,7 +132,6 @@ void CharSelectDialog::action(const std::string& eventId)
if (eventId == "ok" && n_character > 0) {
// Start game
serverCharSelect();
- close_session();
}
else if (eventId == "cancel") {
state = EXIT;
@@ -192,90 +189,99 @@ void CharSelectDialog::setPlayerInfo(PLAYER_INFO *pi)
void CharSelectDialog::serverCharDelete()
{
// Request character deletion
- WFIFOW(0) = net_w_value(0x0068);
- WFIFOL(2) = net_l_value(char_info->id);
- WFIFOSET(46);
+ writeWord(0, 0x0068);
+ writeLong(2, char_info[0]->id);
+ writeSet(46);
+
+ MessageIn msg = get_next_message();
- while ((in_size < 2) || (out_size > 0)) flush();
- if (RFIFOW(0) == 0x006f) {
- RFIFOSKIP(2);
+ if (msg.getId() == 0x006f)
+ {
+ skip(msg.getLength());
+ delete char_info[0];
free(char_info);
n_character = 0;
setPlayerInfo(NULL);
new OkDialog(this, "Info", "Player deleted");
}
- else if (RFIFOW(0) == 0x0070) {
+ else if (msg.getId() == 0x0070)
+ {
new OkDialog(this, "Error", "Failed to delete character.");
- RFIFOSKIP(3);
+ skip(msg.getLength());
}
else {
new OkDialog(this, "Error", "Unknown");
+ skip(msg.getLength());
}
}
void CharSelectDialog::serverCharSelect()
{
// Request character selection
- WFIFOW(0) = net_w_value(0x0066);
- WFIFOB(2) = net_b_value(0);
- WFIFOSET(3);
+ writeWord(0, 0x0066);
+ writeByte(2, 0);
+ writeSet(3);
- while ((in_size < 3) || (out_size > 0)) {
- flush();
- }
+ MessageIn msg = get_next_message();
- logger->log("CharSelect: Packet ID: %x, Length: %d, Packet_in_size %d",
- RFIFOW(0),
- get_length(RFIFOW(0)),
- RFIFOW(2));
- logger->log("CharSelect: In_size: %d", in_size);
+ logger->log("CharSelect: Packet ID: %x, Length: %d, in_size: %d",
+ msg.getId(), msg.getLength(), in_size);
- if (RFIFOW(0) == 0x0071) {
- while (in_size < 28) {
- flush();
- }
- char_ID = RFIFOL(2);
-
- char mapName[17];
- mapName[17] = 0;
- strncpy(mapName, RFIFOP(6), 16);
-
- memset(map_path, '\0', 480);
- strcat(map_path, "maps/");
- strncat(map_path, mapName, 479 - strlen(map_path));
- map_address = RFIFOL(22);
- map_port = RFIFOW(26);
+ if (msg.getId() == 0x0071)
+ {
+ char_ID = msg.readLong();
+ std::string mapPath = "maps/" + msg.readString(16);
+ strcpy(map_path, mapPath.c_str());
+ map_address = msg.readLong();
+ map_port = msg.readShort();
+ player_info = char_info[0];
state = GAME;
- logger->log("CharSelect: Map: %s", mapName);
- logger->log("CharSelect: Server: %s:%d", iptostring(map_address), map_port);
- RFIFOSKIP(28);
+ logger->log("CharSelect: Map: %s", map_path);
+ logger->log("CharSelect: Server: %s:%d", iptostring(map_address),
+ map_port);
close_session();
}
- else if (RFIFOW(0) == 0x006c) {
- switch (RFIFOB(2)) {
+ else if (msg.getId() == 0x006c)
+ {
+ switch (msg.readByte()) {
case 0:
new OkDialog(this, "Error", "Access denied");
break;
case 1:
new OkDialog(this, "Error", "Cannot use this ID");
break;
+ default:
+ new OkDialog(this, "Error",
+ "Unknown failure to select character");
+ break;
}
- RFIFOSKIP(3);
+ skip(msg.getLength());
}
- else if (RFIFOW(0) == 0x0081) {
- new OkDialog(this, "Error",
- "Map server is down, please try again later");
+ else if (msg.getId() == 0x0081)
+ {
+ switch (msg.readByte()) {
+ case 3:
+ new OkDialog(this, "Error", "Speed hack detected");
+ break;
+ case 8:
+ new OkDialog(this, "Error", "Duplicated login");
+ break;
+ default:
+ new OkDialog(this, "Error", "Unkown error with 0x0081");
+ break;
+ }
close_session();
state = LOGIN;
}
+
// Todo: add other packets
}
void CharSelectDialog::logic()
{
if (n_character > 0) {
- setPlayerInfo(char_info);
+ setPlayerInfo(char_info[0]);
}
}
@@ -391,63 +397,84 @@ void CharCreateDialog::action(const std::string& eventId)
playerBox->hairStyle %= NR_HAIR_STYLES;
}
-std::string CharCreateDialog::getName() {
+std::string CharCreateDialog::getName()
+{
return nameField->getText();
}
void CharCreateDialog::serverCharCreate()
{
- n_character = 1;
-
- WFIFOW(0) = net_w_value(0x0067);
- strcpy(WFIFOP(2), getName().c_str());
- WFIFOB(26) = net_b_value(5);
- WFIFOB(27) = net_b_value(5);
- WFIFOB(28) = net_b_value(5);
- WFIFOB(29) = net_b_value(5);
- WFIFOB(30) = net_b_value(5);
- WFIFOB(31) = net_b_value(5);
- WFIFOB(32) = net_b_value(0);
- WFIFOW(33) = net_w_value(playerBox->hairColor + 1);
- WFIFOW(35) = net_w_value(playerBox->hairStyle + 1);
- WFIFOSET(37);
-
- while ((in_size < 3) || (out_size > 0)) flush();
- if (RFIFOW(0) == 0x006d) {
- while (in_size < 108) flush();
- char_info = (PLAYER_INFO *)malloc(sizeof(PLAYER_INFO));
- char_info->id = RFIFOL(2);//account_ID;
- memset(char_info->name, '\0', 24);
- strcpy(char_info[0].name, RFIFOP(2 + 74));
- char_info->hp = RFIFOW(2 + 42);
- char_info->max_hp = RFIFOW(2 + 44);
- char_info->sp = RFIFOW(2 + 46);
- char_info->max_sp = RFIFOW(2 + 48);
- char_info->job_lv = RFIFOL(2 + 16);
- char_info->job_xp = RFIFOL(2 + 12);
- char_info->lv = RFIFOW(2 + 58);
- char_info->xp = RFIFOL(2 + 4);
- char_info->gp = RFIFOL(2 + 8);
- char_info->STR = RFIFOB(2 + 98);
- char_info->AGI = RFIFOB(2 + 99);
- char_info->VIT = RFIFOB(2 + 100);
- char_info->INT = RFIFOB(2 + 101);
- char_info->DEX = RFIFOB(2 + 102);
- char_info->LUK = RFIFOB(2 + 103);
- char_info->hair_style = RFIFOW(2 + 54);
- char_info->hair_color = RFIFOW(2 + 70);
- char_info->weapon = RFIFOW(2 + 56);
- RFIFOSKIP(108);
- //n_character++;
- } else if (RFIFOW(0) == 0x006e) {
+ writeWord(0, 0x0067);
+ strcpy(writePointer(2), getName().c_str());
+ writeByte(26, 5);
+ writeByte(27, 5);
+ writeByte(28, 5);
+ writeByte(29, 5);
+ writeByte(30, 5);
+ writeByte(31, 5);
+ writeByte(32, 0);
+ writeWord(33, playerBox->hairColor + 1);
+ writeWord(35, playerBox->hairStyle + 1);
+ writeSet(37);
+
+ MessageIn msg = get_next_message();
+
+ if (msg.getId() == 0x006d)
+ {
+ char_info = (PLAYER_INFO**)malloc(sizeof(PLAYER_INFO*));
+ char_info[0] = new PLAYER_INFO;
+
+ char_info[0]->id = msg.readLong();
+ char_info[0]->xp = msg.readLong();
+ char_info[0]->gp = msg.readLong();
+ char_info[0]->job_xp = msg.readLong();
+ char_info[0]->job_lv = msg.readLong();
+ msg.skip(8); // unknown
+ msg.readLong(); // option
+ msg.readLong(); // karma
+ msg.readLong(); // manner
+ msg.skip(2); // unknown
+ char_info[0]->hp = msg.readShort();
+ char_info[0]->max_hp = msg.readShort();
+ char_info[0]->sp = msg.readShort();
+ char_info[0]->max_sp = msg.readShort();
+ msg.readShort(); // speed
+ msg.readShort(); // class
+ char_info[0]->hair_style = msg.readShort();
+ char_info[0]->weapon = msg.readShort();
+ char_info[0]->lv = msg.readShort();
+ msg.readShort(); // skill point
+ msg.readShort(); // head bottom
+ msg.readShort(); // shield
+ msg.readShort(); // head option top
+ msg.readShort(); // head option mid
+ char_info[0]->hair_color = msg.readShort();
+ msg.readShort(); // unknown
+ char_info[0]->name = msg.readString(24);
+ char_info[0]->STR = msg.readByte();
+ char_info[0]->AGI = msg.readByte();
+ char_info[0]->VIT = msg.readByte();
+ char_info[0]->INT = msg.readByte();
+ char_info[0]->DEX = msg.readByte();
+ char_info[0]->LUK = msg.readByte();
+ msg.readByte(); // character number
+ msg.readByte(); // unknown
+
+ n_character = 1;
+ }
+ else if (msg.getId() == 0x006e)
+ {
new OkDialog(this, "Error", "Failed to create character");
- RFIFOSKIP(3);
n_character = 0;
- } else {
+ }
+ else
+ {
new OkDialog(this, "Error", "Unknown error");
n_character = 0;
}
+ skip(msg.getLength());
+
// Remove window when succeeded
if (n_character == 1) {
windowContainer->scheduleDelete(this);
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index b4b01350..d3abfe7c 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -23,6 +23,7 @@
#include "char_server.h"
+#include <sstream>
#include <SDL.h>
#include "button.h"
@@ -37,6 +38,8 @@
#include "../net/network.h"
+extern SERVER_INFO **server_info;
+
char server[30];
@@ -107,15 +110,16 @@ void ServerSelectDialog::action(const std::string& eventId)
}
-int ServerListModel::getNumberOfElements() {
+int ServerListModel::getNumberOfElements()
+{
return n_server;
}
-std::string ServerListModel::getElementAt(int i) {
- static char buffer[30];
- sprintf(buffer, "%s (%i)", server_info[i].name,
- server_info[i].online_users);
- return buffer;
+std::string ServerListModel::getElementAt(int i)
+{
+ std::stringstream s;
+ s << server_info[i]->name << " (" << server_info[i]->online_users << ")";
+ return s.str();
}
void charServerInputHandler(SDL_KeyboardEvent *keyEvent)
@@ -130,12 +134,12 @@ void server_char_server(int serverIndex)
{
int ret;
state = LOGIN;
- const char *ipstring = iptostring(server_info[serverIndex].address);
+ const char *ipstring = iptostring(server_info[serverIndex]->address);
// Connect to char server
- ret = open_session(ipstring, server_info[serverIndex].port);
+ ret = open_session(ipstring, server_info[serverIndex]->port);
- if (ret == SOCKET_ERROR)
+ if (ret == -1)
{
std::string str = std::string("Unable to connect to char server ") +
std::string(ipstring);
@@ -144,74 +148,93 @@ void server_char_server(int serverIndex)
}
// Send login infos
- WFIFOW(0) = net_w_value(0x0065);
- WFIFOL(2) = net_l_value(account_ID);
- WFIFOL(6) = net_l_value(session_ID1);
- WFIFOL(10) = net_l_value(session_ID2);
- WFIFOW(14) = 0;
- WFIFOB(16) = net_b_value(sex);
- WFIFOSET(17);
-
+ writeWord(0, 0x0065);
+ writeLong(2, account_ID);
+ writeLong(6, session_ID1);
+ writeLong(10, session_ID2);
+ writeWord(14, 0);
+ writeByte(16, sex);
+ writeSet(17);
+
+ // Skipping a mysterious 4 bytes
while ((in_size < 4) || (out_size > 0)) flush();
- RFIFOSKIP(4);
+ skip(4);
- while (in_size < 3) flush();
+ MessageIn msg = get_next_message();
- if (RFIFOW(0) == 0x006b)
+ if (msg.getId() == 0x006b)
{
- while (in_size < RFIFOW(2)) flush();
+ // Skip length word and an additional mysterious 20 bytes
+ msg.skip(2 + 20);
- n_character = (RFIFOW(2) - 24) / 106;
- char_info = (PLAYER_INFO*)malloc(sizeof(PLAYER_INFO) * n_character);
+ // Derive number of characters from message length
+ n_character = (msg.getLength() - 24) / 106;
+ char_info = (PLAYER_INFO**)malloc(sizeof(PLAYER_INFO*) * n_character);
for (int i = 0; i < n_character; i++)
{
- int n = 24 + 106 * i;
- char_info[i].id = RFIFOL(n);
- strcpy(char_info[i].name, RFIFOP(n + 74));
- char_info[i].hp = RFIFOW( n+ 42);
- char_info[i].max_hp = RFIFOW(n + 44);
- char_info[i].xp = RFIFOL(n + 4);
- char_info[i].gp = RFIFOL(n + 8);
- char_info[i].job_xp = RFIFOL(n + 12);
- char_info[i].job_lv = RFIFOL(n + 16);
- char_info[i].sp = RFIFOW(n + 46);
- char_info[i].max_sp = RFIFOW(n + 48);
- char_info[i].lv = RFIFOW(n + 58);
- char_info[i].STR = RFIFOB(n + 98);
- char_info[i].AGI = RFIFOB(n + 99);
- char_info[i].VIT = RFIFOB(n + 100);
- char_info[i].INT = RFIFOB(n + 101);
- char_info[i].DEX = RFIFOB(n + 102);
- char_info[i].LUK = RFIFOB(n + 103);
- char_info[i].hair_style = RFIFOW(n + 54);
- char_info[i].hair_color = RFIFOW(n + 70);
- char_info[i].weapon = RFIFOW(n + 56);
+ char_info[i] = new PLAYER_INFO;
+
+ char_info[i]->id = msg.readLong();
+ char_info[i]->xp = msg.readLong();
+ char_info[i]->gp = msg.readLong();
+ char_info[i]->job_xp = msg.readLong();
+ char_info[i]->job_lv = msg.readLong();
+ msg.skip(8); // unknown
+ msg.readLong(); // option
+ msg.readLong(); // karma
+ msg.readLong(); // manner
+ msg.skip(2); // unknown
+ char_info[i]->hp = msg.readShort();
+ char_info[i]->max_hp = msg.readShort();
+ char_info[i]->sp = msg.readShort();
+ char_info[i]->max_sp = msg.readShort();
+ msg.readShort(); // speed
+ msg.readShort(); // class
+ char_info[i]->hair_style = msg.readShort();
+ char_info[i]->weapon = msg.readShort();
+ char_info[i]->lv = msg.readShort();
+ msg.readShort(); // skill point
+ msg.readShort(); // head bottom
+ msg.readShort(); // shield
+ msg.readShort(); // head option top
+ msg.readShort(); // head option mid
+ char_info[i]->hair_color = msg.readShort();
+ msg.readShort(); // unknown
+ char_info[i]->name = msg.readString(24);
+ char_info[i]->STR = msg.readByte();
+ char_info[i]->AGI = msg.readByte();
+ char_info[i]->VIT = msg.readByte();
+ char_info[i]->INT = msg.readByte();
+ char_info[i]->DEX = msg.readByte();
+ char_info[i]->LUK = msg.readByte();
+ msg.readByte(); // character number
+ msg.readByte(); // unknown
}
state = CHAR_SELECT;
logger->log("CharServer: Player: %s (Packet ID: %x, Length: %d)",
- char_info->name, RFIFOW(0), RFIFOW(2));
-
+ char_info[0]->name.c_str(), msg.getId(), msg.getLength());
- RFIFOSKIP(RFIFOW(2));
+ skip(msg.getLength());
}
- else if (RFIFOW(0) == 0x006c)
+ else if (msg.getId() == 0x006c)
{
std::string errorStr;
- switch (RFIFOB(2)) {
+ switch (msg.readByte()) {
case 0: errorStr = "Access denied"; break;
case 1: errorStr = "Cannot use this ID"; break;
default: errorStr = "Rejected from server"; break;
}
new OkDialog("Error", errorStr);
- RFIFOSKIP(3);
+ skip(msg.getLength());
close_session();
}
else
{
new OkDialog("Error", "Unknown error");
+ skip(msg.getLength());
}
// Todo: add other packets
}
diff --git a/src/gui/chargedialog.cpp b/src/gui/chargedialog.cpp
index 5a475d72..797d5129 100644
--- a/src/gui/chargedialog.cpp
+++ b/src/gui/chargedialog.cpp
@@ -52,12 +52,15 @@ void ChargeDialog::action(const std::string& eventId)
void ChargeDialog::logic()
{
// calculate time since the last attack was made
- char_info->lastAttackTime += .01; // this a hack until someone explains
+ player_info->lastAttackTime += .01; // this a hack until someone explains
// to me how to work the timer
- if(char_info->lastAttackTime > 1){char_info->lastAttackTime=1;}
-
+ if (player_info->lastAttackTime > 1)
+ {
+ player_info->lastAttackTime = 1;
+ }
+
// reset the progress bar to display accurate time since attack
- progBar->setProgress(char_info->lastAttackTime);
+ progBar->setProgress(player_info->lastAttackTime);
Window::logic();
}
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 72de3c83..e6dabaaa 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -169,7 +169,7 @@ void ChatWindow::action(const std::string& eventId)
curHist = history.end();
// Send the message to the server
- chat_send(char_info[0].name, message.c_str());
+ chat_send(player_info->name.c_str(), message.c_str());
// Clear the text from the chat input
chatInput->setText("");
@@ -217,10 +217,10 @@ char *ChatWindow::chat_send(std::string nick, std::string msg)
msg += "\0";
// send processed message
- WFIFOW(0) = net_w_value(packid);
- WFIFOW(2) = net_w_value((unsigned short)(msg.length()+4));
- memcpy(WFIFOP(4), msg.c_str(), msg.length());
- WFIFOSET((int)msg.length()+4);
+ writeWord(0, packid);
+ writeWord(2, (unsigned short)(msg.length() + 4));
+ memcpy(writePointer(4), msg.c_str(), msg.length());
+ writeSet((int)msg.length()+4);
nick = msg = "";
return "";
}
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index b89f19a3..b65979db 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -105,7 +105,8 @@ void InventoryWindow::logic()
// Update weight information
std::stringstream tempstr;
- tempstr << "Total Weight: " << char_info->totalWeight << " - Maximum Weight: " << char_info->maxWeight;
+ tempstr << "Total Weight: " << player_info->totalWeight
+ << " - Maximum Weight: " << player_info->maxWeight;
weightLabel->setCaption(tempstr.str());
weightLabel->adjustSize();
}
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 9913eb25..bc39c15f 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -30,6 +30,10 @@
#include <guichan/widgets/label.hpp>
#include "../main.h"
+#include "../configuration.h"
+#include "../graphics.h"
+#include "../log.h"
+#include "../serverinfo.h"
#include "button.h"
#include "checkbox.h"
@@ -37,13 +41,10 @@
#include "textfield.h"
#include "ok_dialog.h"
-#include "../configuration.h"
-#include "../log.h"
-#include "../serverinfo.h"
-
#include "../net/network.h"
OkDialog *wrongLoginNotice = NULL;
+SERVER_INFO **server_info;
WrongUsernameNoticeListener wrongUsernameNoticeListener;
WrongPasswordNoticeListener wrongPasswordNoticeListener;
@@ -56,11 +57,11 @@ void WrongPasswordNoticeListener::setLoginDialog(
void WrongPasswordNoticeListener::action(const std::string &eventId)
{
- // Reset the password and put the caret ready to retype it.
- mLoginDialog->passField->setText("");
- mLoginDialog->passField->setCaretPosition(0);
- mLoginDialog->passField->requestFocus();
- wrongLoginNotice = NULL;
+ // Reset the password and put the caret ready to retype it.
+ mLoginDialog->passField->setText("");
+ mLoginDialog->passField->setCaretPosition(0);
+ mLoginDialog->passField->requestFocus();
+ wrongLoginNotice = NULL;
}
void WrongUsernameNoticeListener::setLoginDialog(
@@ -174,61 +175,73 @@ LoginDialog::~LoginDialog()
void LoginDialog::action(const std::string& eventId)
{
- if (eventId == "ok") {
+ if (eventId == "ok")
+ {
const std::string user = userField->getText();
logger->log("Network: Username is %s", user.c_str());
// Store config settings
config.setValue("remember", keepCheck->isMarked());
- if (keepCheck->isMarked()) {
+
+ if (keepCheck->isMarked())
+ {
config.setValue("username", user);
config.setValue("host", serverField->getText());
- } else {
+ }
+ else
+ {
config.setValue("username", "");
}
// Check login
- if (user.length() == 0) {
- wrongLoginNotice = new OkDialog("Error", "Enter your username first", &wrongUsernameNoticeListener);
- } else {
- switch (attemptLogin(user, passField->getText()) )
- {
- case LOGIN_UNKNOWN_ERROR:
- wrongLoginNotice = new OkDialog("Error", "Unknown Error.");
- default:
- break;
-
- case LOGIN_WRONG_PASSWORD:
- wrongLoginNotice = new OkDialog("Error", "Wrong Password", &wrongPasswordNoticeListener);
- break;
-
- case LOGIN_UNREGISTERED_ID:
- wrongLoginNotice = new OkDialog("Error", "Unregistered ID.");
- break;
-
- case LOGIN_EXPIRED:
- wrongLoginNotice = new OkDialog("Error", "This ID is expired");
- break;
-
- case LOGIN_REJECTED:
- wrongLoginNotice = new OkDialog("Error", "Rejected from server");
- break;
-
- case LOGIN_BLOCKED:
- wrongLoginNotice = new OkDialog("Error", "You have been blocked by the GM Team");
- break;
-
- case LOGIN_USERNAME_TWICE:
- wrongLoginNotice = new OkDialog("Error", "The username does already exist.");
- break;
-
+ if (user.length() == 0)
+ {
+ wrongLoginNotice = new OkDialog("Error",
+ "Enter your username first",
+ &wrongUsernameNoticeListener);
+ }
+ else
+ {
+ int ret = attemptLogin(user, passField->getText());
+ if (ret == LOGIN_WRONG_PASSWORD)
+ {
+ wrongLoginNotice = new OkDialog("Error", "Wrong Password",
+ &wrongPasswordNoticeListener);
+ }
+ else if (ret != LOGIN_OK)
+ {
+ std::string errorMsg = "Unknown error.";
+
+ switch (ret)
+ {
+ case LOGIN_UNREGISTERED_ID:
+ errorMsg = "Unregistered ID.";
+ break;
+ case LOGIN_EXPIRED:
+ errorMsg = "This ID is expired";
+ break;
+ case LOGIN_REJECTED:
+ errorMsg = "Rejected from server";
+ break;
+ case LOGIN_BLOCKED:
+ errorMsg = "You have been blocked by the GM Team";
+ break;
+ case LOGIN_USERNAME_TWICE:
+ errorMsg = "The username does already exist.";
+ break;
+ }
+
+ wrongLoginNotice = new OkDialog("Error", errorMsg);
}
- close_session();
}
- } else if (eventId == "cancel") {
+ }
+ else if (eventId == "cancel")
+ {
state = EXIT;
- } else if (eventId == "register") {
+ }
+ else if (eventId == "register")
+ {
const std::string user = userField->getText();
logger->log("LoginDialog::register Username is %s", user.c_str());
@@ -241,46 +254,57 @@ void LoginDialog::action(const std::string& eventId)
}
// Check login
- if (user.length() == 0) // No username
+ if (user.length() == 0)
{
- wrongLoginNotice = new OkDialog("Error", "Enter your username first.", &wrongUsernameNoticeListener);
+ // No username
+ wrongLoginNotice = new OkDialog("Error",
+ "Enter your username first.",
+ &wrongUsernameNoticeListener);
}
- else if (user.length() < LEN_MIN_USERNAME) // Name too short
+ else if (user.length() < LEN_MIN_USERNAME)
{
+ // Name too short
std::stringstream errorMessage;
errorMessage << "The username needs to be at least ";
errorMessage << LEN_MIN_USERNAME;
errorMessage << " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMessage.str(), &wrongUsernameNoticeListener);
+ wrongLoginNotice = new OkDialog("Error", errorMessage.str(),
+ &wrongUsernameNoticeListener);
}
- else if (user.length() > LEN_MAX_USERNAME - 1 ) // Name too long
+ else if (user.length() > LEN_MAX_USERNAME - 1 )
{
+ // Name too long
std::stringstream errorMessage;
errorMessage << "The username needs to be less than ";
errorMessage << LEN_MAX_USERNAME;
errorMessage << " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMessage.str(), &wrongUsernameNoticeListener);
+ wrongLoginNotice = new OkDialog("Error", errorMessage.str(),
+ &wrongUsernameNoticeListener);
}
- else if (passField->getText().length() < LEN_MIN_PASSWORD) // Pass too short
+ else if (passField->getText().length() < LEN_MIN_PASSWORD)
{
+ // Pass too short
std::stringstream errorMessage;
errorMessage << "The password needs to be at least ";
errorMessage << LEN_MIN_PASSWORD;
errorMessage << " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMessage.str(), &wrongPasswordNoticeListener);
+ wrongLoginNotice = new OkDialog("Error", errorMessage.str(),
+ &wrongPasswordNoticeListener);
}
- else if (passField->getText().length() > LEN_MAX_PASSWORD - 1 ) // Pass too long
+ else if (passField->getText().length() > LEN_MAX_PASSWORD - 1 )
{
+ // Pass too long
std::stringstream errorMessage;
errorMessage << "The password needs to be less than ";
errorMessage << LEN_MAX_PASSWORD;
errorMessage << " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMessage.str(), &wrongPasswordNoticeListener);
+ wrongLoginNotice = new OkDialog("Error", errorMessage.str(),
+ &wrongPasswordNoticeListener);
}
- else // If no errors, register the new user.
+ else
{
+ // No errors detected, register the new user.
attemptLogin(user + "_M", passField->getText());
- close_session();
}
}
}
@@ -293,7 +317,8 @@ void loginInputHandler(SDL_KeyboardEvent *keyEvent)
}
}
-int attemptLogin(const std::string& user, const std::string& pass) {
+int attemptLogin(const std::string& user, const std::string& pass)
+{
int ret;
// Connect to login server
@@ -301,55 +326,69 @@ int attemptLogin(const std::string& user, const std::string& pass) {
config.getValue("host", "animesites.de").c_str(),
(short)config.getValue("port", 0));
- if (ret == SOCKET_ERROR) {
+ if (ret == -1) {
state = LOGIN;
- wrongLoginNotice = new OkDialog("Error", "Unable to connect to login server");
+ wrongLoginNotice = new OkDialog("Error",
+ "Unable to connect to login server");
return LOGIN_NO_CONNECTION;
}
- // Send login infos
- WFIFOW(0) = net_w_value(0x0064);
+ // Send login infos
+ MessageOut outMsg;
+ outMsg.writeShort(0x0064);
+ outMsg.writeLong(0); // client version
+ outMsg.writeString(user, 24);
+ outMsg.writeString(pass, 24);
+ outMsg.writeByte(0); // unknown
+ // TODO: still have to use writeSet as skip for reading
+ writeSet(55);
+
+ // Receive reply
+ MessageIn msg = get_next_message();
- WFIFOL(2) = 0;
+ // Login ok
+ if (msg.getId() == 0x0069)
+ {
+ // Skip the length word
+ msg.skip(2);
- memcpy(WFIFOP(6), user.c_str(), LEN_MAX_USERNAME - 1);
- memcpy(WFIFOP(30), pass.c_str(), LEN_MAX_PASSWORD - 1);
- WFIFOB(54) = 0;
- WFIFOSET(55);
+ n_server = (msg.getLength() - 47) / 32;
+ server_info = (SERVER_INFO**)malloc(sizeof(SERVER_INFO*) * n_server);
- while ((in_size < 23) || (out_size > 0)) {
- flush();
- }
+ session_ID1 = msg.readLong();
+ account_ID = msg.readLong();
+ session_ID2 = msg.readLong();
+ msg.skip(30); // unknown
+ sex = msg.readByte();
- // Login ok
- if (RFIFOW(0) == 0x0069) {
- while (in_size < RFIFOW(2)) {
- flush();
- }
- n_server = (RFIFOW(2) - 47) / 32;
- server_info = (SERVER_INFO*)malloc(sizeof(SERVER_INFO) * n_server);
- account_ID = RFIFOL(8);
- session_ID1 = RFIFOL(4);
- session_ID2 = RFIFOL(12);
- sex = RFIFOB(46);
- for (int i = 0; i < n_server; i++) {
- server_info[i].address = RFIFOL(47 + 32 * i);
- memcpy(server_info[i].name, RFIFOP(47 + 32 * i + 6), 20);
- server_info[i].online_users = RFIFOW(47 + 32 * i + 26);
- server_info[i].port = RFIFOW(47 + 32 * i + 4);
- state = CHAR_SERVER;
+ for (int i = 0; i < n_server; i++)
+ {
+ server_info[i] = new SERVER_INFO;
+
+ server_info[i]->address = msg.readLong();
+ server_info[i]->port = msg.readShort();
+ server_info[i]->name = msg.readString(20);
+ server_info[i]->online_users = msg.readLong();
+ msg.skip(2); // unknown
+
+ logger->log("Network: Server: %s (%s:%d)",
+ server_info[i]->name.c_str(),
+ iptostring(server_info[i]->address),
+ server_info[i]->port);
}
- logger->log("Network: Server: %s (%s:%d)", server_info[0].name,
- iptostring(server_info[0].address),
- server_info[0].port);
- RFIFOSKIP(RFIFOW(2));
- return LOGIN_OK;
+
+ state = CHAR_SERVER;
+
+ skip(msg.getLength());
+ ret = LOGIN_OK;
}
- else if (RFIFOW(0) == 0x006a) {
- logger->log("Login::error code: %i", RFIFOB(2));
+ else if (msg.getId() == 0x006a)
+ {
+ int loginError = msg.readByte();
+ logger->log("Login::error code: %i", loginError);
ret = 0;
- switch (RFIFOB(2)) {
+ switch (loginError) {
case 0:
ret = LOGIN_UNREGISTERED_ID;
break;
@@ -369,13 +408,16 @@ int attemptLogin(const std::string& user, const std::string& pass) {
ret = LOGIN_USERNAME_TWICE;
break;
}
+ skip(msg.getLength());
state = LOGIN;
- RFIFOSKIP(23);
- return ret;
}
else {
+ skip(msg.getLength());
state = LOGIN;
- return LOGIN_UNKNOWN_ERROR;
+ ret = LOGIN_UNKNOWN_ERROR;
}
// Todo: add other packets, also encrypted
+
+ close_session();
+ return ret;
}
diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp
index 0756d809..c8d426f3 100644
--- a/src/gui/npc.cpp
+++ b/src/gui/npc.cpp
@@ -70,20 +70,23 @@ NpcListDialog::~NpcListDialog()
delete scrollArea;
}
-int NpcListDialog::getNumberOfElements()
+int
+NpcListDialog::getNumberOfElements()
{
return items.size();
}
-std::string NpcListDialog::getElementAt(int i)
+std::string
+NpcListDialog::getElementAt(int i)
{
return items[i];
}
-void NpcListDialog::parseItems(const char *string, unsigned short len) {
- char *copy = new char[len + 1];
- strncpy(copy, string, len);
- copy[len] = 0;
+void
+NpcListDialog::parseItems(const std::string &itemString)
+{
+ char *copy = new char[itemString.length() + 1];
+ strcpy(copy, itemString.c_str());
char *token = strtok(copy, ":");
while (token) {
@@ -94,20 +97,23 @@ void NpcListDialog::parseItems(const char *string, unsigned short len) {
delete[] copy;
}
-void NpcListDialog::reset() {
+void
+NpcListDialog::reset()
+{
items.clear();
}
-void NpcListDialog::action(const std::string& eventId)
+void
+NpcListDialog::action(const std::string& eventId)
{
if (eventId == "ok") {
// Send the selected index back to the server
int selectedIndex = itemList->getSelected();
if (selectedIndex > -1) {
- WFIFOW(0) = net_w_value(0x00b8);
- WFIFOL(2) = net_l_value(current_npc);
- WFIFOB(6) = net_b_value(selectedIndex + 1);
- WFIFOSET(7);
+ writeWord(0, 0x00b8);
+ writeLong(2, current_npc);
+ writeByte(6, selectedIndex + 1);
+ writeSet(7);
setVisible(false);
current_npc = 0;
reset();
@@ -115,10 +121,10 @@ void NpcListDialog::action(const std::string& eventId)
}
else if (eventId == "cancel") {
// 0xff packet means cancel
- WFIFOW(0) = net_w_value(0x00b8);
- WFIFOL(2) = net_l_value(current_npc);
- WFIFOB(6) = net_b_value(0xff);
- WFIFOSET(7);
+ writeWord(0, 0x00b8);
+ writeLong(2, current_npc);
+ writeByte(6, 0xff);
+ writeSet(7);
setVisible(false);
reset();
current_npc = 0;
diff --git a/src/gui/npc.h b/src/gui/npc.h
index 336bad62..e9960cd2 100644
--- a/src/gui/npc.h
+++ b/src/gui/npc.h
@@ -58,29 +58,34 @@ class NpcListDialog : public Window, public gcn::ActionListener,
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void
+ action(const std::string& eventId);
/**
* Returns the number of items in the choices list.
*/
- int getNumberOfElements();
+ int
+ getNumberOfElements();
/**
* Returns the name of item number i of the choices list.
*/
- std::string getElementAt(int i);
+ std::string
+ getElementAt(int i);
/**
* Fills the options list for an NPC dialog.
*
- * @param string A string with the options separated with colons.
+ * @param itemString A string with the options separated with colons.
*/
- void parseItems(const char *string, unsigned short len);
+ void
+ parseItems(const std::string &itemString);
/**
* Resets the list by removing all items.
*/
- void reset();
+ void
+ reset();
private:
gcn::Button *okButton;
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 7fc59343..67a9e9a3 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -61,22 +61,24 @@ NpcTextDialog::~NpcTextDialog()
delete scrollArea;
}
-void NpcTextDialog::setText(const char *text)
+void
+NpcTextDialog::setText(const char *text)
{
textBox->setText(text);
}
-void NpcTextDialog::addText(const char *text)
+void
+NpcTextDialog::addText(const std::string &text)
{
- textBox->setText(
- textBox->getText() + std::string(text) + std::string("\n"));
+ textBox->setText(textBox->getText() + text + "\n");
}
-void NpcTextDialog::action(const std::string& eventId)
+void
+NpcTextDialog::action(const std::string& eventId)
{
- WFIFOW(0) = net_w_value(0x00b9);
- WFIFOL(2) = net_l_value(current_npc);
- WFIFOSET(6);
+ writeWord(0, 0x00b9);
+ writeLong(2, current_npc);
+ writeSet(6);
setText("");
setVisible(false);
current_npc = 0;
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index 41301aa9..02fae7f4 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -25,11 +25,10 @@
#define _TMW_NPC_TEXT_H
#include <iosfwd>
-
+#include <string>
#include <guichan/actionlistener.hpp>
#include "window.h"
-
#include "../guichanfwd.h"
/**
@@ -55,14 +54,16 @@ class NpcTextDialog : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const std::string& eventId);
+ void
+ action(const std::string &eventId);
/**
* Sets the text shows in the dialog.
*
* @param string The new text.
*/
- void setText(const char *string);
+ void
+ setText(const char *string);
/**
* Adds the text to the text shows in the dialog. Also adds a newline
@@ -70,7 +71,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener
*
* @param string The text to add.
*/
- void addText(const char *string);
+ void
+ addText(const std::string &string);
private:
gcn::Button *okButton;
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 85b1b43a..3ea3e141 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -72,22 +72,22 @@ PopupMenu::~PopupMenu()
void PopupMenu::showPopup(int x, int y, Being *being)
{
- std::string name;
-
this->being = being;
browserBox->clearRows();
switch (being->getType())
{
case Being::PLAYER:
- // Players can be traded with. Later also attack, follow and
- // add as buddy will be options in this menu.
-
- name = being->name;
- //browserBox->addRow("@@attack|Attack " + name + "@@");
- browserBox->addRow("@@trade|Trade With " + name + "@@");
- //browserBox->addRow("@@follow|Follow " + name + "@@");
- //browserBox->addRow("@@buddy|Add " + name + " to Buddy List@@");
+ {
+ // Players can be traded with. Later also attack, follow and
+ // add as buddy will be options in this menu.
+ const std::string &name = being->getName();
+ browserBox->addRow("@@trade|Trade With " + name + "@@");
+
+ //browserBox->addRow("@@attack|Attack " + name + "@@");
+ //browserBox->addRow("@@follow|Follow " + name + "@@");
+ //browserBox->addRow("@@buddy|Add " + name + " to Buddy List@@");
+ }
break;
case Being::NPC:
@@ -114,7 +114,7 @@ void PopupMenu::showPopup(int x, int y, FloorItem *floorItem)
browserBox->clearRows();
// Floor item can be picked up (single option, candidate for removal)
- std::string name = itemDb->getItemInfo(floorItem->id)->getName();
+ std::string name = itemDb->getItemInfo(floorItem->getItemId())->getName();
browserBox->addRow("@@pickup|Pick Up " + name + "@@");
//browserBox->addRow("@@look|Look To@@");
@@ -130,22 +130,22 @@ void PopupMenu::handleLink(const std::string& link)
if ((link == "talk") && being && being->getType() == Being::NPC &&
(current_npc == 0))
{
- WFIFOW(0) = net_w_value(0x0090);
- WFIFOL(2) = net_l_value(being->getId());
- WFIFOB(6) = 0;
- WFIFOSET(7);
+ writeWord(0, 0x0090);
+ writeLong(2, being->getId());
+ writeByte(6, 0);
+ writeSet(7);
current_npc = being->getId();
}
// Trade action
else if ((link == "trade") && being && being->getType() == Being::PLAYER)
{
- WFIFOW(0) = net_w_value(0x00e4);
- WFIFOL(2) = net_l_value(being->getId());
- WFIFOSET(6);
+ writeWord(0, 0x00e4);
+ writeLong(2, being->getId());
+ writeSet(6);
//tradePartner.flush();
//tradePartner << "Trade: You and " << being->name<< "";
- strcpy(tradePartnerName, being->name);
+ tradePartnerName = being->getName();
}
/*
// Follow Player action
@@ -160,15 +160,15 @@ void PopupMenu::handleLink(const std::string& link)
if (!buddyWindow->isVisible())
buddyWindow->setVisible(true);
- buddyWindow->addBuddy(being->name);
+ buddyWindow->addBuddy(being->getName());
}*/
// Pick Up Floor Item action
else if ((link == "pickup") && floorItem)
{
- WFIFOW(0) = net_w_value(0x009f);
- WFIFOL(2) = net_l_value(floorItem->int_id);
- WFIFOSET(6);
+ writeWord(0, 0x009f);
+ writeLong(2, floorItem->getId());
+ writeSet(6);
}
// Look To action
diff --git a/src/gui/requesttrade.cpp b/src/gui/requesttrade.cpp
index 35654562..e3b70fd3 100644
--- a/src/gui/requesttrade.cpp
+++ b/src/gui/requesttrade.cpp
@@ -24,16 +24,14 @@
#include "requesttrade.h"
#include <sstream>
-
#include <guichan/widgets/label.hpp>
#include "button.h"
-
#include "../net/network.h"
bool requestTradeDialogOpen = false;
-RequestTradeDialog::RequestTradeDialog(const char *name):
+RequestTradeDialog::RequestTradeDialog(const std::string &name):
Window("Request for Trade", true)
{
nameLabel[0] = new gcn::Label("");
@@ -88,16 +86,16 @@ void RequestTradeDialog::action(const std::string& eventId)
{
if (eventId == "accept") {
// Send the selected index back to the server
- WFIFOW(0) = net_w_value(0x00e6);
- WFIFOB(2) = net_b_value(3);
- WFIFOSET(3);
+ writeWord(0, 0x00e6);
+ writeByte(2, 3);
+ writeSet(3);
scheduleDelete();
}
else if (eventId == "cancel") {
// 0xff packet means cancel
- WFIFOW(0) = net_w_value(0x00e6);
- WFIFOB(2) = net_b_value(4);
- WFIFOSET(3);
+ writeWord(0, 0x00e6);
+ writeByte(2, 4);
+ writeSet(3);
requestTradeDialogOpen = false;
scheduleDelete();
}
diff --git a/src/gui/requesttrade.h b/src/gui/requesttrade.h
index 8c9ac29a..4cd33a49 100644
--- a/src/gui/requesttrade.h
+++ b/src/gui/requesttrade.h
@@ -21,15 +21,13 @@
* $Id$
*/
-#ifndef _TMW_REQUESTTRADE_H
-#define _TMW_REQUESTTRADE_H
+#ifndef _TMW_REQUESTTRADE_
+#define _TMW_REQUESTTRADE_
#include <iosfwd>
-
#include <guichan/actionlistener.hpp>
#include "window.h"
-
#include "../guichanfwd.h"
extern bool requestTradeDialogOpen;
@@ -47,7 +45,7 @@ class RequestTradeDialog : public Window, public gcn::ActionListener
*
* @see Window::Window
*/
- RequestTradeDialog(const char *name);
+ RequestTradeDialog(const std::string &name);
/**
* Destructor.
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 2684fc2a..b6cbe5df 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -230,11 +230,11 @@ void SellDialog::action(const std::string& eventId)
// Attempt sell
assert(m_amountItems > 0 && m_amountItems <= m_maxItems);
- WFIFOW(0) = net_w_value(0x00c9);
- WFIFOW(2) = net_w_value(8);
- WFIFOW(4) = net_w_value(shopInventory[selectedItem].index);
- WFIFOW(6) = net_w_value(m_amountItems);
- WFIFOSET(8);
+ writeWord(0, 0x00c9);
+ writeWord(2, 8);
+ writeWord(4, shopInventory[selectedItem].index);
+ writeWord(6, m_amountItems);
+ writeSet(8);
m_maxItems -= m_amountItems;
m_amountItems = 0;
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 5244b2f3..0e641768 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -122,12 +122,11 @@ void SkillDialog::action(const std::string& eventId)
{
// Increment skill
int selectedSkill = skillListBox->getSelected();
- if (char_info->skill_point > 0 && selectedSkill >= 0)
+ if (player_info->skill_point > 0 && selectedSkill >= 0)
{
- WFIFOW(0) = net_w_value(0x0112);
- WFIFOW(2) = net_w_value(
- skillList[selectedSkill]->id);
- WFIFOSET(4);
+ writeWord(0, 0x0112);
+ writeWord(2, skillList[selectedSkill]->id);
+ writeSet(4);
}
}
else if (eventId == "skill")
diff --git a/src/gui/stats.cpp b/src/gui/stats.cpp
index f03d2bfc..22f51827 100644
--- a/src/gui/stats.cpp
+++ b/src/gui/stats.cpp
@@ -89,36 +89,36 @@ void StatsWindow::update(){
std::stringstream remainingStatsPointsStr;
statsStr[0] << "Strength:";
- figureStr[0] << (int)char_info->STR;
+ figureStr[0] << (int)player_info->STR;
statsStr[1] << "Agility:";
- figureStr[1] << (int)char_info->AGI;
+ figureStr[1] << (int)player_info->AGI;
statsStr[2] << "Vitality:";
- figureStr[2] << (int)char_info->VIT;
+ figureStr[2] << (int)player_info->VIT;
statsStr[3] << "Intelligence:";
- figureStr[3] << (int)char_info->INT;
+ figureStr[3] << (int)player_info->INT;
statsStr[4] << "Dexterity:";
- figureStr[4] << (int)char_info->DEX;
+ figureStr[4] << (int)player_info->DEX;
statsStr[5] << "Luck:";
- figureStr[5] << (int)char_info->LUK;
+ figureStr[5] << (int)player_info->LUK;
- int statusPoints = char_info->statsPointsToAttribute;
+ int statusPoints = player_info->statsPointsToAttribute;
remainingStatsPointsStr << "Remaining Status Points: " << statusPoints;
-
- pointsStr[0] << (int)char_info->STRUp;
- pointsStr[1] << (int)char_info->AGIUp;
- pointsStr[2] << (int)char_info->VITUp;
- pointsStr[3] << (int)char_info->INTUp;
- pointsStr[4] << (int)char_info->DEXUp;
- pointsStr[5] << (int)char_info->LUKUp;
+
+ pointsStr[0] << (int)player_info->STRUp;
+ pointsStr[1] << (int)player_info->AGIUp;
+ pointsStr[2] << (int)player_info->VITUp;
+ pointsStr[3] << (int)player_info->INTUp;
+ pointsStr[4] << (int)player_info->DEXUp;
+ pointsStr[5] << (int)player_info->LUKUp;
// Enable buttons for which there are enough status points
- statsButton[0]->setEnabled(char_info->STRUp <= statusPoints);
- statsButton[1]->setEnabled(char_info->AGIUp <= statusPoints);
- statsButton[2]->setEnabled(char_info->VITUp <= statusPoints);
- statsButton[3]->setEnabled(char_info->INTUp <= statusPoints);
- statsButton[4]->setEnabled(char_info->DEXUp <= statusPoints);
- statsButton[5]->setEnabled(char_info->LUKUp <= statusPoints);
+ statsButton[0]->setEnabled(player_info->STRUp <= statusPoints);
+ statsButton[1]->setEnabled(player_info->AGIUp <= statusPoints);
+ statsButton[2]->setEnabled(player_info->VITUp <= statusPoints);
+ statsButton[3]->setEnabled(player_info->INTUp <= statusPoints);
+ statsButton[4]->setEnabled(player_info->DEXUp <= statusPoints);
+ statsButton[5]->setEnabled(player_info->LUKUp <= statusPoints);
// Update labels
for (i = 0; i < 6; i++) {
@@ -150,28 +150,28 @@ void StatsWindow::draw(gcn::Graphics *graphics)
}
void StatsWindow::action(const std::string& eventId) {
- WFIFOW(0) = net_w_value(0x00bb);
+ writeWord(0, 0x00bb);
if (eventId == "STR") {
- WFIFOW(2) = net_w_value(0x000d);
+ writeWord(2, 0x000d);
}
if (eventId == "AGI") {
- WFIFOW(2) = net_w_value(0x000e);
+ writeWord(2, 0x000e);
}
if (eventId == "VIT") {
- WFIFOW(2) = net_w_value(0x000f);
+ writeWord(2, 0x000f);
}
if (eventId == "INT") {
- WFIFOW(2) = net_w_value(0x0010);
+ writeWord(2, 0x0010);
}
if (eventId == "DEX") {
- WFIFOW(2) = net_w_value(0x0011);
+ writeWord(2, 0x0011);
}
if (eventId == "LUK") {
- WFIFOW(2) = net_w_value(0x0012);
+ writeWord(2, 0x0012);
}
flush();
- WFIFOW(4) = net_b_value(1);
- WFIFOSET(5);
+ writeByte(4, 1);
+ writeSet(5);
}
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index 7ba14fc7..7964768b 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -157,36 +157,36 @@ void StatusWindow::update()
char *tempstr = new char[64];
sprintf(tempstr, "%s Lvl: % 2i Job: % 2i GP: % 2i",
- char_info->name, char_info->lv, char_info->job_lv,
- char_info->gp);
+ player_info->name.c_str(), player_info->lv, player_info->job_lv,
+ player_info->gp);
setCaption(tempstr);
- sprintf(tempstr, "%d/%d", char_info->hp, char_info->max_hp);
+ sprintf(tempstr, "%d/%d", player_info->hp, player_info->max_hp);
hpValue->setCaption(tempstr);
hpValue->adjustSize();
- sprintf(tempstr, "%d/%d", char_info->sp, char_info->max_sp);
+ sprintf(tempstr, "%d/%d", player_info->sp, player_info->max_sp);
spValue->setCaption(tempstr);
spValue->adjustSize();
sprintf(tempstr, "Exp: %d/%d",
- (int)char_info->xp, (int)char_info->xpForNextLevel);
+ (int)player_info->xp, (int)player_info->xpForNextLevel);
expLabel->setCaption(tempstr);
expLabel->adjustSize();
sprintf(tempstr, "Job: %d/%d",
- (int)char_info->job_xp, (int)char_info->jobXpForNextLevel);
+ (int)player_info->job_xp, (int)player_info->jobXpForNextLevel);
jobExpLabel->setCaption(tempstr);
jobExpLabel->adjustSize();
// HP Bar coloration
- if (char_info->hp < int(char_info->max_hp / 3))
+ if (player_info->hp < int(player_info->max_hp / 3))
{
healthBar->setColor(223, 32, 32); // Red
}
else
{
- if (char_info->hp < int((char_info->max_hp / 3) * 2))
+ if (player_info->hp < int((player_info->max_hp / 3) * 2))
{
healthBar->setColor(230, 171, 34); // Orange
}
@@ -196,12 +196,14 @@ void StatusWindow::update()
}
}
- healthBar->setProgress((float)char_info->hp / (float)char_info->max_hp);
+ healthBar->setProgress((float)player_info->hp /
+ (float)player_info->max_hp);
- xpBar->setProgress(
- (float)char_info->xp / (float)char_info->xpForNextLevel);
- jobXpBar->setProgress(
- (float)char_info->job_xp / (float)char_info->jobXpForNextLevel);
+ xpBar->setProgress((float)player_info->xp /
+ (float)player_info->xpForNextLevel);
+
+ jobXpBar->setProgress((float)player_info->job_xp /
+ (float)player_info->jobXpForNextLevel);
delete[] tempstr;
}
diff --git a/src/gui/status.h b/src/gui/status.h
index d6abd7af..99fbadf5 100644
--- a/src/gui/status.h
+++ b/src/gui/status.h
@@ -64,7 +64,7 @@ class StatusWindow : public Window, public gcn::ActionListener {
private:
/**
- * Updates this dialog with values from PLAYER_INFO *char_info
+ * Updates this dialog with values from <code>player_info</code>
*/
void update();
@@ -73,7 +73,11 @@ class StatusWindow : public Window, public gcn::ActionListener {
gcn::Label *expLabel, *jobExpLabel;
ProgressBar *healthBar, *manaBar;
ProgressBar *xpBar, *jobXpBar;
- gcn::Button *statsButton, *skillsButton, *inventoryButton, *setupButton, *equipmentButton;
+ gcn::Button *statsButton;
+ gcn::Button *skillsButton;
+ gcn::Button *inventoryButton;
+ gcn::Button *setupButton;
+ gcn::Button *equipmentButton;
};
extern StatusWindow *statusWindow;
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index f42ca1e0..e18dc969 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -161,8 +161,7 @@ void TradeWindow::addMoney(int amount)
moneyLabel->adjustSize();
}
-void TradeWindow::addItem(int id, bool own, int quantity,
- bool equipment)
+void TradeWindow::addItem(int id, bool own, int quantity, bool equipment)
{
if (own) {
myInventory->addItem(id, quantity, equipment);
@@ -241,11 +240,11 @@ void TradeWindow::receivedOk(bool own)
void TradeWindow::tradeItem(Item *item, int quantity)
{
- WFIFOW(0) = net_w_value(0x00e8);
- WFIFOW(2) = net_w_value(item->getInvIndex());
- WFIFOL(4) = net_l_value(quantity);
- WFIFOSET(8);
- while ((out_size > 0)) flush();
+ writeWord(0, 0x00e8);
+ writeWord(2, item->getInvIndex());
+ writeLong(4, quantity);
+ writeSet(8);
+ flush();
}
void TradeWindow::mouseClick(int x, int y, int button, int count)
@@ -314,9 +313,9 @@ void TradeWindow::action(const std::string &eventId)
}
else if (eventId == "cancel")
{
- WFIFOW(0) = net_w_value(0x00ed);
- WFIFOSET(2);
- while ((out_size > 0)) flush();
+ writeWord(0, 0x00ed);
+ writeSet(2);
+ flush();
}
else if (eventId == "ok")
{
@@ -328,23 +327,23 @@ void TradeWindow::action(const std::string &eventId)
tempMoney[1] << tempInt;
moneyField->setText(tempMoney[1].str());
- WFIFOW(0) = net_w_value(0x00e8);
- WFIFOW(2) = net_w_value(0);
- WFIFOL(4) = net_l_value(tempInt);
- WFIFOSET(8);
- while ((out_size > 0)) flush();
+ writeWord(0, 0x00e8);
+ writeWord(2, 0);
+ writeLong(4, tempInt);
+ writeSet(8);
+ flush();
} else {
moneyField->setText("");
}
moneyField->setEnabled(false);
- WFIFOW(0) = net_w_value(0x00eb);
- WFIFOSET(2);
- while ((out_size > 0)) flush();
+ writeWord(0, 0x00eb);
+ writeSet(2);
+ flush();
}
else if (eventId == "trade")
{
- WFIFOW(0) = net_w_value(0x00ef);
- WFIFOSET(2);
- while ((out_size > 0)) flush();
+ writeWord(0, 0x00ef);
+ writeSet(2);
+ flush();
}
}