the big owl in legend of ocarina
b
This commit is contained in:
parent
f548bbbfd0
commit
e96d341cb6
3 changed files with 62 additions and 6 deletions
|
@ -20,6 +20,7 @@ namespace SockScape {
|
|||
"Run Master",
|
||||
"Master Port",
|
||||
"Master Addr",
|
||||
"Master Secret",
|
||||
"Max Users"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -5,25 +5,40 @@ using System.Net.Sockets;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Glove;
|
||||
using SockScape.Encryption;
|
||||
|
||||
namespace SockScape {
|
||||
class MasterUdpClient {
|
||||
static class MasterUdpClient {
|
||||
private static Key Key;
|
||||
public static Cipher Encryptor { get; private set; }
|
||||
|
||||
private static UdpClient Sock;
|
||||
private static Thread ListeningThread;
|
||||
private static bool IsOpen;
|
||||
|
||||
public static void Initialize() {
|
||||
if(IsOpen)
|
||||
if(IsOpen || ListeningThread != null)
|
||||
return;
|
||||
|
||||
short port = (short) Configuration.General["Master Port"];
|
||||
short port = (short)Configuration.General["Master Port"];
|
||||
Sock = new UdpClient(Configuration.General["Master Addr"], port);
|
||||
|
||||
Key = new Key();
|
||||
|
||||
IsOpen = true;
|
||||
ListeningThread = new Thread(Listener);
|
||||
ListeningThread.Start();
|
||||
}
|
||||
|
||||
public static void Listener() {
|
||||
while(IsOpen) {
|
||||
while(Sock.Available > 0) {
|
||||
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Close() {
|
||||
|
|
|
@ -6,9 +6,14 @@ using System.Net.Sockets;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Glove;
|
||||
using SockScape.Encryption;
|
||||
|
||||
namespace SockScape {
|
||||
static class MasterUdpServer {
|
||||
private static Dictionary<string, Client> Prospects;
|
||||
private static Dictionary<string, Client> Clients;
|
||||
|
||||
private static UdpClient Sock;
|
||||
private static Thread ListeningThread;
|
||||
private static bool IsOpen;
|
||||
|
@ -17,6 +22,7 @@ namespace SockScape {
|
|||
if(IsOpen || ListeningThread != null)
|
||||
return;
|
||||
|
||||
Clients = new Dictionary<string, Client>();
|
||||
short port = (short)Configuration.General["Master Port"];
|
||||
Sock = new UdpClient(new IPEndPoint(IPAddress.Any, port));
|
||||
|
||||
|
@ -25,10 +31,38 @@ namespace SockScape {
|
|||
ListeningThread.Start();
|
||||
}
|
||||
|
||||
private static bool IsClientConnected(string client) {
|
||||
return Clients.ContainsKey(client);
|
||||
}
|
||||
|
||||
public static void Listener() {
|
||||
while(IsOpen) {
|
||||
IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
while(Sock.Available > 0) {
|
||||
var data = Sock.Receive(ref endPoint);
|
||||
var client = endPoint.ToString();
|
||||
var encryptor = IsClientConnected(client) ? Clients[client].Encryptor : null;
|
||||
|
||||
Packet packet =
|
||||
encryptor == null ? Packet.FromBytes(data)
|
||||
: Packet.FromBytes(encryptor.Parse(data));
|
||||
|
||||
switch((kIntraMasterId)packet.Id) {
|
||||
case kIntraMasterId.InitiationAttempt:
|
||||
if(packet.RegionCount != 1)
|
||||
break;
|
||||
|
||||
if(packet[0] == Configuration.General["Master Secret"]) {
|
||||
var request =
|
||||
|
||||
var request = Key.GenerateRequestPacket().GetBytes();
|
||||
Sock.Send(request, request.Length, endPoint);
|
||||
}
|
||||
break;
|
||||
case kIntraMasterId.KeyExchange:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(1);
|
||||
|
@ -41,5 +75,11 @@ namespace SockScape {
|
|||
ListeningThread = null;
|
||||
Sock.Dispose();
|
||||
}
|
||||
|
||||
class Client {
|
||||
public DateTime LastReceive { get; set; }
|
||||
public Cipher Encryptor { get; set; }
|
||||
public Key Key { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue