mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-07-16 00:44:46 +00:00
Refactored code, cover more private IP address ranges
This commit is contained in:
parent
4e3fdd1de8
commit
3086fd5758
3 changed files with 31 additions and 12 deletions
|
|
@ -1,12 +1,14 @@
|
||||||
# The socket bind address for all net.psforever.services except admin. 127.0.0.1 is the
|
# The socket bind address for all net.psforever.services except admin. 127.0.0.1 is the
|
||||||
# default for local testing, for public servers use 0.0.0.0 instead.
|
# default for local testing, for LAN or public servers use 0.0.0.0 instead.
|
||||||
bind = 127.0.0.1
|
bind = 127.0.0.1
|
||||||
|
|
||||||
# The public host name or IP address. Used to forward clients from the login
|
# The private host name or IP address. Used to forward clients on the local network
|
||||||
# server to the world server. The default value will only allow local connections.
|
# from the login server to the world server. The default value will only allow connections from the host machine,
|
||||||
# If you encounter issues trying to connect to the world from other machines on the same network
|
# set this to the host machines private address on the local network to allow connections from other machines on it.
|
||||||
# when this is not the default value and you have a router that lacks Hairpin NAT support, make sure
|
local = 127.0.0.1
|
||||||
# the hosts file on this system has the host name of the system set to resolve to it's local IP address on the network.
|
|
||||||
|
# The public host name or IP address. Used to forward external clients from outside the local network
|
||||||
|
# from the login server to the world server. The default value will not allow external connections.
|
||||||
public = 127.0.0.1
|
public = 127.0.0.1
|
||||||
|
|
||||||
# Login server configuration
|
# Login server configuration
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ object LoginActor {
|
||||||
|
|
||||||
final case class ReceptionistListing(listing: Receptionist.Listing) extends Command
|
final case class ReceptionistListing(listing: Receptionist.Listing) extends Command
|
||||||
|
|
||||||
|
private val gameTestServerAddressLocal = new InetSocketAddress(InetAddress.getByName(Config.app.local), Config.app.world.port)
|
||||||
|
private val gameTestServerAddressPublic = new InetSocketAddress(InetAddress.getByName(Config.app.public), Config.app.world.port)
|
||||||
|
private val localHostAddress = new InetSocketAddress("127.0.0.1", Config.app.world.port)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What does a token do?
|
* What does a token do?
|
||||||
* No one knows.
|
* No one knows.
|
||||||
|
|
@ -78,6 +82,21 @@ object LoginActor {
|
||||||
//remove color codes from the server name - look for '\\#' followed by six characters or numbers
|
//remove color codes from the server name - look for '\\#' followed by six characters or numbers
|
||||||
name.replaceAll("\\\\#[\\da-fA-F]{6}","")
|
name.replaceAll("\\\\#[\\da-fA-F]{6}","")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the appropriate host address for transfer to world server.
|
||||||
|
* This is a workaround for cases of local connections not working
|
||||||
|
* properly when using a router that lacks Hairpin NAT support.
|
||||||
|
* @param ipAddress the IP address of the connecting client in string form
|
||||||
|
* @return the appropriate host address
|
||||||
|
*/
|
||||||
|
private def selectHostAddress(ipAddress: String): InetSocketAddress = {
|
||||||
|
ipAddress.substring(0, ipAddress.indexOf(".")) match {
|
||||||
|
case "127" => localHostAddress
|
||||||
|
case "10" | "169" | "172" | "192" => gameTestServerAddressLocal
|
||||||
|
case _ => gameTestServerAddressPublic
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], connectionId: String, sessionId: Long)
|
class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], connectionId: String, sessionId: Long)
|
||||||
|
|
@ -96,8 +115,6 @@ class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], conne
|
||||||
private var port: Int = 0
|
private var port: Int = 0
|
||||||
|
|
||||||
private val serverName: String = Config.app.world.serverName
|
private val serverName: String = Config.app.world.serverName
|
||||||
private val gameTestServerAddress = new InetSocketAddress(InetAddress.getByName(Config.app.public), Config.app.world.port)
|
|
||||||
private val localHost: InetAddress = InetAddress.getLocalHost
|
|
||||||
|
|
||||||
private val bcryptRounds = 12
|
private val bcryptRounds = 12
|
||||||
|
|
||||||
|
|
@ -153,8 +170,7 @@ class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], conne
|
||||||
updateServerList()
|
updateServerList()
|
||||||
|
|
||||||
case SocketPane.NextPort(_, _, portNum) =>
|
case SocketPane.NextPort(_, _, portNum) =>
|
||||||
val address = if (ipAddress == "127.0.0.1") ipAddress else if (ipAddress.startsWith("192.168")) localHost.getHostAddress else gameTestServerAddress.getAddress.getHostAddress
|
val address = LoginActor.selectHostAddress(ipAddress).getAddress.getHostAddress
|
||||||
log.info(s"Connecting to ${address.toLowerCase}: $portNum ...")
|
|
||||||
val response = ConnectToWorldMessage(serverName, address, portNum)
|
val response = ConnectToWorldMessage(serverName, address, portNum)
|
||||||
context.become(idlingBehavior)
|
context.become(idlingBehavior)
|
||||||
middlewareActor ! MiddlewareActor.Send(response)
|
middlewareActor ! MiddlewareActor.Send(response)
|
||||||
|
|
@ -166,7 +182,7 @@ class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], conne
|
||||||
|
|
||||||
private def waitingForServerTransferBehavior: Receive = persistentSetupMixinBehavior.orElse {
|
private def waitingForServerTransferBehavior: Receive = persistentSetupMixinBehavior.orElse {
|
||||||
case SocketPane.NextPort(_, _, portNum) =>
|
case SocketPane.NextPort(_, _, portNum) =>
|
||||||
val address = if (ipAddress == "127.0.0.1") ipAddress else if (ipAddress.startsWith("192.168")) localHost.getHostAddress else gameTestServerAddress.getAddress.getHostAddress
|
val address = LoginActor.selectHostAddress(ipAddress).getAddress.getHostAddress
|
||||||
log.info(s"Connecting to ${address.toLowerCase}: $portNum ...")
|
log.info(s"Connecting to ${address.toLowerCase}: $portNum ...")
|
||||||
val response = ConnectToWorldMessage(serverName, address, portNum)
|
val response = ConnectToWorldMessage(serverName, address, portNum)
|
||||||
context.become(idlingBehavior)
|
context.become(idlingBehavior)
|
||||||
|
|
@ -499,7 +515,7 @@ class LoginActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], conne
|
||||||
serverName,
|
serverName,
|
||||||
WorldStatus.Up,
|
WorldStatus.Up,
|
||||||
Config.app.world.serverType,
|
Config.app.world.serverType,
|
||||||
Vector(WorldConnectionInfo(gameTestServerAddress)), //todo ideally, ask for info from SocketPane
|
Vector(WorldConnectionInfo(LoginActor.selectHostAddress(ipAddress))), //todo ideally, ask for info from SocketPane
|
||||||
PlanetSideEmpire.VS
|
PlanetSideEmpire.VS
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ object Config {
|
||||||
|
|
||||||
case class AppConfig(
|
case class AppConfig(
|
||||||
bind: String,
|
bind: String,
|
||||||
|
local: String,
|
||||||
public: String,
|
public: String,
|
||||||
login: LoginConfig,
|
login: LoginConfig,
|
||||||
world: WorldConfig,
|
world: WorldConfig,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue