Support loopback servers for solo play

This commit is contained in:
Paul Chote
2011-05-10 17:29:32 +12:00
parent b1a6eec3d3
commit 33a4f5e29e
6 changed files with 50 additions and 45 deletions

View File

@@ -364,16 +364,20 @@ namespace OpenRA
{
return modData.ObjectCreator.CreateObject<T>( name );
}
public static void CreateServer(Settings settings, string map)
public static void CreateServer(int port, string name, string map)
{
server = new Server.Server(modData, settings, map);
server = new Server.Server(IPAddress.Any, port, name, Settings.Game.Mods, map, modData);
}
public static void CreateAndJoinServer(Settings settings, string map)
public static void CreateLocalServer(string map)
{
CreateServer(settings, map);
JoinServer(IPAddress.Loopback.ToString(), settings.Server.ListenPort);
server = new Server.Server(IPAddress.Loopback,
Game.Settings.Server.LoopbackPort,
"Skirmish Game",
Game.Settings.Game.Mods,
map,
modData);
}
public static bool IsCurrentWorld(World world)

View File

@@ -22,8 +22,9 @@ namespace OpenRA.GameRules
public class ServerSettings
{
public string Name = "OpenRA Game";
public int ListenPort = 1234;
public int ExternalPort = 1234;
public int LoopbackPort = 1234; // Port used for soloplay servers
public int ListenPort = 1234; // Port that we listen on
public int ExternalPort = 1234; // Router port that the master server forwards people to
public bool AdvertiseOnline = true;
public string MasterServer = "http://master.open-ra.org/";
public bool AllowCheats = false;

View File

@@ -49,22 +49,21 @@ namespace OpenRA.Server
shutdown = true;
}
public Server(ModData modData, Settings settings, string map)
public Server(IPAddress ip, int port, string serverName, string[] mods, string map, ModData modData)
{
Log.AddChannel("server", "server.log");
listener = new TcpListener(IPAddress.Any, settings.Server.ListenPort);
Name = settings.Server.Name;
listener = new TcpListener(ip, port);
Name = serverName;
randomSeed = (int)DateTime.Now.ToBinary();
ModData = modData;
foreach (var trait in modData.Manifest.ServerTraits)
ServerTraits.Add( modData.ObjectCreator.CreateObject<ServerTrait>(trait) );
lobbyInfo = new Session( settings.Game.Mods );
lobbyInfo = new Session( mods );
lobbyInfo.GlobalSettings.RandomSeed = randomSeed;
lobbyInfo.GlobalSettings.Map = map;
lobbyInfo.GlobalSettings.ServerName = settings.Server.Name;
lobbyInfo.GlobalSettings.ServerName = serverName;
foreach (var t in ServerTraits.WithInterface<INotifyServerStart>())
t.ServerStarted(this);