Code:
public class ChattingServer : SlotMachine
{
private string ReceiveStringMessage(out Socket sender);
public ChattingServer() : base()
{
//Define more things if you want
}
public void RunServer()
{
Socket s;
string msg = ReceiveStringMessage(out s);
if(msg == "/createRoom -id 5587 -name 'Elio'")
{
ChatRoom room = new ChatRoom(5587);
this.RegisterSlot(room, "Elio");
}
if(msg == "/startRoom -name 'Elio'")
{
this.StartSlot("Elio", true);
}
}
}
Code:
//FILE NAME: Slot.cs
//Creator: Elio Decolli (Richard Nixon)
//- MPGH 2012
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SlotMachine
{
/// <summary>
/// Represents a Slot class. This class must serve as a base.
/// </summary>
[Serializable]
public abstract class Slot
{
long ID = 0x00000000000L;
public Slot(long slotID)
{
ID += slotID;
}
/// <summary>
/// Gets the current Slot ID.
/// </summary>
public long SlotID { get { return ID; } }
/// <summary>
/// Starts the current Slot.
/// </summary>
public void StartSlot()
{
}
/// <summary>
/// Stops the current Slot.
/// </summary>
public void StopSlot()
{
}
}
}
Code:
//FILE NAME: SlotMachine.cs
//Creator: Elio Decolli (Richard Nixon)
//- MPGH 2012
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace SlotMachine
{
/// <summary>
/// Represents a Slot Machine class, used to store and manage slots.
/// </summary>
[Serializable]
public class SlotMachine
{
private Dictionary<string, Slot> PPES = new Dictionary<string, Slot>();
public SlotMachine()
{
}
/// <summary>
/// Adds a new Slot to the Slot Machine.
/// </summary>
/// <param name="slot">The Slot to be added.</param>
/// <param name="name">The UNIQUE name of the Slot.</param>
public void RegisterSlot(Slot slot, string name)
{
if (PPES.ContainsKey(name))
{
throw new Exception("Slot Name is already taken.");
}
PPES.Add(name, slot);
}
/// <summary>
/// Removes a Slot from the storage.
/// </summary>
/// <param name="name">The unique name of the Slot to be removed.</param>
public void RemoveSlot(string name)
{
if (!PPES.ContainsKey(name))
{
throw new Exception("Slot Name doesn't exists in the current contest.");
}
PPES.Remove(name);
}
/// <summary>
/// Removes a Slot from the storage.
/// </summary>
/// <param name="slot">The Slot to be removed.</param>
public void RemoveSlot(Slot slot)
{
if (!PPES.ContainsValue(slot))
{
throw new Exception("Slot doesn't exists in the current contest.");
}
foreach (KeyValuePair<string, Slot> kp in PPES)
{
if (kp.Value == slot)
PPES.Remove(kp.Key);
}
}
/// <summary>
/// Starts a Slot from the storage.
/// </summary>
/// <param name="name">The name of the Slot to start.</param>
/// <param name="createNewThread">If True the Slot will be runned in a new thread, otherwise not.
/// Warning: Once you start a Slot in a new thread you cannot stop it, unless you find and close that thread.</param>
public void StartSlot(string name, bool createNewThread)
{
if (createNewThread)
{
Thread t = new Thread(PPES[name].StartSlot);
t.Start();
}
else
{
PPES[name].StartSlot();
}
}
}
}