summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-08-10 01:03:32 +0300
committerAndrei Karas <akaras@inbox.ru>2016-08-10 01:03:32 +0300
commitcb10231838c918dbf380899a947599331818a4bc (patch)
tree7f92446dd65643a81d7ddf0419ff1c4c60be73be
parent725fb53014ab7d48d43d69f0c1ca21354ef8619c (diff)
downloadplugin-cb10231838c918dbf380899a947599331818a4bc.tar.gz
plugin-cb10231838c918dbf380899a947599331818a4bc.tar.bz2
plugin-cb10231838c918dbf380899a947599331818a4bc.tar.xz
plugin-cb10231838c918dbf380899a947599331818a4bc.zip
Add gm command for send restart events to all servers.
For now it support only one char and one map server. For support this actions need use hercules wrapper.
-rw-r--r--src/Makefile.am2
-rw-r--r--src/echar/char.c28
-rw-r--r--src/echar/char.h4
-rw-r--r--src/echar/init.c1
-rw-r--r--src/elogin/init.c1
-rw-r--r--src/elogin/parse.c17
-rw-r--r--src/elogin/parse.h1
-rw-r--r--src/emap/atcommand.c21
-rw-r--r--src/emap/atcommand.h1
-rw-r--r--src/emap/init.c1
-rw-r--r--src/emap/inter.c23
-rw-r--r--src/emap/inter.h9
12 files changed, 108 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7243854..9888bcf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,6 +52,8 @@ MAP_SRC = emap/atcommand.c \
emap/horse.c \
emap/horse.h \
emap/init.c \
+ emap/inter.c \
+ emap/inter.h \
emap/itemdb.c \
emap/itemdb.h \
emap/lang.c \
diff --git a/src/echar/char.c b/src/echar/char.c
index e5649ad..26e6c61 100644
--- a/src/echar/char.c
+++ b/src/echar/char.c
@@ -14,6 +14,7 @@
#include "common/socket.h"
#include "common/strlib.h"
#include "common/sql.h"
+#include "common/utils.h"
#include "common/timer.h"
#include "char/char.h"
#include "char/inter.h"
@@ -320,3 +321,30 @@ void echar_parse_frommap_request_stats_report_pre(int *fdPtr)
RFIFOFLUSH(fd);
hookStop();
}
+
+void echar_parse_map_serverexit(int mapFd)
+{
+ const int code = RFIFOW(mapFd, 2);
+ switch (code)
+ {
+ case 100: // all exit
+ case 101: // all restart
+ case 102: // restart char and map server
+ echat_send_login_serverexit(code);
+ HSleep(1);
+ core->shutdown_callback();
+ break;
+ case 103: // restart map server
+ break;
+ default:
+ ShowWarning("Unknown termination code: %d\n", code);
+ }
+}
+
+void echat_send_login_serverexit(const int code)
+{
+ WFIFOHEAD(chr->login_fd, 4);
+ WFIFOW(chr->login_fd, 0) = 0x5003;
+ WFIFOW(chr->login_fd, 2) = code;
+ WFIFOSET(chr->login_fd, 4);
+}
diff --git a/src/echar/char.h b/src/echar/char.h
index 726f2c2..e05bde0 100644
--- a/src/echar/char.h
+++ b/src/echar/char.h
@@ -27,4 +27,8 @@ void echar_parse_char_connect_post(int fd, struct char_session_data *sd, uint32
void echar_parse_frommap_request_stats_report_pre(int *fdPtr);
+void echar_parse_map_serverexit(int mapFd);
+
+void echat_send_login_serverexit(const int code);
+
#endif // EVOL_CHAR_CHAR
diff --git a/src/echar/init.c b/src/echar/init.c
index e876065..c8b7e0b 100644
--- a/src/echar/init.c
+++ b/src/echar/init.c
@@ -51,6 +51,7 @@ HPExport void plugin_init (void)
{
addPacket(0x0061, 50, echar_parse_change_paassword, hpParse_Char);
addPacket(0x5001, 7, echar_parse_login_password_change_ack, hpParse_FromLogin);
+ addPacket(0x5002, 4, echar_parse_map_serverexit, hpParse_FromMap);
addHookPre(chr, parse_char_create_new_char, echar_parse_char_create_new_char);
addHookPre(chr, creation_failed, echar_creation_failed);
diff --git a/src/elogin/init.c b/src/elogin/init.c
index af725a0..c3d3fb7 100644
--- a/src/elogin/init.c
+++ b/src/elogin/init.c
@@ -46,6 +46,7 @@ HPExport void plugin_init (void)
addPacket(0x7530, 22, login_parse_version, hpParse_Login);
addPacket(0x027c, 91, elogin_parse_client_login2, hpParse_Login);
addPacket(0x5000, 54, elogin_parse_change_paassword, hpParse_FromChar);
+ addPacket(0x5003, 4, elogin_parse_serverexit, hpParse_FromChar);
addHookPre(login, client_login, elogin_client_login_pre);
addHookPre(login, check_password, elogin_check_password_pre);
diff --git a/src/elogin/parse.c b/src/elogin/parse.c
index d9e644e..78b59c2 100644
--- a/src/elogin/parse.c
+++ b/src/elogin/parse.c
@@ -214,3 +214,20 @@ void elogin_parse_change_paassword(int fd)
}
send_char_password_change_ack(fd, accountId, status);
}
+
+void elogin_parse_serverexit(int fd)
+{
+ const int code = RFIFOW(fd, 2);
+ switch (code)
+ {
+ case 100: // all exit
+ case 101: // all restart
+ core->shutdown_callback();
+ break;
+ case 102: // restart char and map server
+ case 103: // restart map server
+ break;
+ default:
+ ShowWarning("Unknown termination code: %d\n", code);
+ }
+}
diff --git a/src/elogin/parse.h b/src/elogin/parse.h
index 07d2a3d..824a355 100644
--- a/src/elogin/parse.h
+++ b/src/elogin/parse.h
@@ -14,5 +14,6 @@ void elogin_parse_client_login2(int fd);
enum parsefunc_rcode elogin_parse_ping_pre(int *fd,
struct login_session_data **sdPtr);
void elogin_parse_change_paassword(int fd);
+void elogin_parse_serverexit(int fd);
#endif // EVOL_LOGIN_PARSE
diff --git a/src/emap/atcommand.c b/src/emap/atcommand.c
index 7c3f345..1928620 100644
--- a/src/emap/atcommand.c
+++ b/src/emap/atcommand.c
@@ -23,6 +23,7 @@
#include "emap/atcommand.h"
#include "emap/lang.h"
+#include "emap/inter.h"
const char* eatcommand_msgsd_pre(struct map_session_data **sdPtr,
int *msgPtr)
@@ -132,11 +133,29 @@ ACMD2(slide)
ACMD1(mapExit)
{
+ int code = 1;
+ if (!*message || sscanf(message, "%5d", &code) < 1)
+ code = 1;
+
+ map->retval = code;
+ map->do_shutdown();
+ return true;
+}
+
+// 100 - terminate all servers
+// 101 - restart all servers
+// 102 - restart char and map servers
+// 103 - restart map server
+ACMD1(serverExit)
+{
int code = 0;
if (!*message || sscanf(message, "%5d", &code) < 1)
- code = 0;
+ return false;
+
+ send_char_exit(code);
map->retval = code;
map->do_shutdown();
+
return true;
}
diff --git a/src/emap/atcommand.h b/src/emap/atcommand.h
index cd4cd41..95e7e75 100644
--- a/src/emap/atcommand.h
+++ b/src/emap/atcommand.h
@@ -22,5 +22,6 @@ const char* eatcommand_msgfd_pre(int *fdPtr,
ACMD2(setSkill);
ACMD2(slide);
ACMD1(mapExit);
+ACMD1(serverExit);
#endif // EVOL_MAP_ATCOMMAND
diff --git a/src/emap/init.c b/src/emap/init.c
index 33d5025..cb14450 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -94,6 +94,7 @@ HPExport void plugin_init (void)
addAtcommand("setskill", setSkill);
addAtcommand("slide", slide);
addAtcommand("mapexit", mapExit);
+ addAtcommand("serverexit", serverExit);
addScriptCommand("chatjoin", "i*", chatJoin);
addScriptCommand("setcamnpc", "*", setCamNpc);
diff --git a/src/emap/inter.c b/src/emap/inter.c
new file mode 100644
index 0000000..8f36be9
--- /dev/null
+++ b/src/emap/inter.c
@@ -0,0 +1,23 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 - 2015 Evol developers
+
+#include "common/hercules.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "common/HPMi.h"
+#include "common/memmgr.h"
+#include "common/nullpo.h"
+#include "common/socket.h"
+#include "common/strlib.h"
+#include "map/chrif.h"
+
+void send_char_exit(const int code)
+{
+ WFIFOHEAD(chrif->fd, 4);
+ WFIFOW(chrif->fd, 0) = 0x5002;
+ WFIFOW(chrif->fd, 2) = code;
+ WFIFOSET(chrif->fd, 4);
+}
diff --git a/src/emap/inter.h b/src/emap/inter.h
new file mode 100644
index 0000000..2876ee8
--- /dev/null
+++ b/src/emap/inter.h
@@ -0,0 +1,9 @@
+// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// Copyright (c) 2014 - 2015 Evol developers
+
+#ifndef EVOL_MAP_INTER
+#define EVOL_MAP_INTER
+
+void send_char_exit(const int code);
+
+#endif // EVOL_MAP_INTER