Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
8afcc0b8
Commit
8afcc0b8
authored
Apr 23, 2022
by
KingRainbow44
Browse files
Add message for bind failure (HTTP)
parent
a957379a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/netty/MihoyoKcpServer.java
View file @
8afcc0b8
...
...
@@ -64,9 +64,8 @@ public class MihoyoKcpServer extends Thread {
// Wait until the server socket is closed.
f
.
channel
().
closeFuture
().
sync
();
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
Exception
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Unable to start game server."
,
exception
);
}
finally
{
// Close
finish
();
...
...
src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java
View file @
8afcc0b8
...
...
@@ -24,6 +24,7 @@ import emu.grasscutter.utils.Utils;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.SSLContext
;
import
java.io.*
;
import
java.net.BindException
;
import
java.net.InetSocketAddress
;
import
java.net.URI
;
import
java.net.URLDecoder
;
...
...
@@ -158,12 +159,21 @@ public final class DispatchServer {
Grasscutter
.
getLogger
().
error
(
"[Dispatch] Error while initializing region info!"
,
e
);
}
}
private
HttpServer
safelyCreateServer
(
InetSocketAddress
address
)
{
try
{
return
HttpServer
.
create
(
address
,
0
);
}
catch
(
BindException
ignored
)
{
Grasscutter
.
getLogger
().
error
(
"Unable to bind to port: "
+
getAddress
().
getPort
()
+
" (HTTP)"
);
}
catch
(
Exception
exception
)
{
Grasscutter
.
getLogger
().
error
(
"Unable to start HTTP server."
,
exception
);
}
return
null
;
}
public
void
start
()
throws
Exception
{
HttpServer
server
;
if
(
Grasscutter
.
getConfig
().
getDispatchOptions
().
UseSSL
)
{
HttpsServer
httpsServer
;
httpsServer
=
HttpsServer
.
create
(
getAddress
(),
0
);
HttpsServer
httpsServer
=
HttpsServer
.
create
(
getAddress
(),
0
);
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"TLS"
);
try
(
FileInputStream
fis
=
new
FileInputStream
(
Grasscutter
.
getConfig
().
getDispatchOptions
().
KeystorePath
))
{
char
[]
keystorePassword
=
Grasscutter
.
getConfig
().
getDispatchOptions
().
KeystorePassword
.
toCharArray
();
...
...
@@ -176,14 +186,20 @@ public final class DispatchServer {
httpsServer
.
setHttpsConfigurator
(
new
HttpsConfigurator
(
sslContext
));
server
=
httpsServer
;
}
catch
(
BindException
ignored
)
{
Grasscutter
.
getLogger
().
error
(
"Unable to bind to port: "
+
getAddress
().
getPort
()
+
" (HTTPS)"
);
server
=
this
.
safelyCreateServer
(
this
.
getAddress
());
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
warn
(
"[Dispatch] No SSL cert found! Falling back to HTTP server."
);
Grasscutter
.
getConfig
().
getDispatchOptions
().
UseSSL
=
false
;
server
=
HttpServer
.
create
(
getAddress
()
,
0
);
server
=
this
.
safelyCreateServer
(
this
.
getAddress
());
}
}
else
{
server
=
HttpServer
.
create
(
getAddress
()
,
0
);
server
=
this
.
safelyCreateServer
(
this
.
getAddress
());
}
if
(
server
==
null
)
throw
new
NullPointerException
(
"An HTTP server was not created."
);
server
.
createContext
(
"/"
,
t
->
responseHTML
(
t
,
"Hello"
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment