コード例 #1
0
        // Fired on a WebSocket message.
        protected override void OnMessage(MessageEventArgs e)
        {
            User u = ServerGlobals.GetUserFromID(ID);

            if (u != null)
            {
                OnWS(u, e.Data);
            }
        }
コード例 #2
0
        private void CleanupUser(string id)
        {
            foreach (VirtualMachine vm in ServerGlobals.virtualMachines.Values)
            {
                if (vm.id == ServerGlobals.GetUserFromID(ID).vm.id)
                {
                    vm.DisconnectUser(ServerGlobals.GetUserFromID(ID));
                }
            }

            ServerGlobals.users.RemoveAll(pool => pool == ServerGlobals.GetUserFromID(ID));
        }
コード例 #3
0
        // Fired when a client first connects.
        protected override void OnOpen()
        {
            // Block non-CollabVM connnections
            if (!Context.SecWebSocketProtocols.Contains("cvm2"))
            {
                Sessions.CloseSession(ID);
                return;
            }

            ServerGlobals.users.Add(new User(ID, Context.UserEndPoint.Address, Context.WebSocket));
            Utils.Logger.Log(ServerGlobals.GetUserFromID(ID), "Connection opened");
        }
コード例 #4
0
 protected override void OnClose(CloseEventArgs e)
 {
     Utils.Logger.Log(ServerGlobals.GetUserFromID(ID), "Connection closed");
     CleanupUser(ID);
 }
コード例 #5
0
        private void OnWS(User u, string message)
        {
            string[] decoded = ProtocolCodec.Decode(message);
            if (decoded == null)
            {
                return;
            }

            switch (decoded[0])
            {
            default: break;

            case "mouse":
            {
                if (u.vm == null || u.connected == false)
                {
                    break;
                }

                lock (VMLock)
                {
                    u.vm.MouseMove(int.Parse(decoded[1]), int.Parse(decoded[2]));
                }
            } break;

            case "connect":
                lock (VMLock)
                {
                    if (!u.connected)
                    {
                        // Bad but unless you have 1000 vms it should be alright.
                        foreach (string id in ServerGlobals.virtualMachines.Keys)
                        {
                            if (decoded[1] == id)
                            {
                                Utils.Logger.Log(ServerGlobals.GetUserFromID(ID), "Connecting to VM " + id);
                                ServerGlobals.virtualMachines[decoded[1]].ConnectUser(ServerGlobals.GetUserFromID(ID));
                            }
                        }
                    }
                }
                break;

#if false
            case "list":
                if (!u.connected)
                {
                    List <string> vmids = new List <string>();
                    foreach (string id in ServerGlobals.virtualMachines.Keys)
                    {
                        vmids.Add(id);
                        Bitmap scalene_triangle = ServerGlobals.virtualMachines[id].vmc.GetDisplayBitmap();
                        Bitmap scaled           = ResizeImage(scalene_triangle, 160, 160);
                        //vmids.Add();
                    }
                    u.ActionQueue.Enqueue(new Action {
                        inst = vmids.ToArray()
                    });
                }
                break;
#endif
            }
        }