summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-04-18 22:09:42 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-04-18 22:23:16 -0700
commit7f16d356995d4e9c29105f98d502a7e51a4c775d (patch)
tree3fc9f782d67f68d44c36d0dff2c197fc33dac206 /src/map
parent56e149a51562b9d2620bc9037a81735c29ea95af (diff)
parent6d631217271fcdc57143a7f8e03a2595a93ab50f (diff)
downloadtmwa-7f16d356995d4e9c29105f98d502a7e51a4c775d.tar.gz
tmwa-7f16d356995d4e9c29105f98d502a7e51a4c775d.tar.bz2
tmwa-7f16d356995d4e9c29105f98d502a7e51a4c775d.tar.xz
tmwa-7f16d356995d4e9c29105f98d502a7e51a4c775d.zip
Merge tag 'v14.4.18' into master
Conflicts: src/admin/ladmin.cpp src/char/char.cpp src/login/login.cpp src/map/chrif.cpp src/map/clif.cpp src/mmo/socket.cpp
Diffstat (limited to 'src/map')
-rw-r--r--src/map/chrif.cpp27
-rw-r--r--src/map/chrif.hpp1
-rw-r--r--src/map/clif.cpp64
-rw-r--r--src/map/trade.cpp5
4 files changed, 55 insertions, 42 deletions
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp
index 04e82ca..64fd547 100644
--- a/src/map/chrif.cpp
+++ b/src/map/chrif.cpp
@@ -1035,6 +1035,15 @@ void ladmin_itemfrob(Session *s)
}
}
+static
+void chrif_delete(Session *s)
+{
+ assert (s == char_session);
+ PRINTF("Map-server can't connect to char-server (connection #%d).\n"_fmt,
+ s);
+ char_session = nullptr;
+}
+
/*==========================================
*
*------------------------------------------
@@ -1046,15 +1055,9 @@ void chrif_parse(Session *s)
// only char-server can have an access to here.
// so, if it isn't the char-server, we disconnect the session (fd != char_fd).
- if (s != char_session || s->eof)
+ if (s != char_session)
{
- if (s == char_session)
- {
- PRINTF("Map-server can't connect to char-server (connection #%d).\n"_fmt,
- s);
- char_session = nullptr;
- }
- delete_session(s);
+ s->set_eof();
return;
}
@@ -1075,7 +1078,7 @@ void chrif_parse(Session *s)
if (r == 2)
return; // intifで処理したが、データが足りない
- s->eof = 1;
+ s->set_eof();
return;
}
packet_len = packet_len_table[cmd - 0x2af8];
@@ -1158,7 +1161,7 @@ void chrif_parse(Session *s)
if (battle_config.error_log)
PRINTF("chrif_parse : unknown packet %d %d\n"_fmt, s,
RFIFOW(s, 0));
- s->eof = 1;
+ s->set_eof();
return;
}
RFIFOSKIP(s, packet_len);
@@ -1211,10 +1214,10 @@ void check_connect_char_server(TimerData *, tick_t)
{
PRINTF("Attempt to connect to char-server...\n"_fmt);
chrif_state = 0;
- char_session = make_connection(char_ip, char_port);
+ char_session = make_connection(char_ip, char_port,
+ SessionParsers{func_parse: chrif_parse, func_delete: chrif_delete});
if (!char_session)
return;
- char_session->func_parse = chrif_parse;
realloc_fifo(char_session, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
chrif_connect(char_session);
diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp
index 5e8263d..afeba75 100644
--- a/src/map/chrif.hpp
+++ b/src/map/chrif.hpp
@@ -59,6 +59,7 @@ int chrif_send_divorce(int char_id);
void do_init_chrif(void);
// only used by intif.cpp
+// and clif.cpp for the new on_delete stuff ...
extern Session *char_session;
#endif // TMWA_MAP_CHRIF_HPP
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index 2eae52b..3e57a6f 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -145,6 +145,29 @@ int map_port = 5121;
static
int clif_changelook_towards(dumb_ptr<block_list> bl, LOOK type, int val,
dumb_ptr<map_session_data> dstsd);
+static
+void clif_quitsave(Session *, dumb_ptr<map_session_data> sd);
+
+static
+void clif_delete(Session *s)
+{
+ assert (s != char_session);
+
+ dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(s->session_data.get()));
+ if (sd && sd->state.auth)
+ {
+ pc_logout(sd);
+ clif_quitsave(s, sd);
+
+ PRINTF("Player [%s] has logged off your server.\n"_fmt, sd->status_key.name); // Player logout display [Valaris]
+ }
+ else if (sd)
+ { // not authentified! (refused by char-server or disconnect before to be authentified)
+ PRINTF("Player with account [%d] has logged off your server (not auth account).\n"_fmt, sd->bl_id); // Player logout display [Yor]
+ map_deliddb(sd); // account_id has been included in the DB before auth answer
+ }
+}
+
/*==========================================
* map鯖のip設定
@@ -1098,10 +1121,8 @@ void clif_quitsave(Session *, dumb_ptr<map_session_data> sd)
static
void clif_waitclose(TimerData *, tick_t, Session *s)
{
- // TODO: what happens if the player disconnects
- // and someone else connects?
if (s)
- s->eof = 1;
+ s->set_eof();
}
/*==========================================
@@ -1110,10 +1131,10 @@ void clif_waitclose(TimerData *, tick_t, Session *s)
*/
void clif_setwaitclose(Session *s)
{
- Timer(gettick() + std::chrono::seconds(5),
+ s->timed_close = Timer(gettick() + std::chrono::seconds(5),
std::bind(clif_waitclose, ph::_1, ph::_2,
s)
- ).detach();
+ );
}
/*==========================================
@@ -5199,7 +5220,7 @@ int clif_check_packet_flood(Session *s, int cmd)
PRINTF("packet flood detected from %s [0x%x]\n"_fmt, sd->status_key.name, cmd);
if (battle_config.packet_spam_kick)
{
- s->eof = 1; // Kick
+ s->set_eof();
return 1;
}
sd->packet_flood_in = 0;
@@ -5334,32 +5355,18 @@ void clif_parse(Session *s)
{
if (RFIFOREST(s) < 2)
{ // too small a packet disconnect
- s->eof = 1;
+ s->set_eof();
}
if (RFIFOW(s, 0) != 0x72 && RFIFOW(s, 0) != 0x7530)
{
// first packet must be auth or finger
- s->eof = 1;
+ s->set_eof();
}
}
- // 接続が切れてるので後始末
- if (!chrif_isconnect() || s->eof)
- { // char鯖に繋がってない間は接続禁止 (!chrif_isconnect())
- if (sd && sd->state.auth)
- {
- pc_logout(sd);
- clif_quitsave(s, sd);
-
- PRINTF("Player [%s] has logged off your server.\n"_fmt, sd->status_key.name); // Player logout display [Valaris]
- }
- else if (sd)
- { // not authentified! (refused by char-server or disconnect before to be authentified)
- PRINTF("Player with account [%d] has logged off your server (not auth account).\n"_fmt, sd->bl_id); // Player logout display [Yor]
- map_deliddb(sd); // account_id has been included in the DB before auth answer
- }
- if (s)
- delete_session(s);
+ if (!chrif_isconnect())
+ {
+ s->set_eof();
return;
}
@@ -5380,7 +5387,7 @@ void clif_parse(Session *s)
RFIFOSKIP(s, 2);
break;
case 0x7532: // 接続の切断
- s->eof = 1;
+ s->set_eof();
break;
}
return;
@@ -5399,7 +5406,7 @@ void clif_parse(Session *s)
packet_len = RFIFOW(s, 2);
if (packet_len < 4 || packet_len > 32768)
{
- s->eof = 1;
+ s->set_eof();
return; // Runt packet (variable out of bounds)
}
}
@@ -5495,6 +5502,5 @@ void clif_parse(Session *s)
void do_init_clif(void)
{
- set_defaultparse(clif_parse);
- make_listen_port(map_port);
+ make_listen_port(map_port, SessionParsers{func_parse: clif_parse, func_delete: clif_delete});
}
diff --git a/src/map/trade.cpp b/src/map/trade.cpp
index 7fbfbec..86d876f 100644
--- a/src/map/trade.cpp
+++ b/src/map/trade.cpp
@@ -260,8 +260,11 @@ void trade_tradeok(dumb_ptr<map_session_data> sd)
for (trade_i = 0; trade_i < TRADE_MAX; trade_i++)
{
+ int index = sd->deal_item_index[trade_i];
+ if (index < 2 || index >= MAX_INVENTORY + 2)
+ continue;
if (sd->deal_item_amount[trade_i] >
- sd->status.inventory[sd->deal_item_index[trade_i] - 2].amount
+ sd->status.inventory[index - 2].amount
|| sd->deal_item_amount[trade_i] < 0)
{
trade_tradecancel(sd);