public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonHandshakeRequestMessage jsonRequestMessage = JsonHandshakeRequestMessage.Parse(jsonRequest.Message);
            JsonKey jsonRequestKey = jsonRequestMessage.Key;

            // Response
            JsonKey jsonResponseKey = jsonRequestKey;
            JsonHandshakeResponseMessage jsonResponseMessage = new JsonHandshakeResponseMessage()
            {
                Key = jsonResponseKey
            };
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);

            // Data
            session.Key = Key.Parse(jsonRequestKey.Id);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
Example #2
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonTunnelRequestMessage jsonRequestMessage = JsonTunnelRequestMessage.Parse(jsonRequest.Message);

            // Data
            Entity          entity = session.Owner;
            TunnelComponent tunnel = new TunnelComponent(Connection);

            entity.Add(tunnel);

            // Response
            JsonTunnelResponseMessage jsonResponseMessage = new JsonTunnelResponseMessage();
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
Example #3
0
        public Entity Add()
        {
            Entity entity = new Entity();

            ServerComponent server = new ServerComponent()
            {
                Address = "127.0.0.1"
            };

            entity.Add(server);

            MachineComponent machine = new ServerMachineComponent();

            entity.Add(machine);

            SessionComponent session = new SessionComponent();

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

            return(entity);
        }
Example #4
0
        public override bool StartService(Settings settings)
        {
            if (m_Session == null)
            {
                var sessionConfig = ScriptableObject.CreateInstance <SessionConfig>();

                // We're going to manage the camera separately, but this needs to be true
                // so the ARCore native API knows we're going to use the camera.
                sessionConfig.m_enableARBackground = true;
                sessionConfig.m_enablePlaneFinding = settings.enablePlaneDetection;
                sessionConfig.m_enablePointcloud   = settings.enablePointCloud;

                var gameObject = new GameObject("Session Manager");

                // Deactivate the GameObject before adding the SessionComponent
                // or else the Awake method will be called before we have set
                // the session config.
                gameObject.SetActive(false);
                m_Session = gameObject.AddComponent <SessionComponent>();
                m_Session.m_connectOnAwake  = false;
                m_Session.m_arSessionConfig = sessionConfig;

                // We are going to manage the camera separately, so
                // intentionally leave null.
                m_Session.m_firstPersonCamera = null;
                gameObject.SetActive(true);
            }

            m_Session.Connect();
            return(SessionManager.ConnectionState == SessionConnectionState.Connected);
        }
Example #5
0
        public void Add(ClientComponent client, ServerComponent server, GroupComponent group)
        {
            Entity entity = new Entity();

            entity.Add(client);

            ClientOptionsComponent options = new ClientOptionsComponent();

            entity.Add(options);

            entity.Add(server);

            entity.Add(group);

            FolderListComponent folderList = new FolderListComponent();

            entity.Add(folderList);

            FileMapComponent fileMap = new FileMapComponent();

            entity.Add(fileMap);

            FolderMapComponent folderMap = new FolderMapComponent();

            entity.Add(folderMap);

            ClientMachineComponent machine = new ClientMachineComponent();

            entity.Add <MachineComponent>(machine);

            SessionComponent session = new SessionComponent();

            entity.Add(session);

            FileComponent file = new FileComponent();

            entity.Add(file);

            SearchListComponent search = new SearchListComponent(SearchController.Dispatcher);

            entity.Add(search);

            BrowseComponent browse = new BrowseComponent();

            entity.Add(browse);

            DownloadListComponent download = new DownloadListComponent(DownloadController.Dispatcher);

            entity.Add(download);

            UploadListComponent upload = new UploadListComponent(UploadController.Dispatcher);

            entity.Add(upload);
#if DEBUG
            LogComponent log = new LogComponent(LogController);
            entity.Add(log);
#endif
            Add(entity);
        }
Example #6
0
        private void _OnBeforeResumeSession(IntPtr sessionHandle)
        {
            if (SessionComponent == null || sessionHandle == IntPtr.Zero)
            {
                return;
            }

            NativeSession tempNativeSession = _GetNativeSession(sessionHandle);

            var listHandle = tempNativeSession.CameraConfigListApi.Create();

            tempNativeSession.SessionApi.GetSupportedCameraConfigurationsWithFilter(
                SessionComponent.CameraConfigFilter,
                listHandle, m_TempCameraConfigHandles, m_TempCameraConfigs,
                SessionComponent.DeviceCameraDirection);

            if (m_TempCameraConfigHandles.Count == 0)
            {
                Debug.LogWarning(
                    "Unable to choose a custom camera configuration because none are available.");
            }
            else
            {
                var configIndex = 0;
                if (SessionComponent.GetChooseCameraConfigurationCallback() != null)
                {
                    configIndex = SessionComponent.GetChooseCameraConfigurationCallback()(
                        m_TempCameraConfigs);
                }

                if (configIndex >= 0 && configIndex < m_TempCameraConfigHandles.Count)
                {
                    var status = tempNativeSession.SessionApi.SetCameraConfig(
                        m_TempCameraConfigHandles[configIndex]);
                    if (status != ApiArStatus.Success)
                    {
                        Debug.LogErrorFormat(
                            "Failed to set the ARCore camera configuration: {0}", status);
                    }
                }

                for (int i = 0; i < m_TempCameraConfigHandles.Count; i++)
                {
                    tempNativeSession.CameraConfigApi.Destroy(m_TempCameraConfigHandles[i]);
                }
            }

            // clean up
            tempNativeSession.CameraConfigListApi.Destroy(listHandle);

            m_TempCameraConfigHandles.Clear();
            m_TempCameraConfigs.Clear();
        }
Example #7
0
        public void Start()
        {
            ButtonBar.SetActive(false);
            ButtonBar2.SetActive(false);

            spawnerScript = gameObject.GetComponent <Spawner>();
            makePickupArray();
            _arCoreDevice         = GameObject.FindGameObjectWithTag("ARCoreDevice").GetComponent <SessionComponent>();
            _rend                 = tilePrefab.GetComponent <Renderer>();
            _rend.material.shader = Shader.Find("Unlit/GrayscaleTexture");
            _rend.material.SetFloat("_ColorLevel", 0f);
        }
Example #8
0
        public override void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            base.Dispose();

            Session?.Dispose();
            Session  = null;
            Instance = null;
        }
Example #9
0
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            base.Dispose();

            this.Session.Dispose();
            this.Session = null;
            Instance     = null;
        }
Example #10
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonBrowseRequestMessage jsonRequestMessage = JsonBrowseRequestMessage.Parse(jsonRequest.Message);

            JsonClient jsonClient = jsonRequestMessage.Client;

            if (jsonClient == null)
            {
                channel.SendNotFound();
                return;
            }

            Entity entity = ClientMap.Get(jsonClient.Id);

            if (entity == null)
            {
                channel.SendNotFound();
                return;
            }

            // Command
            TunnelComponent      tunnel  = entity.Get <TunnelComponent>();
            BrowseRequestCommand command = new BrowseRequestCommand(entity, tunnel.Connection);
            string jsonData = command.Execute(jsonRequest.Data);

            if (string.IsNullOrEmpty(jsonData))
            {
                channel.SendNotFound();
                return;
            }

            // Response
            JsonBrowseResponseMessage jsonResponseMessage = new JsonBrowseResponseMessage();
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage, jsonData);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
Example #11
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonInfoRequestMessage jsonRequestMessage = JsonInfoRequestMessage.Parse(jsonRequest.Message);

            // Data
            HttpCode        code   = HttpCode.Ok;
            Entity          entity = session.Owner;
            TunnelComponent tunnel = entity.Get <TunnelComponent>();

            if (tunnel != null)
            {
                PingRequestCommand command = new PingRequestCommand(entity, tunnel.Connection);
                code = command.Execute();
                if (code == HttpCode.Ok)
                {
                    entity.Update();
                }
            }

            // Response
            JsonInfoResponseMessage jsonResponseMessage = new JsonInfoResponseMessage()
            {
                Entities = Server.Entities, Sessions = Server.Sessions, Clients = Server.Clients, Groups = Server.Groups
            };
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse(code)
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
        public void Execute(HttpRequest httpRequest)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Data
            Entity entity = new Entity(null);

            entity.EntityShutdown += Listener;

            EntityIdleComponent idle = new EntityIdleComponent();

            entity.Add(idle);

            SessionComponent session = new SessionComponent()
            {
                Key = Key.Parse(httpRequest.Data)
            };

            entity.Add(session);

            SessionMap.Add(session.Id, entity);
            Server.Sessions = SessionMap.Count;

            // TODO: Use Diffie–Hellman
            //
            // Response
            HttpResponse httpResponse = new HttpResponse(session.Id)
            {
                Data = SecurityUtil.Token
            };

            channel.Send(httpResponse);
#if DEBUG
            LogComponent log = new LogComponent(Log.Controller);
            entity.Add(log);

            Log.Add(httpRequest, httpResponse);
#endif
        }
Example #13
0
 public void Awake()
 {
     Instance = this;
 }
Example #14
0
        public JsonAction Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            Clear();

            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonUploadRequestMessage jsonRequestMessage = JsonUploadRequestMessage.Parse(jsonRequest.Message);

            // Data
            string jsonId = jsonRequestMessage.Id;
            Entity entity = TransferMap.Get(jsonId);

            if (entity == null)
            {
                channel.SendNotFound();
                return(JsonAction.None);
            }

            JsonChunk      jsonChunk = jsonRequestMessage.Chunk;
            ChunkComponent transfer  = entity.Get <ChunkComponent>();

            if (jsonChunk != null)
            {
                JsonTransfer jsonTransfer = new JsonTransfer()
                {
                    Chunk = jsonChunk, Data = jsonRequest.Data
                };
                transfer.PushData(jsonTransfer);
            }

            if (!transfer.HasChunk())
            {
                channel.SendNotFound();
                return(JsonAction.None);
            }

            int delay = 0;

            jsonChunk = null;
            if (transfer.HasDataCapacity())
            {
                jsonChunk = transfer.PopChunk();
            }
            else
            {
                delay = (int)DemonTimeout.File.TotalMilliseconds;
            }

            // Response
            JsonUploadResponseMessage jsonResponseMessage = new JsonUploadResponseMessage(jsonId)
            {
                Chunk = jsonChunk, Delay = delay
            };
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            jsonRequest.Data = null;
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
            return(JsonAction.Request);
        }
Example #15
0
        /// <summary>
        /// 登录
        /// </summary>
        public async void OnLogin()
        {
            if (isLogining || this.Id == 0)
            {
                return;
            }

            isLogining = true;
            Session session = null;

            try
            {
                //创建登录服务器连接
                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                session = Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);

                //发送登录请求
                prompt.text = "正在登录中....";
                LoginRe loginRE = await session.Call <LoginRe>(new LoginRt()
                {
                    Account = account.text, Password = password.text
                });

                if (this.Id == 0)
                {
                    isLogining = false;
                    return;
                }

                prompt.text = "";
                if (loginRE.Error == ErrorCode.ERR_AccountOrPasswordError)
                {
                    prompt.text   = "登录失败,账号或密码错误";
                    password.text = "";
                    session.Dispose();
                    isLogining = false;
                    return;
                }
                else if (loginRE.Error == ErrorCode.ERR_AccountOnline)
                {
                    prompt.text   = "登录失败,账号已被登录";
                    password.text = "";
                    session.Dispose();
                    isLogining = false;
                    return;
                }

                //创建Gate服务器连接
                connetEndPoint = NetworkHelper.ToIPEndPoint(loginRE.Address);
                Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                Game.Scene.AddComponent <SessionComponent>().Session = gateSession;

                //登录Gate服务器
                LoginGateRe loginGateRE = await gateSession.Call <LoginGateRe>(new LoginGateRt()
                {
                    Key = loginRE.Key
                });

                if (loginGateRE.Error == ErrorCode.ERR_ConnectGateKeyError)
                {
                    prompt.text   = "登录网关服务器超时";
                    password.text = "";
                    session.Dispose();
                    isLogining = false;
                    return;
                }

                //保存连接,之后所有请求将通过这个连接发送
                SessionComponent sessionComponent = Game.Scene.AddComponent <SessionComponent>();
                sessionComponent.Session = gateSession;
                Log.Info("登录成功");

                //保存本地玩家
                Player player = Model.EntityFactory.CreateWithId <Player>(loginGateRE.PlayerId);
                player.UserID = loginGateRE.UserId;
                ClientComponent.Instance.LocalPlayer = player;

                //跳转到大厅界面
                Hotfix.Scene.GetComponent <UIComponent>().Create(UIType.UILobby);
                Hotfix.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
            }
            catch (Exception e)
            {
                Log.Error(e.ToStr());
            }
            finally
            {
                session?.Dispose();
                isLogining = false;
            }
        }
Example #16
0
        private void ReadServer(XmlReader reader, ref ServerListComponent servers)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            bool   loop = true;
            string name = null;

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

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

            while (loop && reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    name = reader.Name;
                    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);

            MachineComponent machine = new ServerMachineComponent();

            entity.Add(machine);

            SessionComponent session = new SessionComponent();

            entity.Add(session);
#if DEBUG
            LogComponent log = new LogComponent(LogController);
            entity.Add(log);
#endif
            servers.Add(entity);
        }
        public ActionResult LogOut()
        {
            SessionComponent.ClearSession();

            return(RedirectToAction("Login"));
        }
Example #18
0
        public JsonAction Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            Clear();

            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonAction jsonAction = JsonAction.None;
            JsonDownloadRequestMessage jsonRequestMessage = JsonDownloadRequestMessage.Parse(jsonRequest.Message);
            string jsonId = jsonRequestMessage.Id;

            if (jsonId != null)
            {
                // Data
                Entity entity = TransferMap.Get(jsonId);
                if (entity == null)
                {
                    channel.SendNotFound();
                    return(jsonAction);
                }

                ChunkComponent transfer = entity.Get <ChunkComponent>();
                if (transfer == null)
                {
                    channel.SendNotFound();
                    return(jsonAction);
                }

                JsonTransfer jsonTransfer = transfer.PopData();
                if (!transfer.Finished)
                {
                    jsonAction = JsonAction.Request;
                    entity.Update();
                }
                else
                {
                    TransferMap.Remove(jsonId);
                }

                string    jsonData  = null;
                JsonChunk jsonChunk = null;
                if (jsonTransfer != null)
                {
                    jsonData  = jsonTransfer.Data;
                    jsonChunk = jsonTransfer.Chunk;
                }

                // Response
                JsonDownloadResponseMessage jsonResponseMessage = new JsonDownloadResponseMessage(jsonId)
                {
                    Chunk = jsonChunk
                };
                JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage, jsonData);

                HttpResponse httpResponse = new HttpResponse()
                {
                    Data = session.Encrypt(jsonResponse)
                };
                channel.Send(httpResponse);
#if DEBUG
                jsonResponse.Data = null;
                Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
            }
            else
            {
                // Data
                Entity entity = session.Owner;
                SearchListComponent search     = entity.Get <SearchListComponent>();
                JsonClient          jsonClient = jsonRequestMessage.Client;

                // Request
                if (jsonClient == null && search.Empty)
                {
                    channel.SendNotFound();
                    return(jsonAction);
                }

                // Response
                jsonId = SecurityUtil.CreateKeyString();
                JsonDownloadResponseMessage jsonResponseMessage = new JsonDownloadResponseMessage(jsonId);
                JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

                HttpResponse httpResponse = new HttpResponse()
                {
                    Data = session.Encrypt(jsonResponse)
                };
                channel.Send(httpResponse);
#if DEBUG
                Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
                // Data
                entity = new Entity(jsonId);
                EntityIdleComponent idle = new EntityIdleComponent();
                entity.Add(idle);

                JsonChunk      jsonChunk = jsonRequestMessage.Chunk;
                ChunkComponent transfer  = new ChunkComponent(jsonChunk.Size, Options.ChunkSize, Options.MaxChunks);
                entity.Add(transfer);

                TransferMap.Add(entity);

                // Command
                string jsonData = jsonRequest.Data;
                jsonChunk = transfer.PopChunk();

                if (jsonClient == null)
                {
                    foreach (Entity e in search)
                    {
                        CommandState state = new CommandState()
                        {
                            Id = jsonId, Data = jsonData, Chunk = jsonChunk, Entity = e
                        };
                        Thread thread = new Thread(new ParameterizedThreadStart(ExecuteThread))
                        {
                            Priority = ThreadPriority.BelowNormal, IsBackground = true
                        };
                        thread.Start(state);
                    }
                }
                else
                {
                    Entity e = ClientMap.Get(jsonClient.Id);
                    if (e == null)
                    {
                        channel.SendNotFound();
                        return(jsonAction);
                    }

                    CommandState state = new CommandState()
                    {
                        Id = jsonId, Data = jsonData, Chunk = jsonChunk, Entity = e
                    };
                    Thread thread = new Thread(new ParameterizedThreadStart(ExecuteThread))
                    {
                        Priority = ThreadPriority.BelowNormal, IsBackground = true
                    };
                    thread.Start(state);
                }

                jsonAction = JsonAction.Request;
            }

            return(jsonAction);
        }
Example #19
0
        private void ReadClient(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            bool   loop = true;
            string name = null;

            // Components
            Entity                 entity  = new Entity();
            ClientComponent        client  = new ClientComponent();
            ClientOptionsComponent options = new ClientOptionsComponent();

            GroupComponent  group  = new GroupComponent();
            ServerComponent server = new ServerComponent();
            List <string>   paths  = new List <string>();

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

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

                    switch (name)
                    {
                    case XmlTag.Router:
                    {
                        ReadRouter(reader, ref server);
                        break;
                    }

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

                    case XmlTag.Folders:
                    {
                        ReadFolders(reader, ref paths);
                        break;
                    }
                    }

                    break;
                }

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

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

                    case XmlTag.Download:
                    {
                        client.Download = reader.Value;
                        break;
                    }

                    case XmlTag.Group:
                    {
                        group.Path = reader.Value;
                        break;
                    }
                    }

                    break;
                }

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

                    break;
                }
                }
            }

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

            FolderListComponent folderList = new FolderListComponent();

            entity.Add(folderList);

            FileMapComponent fileMap = new FileMapComponent();

            entity.Add(fileMap);

            FolderMapComponent folderMap = new FolderMapComponent();

            entity.Add(folderMap);

            ClientMachineComponent machine = new ClientMachineComponent();

            entity.Add <MachineComponent>(machine);

            SessionComponent session = new SessionComponent();

            entity.Add(session);

            FileComponent file = new FileComponent();

            entity.Add(file);

            SearchListComponent search = new SearchListComponent(SearchController.Dispatcher);

            entity.Add(search);

            BrowseComponent browse = new BrowseComponent();

            entity.Add(browse);

            DownloadListComponent download = new DownloadListComponent(DownloadController.Dispatcher);

            entity.Add(download);

            UploadListComponent upload = new UploadListComponent(UploadController.Dispatcher);

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

            foreach (string path in paths)
            {
                FileComponent shared = new FileComponent(path)
                {
                    Owner = entity
                };
                folderList.Add(shared);
            }
        }
Example #20
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonGroupRequestMessage jsonRequestMessage = JsonGroupRequestMessage.Parse(jsonRequest.Message);

            // Data
            Entity         entity   = session.Owner;
            GroupComponent group    = entity.Get <GroupComponent>();
            EntityList     entities = GroupList.Get(group.Id);

            if (entities == null)
            {
                channel.SendNotFound();
                return;
            }

            List <JsonClient> jsonClients = new List <JsonClient>();

            lock (entities)
            {
                foreach (Entity e in entities)
                {
#if !DEBUG
                    if (entity.Id.Equals(e.Id))
                    {
                        continue;
                    }
#endif
                    ClientComponent c          = e.Get <ClientComponent>();
                    JsonClient      jsonClient = (JsonClient)c;
                    jsonClients.Add(jsonClient);
                }
            }

            if (jsonClients.Count == 0)
            {
                channel.SendNotFound();
                return;
            }

            jsonClients.Sort();

            // Response
            JsonGroupResponseMessage jsonResponseMessage = new JsonGroupResponseMessage()
            {
                Clients = jsonClients
            };
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };
            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
