summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcelest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-04-05 14:32:04 +0000
committercelest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-04-05 14:32:04 +0000
commit573c40f53e1d0fe29c72117fc4ca2d931b274d8c (patch)
tree1c8afefbc96da8878fc94bfc3edd32486b80875f /src
parent6acbd82fb5b77315853f42a9a31b7439a7e58bb9 (diff)
downloadhercules-573c40f53e1d0fe29c72117fc4ca2d931b274d8c.tar.gz
hercules-573c40f53e1d0fe29c72117fc4ca2d931b274d8c.tar.bz2
hercules-573c40f53e1d0fe29c72117fc4ca2d931b274d8c.tar.xz
hercules-573c40f53e1d0fe29c72117fc4ca2d931b274d8c.zip
* Added SERVER_TYPE to core for future plugins support
* Added support for the UPNP plugin to release port mappings and re-close firewall ports on shutdown * Updated showmsg git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1409 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/common/core.c42
-rw-r--r--src/common/core.h10
-rw-r--r--src/common/showmsg.c64
-rw-r--r--src/common/showmsg.h13
-rw-r--r--src/common/socket.c34
5 files changed, 104 insertions, 59 deletions
diff --git a/src/common/core.c b/src/common/core.c
index b325b96e4..0a9e76120 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -14,20 +14,21 @@
#endif
#endif
-#include "../common/mmo.h"
-#include "malloc.h"
#include "core.h"
-#include "socket.h"
-#include "timer.h"
-#include "version.h"
-#include "showmsg.h"
+#include "../common/mmo.h"
+#include "../common/malloc.h"
+#include "../common/socket.h"
+#include "../common/timer.h"
+#include "../common/version.h"
+#include "../common/showmsg.h"
#ifdef MEMWATCH
#include "memwatch.h"
#endif
-char server_type[24];
+char *argp;
int runflag = 1;
+char SERVER_TYPE = SERVER_NONE;
unsigned long ticks = 0; // by MC Cameri
char pid_file[256];
static void (*term_func)(void)=NULL;
@@ -132,7 +133,7 @@ void sig_dump(int sn)
// search for a usable filename
do {
- sprintf (file, "log/%s%04d.stackdump", server_type, ++no);
+ sprintf (file, "log/%s%04d.stackdump", argp, ++no);
} while((fp = fopen(file,"r")) && (fclose(fp), no < 9999));
// dump the trace into the file
@@ -171,12 +172,13 @@ int get_svn_revision(char *svnentry) { // Warning: minor syntax checking
if ((fp = fopen(svnentry, "r")) == NULL) {
return 0;
} else {
- while (fgets(line,1023,fp)) if (strstr(line,"revision=")) break;
+ while (fgets(line,1023,fp))
+ if (strstr(line,"revision=")) break;
fclose(fp);
- if (sscanf(line," %*[^\"]\"%d%*[^\n]",&rev)==1)
- return rev;
+ if (sscanf(line," %*[^\"]\"%d%*[^\n]",&rev) == 1)
+ return rev;
else
- return 0;
+ return 0;
}
// return 0;
}
@@ -273,7 +275,7 @@ void log_uptime(void)
seconds -= (seconds/minute>0)?(seconds/minute)*minute:0;
fprintf(fp, "%s: %s uptime - %ld days, %ld hours, %ld minutes, %ld seconds.\n",
- curtime2, server_type, days, hours, minutes, seconds);
+ curtime2, argp, days, hours, minutes, seconds);
fclose(fp);
}
@@ -285,14 +287,15 @@ int main(int argc,char **argv)
{
int next;
- display_title();
- // call this first so it'll be finalised last
- do_init_memmgr(argv[0]); // 一番最初に実行する必要がある
+ if ((argp = strstr(argv[0], "./")) != NULL)
+ argp+=2;
+ else argp = argv[0];
- sscanf(argv[0], "./%24[^\n]", server_type); // map/char/login?
- atexit(log_uptime);
- pid_create(argv[0]);
+ display_title();
+ do_init_memmgr(argp); // 一番最初に実行する必要がある
+ atexit(log_uptime);
+ pid_create(argp);
Net_Init();
do_socket();
@@ -313,6 +316,7 @@ int main(int argc,char **argv)
ticks = gettick();
do_init(argc,argv);
+
while(runflag){
next=do_timer(gettick_nocache());
do_sendrecv(next);
diff --git a/src/common/core.h b/src/common/core.h
index 23431f297..e9b5c8227 100644
--- a/src/common/core.h
+++ b/src/common/core.h
@@ -3,11 +3,19 @@
#ifndef _CORE_H_
#define _CORE_H_
+extern char *argp;
extern int runflag;
extern unsigned long ticks;
+extern char SERVER_TYPE;
-int do_init(int,char**);
+enum {
+ SERVER_NONE,
+ SERVER_LOGIN,
+ SERVER_CHAR,
+ SERVER_MAP,
+};
+int do_init(int,char**);
void set_termfunc(void (*termfunc)(void));
#endif // _CORE_H_
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index 9901af81b..24d51d2dc 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -5,15 +5,12 @@
char tmp_output[1024] = {"\0"};
-#undef ShowMessage
-
// by MC Cameri
int _vShowMessage(enum msg_type flag, const char *string, va_list ap)
{
// _ShowMessage MUST be used instead of printf as of 10/24/2004.
// Return: 0 = Successful, 1 = Failed.
// int ret = 0;
-// char *output;
char prefix[40];
if (!string || strlen(string) <= 0) {
@@ -21,6 +18,8 @@ int _vShowMessage(enum msg_type flag, const char *string, va_list ap)
return 1;
}
switch (flag) {
+ case MSG_NONE: // direct printf replacement
+ break;
case MSG_STATUS: //Bright Green (To inform about good things)
strcpy(prefix,CL_GREEN"[Status]"CL_RESET":");
break;
@@ -49,22 +48,10 @@ int _vShowMessage(enum msg_type flag, const char *string, va_list ap)
printf("In function _ShowMessage() -> Invalid flag passed.\n");
return 1;
}
- if (!(flag == MSG_DEBUG && !SHOW_DEBUG_MSG)) {
-
-/* output = (char*)aMalloc(sizeof(char)*(strlen(prefix)+strlen(string)+2)); // prefix+string+two chars(space and \0)
- if (output == NULL) {
- return 1;
-// exit(1); // Kill server? Deadly
- }
- strcpy(output,prefix);
- strcat(output," ");
- strcat(output,string);
- vprintf(output, ap);
- fflush(stdout);
- aFree(output);*/
-
- printf ("%s ", prefix);
+ if (!(flag == MSG_DEBUG && !SHOW_DEBUG_MSG)) {
+ if (flag != MSG_NONE)
+ printf ("%s ", prefix);
vprintf (string, ap);
fflush (stdout);
}
@@ -96,51 +83,58 @@ int _ShowMessage(enum msg_type flag, const char *string, ...)
return _vShowMessage(flag, string, ap);
}
+// direct printf replacement
+int ShowMessage(const char *string, ...) {
+ va_list ap;
+
+ va_start(ap, string);
+ return _vShowMessage(MSG_NONE, string, ap);
+}
int ShowStatus(const char *string, ...) {
- va_list ap;
+ va_list ap;
va_start(ap, string);
- return _vShowMessage(MSG_STATUS, string, ap);
+ return _vShowMessage(MSG_STATUS, string, ap);
}
int ShowSQL(const char *string, ...) {
- va_list ap;
+ va_list ap;
va_start(ap, string);
- return _vShowMessage(MSG_SQL, string, ap);
+ return _vShowMessage(MSG_SQL, string, ap);
}
int ShowInfo(const char *string, ...) {
- va_list ap;
+ va_list ap;
va_start(ap, string);
- return _vShowMessage(MSG_INFORMATION, string, ap);
+ return _vShowMessage(MSG_INFORMATION, string, ap);
}
int ShowNotice(const char *string, ...) {
- va_list ap;
+ va_list ap;
va_start(ap, string);
- return _vShowMessage(MSG_NOTICE, string, ap);
+ return _vShowMessage(MSG_NOTICE, string, ap);
}
int ShowWarning(const char *string, ...) {
- va_list ap;
+ va_list ap;
va_start(ap, string);
- return _vShowMessage(MSG_WARNING, string, ap);
+ return _vShowMessage(MSG_WARNING, string, ap);
}
int ShowDebug(const char *string, ...) {
- va_list ap;
+ va_list ap;
va_start(ap, string);
- return _vShowMessage(MSG_DEBUG, string, ap);
+ return _vShowMessage(MSG_DEBUG, string, ap);
}
int ShowError(const char *string, ...) {
- va_list ap;
+ va_list ap;
va_start(ap, string);
- return _vShowMessage(MSG_ERROR, string, ap);
+ return _vShowMessage(MSG_ERROR, string, ap);
}
int ShowFatalError(const char *string, ...) {
- va_list ap;
-
+ va_list ap;
+
va_start(ap, string);
- return _vShowMessage(MSG_FATALERROR, string, ap);
+ return _vShowMessage(MSG_FATALERROR, string, ap);
}
diff --git a/src/common/showmsg.h b/src/common/showmsg.h
index 3461369c3..b5f4d4bfd 100644
--- a/src/common/showmsg.h
+++ b/src/common/showmsg.h
@@ -32,8 +32,19 @@
extern char tmp_output[1024];
-enum msg_type {MSG_STATUS, MSG_SQL, MSG_INFORMATION,MSG_NOTICE,MSG_WARNING,MSG_DEBUG,MSG_ERROR,MSG_FATALERROR};
+enum msg_type {
+ MSG_NONE,
+ MSG_STATUS,
+ MSG_SQL,
+ MSG_INFORMATION,
+ MSG_NOTICE,
+ MSG_WARNING,
+ MSG_DEBUG,
+ MSG_ERROR,
+ MSG_FATALERROR
+};
+extern int ShowMessage(const char *, ...);
extern int ShowStatus(const char *, ...);
extern int ShowSQL(const char *, ...);
extern int ShowInfo(const char *, ...);
diff --git a/src/common/socket.c b/src/common/socket.c
index 2daf00764..64f660a11 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -54,7 +54,10 @@ int (*upnp_init)();
int (*upnp_final)();
int (*firewall_addport)(char *desc, int port);
int (*upnp_addport)(char *desc, char *ip, int port);
-extern char server_type[24];
+extern char *argp;
+
+int release_mappings = 1;
+int close_ports = 1;
#else
#error This doesnt work with non-Windows yet
#endif
@@ -327,10 +330,10 @@ int make_listen_bind(long ip,int port)
char buf[16];
sprintf(buf, "%d.%d.%d.%d", natip[0], natip[1], natip[2], natip[3]);
//printf("natip=%d.%d.%d.%d\n", natip[0], natip[1], natip[2], natip[3]);
- if (firewall_addport(server_type, port))
+ if (firewall_addport(argp, port))
printf ("Firewall port %d successfully opened\n", port);
if (natip[0] == 192 && natip[1] == 168) {
- if (upnp_addport(server_type, natip, port))
+ if (upnp_addport(argp, natip, port))
printf ("Upnp mappings successfull\n");
else printf ("Upnp mapping failed\n");
}
@@ -845,6 +848,20 @@ int socket_config_read(const char *cfgName) {
else if(strcmpi(w2,"no")==0)
access_debug = 0;
else access_debug = atoi(w2);
+ #ifdef UPNP
+ } else if(!strcmpi(w1,"release_mappings")){
+ if(strcmpi(w2,"yes")==0)
+ release_mappings = 1;
+ else if(strcmpi(w2,"no")==0)
+ release_mappings = 0;
+ else release_mappings = atoi(w2);
+ } else if(!strcmpi(w1,"close_ports")){
+ if(strcmpi(w2,"yes")==0)
+ close_ports = 1;
+ else if(strcmpi(w2,"no")==0)
+ close_ports = 0;
+ else close_ports = atoi(w2);
+ #endif
} else if (strcmpi(w1, "import") == 0)
socket_config_read(w2);
}
@@ -957,6 +974,9 @@ int Net_Init(void)
// not implemented yet ^^;
void do_init_upnp(void)
{
+ int *_release_mappings;
+ int *_close_ports;
+
upnp_dll = DLL_OPEN ("upnp.dll");
if (!upnp_dll) {
printf ("Cannot open upnp.dll: %s\n", dlerror());
@@ -972,6 +992,14 @@ void do_init_upnp(void)
upnp_dll = NULL;
return;
}
+
+ DLL_SYM (_release_mappings, upnp_dll, "release_mappings");
+ DLL_SYM (_close_ports, upnp_dll, "close_ports");
+ if (release_mappings && _release_mappings)
+ *_release_mappings = release_mappings;
+ if (close_ports && _close_ports)
+ *_close_ports = close_ports;
+
if (upnp_init() == 0) {
printf ("Error initialising upnp.dll, unloading...\n");
DLL_CLOSE (upnp_dll);