using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace LoginServer
{
public class SessionCmp : ActiveComponent
{
int maxSlots;
public class Session
{
public Socket Socket;
public byte[] Buffer;
public Socket sendSocket;
public Socket listensocket;
public SocketInformation info;
public Session()
{
Buffer =
new byte[Int32.
Parse((string)Components.
Settings().
data["net"]["buffer_size"])];
sendSocket = listensocket;
}
public void Send(byte[] buffer)
{
Socket list =
new Socket
(info
);
// whatever. sendSocket = listensocket;
list.Send(buffer);
}
}
public Session[] Sessions;
public override void Init()
{
maxSlots = Int32.Parse((string)Components.Settings().data["net"]["max_connections"]);
Sessions =
new Session
[maxSlots
];
for (int i = 0; i < maxSlots; i++)
{
Sessions[i] = null;
}
Console.WriteLine("SessionCMP/Init(): Session manager has been created");
}
public override void Load()
{
}
public override void Start()
{
}
public override void Shutdown()
{
}
public override void Update()
{
// some continuity checking can go here later.
}
public int GetSlot()
{
for (int i = 0; i < maxSlots; i++)
{
if (Sessions[i] == null)
{
return i;
}
}
return -1;
}
public void CreateSession(int ID, Socket listensocket)
{
Sessions
[ID
] =
new Session
();
}
public void MarkForDestroy(int ID)
{
// THIS FUNCTION IS BAD! IT DOESNT HAVE ANY MERCY FOR INTERNET DISCONNECTS. REWRITE URGENTLY.
Sessions[ID] = null;
}
}
}