Example #21
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonJoinRequestMessage jsonRequestMessage = JsonJoinRequestMessage.Parse(jsonRequest.Message);

            // Data
            JsonEntity jsonEntity = jsonRequestMessage.Entity;
            Entity     entity     = EntityMap.Get(jsonEntity.Id);

            if (entity != null)
            {
                entity.Shutdown();
            }

            entity    = session.Owner;
            entity.Id = jsonEntity.Id;
            EntityMap.Add(entity.Id, entity);
            Server.Entities = EntityMap.Count;

            JsonGroup jsonGroup = jsonRequestMessage.Group;

            if (jsonGroup == null)
            {
                jsonGroup = JsonGroup.Default;
            }

            JsonClient      jsonClient = jsonRequestMessage.Client;
            ClientComponent client     = new ClientComponent(jsonClient.Id, jsonClient.Name);

            entity.Add(client);

            ClientMap.Add(client.Id, entity);
            Server.Clients = ClientMap.Count;

            GroupComponent group = new GroupComponent(jsonGroup.Id);

            entity.Add(group);

            GroupList.Add(group.Id, entity);
            Server.Groups = GroupList.Count;

            SearchListComponent download = new SearchListComponent();

            entity.Add(download);

            // Response
            JsonJoinResponseMessage jsonResponseMessage = new JsonJoinResponseMessage()
            {
                Entities = Server.Entities, Sessions = Server.Sessions, Clients = Server.Clients, Groups = Server.Groups
            };
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
Example #22
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session)
        {
            Clear();

            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonSearchRequestMessage jsonRequestMessage = JsonSearchRequestMessage.Parse(jsonRequest.Message);

            // Data
            Entity         entity   = session.Owner;
            GroupComponent group    = entity.Get <GroupComponent>();
            EntityList     entities = GroupList.Get(group.Id);

            if (entities == null)
            {
                channel.SendNotFound();
                return;
            }

            // Response
            string jsonId = SecurityUtil.CreateKeyString();
            JsonSearchResponseMessage jsonResponseMessage = new JsonSearchResponseMessage(jsonId);
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage);

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);

            // Optimization: Keep track of the search list for faster downloads
            SearchListComponent download = entity.Get <SearchListComponent>();

            download.Clear();

            // Command
            lock (entities)
            {
                foreach (Entity e in entities)
                {
                    // Do not search yourself
                    if (entity.Id.Equals(e.Id))
                    {
                        continue;
                    }

                    TunnelComponent tunnel = e.Get <TunnelComponent>();
                    if (!tunnel.Connected)
                    {
                        continue;
                    }

                    CommandState state = new CommandState()
                    {
                        Id     = jsonId,
                        Data   = jsonRequest.Data,
                        Source = entity,
                        Target = e
                    };

                    Thread thread = new Thread(new ParameterizedThreadStart(ExecuteThread))
                    {
                        Priority = ThreadPriority.BelowNormal, IsBackground = true
                    };
                    thread.Start(state);
                }
            }
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }
        private ApiPrestoCallbackResult OnBeforeResumeSession(IntPtr sessionHandle)
        {
            ApiPrestoCallbackResult result = ApiPrestoCallbackResult.InvalidCameraConfig;

            if (SessionComponent == null || sessionHandle == IntPtr.Zero)
            {
                return(result);
            }

            NativeSession tempNativeSession = GetNativeSession(sessionHandle);
            var           listHandle        = tempNativeSession.CameraConfigListApi.Create();

            tempNativeSession.SessionApi.GetSupportedCameraConfigurationsWithFilter(
                SessionComponent.CameraConfigFilter,
                listHandle, _tempCameraConfigHandles, _tempCameraConfigs,
                SessionComponent.DeviceCameraDirection);

            if (_tempCameraConfigHandles.Count == 0)
            {
                Debug.LogWarning(
                    "Unable to choose a custom camera configuration because none are available.");
            }
            else
            {
                var configIndex = 0;
                if (SessionComponent.GetChooseCameraConfigurationCallback() != null)
                {
                    configIndex = SessionComponent.GetChooseCameraConfigurationCallback()(
                        _tempCameraConfigs);
                }

                if (configIndex >= 0 && configIndex < _tempCameraConfigHandles.Count)
                {
                    var status = tempNativeSession.SessionApi.SetCameraConfig(
                        _tempCameraConfigHandles[configIndex]);
                    if (status != ApiArStatus.Success)
                    {
                        Debug.LogErrorFormat(
                            "Failed to set the ARCore camera configuration: {0}", status);
                    }
                    else
                    {
                        result = ApiPrestoCallbackResult.Success;

                        // sync the session configuration with the new camera direction.
                        ExternApi.ArPresto_setConfigurationDirty();
                    }
                }

                for (int i = 0; i < _tempCameraConfigHandles.Count; i++)
                {
                    tempNativeSession.CameraConfigApi.Destroy(_tempCameraConfigHandles[i]);
                }
            }

            // clean up
            tempNativeSession.CameraConfigListApi.Destroy(listHandle);
            _tempCameraConfigHandles.Clear();
            _tempCameraConfigs.Clear();
            return(result);
        }