Example #1
0
        public override async Task <bool> Start(SessionSettings settings)
        {
            try
            {
                if (_socket != null && _socket.Connected)
                {
                    _socket.Close();
                    _stream.Close();
                }

                _socket = new TcpClient();
                await _socket.ConnectAsync(settings.Host, settings.Port);

                _stream = _socket.GetStream();
                _writer = new BinaryWriter(_stream);
                _reader = new BinaryReader(_stream);
                _thread = new Thread(ReceiveLoop);

                EditingSessionPlugin.Instance.EditorModeEnter += ExecuteBacklog;

                _writer.Write(settings.Username);

                if (!_reader.ReadBoolean())
                {
                    Debug.Log("Username already taken, closing connection !");
                    Close();
                    return(false);
                }

                var color = settings.SelectionColor;
                _writer.Write(ref color);

                var wp = Editor.Instance.Windows.EditWin.Viewport;

                var position    = wp.ViewPosition;
                var orientation = wp.ViewOrientation;

                _writer.Write(ref position);
                _writer.Write(ref orientation);

                int id = _reader.ReadInt32();
                User = new EditingUser(id, settings.Username, settings.SelectionColor, false, position, orientation);

                _thread.IsBackground = true;
                _thread.Start();

                Debug.Log("Session client launched !");
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return(false);
            }

            return(true);
        }
        public override void Execute()
        {
            EditingUser user;

            EditingSessionPlugin.Instance.Session.AddUser(user = new EditingUser(UserId, Username, SelectionColor,
                                                                                 IsServer, Position, Orientation));
            EditingSessionPlugin.Instance.CollaborateWindow.Rebuild();

            user.Outliner        = FlaxEngine.Object.New <CustomOutliner>();
            user.Outliner.UserId = UserId;
        }
        public override Task <bool> Start(SessionSettings settings)
        {
            try
            {
                try
                {
                    _server = new TcpListener(IPAddress.Any, settings.Port);
                    _server.Start();
                }
                catch (SocketException e)
                {
                    Debug.LogError("Failed to create the server");
                    Debug.LogException(e);
                    return(Task.FromResult(false));
                }

                EditingSessionPlugin.Instance.EditorModeEnter += ExecuteBacklog;

                var wp = Editor.Instance.Windows.EditWin.Viewport;

                var pos = wp.ViewPosition;
                var ori = wp.ViewOrientation;

                AddUser(User = new EditingUser(CreateId(settings.Username), settings.Username,
                                               settings.SelectionColor, true, pos, ori));
                _thread = new Thread(() =>
                {
                    List <SocketUser> _usersToDelete = new List <SocketUser>();
                    bool _activity = false;
                    _running       = true;
                    while (_running)
                    {
                        // TODO: Heartbeat - to make sure that client disconnections get detected.

                        // If a new user is attempting to connect to the server
                        if (_server.Pending())
                        {
                            _activity = true;
                            SocketUser newSocketUser = new SocketUser();
                            newSocketUser.Socket     = _server.AcceptTcpClient();
                            newSocketUser.Reader     = new BinaryReader(newSocketUser.Socket.GetStream());
                            newSocketUser.Writer     = new BinaryWriter(newSocketUser.Socket.GetStream());

                            string username = newSocketUser.Reader.ReadString();

                            Logger.Log("New User: "******"Session server launched !");
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return(Task.FromResult(false));
            }

            return(Task.FromResult(true));
        }
Example #4
0
 public void AddUser(EditingUser u)
 {
     _users.Add(u);
 }
Example #5
0
 public void RemoveUser(EditingUser user)
 {
     _users.Remove(user);
 }