Exemplo n.º 1
0
        public static void AddServer(string key, DirectServerProvider server)
        {
            if (Servers.ContainsKey(key))
            {
                throw new Exception("Server already exists with the given key.");
            }

            Servers[key] = server;
        }
Exemplo n.º 2
0
        public static DirectServerProvider GetServer(string ip, int port)
        {
            lock (Servers) {
                DirectServerProvider server = null;
                Servers.TryGetValue(ip + ":" + port, out server);

                return(server);
            }
        }
Exemplo n.º 3
0
        public void Connect(INetContext context)
        {
            var server = DirectServerProvider.GetServer(context.IPAddress, context.Port);

            if (server == null)
            {
                long tick = Environment.TickCount;
                while (Environment.TickCount < tick + 50 && server == null)
                {
                    server = DirectServerProvider.GetServer(context.IPAddress, context.Port);
                    System.Threading.Thread.Sleep(1);
                }

                if (server == null)
                {
                    throw new Exception("Could not connect to server");
                }
            }
            server.TryConnectClient(this);
        }
Exemplo n.º 4
0
 public void DisconnectFrom(DirectServerProvider Server)
 {
     IsConnected = false;
     UserDisconnected?.Invoke(this, new ProviderUserEventArgs());
 }
Exemplo n.º 5
0
 public void RejectConnection(DirectServerProvider Server)
 {
     IsConnected = false;
     throw new Exception("Server not accepting new connections");
 }
Exemplo n.º 6
0
 public void AcceptConnection(DirectServerProvider Server)
 {
     IsConnected  = true;
     ActiveServer = Server;
     UserConnected?.Invoke(this, new ProviderUserEventArgs());
 }