Commands script folder renamed to BaseCommands. Users creating custom commands are encouraged to create them in a "Commands" or "Custom Commands" folder.
This commit is contained in:
parent
11b2e73f35
commit
32210124e0
8 changed files with 11 additions and 12 deletions
|
@ -0,0 +1,99 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
using MudEngine.Core;
|
||||
using MudEngine.Core.Interfaces;
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
using MudEngine.Game.Environment;
|
||||
using MudEngine.GameScripts;
|
||||
|
||||
namespace MudEngine.GameScripts.Commands
|
||||
{
|
||||
public class CreatePlayer : ICommand
|
||||
{
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<string> Help { get; set; }
|
||||
|
||||
public CreatePlayer()
|
||||
{
|
||||
Help = new List<string>();
|
||||
Name = "CreatePlayer";
|
||||
Description = "Account login command.";
|
||||
}
|
||||
|
||||
public Boolean Execute(string command, Game.Characters.StandardCharacter character)
|
||||
{
|
||||
//reference to the Characters Game.
|
||||
StandardGame game = character.Game;
|
||||
Boolean buildingPassword = true;
|
||||
|
||||
//We need to check if the 3rd Frame on the stack is the CommandLogin Type.
|
||||
//If it isn't, then another Type executed this command and we don't allow it.
|
||||
StackTrace trace = new StackTrace();
|
||||
String callingType = trace.GetFrame(3).GetMethod().ReflectedType.Name;
|
||||
|
||||
//Don't allow anything other than the Login command to start the
|
||||
//character creation process.
|
||||
if (callingType != "Login")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Make sure we build a proper password.
|
||||
while (buildingPassword)
|
||||
{
|
||||
character.SendMessage("Please enter a password for this character: ", false);
|
||||
String password1, password2;
|
||||
password1 = character.GetInput();
|
||||
|
||||
//We do not perform any IsLetterOrDigit() checks on passwords. The more
|
||||
//special characters the better.
|
||||
//We do however want to make sure the length of the password is sufficient
|
||||
if (password1.Length < character.Game.MinimumPasswordSize)
|
||||
{
|
||||
character.SendMessage("Passwords must have a minimum of " + character.Game.MinimumPasswordSize.ToString() + " characters!");
|
||||
continue;
|
||||
}
|
||||
|
||||
character.SendMessage("Please re-enter your password for confirmation: ", false);
|
||||
password2 = character.GetInput();
|
||||
|
||||
if (password1 == password2)
|
||||
{
|
||||
buildingPassword = false;
|
||||
character.Password = password1;
|
||||
}
|
||||
else
|
||||
{
|
||||
character.SendMessage("Passwords did not match!");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
character.Move(game.World.StartLocation);
|
||||
|
||||
//TODO: Create a class and setup Stats.
|
||||
character.Save(character.Filename, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine(ex.Message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
165
MudEngine/WinPC_Engine/GameScripts/BaseCommands/Login.cs
Normal file
165
MudEngine/WinPC_Engine/GameScripts/BaseCommands/Login.cs
Normal file
|
@ -0,0 +1,165 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
|
||||
using MudEngine.Core.Interfaces;
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
using MudEngine.Game.Environment;
|
||||
using MudEngine.GameScripts;
|
||||
|
||||
namespace MudEngine.GameScripts.Commands
|
||||
{
|
||||
public class Login : ICommand
|
||||
{
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<string> Help { get; set; }
|
||||
|
||||
public Login()
|
||||
{
|
||||
Help = new List<string>();
|
||||
//Name = "Login";
|
||||
Description = "Account login command.";
|
||||
}
|
||||
|
||||
public Boolean Execute(string command, Game.Characters.StandardCharacter character)
|
||||
{
|
||||
//reference to the Characters Game.
|
||||
StandardGame game = character.Game;
|
||||
|
||||
//Store a reference to this character for other methods within this class.
|
||||
this._Character = character;
|
||||
|
||||
if (character.LoggedIn)
|
||||
{
|
||||
character.SendMessage("You are already logged in!");
|
||||
return false;
|
||||
}
|
||||
|
||||
character.SendMessage("Please enter character name: ");
|
||||
String name = String.Empty;
|
||||
|
||||
//Repeat the login process until we get a valid name.
|
||||
while (String.IsNullOrEmpty(name) && character.Connected)
|
||||
{
|
||||
character.SendMessage("Enter your character name: ", false);
|
||||
|
||||
name = String.Empty;
|
||||
Boolean isFound = false;
|
||||
|
||||
//Get the supplied name
|
||||
name = character.GetInput();
|
||||
|
||||
//Entering their username is the first time input has been
|
||||
//made by the user. Expect their Telnet client to send Header
|
||||
//information, so we strip it out by forcing only a whole
|
||||
//word to be saved and everything else discarded.
|
||||
//Note that this wouldn't work if first and last names were supported
|
||||
//as this only returns the first word found and that is all.
|
||||
Match m = Regex.Match(name, @"\w+");
|
||||
name = m.Value;
|
||||
|
||||
//Make sure no illegal characters are in the name such as underbars or asteriks
|
||||
if (!name.All(Char.IsLetterOrDigit))
|
||||
{
|
||||
character.SendMessage("Invalid character name supplied. Only letters and numbers are allowed.");
|
||||
name = String.Empty;
|
||||
continue;
|
||||
}
|
||||
|
||||
//Uncomment this if first/last name combinations are used in
|
||||
//the game. Note that this does support numbers and other
|
||||
//special characters. If you do not want them, you will need
|
||||
//to modify the Regular Expression Evaluator below.
|
||||
/*
|
||||
MatchCollection m = Regex.Matches(name, @"\w+");
|
||||
name = String.Empty;
|
||||
foreach (Match word in m)
|
||||
{
|
||||
name += word.Value + " ";
|
||||
}
|
||||
*/
|
||||
|
||||
//Check if the name entered is blank. Ensure that we remove leading and ending spaces
|
||||
if (String.IsNullOrEmpty(name))
|
||||
continue;
|
||||
|
||||
//Look if the file exists.
|
||||
String filename = game.SavePaths.GetFilePath(DAL.DataTypes.Players, name);
|
||||
|
||||
if (File.Exists(filename))
|
||||
isFound = true;
|
||||
|
||||
//if the character name supplied exists, load it.
|
||||
if (isFound)
|
||||
{
|
||||
//Perform a password check
|
||||
character.SendMessage("Please enter a password for " + name);
|
||||
String password = character.GetInput();
|
||||
|
||||
//If the password is empty, then restart the process.
|
||||
if (String.IsNullOrEmpty(password))
|
||||
{
|
||||
name = String.Empty;
|
||||
continue;
|
||||
}
|
||||
|
||||
//Load the character from file.
|
||||
character.Load(filename);
|
||||
|
||||
//Check if the characters password matches that of the saved player password
|
||||
if (character.Password != password)
|
||||
{
|
||||
//No match, bail.
|
||||
character.SendMessage("Invalid password provided.");
|
||||
name = String.Empty;
|
||||
continue;
|
||||
}
|
||||
else //End our loading.
|
||||
{
|
||||
character.SendMessage("Welcome back " + character.Name + "!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
character.SendMessage("No character with that name was found. Create a new one? (Yes/No)");
|
||||
String result = character.GetInput();
|
||||
if (result.ToLower() == "yes")
|
||||
{
|
||||
//Store the character name.
|
||||
character.Name = name;
|
||||
|
||||
|
||||
if (!character.ExecuteSilentCommand("CreatePlayer"))
|
||||
{
|
||||
name = String.Empty;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//We complete the login process..
|
||||
character.SendMessage(character.Name + " created!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name = String.Empty;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private StandardCharacter _Character;
|
||||
}
|
||||
}
|
31
MudEngine/WinPC_Engine/GameScripts/BaseCommands/Look.cs
Normal file
31
MudEngine/WinPC_Engine/GameScripts/BaseCommands/Look.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
using MudEngine.Game.Environment;
|
||||
using MudEngine.Core.Interfaces;
|
||||
|
||||
namespace MudEngine.GameScripts.Commands
|
||||
{
|
||||
public class Look : ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<string> Help { get; set; }
|
||||
|
||||
public Look()
|
||||
{
|
||||
this.Name = "Look";
|
||||
}
|
||||
|
||||
public bool Execute(string command, StandardCharacter character)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
49
MudEngine/WinPC_Engine/GameScripts/BaseCommands/Say.cs
Normal file
49
MudEngine/WinPC_Engine/GameScripts/BaseCommands/Say.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using MudEngine.Core.Interfaces;
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
using MudEngine.Networking;
|
||||
|
||||
namespace MudEngine.GameScripts.Commands
|
||||
{
|
||||
public class Say : ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<string> Help { get; set; }
|
||||
|
||||
public Say()
|
||||
{
|
||||
this.Name = "Say";
|
||||
this.Description = "Chat command that allows objects to communicate.";
|
||||
}
|
||||
|
||||
public Boolean Execute(string command, StandardCharacter character)
|
||||
{
|
||||
//Grab a reference to the character for simplifying access.
|
||||
StandardGame game = character.Game;
|
||||
//Remove the command "Say " from the string so we only have it's message
|
||||
String message = command.Substring(3).Trim();
|
||||
|
||||
//Loop through each character on the server and broadcast the message.
|
||||
//TODO: This should only broadcast to characters that are in the same Environment.
|
||||
foreach (StandardCharacter c in character.Game.Server.ConnectionManager.GetConnectedCharacters())
|
||||
{
|
||||
//Only broadcast this message to those that are not the broadcastor.
|
||||
if (c != character)
|
||||
c.SendMessage(character.ToString() + " says: " + message);
|
||||
}
|
||||
|
||||
//Send a different copy of the message to the broadcastor.
|
||||
character.SendMessage("You say: " + message);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
107
MudEngine/WinPC_Engine/GameScripts/BaseCommands/SetRole.cs
Normal file
107
MudEngine/WinPC_Engine/GameScripts/BaseCommands/SetRole.cs
Normal file
|
@ -0,0 +1,107 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using MudEngine.Core.Interfaces;
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
using MudEngine.Networking;
|
||||
|
||||
namespace MudEngine.GameScripts.Commands
|
||||
{
|
||||
public class SetRole : ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<string> Help { get; set; }
|
||||
|
||||
public SetRole()
|
||||
{
|
||||
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.Role == CharacterRoles.Admin)
|
||||
{
|
||||
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.ApplyRole(character, target);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyRole(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);
|
||||
}
|
||||
}
|
||||
}
|
47
MudEngine/WinPC_Engine/GameScripts/BaseCommands/Stop.cs
Normal file
47
MudEngine/WinPC_Engine/GameScripts/BaseCommands/Stop.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
using MudEngine.Core.Interfaces;
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
using MudEngine.Networking;
|
||||
|
||||
namespace MudEngine.GameScripts.Commands
|
||||
{
|
||||
public class Stop : ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<string> Help { get; set; }
|
||||
|
||||
public Stop()
|
||||
{
|
||||
this.Name = "Stop";
|
||||
this.Description = "Chat command that allows objects to communicate.";
|
||||
}
|
||||
|
||||
public Boolean Execute(string command, StandardCharacter character)
|
||||
{
|
||||
//Grab a reference to the character for simplifying access.
|
||||
StandardGame game = character.Game;
|
||||
|
||||
//Stop the game.
|
||||
if (character.Role == CharacterRoles.Admin)
|
||||
{
|
||||
new Thread(game.Stop).Start();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Since a non-admin character attempted this command,
|
||||
//tell them they used a invalid command
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue