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"
This commit is contained in:
parent
bec840f5e4
commit
a0c406d482
37 changed files with 960 additions and 3 deletions
|
@ -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
|
||||
|
|
7
MudEngine/WinPC.Engine/Abstract.Actions/ILoadable.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Actions/ILoadable.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Actions
|
||||
{
|
||||
public interface ILoadable
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Actions/ISaveable.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Actions/ISaveable.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Actions
|
||||
{
|
||||
public interface ISaveable
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Actions/IUseable.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Actions/IUseable.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Actions
|
||||
{
|
||||
public interface IUseable
|
||||
{
|
||||
|
||||
}
|
||||
}
|
9
MudEngine/WinPC.Engine/Abstract.Core/ICommand.cs
Normal file
9
MudEngine/WinPC.Engine/Abstract.Core/ICommand.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using System.Net.Sockets;
|
||||
|
||||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface ICommand
|
||||
{
|
||||
void Execute();
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Core/IEngine.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Core/IEngine.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IEngine
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Core/IGame.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Core/IGame.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IGame
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Core/IGameObject.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Core/IGameObject.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IGameObject
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Core/IInventory.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Core/IInventory.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IInventory
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Core/ILogger.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Core/ILogger.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
|
||||
}
|
||||
}
|
9
MudEngine/WinPC.Engine/Abstract.Core/IPlayer.cs
Normal file
9
MudEngine/WinPC.Engine/Abstract.Core/IPlayer.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IPlayer
|
||||
{
|
||||
IState CurrentState { get; }
|
||||
|
||||
void Disconnect();
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Core/IRealm.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Core/IRealm.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IRealm
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Core/IRoom.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Core/IRoom.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IRoom
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Core/IRule.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Core/IRule.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IRule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
9
MudEngine/WinPC.Engine/Abstract.Core/IState.cs
Normal file
9
MudEngine/WinPC.Engine/Abstract.Core/IState.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace WinPC.Engine.Abstract.Core
|
||||
{
|
||||
public interface IState
|
||||
{
|
||||
void Render(int index);
|
||||
ICommand GetCommand();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Directors
|
||||
{
|
||||
public interface IConnectionsDirector
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Directors
|
||||
{
|
||||
public interface IRuleDirector
|
||||
{
|
||||
|
||||
}
|
||||
}
|
19
MudEngine/WinPC.Engine/Abstract.Directors/IServerDirector.cs
Normal file
19
MudEngine/WinPC.Engine/Abstract.Directors/IServerDirector.cs
Normal file
|
@ -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<Thread> ConnectionThreads { get; }
|
||||
|
||||
void AddConnection(Socket connection);
|
||||
void ReceiveDataThread(Object index);
|
||||
void DisconnectAll();
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Networking
|
||||
{
|
||||
public interface IConnection
|
||||
{
|
||||
|
||||
}
|
||||
}
|
29
MudEngine/WinPC.Engine/Abstract.Networking/IServer.cs
Normal file
29
MudEngine/WinPC.Engine/Abstract.Networking/IServer.cs
Normal file
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
7
MudEngine/WinPC.Engine/Abstract.Objects/IItem.cs
Normal file
7
MudEngine/WinPC.Engine/Abstract.Objects/IItem.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace WinPC.Engine.Abstract.Objects
|
||||
{
|
||||
public interface IItem
|
||||
{
|
||||
|
||||
}
|
||||
}
|
24
MudEngine/WinPC.Engine/Commands/InvalidCommand.cs
Normal file
24
MudEngine/WinPC.Engine/Commands/InvalidCommand.cs
Normal file
|
@ -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"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
115
MudEngine/WinPC.Engine/Core/Logger.cs
Normal file
115
MudEngine/WinPC.Engine/Core/Logger.cs
Normal file
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WinPC.Engine.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Public Engine Logging Class.
|
||||
/// </summary>
|
||||
public static class Logger
|
||||
{
|
||||
public enum Importance
|
||||
{
|
||||
Critical = 0,
|
||||
Error = 1,
|
||||
Warning = 2,
|
||||
Information = 3,
|
||||
Chat = 4,
|
||||
All = 5
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Log Filename for the engine log.
|
||||
/// </summary>
|
||||
public static string LogFilename { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets if the Logger is enabled or disabled.
|
||||
/// </summary>
|
||||
public static Boolean Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets if the logger will output it's information to the Console.
|
||||
/// </summary>
|
||||
public static Boolean ConsoleOutPut { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Clears the queued log messages from cache
|
||||
/// </summary>
|
||||
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<string>();
|
||||
|
||||
//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 + ").");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a single line to the engine log file.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public static void WriteLine(String message)
|
||||
{
|
||||
//Just output as typical informational stuff.
|
||||
Logger.WriteLine(message, Importance.Information);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array of messages that have been queued in the log cache.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static String[] GetMessages()
|
||||
{
|
||||
if (_Messages == null)
|
||||
return new string[0];
|
||||
else
|
||||
return _Messages.ToArray();
|
||||
}
|
||||
|
||||
private static List<String> _Messages;
|
||||
}
|
||||
}
|
25
MudEngine/WinPC.Engine/Core/Player.cs
Normal file
25
MudEngine/WinPC.Engine/Core/Player.cs
Normal file
|
@ -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<byte> buffer = new List<byte>();
|
||||
|
||||
public Player(IState initialState, Socket connection)
|
||||
{
|
||||
Connection = connection;
|
||||
CurrentState = initialState;
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
Connection.Close();
|
||||
}
|
||||
}
|
||||
}
|
116
MudEngine/WinPC.Engine/Directors/ServerDirector.cs
Normal file
116
MudEngine/WinPC.Engine/Directors/ServerDirector.cs
Normal file
|
@ -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<Thread> ConnectionThreads { get; private set; }
|
||||
public List<Player> ConnectedPlayers { get; private set; }
|
||||
public IServer Server { get; set; }
|
||||
|
||||
public ServerDirector(IServer server)
|
||||
{
|
||||
Server = server;
|
||||
ConnectedPlayers = new List<Player>(Server.MaxConnections);
|
||||
ConnectionThreads = new List<Thread>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
MudEngine/WinPC.Engine/Engine.cs
Normal file
13
MudEngine/WinPC.Engine/Engine.cs
Normal file
|
@ -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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
109
MudEngine/WinPC.Engine/Networking/Server.cs
Normal file
109
MudEngine/WinPC.Engine/Networking/Server.cs
Normal file
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
36
MudEngine/WinPC.Engine/Properties/AssemblyInfo.cs
Normal file
36
MudEngine/WinPC.Engine/Properties/AssemblyInfo.cs
Normal file
|
@ -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")]
|
44
MudEngine/WinPC.Engine/States/ConnectState.cs
Normal file
44
MudEngine/WinPC.Engine/States/ConnectState.cs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
18
MudEngine/WinPC.Engine/States/MainMenuState.cs
Normal file
18
MudEngine/WinPC.Engine/States/MainMenuState.cs
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
86
MudEngine/WinPC.Engine/WinPC.Engine.csproj
Normal file
86
MudEngine/WinPC.Engine/WinPC.Engine.csproj
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9D9E8CAC-8876-4725-9A65-2077DE4322DD}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WinPC.Engine</RootNamespace>
|
||||
<AssemblyName>WinPC.Engine</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Abstract.Actions\ILoadable.cs" />
|
||||
<Compile Include="Abstract.Actions\ISaveable.cs" />
|
||||
<Compile Include="Abstract.Core\ICommand.cs" />
|
||||
<Compile Include="Abstract.Core\IEngine.cs" />
|
||||
<Compile Include="Abstract.Core\IGame.cs" />
|
||||
<Compile Include="Abstract.Core\IGameObject.cs" />
|
||||
<Compile Include="Abstract.Core\IInventory.cs" />
|
||||
<Compile Include="Abstract.Core\ILogger.cs" />
|
||||
<Compile Include="Abstract.Core\IPlayer.cs" />
|
||||
<Compile Include="Abstract.Core\IRealm.cs" />
|
||||
<Compile Include="Abstract.Core\IRoom.cs" />
|
||||
<Compile Include="Abstract.Core\IRule.cs" />
|
||||
<Compile Include="Abstract.Core\IState.cs" />
|
||||
<Compile Include="Abstract.Actions\IUseable.cs" />
|
||||
<Compile Include="Abstract.Directors\IConnectionsDirector.cs" />
|
||||
<Compile Include="Abstract.Directors\IRuleDirector.cs" />
|
||||
<Compile Include="Abstract.Directors\IServerDirector.cs" />
|
||||
<Compile Include="Abstract.Networking\IConnection.cs" />
|
||||
<Compile Include="Abstract.Networking\IServer.cs" />
|
||||
<Compile Include="Abstract.Objects\IItem.cs" />
|
||||
<Compile Include="Commands\InvalidCommand.cs" />
|
||||
<Compile Include="Core\Logger.cs" />
|
||||
<Compile Include="Core\Player.cs" />
|
||||
<Compile Include="Directors\ServerDirector.cs" />
|
||||
<Compile Include="Engine.cs" />
|
||||
<Compile Include="Networking\Server.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="States\ConnectState.cs" />
|
||||
<Compile Include="States\MainMenuState.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
10
MudEngine/WinPC.Engine/WinPC.Engine.csproj.vspscc
Normal file
10
MudEngine/WinPC.Engine/WinPC.Engine.csproj.vspscc
Normal file
|
@ -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"
|
||||
}
|
38
MudEngine/WinPC.Server/Program.cs
Normal file
38
MudEngine/WinPC.Server/Program.cs
Normal file
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
36
MudEngine/WinPC.Server/Properties/AssemblyInfo.cs
Normal file
36
MudEngine/WinPC.Server/Properties/AssemblyInfo.cs
Normal file
|
@ -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")]
|
67
MudEngine/WinPC.Server/WinPC.Server.csproj
Normal file
67
MudEngine/WinPC.Server/WinPC.Server.csproj
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{161E78DB-10C5-43A6-BC15-0945BC6F941F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WinPC.Server</RootNamespace>
|
||||
<AssemblyName>WinPC.Server</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WinPC.Engine\WinPC.Engine.csproj">
|
||||
<Project>{9D9E8CAC-8876-4725-9A65-2077DE4322DD}</Project>
|
||||
<Name>WinPC.Engine</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
10
MudEngine/WinPC.Server/WinPC.Server.csproj.vspscc
Normal file
10
MudEngine/WinPC.Server/WinPC.Server.csproj.vspscc
Normal file
|
@ -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"
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue