-
-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from Frederikam/feature/close-events
Release v3.1
- Loading branch information
Showing
21 changed files
with
333 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 20 additions & 22 deletions
42
LavalinkServer/src/main/java/lavalink/server/config/WebsocketConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
package lavalink.server.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
import lavalink.server.io.HandshakeInterceptorImpl; | ||
import lavalink.server.io.SocketServer; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocket; | ||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; | ||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; | ||
|
||
/** | ||
* Created by napster on 05.03.18. | ||
*/ | ||
@ConfigurationProperties(prefix = "lavalink.server.ws") | ||
@Component | ||
public class WebsocketConfig { | ||
@Configuration | ||
@EnableWebSocket | ||
public class WebsocketConfig implements WebSocketConfigurer { | ||
|
||
private int port = 80; | ||
private String host = "0.0.0.0"; | ||
private final SocketServer server; | ||
private final HandshakeInterceptorImpl handshakeInterceptor; | ||
|
||
public int getPort() { | ||
return port; | ||
@Autowired | ||
public WebsocketConfig(SocketServer server, HandshakeInterceptorImpl handshakeInterceptor) { | ||
this.server = server; | ||
this.handshakeInterceptor = handshakeInterceptor; | ||
} | ||
|
||
public void setPort(int port) { | ||
this.port = port; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public void setHost(String host) { | ||
this.host = host; | ||
@Override | ||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { | ||
registry.addHandler(server, "/") | ||
.addInterceptors(handshakeInterceptor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
LavalinkServer/src/main/java/lavalink/server/io/ConnectionManagerImpl.java
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
LavalinkServer/src/main/java/lavalink/server/io/CoreClientImpl.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
LavalinkServer/src/main/java/lavalink/server/io/HandshakeInterceptorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package lavalink.server.io; | ||
|
||
import lavalink.server.config.ServerConfig; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.server.ServerHttpRequest; | ||
import org.springframework.http.server.ServerHttpResponse; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.socket.WebSocketHandler; | ||
import org.springframework.web.socket.server.HandshakeInterceptor; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
@Controller | ||
public class HandshakeInterceptorImpl implements HandshakeInterceptor { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(HandshakeInterceptorImpl.class); | ||
private final ServerConfig serverConfig; | ||
|
||
@Autowired | ||
public HandshakeInterceptorImpl(ServerConfig serverConfig) { | ||
this.serverConfig = serverConfig; | ||
} | ||
|
||
/** | ||
* Checks credentials and sets the Lavalink version header | ||
* | ||
* @return true if authenticated | ||
*/ | ||
@Override | ||
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, | ||
Map<String, Object> attributes) { | ||
response.getHeaders().add("Lavalink-Major-Version", "3"); | ||
|
||
String password = request.getHeaders().getFirst("Authorization"); | ||
boolean matches = Objects.equals(password, serverConfig.getPassword()); | ||
|
||
if (matches) { | ||
log.info("Incoming connection from " + request.getRemoteAddress()); | ||
} else { | ||
log.error("Authentication failed from " + request.getRemoteAddress()); | ||
} | ||
|
||
return matches; | ||
} | ||
|
||
// No action required | ||
@Override | ||
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, | ||
Exception exception) {} | ||
} |
Oops, something went wrong.