Initial Check-in for Alpha 2.0 source code.
Includes working Telnet server, working command engine and Character code.
This commit is contained in:
parent
224f754514
commit
3d8051c995
28 changed files with 1495 additions and 0 deletions
65
MudEngine/WinPC_Engine/Networking/ConnectionManager.cs
Normal file
65
MudEngine/WinPC_Engine/Networking/ConnectionManager.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
using MudEngine.Game;
|
||||
using MudEngine.Game.Characters;
|
||||
|
||||
namespace MudEngine.Networking
|
||||
{
|
||||
public static class ConnectionManager
|
||||
{
|
||||
//Collection of currently connected players.
|
||||
public static List<StandardCharacter> Connections { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new character for the player and sets it up on the server.
|
||||
/// </summary>
|
||||
/// <param name="game"></param>
|
||||
/// <param name="connection"></param>
|
||||
public static void AddConnection(StandardGame game, Socket connection)
|
||||
{
|
||||
//Exception checking.
|
||||
if (Connections == null)
|
||||
Connections = new List<StandardCharacter>();
|
||||
|
||||
//Instance a new character and provide it with the Socket.
|
||||
StandardCharacter character = new StandardCharacter("New Player", "New networked client.", game, connection);
|
||||
|
||||
//Add it to the Connections collection
|
||||
Connections.Add(character);
|
||||
|
||||
//Invoke the Characters Server connection method
|
||||
character.Connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the specified player character from the server.
|
||||
/// </summary>
|
||||
/// <param name="character"></param>
|
||||
public static void RemoveConnection(StandardCharacter character)
|
||||
{
|
||||
Connections.Remove(character);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects all of the currently connected clients.
|
||||
/// </summary>
|
||||
public static void DisconnectAll()
|
||||
{
|
||||
if (Connections == null)
|
||||
return;
|
||||
|
||||
foreach (StandardCharacter character in Connections)
|
||||
{
|
||||
character.Disconnect();
|
||||
}
|
||||
Connections.Clear();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue