* ConnectionManager now has a helper method for returning a Connected Character that matches the supplied name
* Added a new Command. SetRole allows Admins to assign a Server Role (Admin, Player, GM etc) to a specified character. Server.ServerOwner is the only Character that can use this command regardless of server role. Any other Character must have a Role of Admin in order to use it. * StandardCharacter now checks if the character is connected as well as being enabled during execution of commands. * Re-organized how the StandardCharacter save code was invoked during disconnection from server. * StandardCharacter.Role is now saved and loaded from file.
This commit is contained in:
parent
f2c5b594c5
commit
2622c2d8c7
4 changed files with 170 additions and 6 deletions
108
MudEngine/WinPC_Engine/GameScripts/Commands/CommandSetRole.cs
Normal file
108
MudEngine/WinPC_Engine/GameScripts/Commands/CommandSetRole.cs
Normal file
|
@ -0,0 +1,108 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using MudEngine.Core.Interface;
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
using MudEngine.Networking;
|
||||
|
||||
namespace MudEngine.GameScripts.Commands
|
||||
{
|
||||
public class CommandSetRole : ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<string> Help { get; set; }
|
||||
|
||||
public CommandSetRole()
|
||||
{
|
||||
this.Name = "SetRole";
|
||||
this.Description = "Chat command that allows objects to communicate.";
|
||||
|
||||
this.Help = new List<string>();
|
||||
this.Help.Add("Usage: SetRole TargetCharacterNameHere");
|
||||
}
|
||||
|
||||
public Boolean Execute(string command, StandardCharacter character)
|
||||
{
|
||||
//Grab a reference to the character for simplifying access.
|
||||
StandardGame game = character.Game;
|
||||
MatchCollection matches = Regex.Matches(command.Substring("setrole".Length).Trim(), @"\w+");
|
||||
List<String> names = new List<string>();
|
||||
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
names.Add(match.Value.ToLower());
|
||||
}
|
||||
|
||||
if (names.Count < 1)
|
||||
{
|
||||
character.SendMessage("You must provide a target character name.");
|
||||
ShowHelp(character);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (character.Role == CharacterRoles.Admin || character.Name == game.Server.ServerOwner)
|
||||
{
|
||||
StandardCharacter target = game.Server.ConnectionManager.GetConnectedCharacter(names[0].ToLower());
|
||||
|
||||
this.SetRole(character, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
character.SendMessage("Invalid Command Used.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetRole(StandardCharacter admin, StandardCharacter target)
|
||||
{
|
||||
admin.SendMessage("Please choose from one of the available Roles:");
|
||||
|
||||
//Blow all of the available values up into an array.
|
||||
Array values = Enum.GetValues(typeof(CharacterRoles));
|
||||
List<String> roles = new List<string>();
|
||||
|
||||
//Loop through each available value, converting it into a string.
|
||||
foreach (Int32 value in values)
|
||||
{
|
||||
//Get the string representation of the current value
|
||||
String displayName = Enum.GetName(typeof(CharacterRoles), value);
|
||||
roles.Add(displayName);
|
||||
|
||||
admin.SendMessage(displayName);
|
||||
}
|
||||
admin.SendMessage("Selection: ", false);
|
||||
String result = admin.GetInput();
|
||||
|
||||
if (String.IsNullOrEmpty(result))
|
||||
{
|
||||
admin.SendMessage("You did not select a valid Role.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (roles.Contains(result))
|
||||
{
|
||||
target.SetRole(admin, target, (CharacterRoles)Enum.Parse(typeof(CharacterRoles), result));
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowHelp(StandardCharacter character)
|
||||
{
|
||||
String help = String.Empty;
|
||||
|
||||
foreach (String entry in this.Help)
|
||||
{
|
||||
help += entry + "\n";
|
||||
}
|
||||
|
||||
character.SendMessage(help);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue