MudCompiler: No longer works. Needs to be re-wrote to support the new Alpha 2.0 engine MudDesigenr: Removed most of the forms since we are not working on it. Only form left is Project Manager, which will be removed shortly as well. MudGame: No longer runs. All of the source code was removed due to MudEngine Alpha 2.0 source changing drastically. MudEngine: Alpha 2.0 source code finally checked-in. It contains the full re-build of the engine. A lot of new abstract classes have been added.
86 lines
2.6 KiB
C#
86 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Threading;
|
|
using System.Text;
|
|
|
|
using MudEngine.Core;
|
|
|
|
namespace MudEngine.Communication
|
|
{
|
|
public class Server : BaseServer
|
|
{
|
|
//Listens for incoming connections
|
|
private TcpListener _Listener;
|
|
|
|
//Dedicated thread for accepting and processing new connections
|
|
private Thread _Connect;
|
|
|
|
private Dictionary<BaseCharacter, Thread> _ClientCollection;
|
|
|
|
/// <summary>
|
|
/// Server constructor. Requires a currently active game to start.
|
|
/// </summary>
|
|
/// <param name="game"></param>
|
|
public Server(BaseGame game) : base(game)
|
|
{
|
|
this._Listener = new TcpListener(IPAddress.Any, 555);
|
|
this._Connect = new Thread(new ThreadStart(ListenForConnections));
|
|
this._ClientCollection = new Dictionary<BaseCharacter, Thread>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Server constructor. Requires a currently active game and desired port number to start.
|
|
/// </summary>
|
|
/// <param name="game"></param>
|
|
/// <param name="port"></param>
|
|
public Server(BaseGame game, int port)
|
|
: base(game)
|
|
{
|
|
this._Listener = new TcpListener(IPAddress.Any, port);
|
|
this._Connect = new Thread(new ThreadStart(ListenForConnections));
|
|
this._ClientCollection = new Dictionary<BaseCharacter, Thread>();
|
|
}
|
|
|
|
//Listens for incoming client connections.
|
|
private void ListenForConnections()
|
|
{
|
|
this._Listener.Start();
|
|
|
|
while (true)
|
|
{
|
|
TcpClient client = this._Listener.AcceptTcpClient();
|
|
|
|
//Someone connects, send them to a new thread.
|
|
Thread newClient = new Thread(new ParameterizedThreadStart(OnConnect));
|
|
newClient.Start(client);
|
|
}
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
this._Connect.Start();
|
|
}
|
|
|
|
public override void OnConnect(object client)
|
|
{
|
|
this.ActiveGame.OnConnect((TcpClient)client);
|
|
}
|
|
|
|
public override void OnDisconnect(object client)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void RecieveData(string data)
|
|
{
|
|
//TODO: command needs to be executed.
|
|
}
|
|
|
|
public override void SendData(string data)
|
|
{
|
|
}
|
|
}
|
|
}
|