コード例 #1
0
        public override void Update()
        {
            base.Update();

            ServerComponent    server   = Owner.Get <ServerComponent>();
            EntityMapComponent entities = Owner.Get <EntityMapComponent>();

            if (entities != null)
            {
                server.Entities = entities.Count;
            }

            ClientMapComponent clients = Owner.Get <ClientMapComponent>();

            if (clients != null)
            {
                server.Clients = clients.Count;
            }

            GroupListMapComponent groups = Owner.Get <GroupListMapComponent>();

            if (groups != null)
            {
                server.Groups = groups.Count;
            }

            SessionMapComponent sessions = Owner.Get <SessionMapComponent>();

            if (sessions != null)
            {
                server.Sessions = sessions.Count;
            }
        }
コード例 #2
0
ファイル: ServerController.cs プロジェクト: vaginessa/Code
        public Entity Add()
        {
            Entity entity = new Entity();

            ServerComponent server = new ServerComponent()
            {
                Name = Environment.MachineName, Address = "127.0.0.1"
            };

            entity.Add(server);

            ServerOptionsComponent options = new ServerOptionsComponent();

            entity.Add(options);

            ServerStatusComponent status = new ServerStatusComponent();

            entity.Add(status);

            MachineComponent machine = new ServerMachineComponent();

            entity.Add(machine);

            SessionMapComponent sessions = new SessionMapComponent();

            entity.Add(sessions);
#if DEBUG
            LogComponent log = new LogComponent(LogController);
            entity.Add(log);
#endif
            Add(entity);

            return(entity);
        }
コード例 #3
0
        public Entity Add()
        {
            Entity entity = new Entity();

            ServerComponent server = new ServerComponent()
            {
                Name = Environment.MachineName, Address = "127.0.0.1"
            };

            entity.Add(server);

            ServerOptionsComponent options = new ServerOptionsComponent();

            entity.Add(options);

            ServerStatusComponent status = new ServerStatusComponent();

            entity.Add(status);

            MachineComponent machine = new RouterMachineComponent();

            entity.Add(machine);

            ServerListComponent servers = new ServerListComponent();

            entity.Add(servers);

            EntityMapComponent entities = new EntityMapComponent();

            entity.Add(entities);

            SessionMapComponent sessions = new SessionMapComponent();

            entity.Add(sessions);

            GroupListMapComponent groups = new GroupListMapComponent();

            entity.Add(groups);

            ClientMapComponent clients = new ClientMapComponent();

            entity.Add(clients);

            TransferMapComponent transfers = new TransferMapComponent();

            entity.Add(transfers);
#if DEBUG
            LogComponent log = new LogComponent(LogController);
            entity.Add(log);
#endif
            Add(entity);

            return(entity);
        }
コード例 #4
0
        private void DebugTab_DestroySessions(object sender, RoutedEventArgs e)
        {
            //DemonSaw.Entity.Entity entity = RouterController.SelectedItem;
            //if (entity == null)
            //	return;

            //ClientMapComponent clients = entity.Get<ClientMapComponent>();
            //foreach (DemonSaw.Entity.Entity ent in clients.Map.Values)
            //{
            //	TunnelComponent tunnel = ent.Get<TunnelComponent>();
            //	PingRequestCommand req = new PingRequestCommand(ent, tunnel.Connection);
            //	HttpCode code = req.Execute();
            //}

            foreach (DemonSaw.Entity.Entity entity in RouterController.List)
            {
                SessionMapComponent sessions = entity.Get <SessionMapComponent>();
                sessions.Clear();
            }
        }
コード例 #5
0
        private void ProcessState(object obj)
        {
            Socket         socket  = (Socket)obj;
            NetworkChannel channel = null;

            JsonAction action   = JsonAction.None;
            JsonType   jsonType = JsonType.None;

            try
            {
                do
                {
                    // Connect
                    channel = new NetworkChannel(socket);

                    // Receive
                    HttpRequest httpRequest;
                    channel.Receive(out httpRequest);
                    if (httpRequest == null)
                    {
                        channel.SendBadRequest();
                        return;
                    }

                    // Data
                    Status = DemonStatus.Success;

                    // Handshake
                    if (httpRequest.Session == null)
                    {
                        ServerStatusComponent    status  = Owner.Get <ServerStatusComponent>();
                        HandshakeResponseCommand command = new HandshakeResponseCommand(Owner, socket)
                        {
                            Listener = status.Update
                        };
                        command.Execute(httpRequest);
                        break;
                    }

                    // Session
                    SessionMapComponent sessions = Owner.Get <SessionMapComponent>();
                    Entity entity = sessions.Get(httpRequest.Session);
                    if (entity == null)
                    {
                        channel.SendUnauthorized();
                        break;
                    }

                    // TODO: Version check
                    //
                    // Message
                    SessionComponent session            = entity.Get <SessionComponent>();
                    string           decrypted          = session.Decrypt(httpRequest.Data);
                    JsonPacket       jsonRequest        = JsonPacket.Parse(decrypted);
                    JsonMessage      jsonRequestMessage = JsonMessage.Parse(jsonRequest.Message);
                    jsonType = jsonRequestMessage.Type;

                    switch (jsonType)
                    {
                    case JsonType.Handshake:
                    {
                        HandshakeResponseCommand command = new HandshakeResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Ping:
                    {
                        PingResponseCommand command = new PingResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Info:
                    {
                        InfoResponseCommand command = new InfoResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Join:
                    {
                        JoinResponseCommand command = new JoinResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Tunnel:
                    {
                        TunnelResponseCommand command = new TunnelResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Search:
                    {
                        SearchResponseCommand command = new SearchResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Group:
                    {
                        GroupResponseCommand command = new GroupResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Browse:
                    {
                        BrowseResponseCommand command = new BrowseResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Download:
                    {
                        // TODO: Add max transfer check!
                        //
                        DownloadResponseCommand command = new DownloadResponseCommand(Owner, socket);
                        action = command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Upload:
                    {
                        UploadResponseCommand command = new UploadResponseCommand(Owner, socket);
                        action = command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    case JsonType.Quit:
                    {
                        QuitResponseCommand command = new QuitResponseCommand(Owner, socket);
                        command.Execute(httpRequest, jsonRequest, session);
                        break;
                    }

                    default:
                    {
                        channel.SendBadRequest();
                        return;
                    }
                    }
                }while (action != JsonAction.None);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Status = DemonStatus.Error;
                channel.SendInternalServerError();
            }
            finally
            {
                if (channel != null)
                {
                    channel.Shutdown();
                }

                if (jsonType != JsonType.Tunnel)
                {
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }
            }
        }
コード例 #6
0
ファイル: ConfigFile.cs プロジェクト: vaginessa/Code
        private void ReadServer(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            bool   loop = true;
            string name = null;

            // Components
            Entity                 entity  = new Entity();
            ServerComponent        server  = new ServerComponent();
            ServerOptionsComponent options = new ServerOptionsComponent();

            server.Enabled = bool.Parse(reader.GetAttribute(XmlTag.Enabled));

            while (loop && reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    name = reader.Name;

                    switch (name)
                    {
                    case XmlTag.Options:
                    {
                        ReadOptions(reader, ref options);
                        break;
                    }
                    }

                    break;
                }

                case XmlNodeType.Text:
                {
                    switch (name)
                    {
                    case XmlTag.Id:
                    {
                        entity.Id = reader.Value;
                        break;
                    }

                    case XmlTag.Name:
                    {
                        server.Name = reader.Value;
                        break;
                    }

                    case XmlTag.Passphrase:
                    {
                        server.Passphrase = reader.Value;
                        break;
                    }

                    case XmlTag.Address:
                    {
                        server.Address = reader.Value;
                        break;
                    }

                    case XmlTag.Port:
                    {
                        server.Port = int.Parse(reader.Value);
                        break;
                    }
                    }

                    break;
                }

                case XmlNodeType.EndElement:
                {
                    if (XmlTag.Server.Equals(reader.Name))
                    {
                        loop = false;
                    }

                    break;
                }
                }
            }

            // Components
            entity.Add(server);
            entity.Add(options);

            ServerStatusComponent status = new ServerStatusComponent();

            entity.Add(status);

            MachineComponent machine = new ServerMachineComponent();

            entity.Add(machine);

            SessionMapComponent sessions = new SessionMapComponent();

            entity.Add(sessions);
#if DEBUG
            LogComponent log = new LogComponent(LogController);
            entity.Add(log);
#endif
            Server.Add(entity);
        }