global settings in lobbyinfo; map change uses it.

This commit is contained in:
Chris Forbes
2010-01-16 11:14:35 +13:00
parent acd5470ce1
commit 705954ebca
5 changed files with 38 additions and 15 deletions

View File

@@ -22,6 +22,7 @@ namespace OpenRA.Server
listener.Start(); listener.Start();
Console.WriteLine("Server started."); Console.WriteLine("Server started.");
Console.WriteLine("Testing.");
for (; ; ) for (; ; )
{ {
@@ -282,8 +283,8 @@ namespace OpenRA.Server
return true; return true;
} }
DispatchOrders( null, 0, lobbyInfo.GlobalSettings.Map = s;
new ServerOrder(0, "ChangeMap", s).Serialize()); SyncLobbyInfo();
return true; return true;
}}, }},
}; };
@@ -379,10 +380,12 @@ namespace OpenRA.Server
{ {
var clientData = lobbyInfo.Clients.ToDictionary( var clientData = lobbyInfo.Clients.ToDictionary(
a => a.Index.ToString(), a => a.Index.ToString(),
a => FieldSaver.Save(a)).WriteToString(); a => FieldSaver.Save(a));
clientData["GlobalSettings"] = FieldSaver.Save(lobbyInfo.GlobalSettings);
DispatchOrders(null, 0, DispatchOrders(null, 0,
new ServerOrder(0, "SyncInfo", clientData).Serialize()); new ServerOrder(0, "SyncInfo", clientData.WriteToString()).Serialize());
} }
} }
} }

View File

@@ -22,12 +22,13 @@ namespace OpenRa.FileFormats
var field = self.GetType().GetField(x.Key.Trim()); var field = self.GetType().GetField(x.Key.Trim());
if (field == null) if (field == null)
throw new NotImplementedException("Missing field `{0}` on `{1}`".F(x.Key.Trim(), self.GetType().Name)); throw new NotImplementedException("Missing field `{0}` on `{1}`".F(x.Key.Trim(), self.GetType().Name));
field.SetValue(self, GetValue(field.FieldType, x.Value.Value.Trim())); field.SetValue(self, GetValue(field.FieldType, x.Value.Value));
} }
} }
static object GetValue( Type fieldType, string x ) static object GetValue( Type fieldType, string x )
{ {
if (x != null) x = x.Trim();
if( fieldType == typeof( int ) ) if( fieldType == typeof( int ) )
return int.Parse( x ); return int.Parse( x );
@@ -45,6 +46,9 @@ namespace OpenRa.FileFormats
else if (fieldType.IsArray) else if (fieldType.IsArray)
{ {
if (x == null)
return Array.CreateInstance(fieldType.GetElementType(), 0);
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var ret = Array.CreateInstance(fieldType.GetElementType(), parts.Length); var ret = Array.CreateInstance(fieldType.GetElementType(), parts.Length);

View File

@@ -8,13 +8,12 @@ namespace OpenRa.FileFormats
public class Session public class Session
{ {
public List<Client> Clients = new List<Client>(); public List<Client> Clients = new List<Client>();
// todo: add mods, mapname, global settings here public Global GlobalSettings = new Global();
public enum ClientState public enum ClientState
{ {
NotReady, NotReady,
// Downloading, Downloading,
// Uploading,
Ready Ready
} }
@@ -27,5 +26,12 @@ namespace OpenRa.FileFormats
public string Name; public string Name;
public ClientState State; public ClientState State;
} }
public class Global
{
public string Map = "scm12ea.ini";
public string[] Mods = {}; // filename:sha1 pairs.
public int OrderLatency;
}
} }
} }

View File

@@ -48,12 +48,14 @@ namespace OpenRa.Game
static bool usingAftermath; static bool usingAftermath;
static int2 clientSize; static int2 clientSize;
static HardwarePalette palette; static HardwarePalette palette;
static string mapName;
public static Minimap minimap; public static Minimap minimap;
public static Session LobbyInfo = new Session(); public static Session LobbyInfo = new Session();
public static void ChangeMap(string mapName) public static void ChangeMap(string mapName)
{ {
Game.mapName = mapName;
SheetBuilder.Initialize(renderer); SheetBuilder.Initialize(renderer);
SpriteSheetBuilder.Initialize(); SpriteSheetBuilder.Initialize();
FileSystem.UnmountTemporaryPackages(); FileSystem.UnmountTemporaryPackages();
@@ -352,6 +354,12 @@ namespace OpenRa.Game
var ys = MiniYaml.FromString(data); var ys = MiniYaml.FromString(data);
foreach (var y in ys) foreach (var y in ys)
{ {
if (y.Key == "GlobalSettings")
{
FieldLoader.Load(session.GlobalSettings, y.Value);
continue;
}
int index; int index;
if (!int.TryParse(y.Key, out index)) if (!int.TryParse(y.Key, out index))
continue; // not a player. continue; // not a player.
@@ -364,6 +372,14 @@ namespace OpenRa.Game
} }
LobbyInfo = session; LobbyInfo = session;
// todo: if we don't have all the resources, we don't want to do this yet.
if (mapName != LobbyInfo.GlobalSettings.Map)
{
chat.AddLine(Color.White, "Debug", "Map change {0} -> {1}".F(mapName, session.GlobalSettings.Map));
ChangeMap(LobbyInfo.GlobalSettings.Map);
}
} }
} }
} }

View File

@@ -68,12 +68,6 @@ namespace OpenRa.Game.Orders
Game.orderManager.StartGame(); Game.orderManager.StartGame();
break; break;
} }
case "ChangeMap":
{
Game.chat.AddLine(Color.White, "Server", "Changing map to {0}".F(order.TargetString));
Game.ChangeMap(order.TargetString);
break;
}
case "SyncInfo": case "SyncInfo":
{ {
// Game.chat.AddLine(Color.White, "Server", "Synchronizing lobby info..."); // Game.chat.AddLine(Color.White, "Server", "Synchronizing lobby info...");