diff --git a/source/src/client.cpp b/source/src/client.cpp index e4516ec8..a3654af8 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -60,7 +60,7 @@ void abortconnect() clienthost = NULL; } -void connects(char *servername, char *password) +void connects(char *servername, char *port, char *password) { if(connpeer) { @@ -71,7 +71,8 @@ void connects(char *servername, char *password) s_strcpy(clientpassword, password ? password : ""); ENetAddress address; - address.port = CUBE_SERVER_PORT; + int p = atoi(port); + address.port = p > 0 ? p : CUBE_DEFAULT_SERVER_PORT; if(servername) { @@ -188,7 +189,7 @@ void echo(char *text) { conoutf("%s", text); } COMMAND(echo, ARG_VARI); COMMANDN(say, toserver, ARG_VARI); -COMMANDN(connect, connects, ARG_2STR); +COMMANDN(connect, connects, ARG_3STR); COMMAND(connectadmin, ARG_2STR); COMMAND(lanconnect, ARG_NONE); COMMANDN(disconnect, trydisconnect, ARG_NONE); diff --git a/source/src/main.cpp b/source/src/main.cpp index f72648d5..eb9a2188 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -209,7 +209,7 @@ VARF(gamespeed, 10, 100, 1000, if(multiplayer()) gamespeed = 100); int main(int argc, char **argv) { bool dedicated = false; - int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = DEFAULTCLIENTS, scthreshold = -5; + int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = DEFAULTCLIENTS, scthreshold = -5, port = 0; char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = NULL, *adminpwd = NULL, *srvmsg = NULL; #define initlog(s) puts("init: " s) @@ -253,6 +253,7 @@ int main(int argc, char **argv) case 'c': maxcl = atoi(a); break; case 'o': srvmsg = a; break; case 'k': scthreshold = atoi(a); break; + case 'f': port = atoi(a); break; default: conoutf("unknown commandline option"); } else conoutf("unknown commandline argument"); @@ -270,7 +271,7 @@ int main(int argc, char **argv) if(enet_initialize()<0) fatal("Unable to initialise network module"); initclient(); - initserver(dedicated, uprate, sdesc, ip, master, passwd, maxcl, maprot, adminpwd, srvmsg, scthreshold); // never returns if dedicated + initserver(dedicated, uprate, sdesc, ip, port, master, passwd, maxcl, maprot, adminpwd, srvmsg, scthreshold); // never returns if dedicated initlog("world"); empty_world(7, true); diff --git a/source/src/protocol.h b/source/src/protocol.h index 442db845..b9d0e8ff 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -1,7 +1,7 @@ #define MAXCLIENTS 256 // in a multiplayer game, can be arbitrarily changed #define DEFAULTCLIENTS 6 #define MAXTRANS 5000 // max amount of data to swallow in 1 go -#define CUBE_SERVER_PORT 28763 +#define CUBE_DEFAULT_SERVER_PORT 28763 #define CUBE_SERVINFO_PORT 28764 #define PROTOCOL_VERSION 1126 // bump when protocol changes diff --git a/source/src/protos.h b/source/src/protos.h index 1e6c6746..34e6b587 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -105,7 +105,7 @@ extern void renderstripssky(); extern void renderstrips(); // client -extern void connects(char *servername, char *password = NULL); +extern void connects(char *servername, char *port = NULL, char *password = NULL); extern void abortconnect(); extern void disconnect(int onlyclean = 0, int async = 0); extern void toserver(char *text); @@ -357,7 +357,7 @@ extern void scrolldoc(int i); extern void localservertoclient(int chan, uchar *buf, int len); extern const char *modestr(int n); extern void fatal(char *s, char *o = ""); -extern void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, char *passwd, int maxcl, char *maprot, char *adminpwd, char *srvmsg, int scthreshold); +extern void initserver(bool dedicated, int uprate, char *sdesc, char *ip, int port, char *master, char *passwd, int maxcl, char *maprot, char *adminpwd, char *srvmsg, int scthreshold); extern void cleanupserver(); extern void localconnect(); extern void localdisconnect(); diff --git a/source/src/server.cpp b/source/src/server.cpp index aedc55d2..684c5b58 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -1795,7 +1795,7 @@ void localconnect() } #endif -void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, char *passwd, int maxcl, char *maprot, char *adminpwd, char *srvmsg, int scthreshold) +void initserver(bool dedicated, int uprate, char *sdesc, char *ip, int port, char *master, char *passwd, int maxcl, char *maprot, char *adminpwd, char *srvmsg, int scthreshold) { if(passwd) s_strcpy(serverpassword, passwd); maxclients = maxcl > 0 ? min(maxcl, MAXCLIENTS) : DEFAULTCLIENTS; @@ -1803,7 +1803,7 @@ void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, if(isdedicated = dedicated) { - ENetAddress address = { ENET_HOST_ANY, CUBE_SERVER_PORT }; + ENetAddress address = { ENET_HOST_ANY, port > 0 ? port : CUBE_DEFAULT_SERVER_PORT }; if(*ip && enet_address_set_host(&address, ip)<0) printf("WARNING: server ip not resolved"); serverhost = enet_host_create(&address, maxclients+1, 0, uprate); if(!serverhost) fatal("could not create server host\n"); @@ -1836,7 +1836,7 @@ void fatal(char *s, char *o) { cleanupserver(); printf("fatal: %s\n", s); exit(E int main(int argc, char **argv) { - int uprate = 0, maxcl = DEFAULTCLIENTS, scthreshold = -5; + int uprate = 0, maxcl = DEFAULTCLIENTS, scthreshold = -5, port = 0; char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = "", *adminpasswd = NULL, *srvmsg = NULL; bool service = false; @@ -1856,6 +1856,7 @@ int main(int argc, char **argv) case 'o': srvmsg = a; break; case 'k': scthreshold = atoi(a); break; case 's': service = true; break; + case 'f': port = atoi(a); break; default: printf("WARNING: unknown commandline option\n"); } } @@ -1873,7 +1874,7 @@ int main(int argc, char **argv) } if(enet_initialize()<0) fatal("Unable to initialise network module"); - initserver(true, uprate, sdesc, ip, master, passwd, maxcl, maprot, adminpasswd, srvmsg, scthreshold); + initserver(true, uprate, sdesc, ip, port, master, passwd, maxcl, maprot, adminpasswd, srvmsg, scthreshold); return EXIT_SUCCESS; } #endif