(listen_addr): New econfig key.
(player_init): Implement it. (player_init): Support service name in econfig key loginport. Service empire no longer takes precedence over econfig. Closes #797096.
This commit is contained in:
parent
d253e1266f
commit
1580b1f734
3 changed files with 26 additions and 8 deletions
|
@ -58,6 +58,8 @@ EMPCFBOTH("data", datadir, char *, NSC_STRING, KM_INTERNAL,
|
||||||
"Directory the data is stored in")
|
"Directory the data is stored in")
|
||||||
EMPCFBOTH("info", infodir, char *, NSC_STRING, KM_INTERNAL,
|
EMPCFBOTH("info", infodir, char *, NSC_STRING, KM_INTERNAL,
|
||||||
"Directory the info pages are stored in")
|
"Directory the info pages are stored in")
|
||||||
|
EMPCFBOTH("listen_addr", listen_addr, char *, NSC_STRING, KM_INTERNAL,
|
||||||
|
"Local address the server should listen on. \"\" listens on all.")
|
||||||
EMPCFBOTH("port", loginport, char *, NSC_STRING, KM_INTERNAL,
|
EMPCFBOTH("port", loginport, char *, NSC_STRING, KM_INTERNAL,
|
||||||
"TCP/IP port the server will start up on")
|
"TCP/IP port the server will start up on")
|
||||||
EMPCFBOTH("privname", privname, char *, NSC_STRING, 0,
|
EMPCFBOTH("privname", privname, char *, NSC_STRING, 0,
|
||||||
|
|
|
@ -50,4 +50,5 @@ char *banfil = "ban";
|
||||||
char *authfil = "auth";
|
char *authfil = "auth";
|
||||||
char *timestampfil = "timestamp";
|
char *timestampfil = "timestamp";
|
||||||
|
|
||||||
|
char *listen_addr = "";
|
||||||
char *loginport = EMP_PORT;
|
char *loginport = EMP_PORT;
|
||||||
|
|
|
@ -71,22 +71,37 @@ void
|
||||||
player_init(void)
|
player_init(void)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
struct hostent *hp;
|
||||||
struct servent *sp;
|
struct servent *sp;
|
||||||
int s;
|
int s;
|
||||||
short port;
|
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
emp_initque(&Players);
|
emp_initque(&Players);
|
||||||
init_player_commands();
|
init_player_commands();
|
||||||
|
|
||||||
sp = getservbyname("empire", "tcp");
|
|
||||||
if (sp == 0)
|
|
||||||
port = htons(atoi(loginport));
|
|
||||||
else
|
|
||||||
port = sp->s_port;
|
|
||||||
sin.sin_addr.s_addr = INADDR_ANY;
|
|
||||||
sin.sin_port = port;
|
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
|
if (!*listen_addr)
|
||||||
|
sin.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
else if (isdigit(*listen_addr))
|
||||||
|
sin.sin_addr.s_addr = inet_addr(listen_addr);
|
||||||
|
else {
|
||||||
|
hp = gethostbyname(listen_addr);
|
||||||
|
if (!hp) {
|
||||||
|
logerror("Can't resolve listen address %s", listen_addr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
|
||||||
|
}
|
||||||
|
if (isdigit(*loginport))
|
||||||
|
sin.sin_port = htons(atoi(loginport));
|
||||||
|
else {
|
||||||
|
sp = getservbyname(loginport, "tcp");
|
||||||
|
if (!sp) {
|
||||||
|
logerror("Can't resolve service %s", loginport);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
sin.sin_port = sp->s_port;
|
||||||
|
}
|
||||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
logerror("inet socket create");
|
logerror("inet socket create");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue