MudEngine:

- Set the Game.PlayerCollection property to Protected. You can no longer modify this list unless the class inherits from Game. Only 1 script is allowed to inherit from Game.
 - Created Game.GetPlayerCollection() method for retrieving a read-only reference to the playerCollection so scripts can access player data it might needs.
 - Updated various classes and scripts due to no longer being able to access the PlayerCollection property.
This commit is contained in:
Scionwest_cp 2010-08-20 14:55:06 -07:00
parent 386d90df19
commit c7d227745c
11 changed files with 69 additions and 38 deletions

View file

@ -29,18 +29,18 @@ namespace MudEngine.Commands
if (player.ActiveGame.IsMultiplayer) if (player.ActiveGame.IsMultiplayer)
{ {
//Let other players know that the user walked in. //Let other players know that the user walked in.
for (Int32 i = 0; i != player.ActiveGame.PlayerCollection.Length; i++) for (Int32 i = 0; i != player.ActiveGame.GetPlayerCollection().Length; i++)
{ {
if (player.ActiveGame.PlayerCollection[i].Name == player.Name) if (player.ActiveGame.GetPlayerCollection()[i].Name == player.Name)
continue; continue;
String room = player.ActiveGame.PlayerCollection[i].CurrentRoom.Name; String room = player.ActiveGame.GetPlayerCollection()[i].CurrentRoom.Name;
String realm = player.ActiveGame.PlayerCollection[i].CurrentRoom.Realm; String realm = player.ActiveGame.GetPlayerCollection()[i].CurrentRoom.Realm;
String zone = player.ActiveGame.PlayerCollection[i].CurrentRoom.Zone; String zone = player.ActiveGame.GetPlayerCollection()[i].CurrentRoom.Zone;
if ((room == player.CurrentRoom.Name) && (realm == player.CurrentRoom.Realm) && (zone == player.CurrentRoom.Zone)) if ((room == player.CurrentRoom.Name) && (realm == player.CurrentRoom.Realm) && (zone == player.CurrentRoom.Zone))
{ {
player.ActiveGame.PlayerCollection[i].Send(player.Name + " has left."); player.ActiveGame.GetPlayerCollection()[i].Send(player.Name + " has left.");
} }
} }

View file

@ -65,7 +65,6 @@ namespace MudEngine.Commands
{ {
if (Path.GetFileNameWithoutExtension(filename).ToLower() == playerName.ToLower()) if (Path.GetFileNameWithoutExtension(filename).ToLower() == playerName.ToLower())
{ {
//TODO: Ask for password.
savedFile = filename; savedFile = filename;
playerFound = true; playerFound = true;
break; break;
@ -78,11 +77,11 @@ namespace MudEngine.Commands
{ {
if (player.ActiveGame.IsMultiplayer) if (player.ActiveGame.IsMultiplayer)
{ {
for (Int32 i = 0; i <= player.ActiveGame.PlayerCollection.Length - 1; i++) for (Int32 i = 0; i <= player.ActiveGame.GetPlayerCollection().Length - 1; i++)
{ {
if (player.ActiveGame.PlayerCollection[i].Name.ToLower() == playerName.ToLower()) if (player.ActiveGame.GetPlayerCollection()[i].Name.ToLower() == playerName.ToLower())
{ {
player.ActiveGame.PlayerCollection[i].Disconnect(); player.ActiveGame.GetPlayerCollection()[i].Disconnect();
} }
} }
} }
@ -116,18 +115,18 @@ namespace MudEngine.Commands
//Let other players know that the user walked in. //Let other players know that the user walked in.
if (player.ActiveGame.IsMultiplayer) if (player.ActiveGame.IsMultiplayer)
{ {
for (Int32 i = 0; i != player.ActiveGame.PlayerCollection.Length; i++) for (Int32 i = 0; i != player.ActiveGame.GetPlayerCollection().Length; i++)
{ {
if (player.ActiveGame.PlayerCollection[i].Name == player.Name) if (player.ActiveGame.GetPlayerCollection()[i].Name == player.Name)
continue; continue;
String room = player.ActiveGame.PlayerCollection[i].CurrentRoom.Name; String room = player.ActiveGame.GetPlayerCollection()[i].CurrentRoom.Name;
String realm = player.ActiveGame.PlayerCollection[i].CurrentRoom.Realm; String realm = player.ActiveGame.GetPlayerCollection()[i].CurrentRoom.Realm;
String zone = player.ActiveGame.PlayerCollection[i].CurrentRoom.Zone; String zone = player.ActiveGame.GetPlayerCollection()[i].CurrentRoom.Zone;
if ((room == player.CurrentRoom.Name) && (realm == player.CurrentRoom.Realm) && (zone == player.CurrentRoom.Zone)) if ((room == player.CurrentRoom.Name) && (realm == player.CurrentRoom.Realm) && (zone == player.CurrentRoom.Zone))
{ {
player.ActiveGame.PlayerCollection[i].Send(player.Name + " arrived."); player.ActiveGame.GetPlayerCollection()[i].Send(player.Name + " arrived.");
} }
} }
} }

View file

@ -27,18 +27,18 @@ namespace MudEngine.Commands
{ {
String path = player.ActiveGame.DataPaths.Players; String path = player.ActiveGame.DataPaths.Players;
for (Int32 i = 0; i < player.ActiveGame.PlayerCollection.Length; i++) for (Int32 i = 0; i < player.ActiveGame.GetPlayerCollection().Length; i++)
{ {
String filename = Path.Combine(path, player.ActiveGame.PlayerCollection[i].Filename); String filename = Path.Combine(path, player.ActiveGame.GetPlayerCollection()[i].Filename);
player.ActiveGame.PlayerCollection[i].Save(filename); player.ActiveGame.GetPlayerCollection()[i].Save(filename);
} }
//player.ActiveGame.Server.EndServer(); //-Handled in Game.Shutdown() below. //player.ActiveGame.Server.EndServer(); //-Handled in Game.Shutdown() below.
player.ActiveGame.Shutdown(); player.ActiveGame.Shutdown();
player.ActiveGame.Start(); player.ActiveGame.Start();
/* Game.Start() calls this, do we need a reference to the playercollection? /* Game.Start() calls this, do we need a reference to the GetPlayerCollection()?
* They should be unloaded anyway and re-loaded during game.start to force a clean restart of all objects. * They should be unloaded anyway and re-loaded during game.start to force a clean restart of all objects.
player.ActiveGame.Server.Initialize(555, ref player.ActiveGame.PlayerCollection); player.ActiveGame.Server.Initialize(555, ref player.ActiveGame.GetPlayerCollection());
*/ */
Log.Write("Server Restart Completed."); Log.Write("Server Restart Completed.");

View file

@ -154,11 +154,10 @@ namespace MudEngine.GameManagement
#endregion #endregion
#region Networking #region Networking
//TODO: This should be internal only; C# property using get; internal set; so only MudEngine.dll may edit this collection
/// <summary> /// <summary>
/// Collection of players currently running on the server. /// Collection of players currently running on the server.
/// </summary> /// </summary>
public BaseCharacter[] PlayerCollection; protected BaseCharacter[] PlayerCollection;
/// <summary> /// <summary>
/// Gets the current running Server object. /// Gets the current running Server object.
@ -279,7 +278,7 @@ namespace MudEngine.GameManagement
/// <summary> /// <summary>
/// Shuts down the Game and Server. /// Shuts down the Game and Server.
/// </summary> /// </summary>
public void Shutdown() public virtual void Shutdown()
{ {
Log.Write("Server shutdown requested..."); Log.Write("Server shutdown requested...");
@ -429,6 +428,11 @@ namespace MudEngine.GameManagement
Log.Write("Game Restore complete."); Log.Write("Game Restore complete.");
} }
public BaseCharacter[] GetPlayerCollection()
{
return PlayerCollection;
}
/// <summary> /// <summary>
/// Starts the Server. /// Starts the Server.
/// </summary> /// </summary>

View file

@ -175,18 +175,18 @@
} }
//Let other players know that the user walked out. //Let other players know that the user walked out.
for (Int32 i = 0; i != ActiveGame.PlayerCollection.Length; i++) for (Int32 i = 0; i != ActiveGame.GetPlayerCollection().Length; i++)
{ {
if (ActiveGame.PlayerCollection[i].Name == Name) if (ActiveGame.GetPlayerCollection()[i].Name == Name)
continue; continue;
String room = ActiveGame.PlayerCollection[i].CurrentRoom.Filename; String room = ActiveGame.GetPlayerCollection()[i].CurrentRoom.Filename;
String realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm; String realm = ActiveGame.GetPlayerCollection()[i].CurrentRoom.Realm;
String zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone; String zone = ActiveGame.GetPlayerCollection()[i].CurrentRoom.Zone;
if ((room == CurrentRoom.Filename) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone)) if ((room == CurrentRoom.Filename) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone))
{ {
ActiveGame.PlayerCollection[i].Send(Name + " walked out towards the " + travelDirection.ToString()); ActiveGame.GetPlayerCollection()[i].Send(Name + " walked out towards the " + travelDirection.ToString());
} }
} }
@ -202,18 +202,18 @@
{ {
//TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel. //TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel.
//Let other players know that the user walked in. //Let other players know that the user walked in.
for (Int32 i = 0; i != ActiveGame.PlayerCollection.Length; i++) for (Int32 i = 0; i != ActiveGame.GetPlayerCollection().Length; i++)
{ {
if (ActiveGame.PlayerCollection[i].Name == Name) if (ActiveGame.GetPlayerCollection()[i].Name == Name)
continue; continue;
String room = ActiveGame.PlayerCollection[i].CurrentRoom.Name; String room = ActiveGame.GetPlayerCollection()[i].CurrentRoom.Name;
String realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm; String realm = ActiveGame.GetPlayerCollection()[i].CurrentRoom.Realm;
String zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone; String zone = ActiveGame.GetPlayerCollection()[i].CurrentRoom.Zone;
if ((room == CurrentRoom.Name) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone)) if ((room == CurrentRoom.Name) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone))
{ {
ActiveGame.PlayerCollection[i].Send(Name + " walked in from the " + TravelDirections.GetReverseDirection(travelDirection)); ActiveGame.GetPlayerCollection()[i].Send(Name + " walked in from the " + TravelDirections.GetReverseDirection(travelDirection));
} }
} }
} }

View file

@ -1,2 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:ignore</Name><Value>obj <?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:ignore</Name><Value>obj
</Value></Property><Property><Name>svn:ignore</Name><Value>obj
Settings.ini
</Value></Property></Properties></ItemProperties> </Value></Property></Properties></ItemProperties>

View file

@ -104,7 +104,7 @@ namespace MudGame
//scripts might miss this, so we check for it. //scripts might miss this, so we check for it.
if (!game.IsMultiplayer) if (!game.IsMultiplayer)
{ {
if ((game.PlayerCollection[0] == null) || (game.PlayerCollection[0].Name == "New BaseCharacter")) if ((game.GetPlayerCollection()[0] == null) || (game.GetPlayerCollection()[0].Name == "New BaseCharacter"))
{ {
Log.Write("Error! No player available for creation!", true); Log.Write("Error! No player available for creation!", true);
return; return;

View file

@ -12,7 +12,7 @@ public class CommandSay : IGameCommand
String message = command.Substring("Say ".Length); String message = command.Substring("Say ".Length);
foreach (BaseCharacter p in player.ActiveGame.PlayerCollection) foreach (BaseCharacter p in player.ActiveGame.GetPlayerCollection())
{ {
if ((p.CurrentRoom.Realm == player.CurrentRoom.Realm) && (p.CurrentRoom.Zone == player.CurrentRoom.Zone) && (p.CurrentRoom.Filename == player.CurrentRoom.Filename)) if ((p.CurrentRoom.Realm == player.CurrentRoom.Realm) && (p.CurrentRoom.Zone == player.CurrentRoom.Zone) && (p.CurrentRoom.Filename == player.CurrentRoom.Filename))
{ {

View file

@ -29,4 +29,18 @@ temp
Realms Realms
Mud Designer Example Game.ini Mud Designer Example Game.ini
World World
</Value></Property><Property><Name>svn:ignore</Name><Value>Log.txt
MudEngine.dll
MudEngine.pdb
MudGame.exe
MudGame.pdb
MudGame.vshost.exe
MudGame.vshost.exe.manifest
Player
temp
Realms
Mud Designer Example Game.ini
World
Planet Earth MUD.ini
Saved
</Value></Property></Properties></ItemProperties> </Value></Property></Properties></ItemProperties>

View file

@ -2,4 +2,9 @@
CommandCreate.cs CommandCreate.cs
CommandSay.cs CommandSay.cs
EarthGame.cs EarthGame.cs
</Value></Property><Property><Name>svn:ignore</Name><Value>CommandClear.cs
CommandCreate.cs
CommandSay.cs
EarthGame.cs
CommandHelp.cs
</Value></Property></Properties></ItemProperties> </Value></Property></Properties></ItemProperties>

View file

@ -7,4 +7,11 @@ MudEngine.pdb
MudGame.exe MudGame.exe
MudGame.pdb MudGame.pdb
Scripts Scripts
</Value></Property><Property><Name>svn:ignore</Name><Value>MudEngine.dll
MudEngine.pdb
MudGame.exe
MudGame.pdb
Scripts
Commands
Settings.ini
</Value></Property></Properties></ItemProperties> </Value></Property></Properties></ItemProperties>