beautify starting unit notification when joining server

move LobbySettingsNotification into it's own ServerTrait
This commit is contained in:
Matthias Mailänder
2014-08-16 17:43:54 +02:00
parent 24a3fd3196
commit fa2b2bea0b
7 changed files with 65 additions and 37 deletions

View File

@@ -336,10 +336,6 @@ namespace OpenRA.Server
// Send initial ping
SendOrderTo(newConn, "Ping", Game.RunTime.ToString());
// Send Lobby info to newly connected client
if (!client.IsAdmin)
NotifyNewClientOfLobbyInfo(newConn);
if (Settings.Dedicated)
{
var motdFile = Path.Combine(Platform.SupportDir, "motd.txt");
@@ -359,39 +355,6 @@ namespace OpenRA.Server
catch (Exception) { DropClient(newConn); }
}
void NotifyNewClientOfLobbyInfo(Connection newConn)
{
var defaults = new Session.Global();
FieldLoader.Load(defaults, Game.modData.Manifest.LobbyDefaults);
if (LobbyInfo.GlobalSettings.FragileAlliances != defaults.FragileAlliances)
SendOrderTo(newConn, "Message", "Diplomacy Changes: {0}".F(LobbyInfo.GlobalSettings.FragileAlliances));
if (LobbyInfo.GlobalSettings.AllowCheats != defaults.AllowCheats)
SendOrderTo(newConn, "Message", "Allow Cheats: {0}".F(LobbyInfo.GlobalSettings.AllowCheats));
if (LobbyInfo.GlobalSettings.Shroud != defaults.Shroud)
SendOrderTo(newConn, "Message", "Shroud: {0}".F(LobbyInfo.GlobalSettings.Shroud));
if (LobbyInfo.GlobalSettings.Fog != defaults.Fog)
SendOrderTo(newConn, "Message", "Fog of war: {0}".F(LobbyInfo.GlobalSettings.Fog));
if (LobbyInfo.GlobalSettings.Crates != defaults.Crates)
SendOrderTo(newConn, "Message", "Crates Appear: {0}".F(LobbyInfo.GlobalSettings.Crates));
if (LobbyInfo.GlobalSettings.AllyBuildRadius != defaults.AllyBuildRadius)
SendOrderTo(newConn, "Message", "Build off Ally ConYards: {0}".F(LobbyInfo.GlobalSettings.AllyBuildRadius));
if (LobbyInfo.GlobalSettings.StartingUnitsClass != defaults.StartingUnitsClass)
SendOrderTo(newConn, "Message", "Starting Units: {0}".F(LobbyInfo.GlobalSettings.StartingUnitsClass));
if (LobbyInfo.GlobalSettings.StartingCash != defaults.StartingCash)
SendOrderTo(newConn, "Message", "Starting Cash: ${0}".F(LobbyInfo.GlobalSettings.StartingCash));
if (LobbyInfo.GlobalSettings.TechLevel != defaults.TechLevel)
SendOrderTo(newConn, "Message", "Tech Level: {0}".F(LobbyInfo.GlobalSettings.TechLevel));
}
void SetOrderLag()
{
if (LobbyInfo.IsSinglePlayer)

View File

@@ -559,6 +559,7 @@
<Compile Include="Player\GlobalUpgradeManager.cs" />
<Compile Include="GainsStatUpgrades.cs" />
<Compile Include="Player\Extensions.cs" />
<Compile Include="ServerTraits\LobbySettingsNotification.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -0,0 +1,60 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Network;
using OpenRA.Server;
namespace OpenRA.Mods.RA.Server
{
public class LobbySettingsNotification : ServerTrait, IClientJoined
{
public void ClientJoined(OpenRA.Server.Server server, Connection conn)
{
if (server.LobbyInfo.ClientWithIndex(conn.PlayerIndex).IsAdmin)
return;
var defaults = new Session.Global();
FieldLoader.Load(defaults, Game.modData.Manifest.LobbyDefaults);
if (server.LobbyInfo.GlobalSettings.FragileAlliances != defaults.FragileAlliances)
server.SendOrderTo(conn, "Message", "Diplomacy Changes: {0}".F(server.LobbyInfo.GlobalSettings.FragileAlliances));
if (server.LobbyInfo.GlobalSettings.AllowCheats != defaults.AllowCheats)
server.SendOrderTo(conn, "Message", "Allow Cheats: {0}".F(server.LobbyInfo.GlobalSettings.AllowCheats));
if (server.LobbyInfo.GlobalSettings.Shroud != defaults.Shroud)
server.SendOrderTo(conn, "Message", "Shroud: {0}".F(server.LobbyInfo.GlobalSettings.Shroud));
if (server.LobbyInfo.GlobalSettings.Fog != defaults.Fog)
server.SendOrderTo(conn, "Message", "Fog of war: {0}".F(server.LobbyInfo.GlobalSettings.Fog));
if (server.LobbyInfo.GlobalSettings.Crates != defaults.Crates)
server.SendOrderTo(conn, "Message", "Crates Appear: {0}".F(server.LobbyInfo.GlobalSettings.Crates));
if (server.LobbyInfo.GlobalSettings.AllyBuildRadius != defaults.AllyBuildRadius)
server.SendOrderTo(conn, "Message", "Build off Ally ConYards: {0}".F(server.LobbyInfo.GlobalSettings.AllyBuildRadius));
if (server.LobbyInfo.GlobalSettings.StartingUnitsClass != defaults.StartingUnitsClass)
{
var startUnitsInfo = server.Map.Rules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>();
var selectedClass = startUnitsInfo.Where(u => u.Class == server.LobbyInfo.GlobalSettings.StartingUnitsClass).Select(u => u.ClassName).FirstOrDefault();
var className = selectedClass != null ? selectedClass : server.LobbyInfo.GlobalSettings.StartingUnitsClass;
server.SendOrderTo(conn, "Message", "Starting Units: {0}".F(className));
}
if (server.LobbyInfo.GlobalSettings.StartingCash != defaults.StartingCash)
server.SendOrderTo(conn, "Message", "Starting Cash: ${0}".F(server.LobbyInfo.GlobalSettings.StartingCash));
if (server.LobbyInfo.GlobalSettings.TechLevel != defaults.TechLevel)
server.SendOrderTo(conn, "Message", "Tech Level: {0}".F(server.LobbyInfo.GlobalSettings.TechLevel));
}
}
}

View File

@@ -152,6 +152,7 @@ ServerTraits:
LobbyCommands
PlayerPinger
MasterServerPinger
LobbySettingsNotification
LobbyDefaults:
AllowCheats: false

View File

@@ -134,6 +134,7 @@ ServerTraits:
LobbyCommands
PlayerPinger
MasterServerPinger
LobbySettingsNotification
LobbyDefaults:
AllowCheats: false

View File

@@ -150,6 +150,7 @@ ServerTraits:
LobbyCommands
PlayerPinger
MasterServerPinger
LobbySettingsNotification
LobbyDefaults:
AllowCheats: false

View File

@@ -179,6 +179,7 @@ ServerTraits:
LobbyCommands
PlayerPinger
MasterServerPinger
LobbySettingsNotification
LobbyDefaults:
AllowCheats: true