MudEngine:

- Sending messages to the client from the server is now an added feature. Use Game.SendMessage()
 - Added Load and Save commands for players.
 - Added Missing SaveDataPaths struct file.
This commit is contained in:
Scionwest_cp 2010-07-30 19:31:49 -07:00
parent 4be5a831b1
commit 607bd673a5
7 changed files with 122 additions and 1 deletions

View file

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MudEngine.FileSystem;
using MudEngine.GameManagement;
using MudEngine.GameObjects;
using MudEngine.GameObjects.Characters;
namespace MudEngine.Commands
{
public class CommandLoad : IGameCommand
{
public bool Override { get; set; }
public string Name { get; set; }
public CommandResults Execute(string command, BaseCharacter player)
{
string path = player.ActiveGame.DataPaths.Players;
string filename = Path.Combine(path, player.Filename);
player.Load(filename);
return new CommandResults();
}
}
}

View file

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MudEngine.GameObjects.Characters;
using MudEngine.GameManagement;
using MudEngine.Commands;
using MudEngine.GameObjects.Environment;
namespace MudEngine.Commands
{
public class CommandLogin : IGameCommand
{
public bool Override { get; set; }
public string Name { get; set; }
public CommandResults Execute(string command, BaseCharacter player)
{
player.ActiveGame.SendMessage(player.ActiveGame.GameTitle, player);
player.ActiveGame.SendMessage(player.ActiveGame.Version, player);
player.ActiveGame.SendMessage(player.ActiveGame.Story, player);
player.ActiveGame.SendMessage("", player);
player.ActiveGame.SendMessage("Enter Character Name: ", player, false);
//TODO: Read user input...
return new CommandResults();
}
}
}

View file

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MudEngine.FileSystem;
using MudEngine.GameManagement;
using MudEngine.GameObjects;
using MudEngine.GameObjects.Characters;
namespace MudEngine.Commands
{
public class CommandSave : IGameCommand
{
public bool Override { get; set; }
public string Name { get; set; }
public CommandResults Execute(string command, BaseCharacter player)
{
string path = player.ActiveGame.DataPaths.Players;
string filename = Path.Combine(path, player.Filename);
player.Save(filename);
return new CommandResults();
}
}
}

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MudEngine.FileSystem
{
public struct SaveDataPaths
{
public string Players { get; set; }
public string Environment { get; set; }
}
}

View file

@ -197,6 +197,8 @@ namespace MudEngine.GameManagement
BaseCurrencyAmount = 1; BaseCurrencyAmount = 1;
BaseCurrencyName = "Copper"; BaseCurrencyName = "Copper";
IsMultiplayer = true; //default. IsMultiplayer = true; //default.
Version = "1.0";
Story = "";
} }
/// <summary> /// <summary>
@ -341,5 +343,19 @@ namespace MudEngine.GameManagement
Server.Initialize(ServerPort, ref PlayerCollection); Server.Initialize(ServerPort, ref PlayerCollection);
Server.Start(); Server.Start();
} }
public void SendMessage(string message, BaseCharacter player)
{
SendMessage(message, player, true);
}
public void SendMessage(string message, BaseCharacter player, bool newLine)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
if (newLine)
message += "\n\r";
player.Send(encoding.GetBytes(message));
}
} }
} }

View file

@ -140,8 +140,10 @@ namespace MudEngine.GameObjects.Characters
internal void Initialize() internal void Initialize()
{ {
CurrentRoom = ActiveGame.InitialRealm.InitialZone.InitialRoom; string result = ExecuteCommand("Login");
CurrentRoom = ActiveGame.InitialRealm.InitialZone.InitialRoom;
IsActive = true; IsActive = true;
} }
internal void Receive(byte[] data) internal void Receive(byte[] data)

View file

@ -56,6 +56,7 @@
<Compile Include="Commands\CommandSave.cs" /> <Compile Include="Commands\CommandSave.cs" />
<Compile Include="Commands\CommandWalk.cs" /> <Compile Include="Commands\CommandWalk.cs" />
<Compile Include="Commands\CommandLoad.cs" /> <Compile Include="Commands\CommandLoad.cs" />
<Compile Include="Commands\CommandLogin.cs" />
<Compile Include="FileSystem\SaveDataPaths.cs" /> <Compile Include="FileSystem\SaveDataPaths.cs" />
<Compile Include="GameManagement\CommandEngine.cs" /> <Compile Include="GameManagement\CommandEngine.cs" />
<Compile Include="GameManagement\CommandResults.cs" /> <Compile Include="GameManagement\CommandResults.cs" />