Implement allnet host and port override

pull/1/head
akiroz 2021-12-31 00:57:32 +08:00
parent bdb3d4494d
commit b3f3e23974
No known key found for this signature in database
GPG Key ID: 8A5957C4A2F68ACC
7 changed files with 52 additions and 39 deletions

View File

@ -16,10 +16,7 @@ Requirements:
* Java 11 or above
* Optional: MariaDB or MySQL (<8.0)
1. Edit `application.properties` , change the `allnet.server.host` to your IP address or hostname.
Many games won't work with localhost and 127.0.0.1
2. Run `java -jar aqua.jar` or use the `start.bat` if you are using windows.
Run `java -jar aqua.jar` or use the `start.bat` if you are using windows.
By default, aqua will use sqlite and save user data in data/db.sqlite.
@ -30,7 +27,7 @@ Please go to the database migration tool's website to check if your database ver
### Configuration:
Configuration is save in `application.properties`
- If you are going to deploy on other machine, you must change the `allnet.server.host` and `allnet.server.port` to the IP or Hostname of the hosting machine.
- The host and port of game title servers can be overritten in `allnet.server.host` and `allnet.server.port`. By default it will send the same host and port the client used the request this information.
This will be send to the game at booting and being used by following request.
- You can switch to MySQL (or MariaDB) database by commenting the Sqlite part.

0
mvnw vendored 100644 → 100755
View File

View File

@ -31,13 +31,13 @@ public class AllNetController {
private static final Logger logger = LoggerFactory.getLogger(AllNetController.class);
private final ObjectMapper mapper = new ObjectMapper();
private final String HOST;
private final String PORT;
private final String HOST_OVERRIDE;
private final String PORT_OVERRIDE;
public AllNetController(@Value("${allnet.server.host}") String HOST,
@Value("${allnet.server.port}") String PORT) {
this.HOST = HOST;
this.PORT = PORT;
public AllNetController(@Value("${allnet.server.host:}") String HOST,
@Value("${allnet.server.port:}") String PORT) {
this.HOST_OVERRIDE = HOST;
this.PORT_OVERRIDE = PORT;
}
@GetMapping("/")
@ -121,28 +121,32 @@ public class AllNetController {
}
private String switchUri(String localAddr, String localPort, String gameId, String ver, String serial) {
String addr = HOST_OVERRIDE.equals("") ? localAddr : HOST_OVERRIDE;
String port = PORT_OVERRIDE.equals("") ? localPort : PORT_OVERRIDE;
switch (gameId) {
case "SDBT":
return "http://" + localAddr + ":" + localPort + "/ChuniServlet/" + ver + "/" + serial + "/";
return "http://" + addr + ":" + port + "/ChuniServlet/" + ver + "/" + serial + "/";
case "SBZV":
return "http://" + localAddr + ":" + localPort + "/diva/";
return "http://" + addr + ":" + port + "/diva/";
case "SDDT":
return "http://" + localAddr + ":" + localPort + "/OngekiServlet/";
return "http://" + addr + ":" + port + "/OngekiServlet/";
case "SDEY":
return "http://" + localAddr + ":" + localPort + "/MaimaiServlet/";
return "http://" + addr + ":" + port + "/MaimaiServlet/";
case "SDEZ":
return "http://" + localAddr + ":" + localPort + "/";
return "http://" + addr + ":" + port + "/";
default:
return "http://" + localAddr + ":" + localPort + "/";
return "http://" + addr + ":" + port + "/";
}
}
private String switchHost(String localAddr, String localPort, String gameId) {
String addr = HOST_OVERRIDE.equals("") ? localAddr : HOST_OVERRIDE;
String port = PORT_OVERRIDE.equals("") ? localPort : PORT_OVERRIDE;
switch (gameId) {
case "SDDF":
return localAddr + ":" + localPort + "/";
return addr + ":" + port + "/";
default:
return localAddr;
return addr;
}
}

View File

@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
/**
* @author samnyan (privateamusement@protonmail.com)
@ -77,7 +78,9 @@ public class MaimaiServletController {
}
@PostMapping("GetGameSettingApi")
public String getGameSetting(@ModelAttribute Map<String, Object> request) throws JsonProcessingException {
public String getGameSetting(@ModelAttribute Map<String, Object> request, HttpServletRequest http) throws JsonProcessingException {
request.put("localAddr", http.getLocalAddr());
request.put("localPort", Integer.toString(http.getLocalPort()));
return getGameSettingHandler.handle(request);
}

View File

@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
/**
* @author samnyan (privateamusement@protonmail.com)
@ -27,17 +28,17 @@ public class GetGameSettingHandler implements BaseHandler {
private final PropertyEntryRepository propertyEntryRepository;
private final String HOST;
private final String PORT;
private final String HOST_OVERRIDE;
private final String PORT_OVERRIDE;
@Autowired
public GetGameSettingHandler(BasicMapper mapper, PropertyEntryRepository propertyEntryRepository,
@Value("${allnet.server.host}") String HOST,
@Value("${allnet.server.port}") String PORT) {
@Value("${allnet.server.host:}") String HOST,
@Value("${allnet.server.port:}") String PORT) {
this.mapper = mapper;
this.propertyEntryRepository = propertyEntryRepository;
this.HOST = HOST;
this.PORT = PORT;
this.HOST_OVERRIDE = HOST;
this.PORT_OVERRIDE = PORT;
}
@Override
@ -48,6 +49,9 @@ public class GetGameSettingHandler implements BaseHandler {
PropertyEntry end = propertyEntryRepository.findByPropertyKey("reboot_end_time")
.orElseGet(() -> new PropertyEntry("reboot_end_time", "2020-01-01 07:59:59.0"));
String addr = HOST_OVERRIDE.equals("") ? (String) request.get("localAddr") : HOST_OVERRIDE;
String port = PORT_OVERRIDE.equals("") ? (String) request.get("localPort") : PORT_OVERRIDE;
GameSetting gameSetting = new GameSetting(
false,
1800,
@ -57,7 +61,7 @@ public class GetGameSettingHandler implements BaseHandler {
0,
"",
"",
"http://" + HOST + ":" + PORT + "/",
"http://" + addr + ":" + port + "/",
"");
GetGameSettingResp resp = new GetGameSettingResp(

View File

@ -21,19 +21,22 @@ public class AutoChecker {
private final String LINEBREAK = System.getProperty("line.separator");
private final String ALLNET_HOST;
private final String ALLNET_PORT;
private final String SERVER_PORT;
private final String ALLNET_HOST_OVERRIDE;
private final String ALLNET_PORT_OVERRIDE;
private final String AIMEDB_BIND;
private final int AIMEDB_PORT;
private final boolean AIMEDB_ENABLED;
public AutoChecker(
@Value("${allnet.server.host}") String ALLNET_HOST,
@Value("${allnet.server.port}") String ALLNET_PORT,
@Value("${server.host:}") String SERVER_PORT,
@Value("${allnet.server.host:}") String ALLNET_HOST,
@Value("${allnet.server.port:}") String ALLNET_PORT,
@Value("${aimedb.server.address}") String AIMEDB_BIND,
@Value("${aimedb.server.port}") int AIMEDB_PORT,
@Value("${aimedb.server.enable}") boolean AIMEDB_ENABLED) {
this.ALLNET_HOST = ALLNET_HOST;
this.ALLNET_PORT = ALLNET_PORT;
this.SERVER_PORT = SERVER_PORT;
this.ALLNET_HOST_OVERRIDE = ALLNET_HOST;
this.ALLNET_PORT_OVERRIDE = ALLNET_PORT;
this.AIMEDB_BIND = AIMEDB_BIND;
this.AIMEDB_PORT = AIMEDB_PORT;
this.AIMEDB_ENABLED = AIMEDB_ENABLED;
@ -71,7 +74,7 @@ public class AutoChecker {
// Check http part
System.out.print(" AllNet : ");
StringBuilder allNetSb = new StringBuilder();
if(ALLNET_HOST.equals("localhost")||ALLNET_HOST.startsWith("127.0.0.")) {
if(ALLNET_HOST_OVERRIDE.equals("localhost")||ALLNET_HOST_OVERRIDE.startsWith("127.0.0.")) {
System.out.print("WARNING!! ");
allNetSb.append("You are using loopback address.").append(LINEBREAK);
allNetSb.append("Some game won't connect with loopback address,").append(LINEBREAK);
@ -79,7 +82,9 @@ public class AutoChecker {
}
RestTemplate restTemplate = new RestTemplate();
String url = "http://" + ALLNET_HOST + ":" + ALLNET_PORT + "/sys/test";
String host = ALLNET_HOST_OVERRIDE.equals("") ? "127.0.0.1" : ALLNET_HOST_OVERRIDE;
String port = ALLNET_PORT_OVERRIDE.equals("") ? SERVER_PORT : ALLNET_PORT_OVERRIDE;
String url = "http://" + host + ":" + port + "/sys/test";
try{
ResponseEntity<String> resp = restTemplate.getForEntity(url, String.class);
if(resp.getStatusCode().is2xxSuccessful() && Objects.equals(resp.getBody(), "Server running")) {

View File

@ -2,11 +2,11 @@
aimedb.server.enable=true
aimedb.server.address=0.0.0.0
aimedb.server.port=22345
## Server host return to client when boot up.
## Server host & port return to client when boot up.
## By default the same address and port from the client connection is returned.
## Please notice DIVA won't work with localhost or 127.0.0.1
## Set this to same port to Http Server Port
allnet.server.host=localhost
allnet.server.port=80
#allnet.server.host=localhost
#allnet.server.port=80
## Http Server Port
## Only change this if you have a reverse proxy running.
## The game rely on 80 port for boot up command