From a0c406d48239f6e15b0bb8cc331deb241e2c6af5 Mon Sep 17 00:00:00 2001 From: darxval_cp Date: Mon, 4 Jun 2012 18:40:46 -0700 Subject: [PATCH] Created 2 new projects that are basically rewrites of the other two, many many many things are missing. but I want to effectively be able to switch states and commands without having to create dependencies. Currently you can connect and Reach the "ConnectState" from there anything you state will just be an "InvalidCommand" --- MudEngine/MudEngine.sln | 32 ++++- .../Abstract.Actions/ILoadable.cs | 7 ++ .../Abstract.Actions/ISaveable.cs | 7 ++ .../WinPC.Engine/Abstract.Actions/IUseable.cs | 7 ++ .../WinPC.Engine/Abstract.Core/ICommand.cs | 9 ++ .../WinPC.Engine/Abstract.Core/IEngine.cs | 7 ++ MudEngine/WinPC.Engine/Abstract.Core/IGame.cs | 7 ++ .../WinPC.Engine/Abstract.Core/IGameObject.cs | 7 ++ .../WinPC.Engine/Abstract.Core/IInventory.cs | 7 ++ .../WinPC.Engine/Abstract.Core/ILogger.cs | 7 ++ .../WinPC.Engine/Abstract.Core/IPlayer.cs | 9 ++ .../WinPC.Engine/Abstract.Core/IRealm.cs | 7 ++ MudEngine/WinPC.Engine/Abstract.Core/IRoom.cs | 7 ++ MudEngine/WinPC.Engine/Abstract.Core/IRule.cs | 7 ++ .../WinPC.Engine/Abstract.Core/IState.cs | 9 ++ .../IConnectionsDirector.cs | 7 ++ .../Abstract.Directors/IRuleDirector.cs | 7 ++ .../Abstract.Directors/IServerDirector.cs | 19 +++ .../Abstract.Networking/IConnection.cs | 7 ++ .../Abstract.Networking/IServer.cs | 29 +++++ .../WinPC.Engine/Abstract.Objects/IItem.cs | 7 ++ .../WinPC.Engine/Commands/InvalidCommand.cs | 24 ++++ MudEngine/WinPC.Engine/Core/Logger.cs | 115 +++++++++++++++++ MudEngine/WinPC.Engine/Core/Player.cs | 25 ++++ .../WinPC.Engine/Directors/ServerDirector.cs | 116 ++++++++++++++++++ MudEngine/WinPC.Engine/Engine.cs | 13 ++ MudEngine/WinPC.Engine/Networking/Server.cs | 109 ++++++++++++++++ .../WinPC.Engine/Properties/AssemblyInfo.cs | 36 ++++++ MudEngine/WinPC.Engine/States/ConnectState.cs | 44 +++++++ .../WinPC.Engine/States/MainMenuState.cs | 18 +++ MudEngine/WinPC.Engine/WinPC.Engine.csproj | 86 +++++++++++++ .../WinPC.Engine/WinPC.Engine.csproj.vspscc | 10 ++ MudEngine/WinPC.Server/Program.cs | 38 ++++++ .../WinPC.Server/Properties/AssemblyInfo.cs | 36 ++++++ MudEngine/WinPC.Server/WinPC.Server.csproj | 67 ++++++++++ .../WinPC.Server/WinPC.Server.csproj.vspscc | 10 ++ MudEngine/WinPC_Engine/Networking/Server.cs | 4 +- 37 files changed, 960 insertions(+), 3 deletions(-) create mode 100644 MudEngine/WinPC.Engine/Abstract.Actions/ILoadable.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Actions/ISaveable.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Actions/IUseable.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/ICommand.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IEngine.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IGame.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IGameObject.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IInventory.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/ILogger.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IPlayer.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IRealm.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IRoom.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IRule.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Core/IState.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Directors/IConnectionsDirector.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Directors/IRuleDirector.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Directors/IServerDirector.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Networking/IConnection.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Networking/IServer.cs create mode 100644 MudEngine/WinPC.Engine/Abstract.Objects/IItem.cs create mode 100644 MudEngine/WinPC.Engine/Commands/InvalidCommand.cs create mode 100644 MudEngine/WinPC.Engine/Core/Logger.cs create mode 100644 MudEngine/WinPC.Engine/Core/Player.cs create mode 100644 MudEngine/WinPC.Engine/Directors/ServerDirector.cs create mode 100644 MudEngine/WinPC.Engine/Engine.cs create mode 100644 MudEngine/WinPC.Engine/Networking/Server.cs create mode 100644 MudEngine/WinPC.Engine/Properties/AssemblyInfo.cs create mode 100644 MudEngine/WinPC.Engine/States/ConnectState.cs create mode 100644 MudEngine/WinPC.Engine/States/MainMenuState.cs create mode 100644 MudEngine/WinPC.Engine/WinPC.Engine.csproj create mode 100644 MudEngine/WinPC.Engine/WinPC.Engine.csproj.vspscc create mode 100644 MudEngine/WinPC.Server/Program.cs create mode 100644 MudEngine/WinPC.Server/Properties/AssemblyInfo.cs create mode 100644 MudEngine/WinPC.Server/WinPC.Server.csproj create mode 100644 MudEngine/WinPC.Server/WinPC.Server.csproj.vspscc diff --git a/MudEngine/MudEngine.sln b/MudEngine/MudEngine.sln index 70d831e..71ff058 100644 --- a/MudEngine/MudEngine.sln +++ b/MudEngine/MudEngine.sln @@ -5,9 +5,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinPC_Server", "WinPC_Serve EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinPC_Engine", "WinPC_Engine\WinPC_Engine.csproj", "{27C84625-1D4A-4DBF-9770-46D535506485}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinPC.Engine", "WinPC.Engine\WinPC.Engine.csproj", "{9D9E8CAC-8876-4725-9A65-2077DE4322DD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinPC.Server", "WinPC.Server\WinPC.Server.csproj", "{161E78DB-10C5-43A6-BC15-0945BC6F941F}" +EndProject Global GlobalSection(TeamFoundationVersionControl) = preSolution - SccNumberOfProjects = 3 + SccNumberOfProjects = 5 SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs03 SccLocalPath0 = . @@ -17,6 +21,12 @@ Global SccProjectUniqueName2 = WinPC_Server\\WinPC_Server.csproj SccProjectName2 = WinPC_Server SccLocalPath2 = WinPC_Server + SccProjectUniqueName3 = WinPC.Engine\\WinPC.Engine.csproj + SccProjectName3 = WinPC.Engine + SccLocalPath3 = WinPC.Engine + SccProjectUniqueName4 = WinPC.Server\\WinPC.Server.csproj + SccProjectName4 = WinPC.Server + SccLocalPath4 = WinPC.Server EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,6 +57,26 @@ Global {27C84625-1D4A-4DBF-9770-46D535506485}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {27C84625-1D4A-4DBF-9770-46D535506485}.Release|Mixed Platforms.Build.0 = Release|Any CPU {27C84625-1D4A-4DBF-9770-46D535506485}.Release|x86.ActiveCfg = Release|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Debug|x86.ActiveCfg = Debug|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Release|Any CPU.Build.0 = Release|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {9D9E8CAC-8876-4725-9A65-2077DE4322DD}.Release|x86.ActiveCfg = Release|Any CPU + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Debug|Any CPU.ActiveCfg = Debug|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Debug|x86.ActiveCfg = Debug|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Debug|x86.Build.0 = Debug|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Release|Any CPU.ActiveCfg = Release|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Release|Mixed Platforms.Build.0 = Release|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Release|x86.ActiveCfg = Release|x86 + {161E78DB-10C5-43A6-BC15-0945BC6F941F}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MudEngine/WinPC.Engine/Abstract.Actions/ILoadable.cs b/MudEngine/WinPC.Engine/Abstract.Actions/ILoadable.cs new file mode 100644 index 0000000..d617125 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Actions/ILoadable.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Actions +{ + public interface ILoadable + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Actions/ISaveable.cs b/MudEngine/WinPC.Engine/Abstract.Actions/ISaveable.cs new file mode 100644 index 0000000..5167bec --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Actions/ISaveable.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Actions +{ + public interface ISaveable + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Actions/IUseable.cs b/MudEngine/WinPC.Engine/Abstract.Actions/IUseable.cs new file mode 100644 index 0000000..9da4eef --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Actions/IUseable.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Actions +{ + public interface IUseable + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/ICommand.cs b/MudEngine/WinPC.Engine/Abstract.Core/ICommand.cs new file mode 100644 index 0000000..69234de --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/ICommand.cs @@ -0,0 +1,9 @@ +using System.Net.Sockets; + +namespace WinPC.Engine.Abstract.Core +{ + public interface ICommand + { + void Execute(); + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IEngine.cs b/MudEngine/WinPC.Engine/Abstract.Core/IEngine.cs new file mode 100644 index 0000000..dfc1558 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IEngine.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IEngine + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IGame.cs b/MudEngine/WinPC.Engine/Abstract.Core/IGame.cs new file mode 100644 index 0000000..11c9e23 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IGame.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IGame + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IGameObject.cs b/MudEngine/WinPC.Engine/Abstract.Core/IGameObject.cs new file mode 100644 index 0000000..a8b6157 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IGameObject.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IGameObject + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IInventory.cs b/MudEngine/WinPC.Engine/Abstract.Core/IInventory.cs new file mode 100644 index 0000000..29645a2 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IInventory.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IInventory + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/ILogger.cs b/MudEngine/WinPC.Engine/Abstract.Core/ILogger.cs new file mode 100644 index 0000000..a8d64d7 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/ILogger.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface ILogger + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IPlayer.cs b/MudEngine/WinPC.Engine/Abstract.Core/IPlayer.cs new file mode 100644 index 0000000..9821eea --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IPlayer.cs @@ -0,0 +1,9 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IPlayer + { + IState CurrentState { get; } + + void Disconnect(); + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IRealm.cs b/MudEngine/WinPC.Engine/Abstract.Core/IRealm.cs new file mode 100644 index 0000000..bf1c151 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IRealm.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IRealm + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IRoom.cs b/MudEngine/WinPC.Engine/Abstract.Core/IRoom.cs new file mode 100644 index 0000000..944f9ef --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IRoom.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IRoom + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IRule.cs b/MudEngine/WinPC.Engine/Abstract.Core/IRule.cs new file mode 100644 index 0000000..8c8782c --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IRule.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IRule + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Core/IState.cs b/MudEngine/WinPC.Engine/Abstract.Core/IState.cs new file mode 100644 index 0000000..61ff214 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Core/IState.cs @@ -0,0 +1,9 @@ +namespace WinPC.Engine.Abstract.Core +{ + public interface IState + { + void Render(int index); + ICommand GetCommand(); + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Directors/IConnectionsDirector.cs b/MudEngine/WinPC.Engine/Abstract.Directors/IConnectionsDirector.cs new file mode 100644 index 0000000..ebd1ed6 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Directors/IConnectionsDirector.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Directors +{ + public interface IConnectionsDirector + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Directors/IRuleDirector.cs b/MudEngine/WinPC.Engine/Abstract.Directors/IRuleDirector.cs new file mode 100644 index 0000000..45f0af9 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Directors/IRuleDirector.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Directors +{ + public interface IRuleDirector + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Directors/IServerDirector.cs b/MudEngine/WinPC.Engine/Abstract.Directors/IServerDirector.cs new file mode 100644 index 0000000..d3c6359 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Directors/IServerDirector.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Net.Sockets; +using System.Threading; + +namespace WinPC.Engine.Abstract.Directors +{ + public interface IServerDirector + { + + List ConnectionThreads { get; } + + void AddConnection(Socket connection); + void ReceiveDataThread(Object index); + void DisconnectAll(); + + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Networking/IConnection.cs b/MudEngine/WinPC.Engine/Abstract.Networking/IConnection.cs new file mode 100644 index 0000000..e9a4b6c --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Networking/IConnection.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Networking +{ + public interface IConnection + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Networking/IServer.cs b/MudEngine/WinPC.Engine/Abstract.Networking/IServer.cs new file mode 100644 index 0000000..0eba2c0 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Networking/IServer.cs @@ -0,0 +1,29 @@ +using System; + +namespace WinPC.Engine.Abstract.Networking +{ + public enum ServerStatus + { + Stopped = 0, + Starting = 1, + Running = 2 + } + + + public interface IServer + { + int Port { get; } + int MaxConnections { get; } + int MaxQueuedConnections { get; } + bool Enabled { get; } + + string MOTD { get; } + + string ServerOwner { get; } + + void Start(Int32 maxConnections, Int32 maxQueueSize); + void Stop(); + void Running(); + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Abstract.Objects/IItem.cs b/MudEngine/WinPC.Engine/Abstract.Objects/IItem.cs new file mode 100644 index 0000000..0cee6c9 --- /dev/null +++ b/MudEngine/WinPC.Engine/Abstract.Objects/IItem.cs @@ -0,0 +1,7 @@ +namespace WinPC.Engine.Abstract.Objects +{ + public interface IItem + { + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Commands/InvalidCommand.cs b/MudEngine/WinPC.Engine/Commands/InvalidCommand.cs new file mode 100644 index 0000000..3114870 --- /dev/null +++ b/MudEngine/WinPC.Engine/Commands/InvalidCommand.cs @@ -0,0 +1,24 @@ +using System; +using System.Net.Sockets; +using System.Text; +using WinPC.Engine.Abstract.Core; + +namespace WinPC.Engine.Commands +{ + public class InvalidCommand : ICommand + { + private Socket Connection { get; set; } + public InvalidCommand(Socket connnection) + { + Connection = connnection; + } + + public void Execute() + { + ASCIIEncoding encoding = new ASCIIEncoding(); + Connection.Send(encoding.GetBytes("Invalid Command!" + "\n\r")); + + } + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Core/Logger.cs b/MudEngine/WinPC.Engine/Core/Logger.cs new file mode 100644 index 0000000..bc5d173 --- /dev/null +++ b/MudEngine/WinPC.Engine/Core/Logger.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; + +namespace WinPC.Engine.Core +{ + /// + /// Public Engine Logging Class. + /// + public static class Logger + { + public enum Importance + { + Critical = 0, + Error = 1, + Warning = 2, + Information = 3, + Chat = 4, + All = 5 + } + + /// + /// The Log Filename for the engine log. + /// + public static string LogFilename { get; set; } + + /// + /// Gets or Sets if the Logger is enabled or disabled. + /// + public static Boolean Enabled { get; set; } + + /// + /// Gets or Sets if the logger will output it's information to the Console. + /// + public static Boolean ConsoleOutPut { get; set; } + + /// + /// Clears the queued log messages from cache + /// + public static void ClearLog() + { + //If the log file exists, delete it. + if (String.IsNullOrEmpty(LogFilename)) + LogFilename = "Engine.Log"; + + if (System.IO.File.Exists(LogFilename)) + System.IO.File.Delete(LogFilename); + + //Clear the cache. + if (_Messages != null) + _Messages.Clear(); + } + + public static void WriteLine(String message, Importance importance) + { + //Only write to log if enabled. + if (!Enabled) + return; + + //Make sure we have a valid filename + if (String.IsNullOrEmpty(LogFilename)) + LogFilename = "Engine.Log"; + + //Ensure that the log messages cache is not null + if (_Messages == null) + _Messages = new List(); + + //Get the current time and format it + String Time = DateTime.Now.ToString("h:mm:ss:ff tt"); + + //Output to console if enabled. + if (ConsoleOutPut) + Console.WriteLine(Time + ": " + message); + + //Try to write the message to the log file. + try + { + using (System.IO.StreamWriter file = new System.IO.StreamWriter(LogFilename, true)) + { + //Write the message to file + file.WriteLine(Time + ": " + message); + //Add it to the messages cache. + _Messages.Add(Time + ": " + message); + } + } + catch + { + throw new Exception("Unable to write message (" + message + ") to log file (" + LogFilename + ")."); + } + } + + /// + /// Writes a single line to the engine log file. + /// + /// + public static void WriteLine(String message) + { + //Just output as typical informational stuff. + Logger.WriteLine(message, Importance.Information); + } + + /// + /// Returns an array of messages that have been queued in the log cache. + /// + /// + public static String[] GetMessages() + { + if (_Messages == null) + return new string[0]; + else + return _Messages.ToArray(); + } + + private static List _Messages; + } +} diff --git a/MudEngine/WinPC.Engine/Core/Player.cs b/MudEngine/WinPC.Engine/Core/Player.cs new file mode 100644 index 0000000..87559b3 --- /dev/null +++ b/MudEngine/WinPC.Engine/Core/Player.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Net.Sockets; +using WinPC.Engine.Abstract.Core; + +namespace WinPC.Engine.Core +{ + public class Player : IPlayer + { + public Socket Connection { get; private set; } + public IState CurrentState { get; private set; } + + public List buffer = new List(); + + public Player(IState initialState, Socket connection) + { + Connection = connection; + CurrentState = initialState; + } + + public void Disconnect() + { + Connection.Close(); + } + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Directors/ServerDirector.cs b/MudEngine/WinPC.Engine/Directors/ServerDirector.cs new file mode 100644 index 0000000..e6316e7 --- /dev/null +++ b/MudEngine/WinPC.Engine/Directors/ServerDirector.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Net.Sockets; +using System.Threading; +using WinPC.Engine.Abstract.Directors; +using WinPC.Engine.Abstract.Networking; +using WinPC.Engine.Core; +using WinPC.Engine.States; + +namespace WinPC.Engine.Directors +{ + public class ServerDirector : IServerDirector + { + + public List ConnectionThreads { get; private set; } + public List ConnectedPlayers { get; private set; } + public IServer Server { get; set; } + + public ServerDirector(IServer server) + { + Server = server; + ConnectedPlayers = new List(Server.MaxConnections); + ConnectionThreads = new List(Server.MaxConnections); + + } + + public void AddConnection(Socket connection) + { + var player = new Player(new ConnectState(this), connection); + ConnectedPlayers.Add(player); + + + ConnectionThreads.Add(new Thread(ReceiveDataThread)); + var index = ConnectionThreads.Count - 1; + + ConnectionThreads[index].Name = "Player"; + ConnectionThreads[index].Start(index); + + + } + + public void ReceiveDataThread(object index) + { + var player = ConnectedPlayers[(int) index]; + + while (Server.Enabled) + { + player.CurrentState.Render((int) index); + var command = player.CurrentState.GetCommand(); + command.Execute(); + } + } + + public void DisconnectAll() + { + foreach(var player in ConnectedPlayers) + { + player.Disconnect(); + } + + foreach (var thread in ConnectionThreads) + { + thread.Abort(); + + } + + ConnectedPlayers.Clear(); + ConnectionThreads.Clear(); + } + + + public String RecieveInput(int index) + { + string input = String.Empty; + + while (true) + { + try + { + byte[] buf = new byte[1]; + Int32 recved = ConnectedPlayers[index].Connection.Receive(buf); + + if (recved > 0) + { + if (buf[0] == '\n' && ConnectedPlayers[index].buffer.Count > 0) + { + if (ConnectedPlayers[index].buffer[ConnectedPlayers[index].buffer.Count - 1] == '\r') + ConnectedPlayers[index].buffer.RemoveAt(ConnectedPlayers[index].buffer.Count - 1); + + System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); + input = enc.GetString(ConnectedPlayers[index].buffer.ToArray()); + ConnectedPlayers[index].buffer.Clear(); + //Return a trimmed string. + return input; + } + else + ConnectedPlayers[index].buffer.Add(buf[0]); + } + else if (recved == 0) //Disconnected + { + // ConnectedPlayers[index]. Connected = false; + // this.LoggedIn = false; + return "Disconnected."; + } + } + catch (Exception e) + { + //Flag as disabled + // this.Connected = false; + // this.LoggedIn = false; + return e.Message; + } + } + } + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Engine.cs b/MudEngine/WinPC.Engine/Engine.cs new file mode 100644 index 0000000..d4b83ac --- /dev/null +++ b/MudEngine/WinPC.Engine/Engine.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WinPC.Engine.Abstract.Core; + +namespace WinPC.Engine +{ + public class Engine : IEngine + { + + } +} diff --git a/MudEngine/WinPC.Engine/Networking/Server.cs b/MudEngine/WinPC.Engine/Networking/Server.cs new file mode 100644 index 0000000..d873107 --- /dev/null +++ b/MudEngine/WinPC.Engine/Networking/Server.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using WinPC.Engine.Abstract.Networking; +using WinPC.Engine.Core; +using WinPC.Engine.Directors; + +namespace WinPC.Engine.Networking +{ + public class Server : IServer + { + public Socket Socket { get; private set; } + public ServerStatus Status { get; private set; } + + public int Port { get; private set; } + + public ServerDirector ServerDirector { get; private set; } + + public int MaxConnections {get; private set; } + + public int MaxQueuedConnections { get; private set; } + + public bool Enabled { get; private set; } + + public string MOTD { get; private set; } + + public string ServerOwner { get; private set; } + + private Thread ServerThread { get; set; } + + + public Server() + { + + } + + [Category("Networking")] + public Server(int port) + { + Port = port; + Status = ServerStatus.Stopped; + MaxConnections = 100; + MaxQueuedConnections = 10; + + Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + + } + + public void Start(Int32 maxConnections, Int32 maxQueueSize) + { + Logger.WriteLine("Game Server System Starting..."); + if (Status != ServerStatus.Stopped) + return; + + Status = ServerStatus.Starting; + + + ServerDirector = new ServerDirector(this); + + try + { + IPEndPoint ip = new IPEndPoint(IPAddress.Any, this.Port); + Socket.Bind(ip); + Socket.Listen(this.MaxQueuedConnections); + + this.Status = ServerStatus.Running; + this.Enabled = true; + + ServerThread = new Thread(Running); + ServerThread.Start(); + + Logger.WriteLine("Server status: Running"); + } + catch + { + Logger.WriteLine("Failed to star the Engines Networking Server!"); + this.Status = ServerStatus.Stopped; + Logger.WriteLine("Server status: Stopped"); + } + } + + public void Stop() + { + ServerDirector.DisconnectAll(); + ServerThread.Abort(); + Socket.Close(); + Socket = null; + + Enabled = false; + Status = ServerStatus.Stopped; + + } + + public void Running() + { + while (Status == ServerStatus.Running) + { + ServerDirector.AddConnection(Socket.Accept()); + } + } + + + + + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/Properties/AssemblyInfo.cs b/MudEngine/WinPC.Engine/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..77cd262 --- /dev/null +++ b/MudEngine/WinPC.Engine/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WinPC.Engine")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WinPC.Engine")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3afea0e1-5a14-474a-b477-03ba36fcc8b7")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MudEngine/WinPC.Engine/States/ConnectState.cs b/MudEngine/WinPC.Engine/States/ConnectState.cs new file mode 100644 index 0000000..225fd6c --- /dev/null +++ b/MudEngine/WinPC.Engine/States/ConnectState.cs @@ -0,0 +1,44 @@ +using System; +using System.Net.Sockets; +using System.Text; +using WinPC.Engine.Abstract.Core; +using WinPC.Engine.Commands; +using WinPC.Engine.Directors; + +namespace WinPC.Engine.States +{ + public class ConnectState : IState + { + public ServerDirector Director { get; private set; } + private Socket Connection { get; set; } + private ASCIIEncoding Encoding { get; set; } + private int Index; + + public ConnectState(ServerDirector director) + { + Director = director; + Encoding = new ASCIIEncoding(); + + } + public void Render(int index) + { + Index = index; + + Connection = Director.ConnectedPlayers[index].Connection; + + Director.ConnectedPlayers[index].Connection.Send(Encoding.GetBytes("Welcome to Scionwest's Mud Engine!"+"\n\r")); + Director.ConnectedPlayers[index].Connection.Send(Encoding.GetBytes("Please enter your name" + "\n\r")); + + + + } + + public ICommand GetCommand() + { + + var input = Director.RecieveInput(Index); + + return new InvalidCommand(Connection); + } + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/States/MainMenuState.cs b/MudEngine/WinPC.Engine/States/MainMenuState.cs new file mode 100644 index 0000000..aa2a933 --- /dev/null +++ b/MudEngine/WinPC.Engine/States/MainMenuState.cs @@ -0,0 +1,18 @@ +using WinPC.Engine.Abstract.Core; + +namespace WinPC.Engine.States +{ + public class MainMenuState : IState + { + + public void Render(int index) + { + throw new System.NotImplementedException(); + } + + public ICommand GetCommand() + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/WinPC.Engine.csproj b/MudEngine/WinPC.Engine/WinPC.Engine.csproj new file mode 100644 index 0000000..67483d7 --- /dev/null +++ b/MudEngine/WinPC.Engine/WinPC.Engine.csproj @@ -0,0 +1,86 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {9D9E8CAC-8876-4725-9A65-2077DE4322DD} + Library + Properties + WinPC.Engine + WinPC.Engine + v4.0 + 512 + SAK + SAK + SAK + SAK + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MudEngine/WinPC.Engine/WinPC.Engine.csproj.vspscc b/MudEngine/WinPC.Engine/WinPC.Engine.csproj.vspscc new file mode 100644 index 0000000..feffdec --- /dev/null +++ b/MudEngine/WinPC.Engine/WinPC.Engine.csproj.vspscc @@ -0,0 +1,10 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" +} diff --git a/MudEngine/WinPC.Server/Program.cs b/MudEngine/WinPC.Server/Program.cs new file mode 100644 index 0000000..bc60625 --- /dev/null +++ b/MudEngine/WinPC.Server/Program.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WinPC.Engine; +using WinPC.Engine.Abstract.Networking; +using WinPC.Engine.Core; +using WinPC.Engine.Networking; + +namespace WinPC.Server +{ + class Program + { + static void Main(string[] args) + { + //Setup the engines log system + Logger.LogFilename = "StandardGame.Log"; + Logger.Enabled = true; + Logger.ConsoleOutPut = true; + Logger.ClearLog(); //Delete previous file. + Logger.WriteLine("Server app starting..."); + + IServer server = new Engine.Networking.Server(4000); + + server.Start(100,20); + + while (server.Enabled) + { + + } + + server = null; + //System.Windows.Forms.Application.Exit(); + + + } + } +} diff --git a/MudEngine/WinPC.Server/Properties/AssemblyInfo.cs b/MudEngine/WinPC.Server/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..726064c --- /dev/null +++ b/MudEngine/WinPC.Server/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WinPC.Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WinPC.Server")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b48ada4f-5fc4-40e5-8f31-21f9745850d9")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MudEngine/WinPC.Server/WinPC.Server.csproj b/MudEngine/WinPC.Server/WinPC.Server.csproj new file mode 100644 index 0000000..1f15e5d --- /dev/null +++ b/MudEngine/WinPC.Server/WinPC.Server.csproj @@ -0,0 +1,67 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {161E78DB-10C5-43A6-BC15-0945BC6F941F} + Exe + Properties + WinPC.Server + WinPC.Server + v4.0 + Client + 512 + SAK + SAK + SAK + SAK + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + {9D9E8CAC-8876-4725-9A65-2077DE4322DD} + WinPC.Engine + + + + + \ No newline at end of file diff --git a/MudEngine/WinPC.Server/WinPC.Server.csproj.vspscc b/MudEngine/WinPC.Server/WinPC.Server.csproj.vspscc new file mode 100644 index 0000000..feffdec --- /dev/null +++ b/MudEngine/WinPC.Server/WinPC.Server.csproj.vspscc @@ -0,0 +1,10 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" +} diff --git a/MudEngine/WinPC_Engine/Networking/Server.cs b/MudEngine/WinPC_Engine/Networking/Server.cs index 3b209f9..1e5b342 100644 --- a/MudEngine/WinPC_Engine/Networking/Server.cs +++ b/MudEngine/WinPC_Engine/Networking/Server.cs @@ -100,12 +100,12 @@ namespace MudEngine.Networking this._Server = null; this.Enabled = false; - this.Status = ServerStatus.Stopped; + Status = ServerStatus.Stopped; } private void ServerLoop() { - while (this.Status == ServerStatus.Running) + while (Status == ServerStatus.Running) { this.ConnectionManager.AddConnection(this._Game, this._Server.Accept()); }