2017-06-16 21:00:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2017-07-22 19:27:41 +00:00
|
|
|
|
namespace SockScape {
|
2017-09-06 20:59:38 +00:00
|
|
|
|
static class ServerList {
|
|
|
|
|
private static ServerDictionary Servers { get; }
|
|
|
|
|
= new ServerDictionary();
|
2017-06-16 21:00:01 +00:00
|
|
|
|
|
2017-09-06 20:59:38 +00:00
|
|
|
|
private static Dictionary<UInt16, Server> List
|
|
|
|
|
=> Servers.List;
|
|
|
|
|
|
|
|
|
|
public static void Write(Server server) {
|
|
|
|
|
lock(Servers) {
|
|
|
|
|
if(HasId(server.Id) && !List[server.Id].Address.Equals(server.Address))
|
|
|
|
|
Console.WriteLine($"{DateTime.Now.ToShortTimeString()} - Server {server.Id} has changed IP addresses.");
|
|
|
|
|
|
|
|
|
|
List[server.Id] = server;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Packet ReportPacket {
|
|
|
|
|
get {
|
|
|
|
|
var packet = new Packet(kInterMasterId.);
|
|
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
|
}
|
2017-08-31 20:59:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 20:59:38 +00:00
|
|
|
|
public static bool HasId(UInt16 id)
|
|
|
|
|
=> List.ContainsKey(id);
|
|
|
|
|
|
|
|
|
|
public static void Clear()
|
|
|
|
|
=> List.Clear();
|
2017-08-31 20:59:57 +00:00
|
|
|
|
|
2017-09-06 20:59:38 +00:00
|
|
|
|
public class ServerDictionary {
|
|
|
|
|
public Dictionary<UInt16, Server> List { get; }
|
|
|
|
|
= new Dictionary<UInt16, Server>();
|
|
|
|
|
|
|
|
|
|
public Server this[UInt16 i] {
|
|
|
|
|
get => List.ContainsKey(i) ? List[i] : null;
|
|
|
|
|
set => List[i] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-31 20:59:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Server {
|
|
|
|
|
public ushort Id { get; set; }
|
|
|
|
|
public ushort UserCount { get; set; }
|
2017-09-06 20:59:38 +00:00
|
|
|
|
public IPAddress Address { get; set; }
|
|
|
|
|
public ushort Port { get; set; }
|
2017-06-16 21:00:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|