Example #1
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            HttpResponse thisResponse = getBasicResponse();

            switch (returnPath)
            {
            case PATH.DESKTOP:
                thisResponse.Body = Environment.GetFolderPath(Environment.SpecialFolder.Desktop).Replace('\\', '/');
                break;

            case PATH.FAVORITES:
                thisResponse.Body = Environment.GetFolderPath(Environment.SpecialFolder.Favorites).Replace('\\', '/');
                break;

            case PATH.MY_DOCUMENTS:
                thisResponse.Body = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).Replace('\\', '/');
                break;

            case PATH.RECENT:
                thisResponse.Body = Environment.GetFolderPath(Environment.SpecialFolder.Recent).Replace('\\', '/');
                break;

            case PATH.USER_PROFILE:
                thisResponse.Body = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile).Replace('\\', '/');
                break;
            }
            thisResponse.guessContentLength();

            return(thisResponse);
        }
Example #2
0
 internal void ClientDisconnect(ClientContainer client)
 {
     if (client != null)
     {
         lock (syncObjectClients) _clients.Remove(client);
         var socket = client.socket;
         if (socket != null)
         {
             LingerOption lingerOption = new LingerOption(true, 1);
             socket.LingerState = lingerOption;
             try
             {
                 if (socket.Connected)
                 {
                     socket.Shutdown(SocketShutdown.Both);
                     socket.Close();
                 }
             }
             catch (Exception ex)
             {
                 if (_showFail)
                 {
                     Debug.Fail(ex.Message, ex.StackTrace);
                 }
             }
         }
         if (client.ClientId > 0)
         {
             CallClientDisconnect(client.ClientId);
         }
         client.Dispose();
     }
 }
        private void SetupSync()
        {
            // Set up client
            ILog clientLogger = LogManager.GetLogger("Client");

            log4net.Config.XmlConfigurator.Configure(clientLogger.Logger.Repository);
            ClientContainer.Register <ILog>(clientLogger);
            ClientContainer.Register <IRepository <TestItem, Guid> >(ClientRepository);
            ClientContainer.Register <ISyncResult <TestItem, Guid>, SyncResult <TestItem, Guid> >();
            ClientContainer.Register <IReplica>(new Replica("Client"));

            // Set up server
            ILog serverLogger = LogManager.GetLogger("Server");

            log4net.Config.XmlConfigurator.Configure(serverLogger.Logger.Repository);
            ServerContainer.Register <ILog>(clientLogger);
            ServerContainer.Register <IRepository <TestItem, Guid> >(ServerRepository);
            ServerContainer.Register <ISyncResult <TestItem, Guid>, SyncResult <TestItem, Guid> >();
            ServerContainer.Register <IReplica>(ServerReplica);
            ServerRepository.Insert(TestItemR0);             // Start with an item on the server

            // Used for both client and server
            Container.Register <ISyncConflictResolver <TestItem, Guid>, TestItemConflictResolver>();

            // Just pass the sync requests directly between the server and client
            // Ordinarily these would by serialized and sent over a wire, but the
            // TestSyncRequestSender, just passes the object directly.
            ClientContainer.Register <ISyncRequestSender <TestItem, Guid> >(new TestSyncRequestSender <TestItem, Guid>(ServerSendingSynchronizer));

            ClientSendingSynchronizer.BeginSync(ServerReplica);
        }
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            if (arguments.ContainsKey(hWndID))
            {
                try
                {
                    IntPtr hWnd = new IntPtr(Convert.ToInt32(arguments[hWndID]));
                    if ((WinAPI.GetWindowLong(hWnd, WinAPI.GET_WINDOW_LONG.GWL_EXSTYLE)
                         & (long)WinAPI.GET_WINDOW_LONG.GWL_EXSTYLE_RETURN.WS_EX_TOPMOST) == 0)
                    {
                        WinAPI.SetWindowPos(hWnd, WinAPI.SET_WINDOW_POS.hWndInsertAfter.HWND_TOPMOST, 0, 0, 0, 0, WinAPI.SET_WINDOW_POS.uFlags.SWP_NOMOVE | WinAPI.SET_WINDOW_POS.uFlags.SWP_NOSIZE);
                    }
                    else
                    {
                        WinAPI.SetWindowPos(hWnd, WinAPI.SET_WINDOW_POS.hWndInsertAfter.HWND_NOTOPMOST, 0, 0, 0, 0, WinAPI.SET_WINDOW_POS.uFlags.SWP_NOSIZE | WinAPI.SET_WINDOW_POS.uFlags.SWP_NOMOVE);
                    }

                    return(FormatInvokeSuccess());
                }
                catch (FormatException) { return(FormatInvokeFailure()); }
            }
            else
            {
                return(FormatInvokeFailure());
            }
        }
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            if (arguments == null || !arguments.ContainsKey(filePathVariable) || !arguments.ContainsKey(destPathVariable))
            {
                procedureFail(client);
                return(FormatInvokeFailure());
            }

            string src  = (arguments[filePathVariable]).Replace('/', '\\').Trim();
            string dest = (arguments[destPathVariable]).Replace('/', '\\').Trim();

            string[] filename = src.Split('\\');

            try
            {
                File.Copy(src, dest + filename[filename.Length - 1]);
                if (isMove)
                {
                    File.Delete(src);
                }
            }
            catch (IOException)
            {
                return(procedureFail(client));
            }
            catch (UnauthorizedAccessException)
            {
                return(procedureFail(client));
            }

            return(FormatInvokeSuccess()); // do not send out a response from the engine
        }
        private HttpResponse procedureFail(ClientContainer client)
        {
            HttpResponse response = new HttpResponse(HttpResponse.ConnectionStatus.NO_CONTENT, "keep-alive", null);

            response.addHeader("Content-Length", "0");

            return(response);
        }
Example #7
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            foreach (ATool thisTool in tools)
            {
                thisTool.Invoke(arguments, client);
            }

            return(FormatInvokeSuccess()); // do not send out a response from the engine
        }
Example #8
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            HttpResponse response = FormatInvokeSuccess();

            response.Body = Screen.PrimaryScreen.Bounds.Width + "," + Screen.PrimaryScreen.Bounds.Height;
            response.guessContentLength();

            return(response);
        }
Example #9
0
        private void RaiseSessionClosed(IWampConnection <TMessage> connection)
        {
            EventHandler <WampSessionEventArgs> sessionClosed = SessionClosed;

            if (sessionClosed != null)
            {
                IWampClient client = ClientContainer.GetClient(connection);
                sessionClosed(this, new WampSessionEventArgs(client.SessionId));
            }
        }
Example #10
0
        protected override void OnNewConnection(IWampConnection <TMessage> connection)
        {
            base.OnNewConnection(connection);

            IWampClientProxy <TMessage> client = ClientContainer.GetClient(connection);

            mLogger.DebugFormat("Client connected, session id: {SessionId}", client.Session);

            mSessionHandler.OnNewClient(client);
        }
Example #11
0
        protected override void OnCloseConnection(IWampConnection <TMessage> connection)
        {
            if (ClientContainer.TryGetClient(connection, out IWampClientProxy <TMessage> client))
            {
                mLogger.DebugFormat("Client disconnected, session id: {SessionId}", client.Session);

                mSessionHandler.OnClientDisconnect(client);
            }

            base.OnCloseConnection(connection);
        }
Example #12
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            int dwdata = (int)button;

            try
            {
                if (posxKey != null)
                {
                    posx = Convert.ToInt32(Math.Round(Convert.ToDouble(arguments[PosxKey])));
                }
                if (posyKey != null)
                {
                    posy = Convert.ToInt32(Math.Round(Convert.ToDouble(arguments[PosyKey])));
                }
            }
            catch (OverflowException)
            {
                return(FormatInvokeFailure());
            }
            catch (FormatException)
            {
                return(FormatInvokeFailure());
            }
            if (wheelDeltaKey != null)
            {
                try
                {
                    dwdata = Convert.ToInt32(arguments[wheelDeltaKey]) * WHEEL_DELTA_CLICK;
                }
                catch (KeyNotFoundException)
                {
                    return(FormatInvokeFailure());
                }
                catch (FormatException)
                {
                    return(FormatInvokeFailure());
                }
            }
            else
            {
            }

            if ((flags & WinAPI.MOUSE_EVENT.dwFlags.MOUSEEVENTF_ABSOLUTE) == WinAPI.MOUSE_EVENT.dwFlags.MOUSEEVENTF_ABSOLUTE)
            {
                int xscale = MAX_POS / Screen.PrimaryScreen.Bounds.Width;
                int yscale = MAX_POS / Screen.PrimaryScreen.Bounds.Height;
                posx *= xscale;
                posy *= yscale;
            }

            WinAPI.mouse_event(flags, posx, posy, dwdata, 0);

            return(FormatInvokeSuccess());
        }
Example #13
0
        public void Disconnect(CloseReason reason = CloseReason.ClientClosed)
        {
            ClientContainer.Shutdown(reason);

            Address = "";
            Port    = 0;
            KeySize = 0;

            ClientContainer.Dispose();
            ClientContainer = null;
        }
Example #14
0
        protected override void OnCloseConnection(IWampConnection <TMessage> connection)
        {
            RaiseSessionClosed(connection);

            if (mLogger.IsDebugEnabled())
            {
                IWampClient client = ClientContainer.GetClient(connection);
                mLogger.DebugFormat("Client disconnected, session id: {SessionId}", client.SessionId);
            }

            base.OnCloseConnection(connection);
        }
Example #15
0
        protected override void OnConnectionOpen(IWampConnection <TMessage> connection)
        {
            base.OnConnectionOpen(connection);

            IWampClient client = ClientContainer.GetClient(connection);

            mLogger.DebugFormat("Client connected, session id: {SessionId}", client.SessionId);

            client.Welcome(client.SessionId, 1, "WampSharp");

            RaiseSessionCreated(client);
        }
Example #16
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            Process newProcess = new Process();

            newProcess.StartInfo = startInfo;
            if (elevatePrivileges)
            {
                newProcess.StartInfo.Verb = "runas";
            }
            newProcess.Start();
            return(FormatInvokeSuccess());
        }
Example #17
0
        private void AcceptCallback(IAsyncResult result)
        {
            if (_listenningStatus == ServerStatusType.Listening)
            {
                var client = new ClientContainer();
                try
                {
                    var socket = _socket.EndAccept(result);
                    socket.ReceiveTimeout    = DefaultReceiveTimeout;
                    socket.SendTimeout       = DefaultSendTimeout;
                    socket.ReceiveBufferSize = DefaultReceiveBufferSize;
                    socket.SendBufferSize    = DefaultSendBufferSize;

                    client.SetSocket(socket)
                    .SetBufferSize(DefaultReceiveBufferSize);

                    lock (syncObjectClients) _clients.Add(client);

                    socket.BeginReceive(client.ReadBuffer,
                                        0, client.ReadBuffer.Length, SocketFlags.None,
                                        new AsyncCallback(ReceiveCallback),
                                        client);

                    CallClientConnect(client.ClientId);
                }
                catch (Exception ex)
                {
                    if (_showFail)
                    {
                        Debug.Fail(ex.Message, ex.StackTrace);
                    }
                    ClientDisconnect(client);
                }
                finally
                {
                    try
                    {
                        if (_socket != null && _socket.IsBound)
                        {
                            _socket.BeginAccept(new AsyncCallback(AcceptCallback), null);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (_showFail)
                        {
                            Debug.Fail(ex.Message, ex.StackTrace);
                        }
                    }
                }
            }
        }
Example #18
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            StringBuilder procTable = new StringBuilder();

            Array.ForEach(Process.GetProcesses(), (Process p) => procTable.AppendLine("<li><a>" + p.ProcessName + "</a><a onclick=\'$.post(\"/pkill\",\"pid=" + p.Id.ToString() + "\",function(){location.reload(true);})'>Kill</a></li>"));

            HttpResponse r = getBasicResponse();

            r.Body = procTable.ToString();
            r.guessContentLength();

            return(r);
        }
Example #19
0
 private void CallReceive(ClientContainer client, byte[] value)
 {
     try
     {
         OnReceive?.Invoke(this, new ReceivedArgs(client.ClientId, client.RemoteEndPoint, value));
     }
     catch (Exception ex)
     {
         if (_showFail)
         {
             Debug.Fail(ex.Message, ex.StackTrace);
         }
     }
 }
Example #20
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            switch (state)
            {
            case STATE.HIBERNATE:
                WinAPI.SetSuspendState(true, true, true);
                break;

            case STATE.SLEEP:
                WinAPI.SetSuspendState(false, true, true);
                break;
            }
            return(FormatInvokeSuccess());
        }
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            if (ishWndArgument)
            {
                try
                {
                    hWnd = new IntPtr(Convert.ToInt32(arguments[HWNDARGUMENTNAME]));
                }
                catch (FormatException) { return(FormatInvokeFailure()); }
            }

            WinAPI.SetWindowPos(hWnd, hWndInsertAfter, x, y, cx, cy, uFlags);

            return(FormatInvokeSuccess());
        }
Example #22
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            IntPtr hWnd;

            if (ishWndArgument)
            {
                try
                {
                    hWnd = new IntPtr(Convert.ToInt32(arguments[HWNDARGUMENTNAME]));
                    WinAPI.AnimateWindow(hWnd, time, flags);
                }
                catch (FormatException) { return(FormatInvokeFailure(flags.ToString())); }
            }

            return(FormatInvokeSuccess(flags.ToString()));
        }
Example #23
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            IntPtr capture;
            IntPtr hWnd;

            if (broadcast)
            {
                hWnd = WinAPI.HWND_BROADCAST;
            }
            else
            {
                hWnd = WinAPI.GetTopWindow(IntPtr.Zero);
                //hWnd = Process.GetProcessesByName("explorer")[0].Handle;
                //hWnd = WinAPI.GetDesktopWindow();
            }

            //int capture = WinAPI.SENDMESSAGE._RETURN.WM_COPYDATA; //Set to this for the end condition

            if (ishWndArgument)
            {
                try
                {
                    hWnd = new IntPtr(Convert.ToInt32(arguments[HWNDARGUMENTNAME]));
                }
                catch (FormatException) { }
                WinAPI.SendMessage(hWnd, WinAPI.SENDMESSAGE._MSG.WM_SYSCOMMAND, (IntPtr)command, lParam);
                return(FormatInvokeSuccess());
            }
            else
            {
                IntPtr lasthWnd = WinAPI.GetWindow(IntPtr.Zero, (uint)WinAPI.GET_WINDOW_CMD.GW_HWNDLAST);
                while ((!(capture = (WinAPI.SendMessage(hWnd, WinAPI.SENDMESSAGE._MSG.WM_SYSCOMMAND, (IntPtr)command, lParam))).Equals(new IntPtr(0))) &&
                       (lasthWnd != hWnd))
                {
                    hWnd = WinAPI.GetWindow(hWnd, (uint)WinAPI.GET_WINDOW_CMD.GW_HWNDPREV);
                }
                //http://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx 1 is TRUE
                if (capture.Equals(new IntPtr(0)))
                {
                    return(FormatInvokeSuccess());
                }
                else
                {
                    return(FormatInvokeFailure());
                }
            }
        }
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            HttpResponse response;

            helper = new HelperClass(client.getClient().GetStream(), client.getClient());

            if (arguments == null || arguments.Count < 1 || !arguments.ContainsKey(filePathVariable) || !arguments.ContainsKey(fileNameVariable))
            {
                procedureFail(client);
                return(FormatInvokeFailure());
            }
            string path = (arguments[filePathVariable]).Replace('/', '\\').Trim();

            if (!path.EndsWith("\\"))
            {
                path += '\\';
            }
            path += arguments[fileNameVariable];
            try
            {
                FileInfo thisfile = new FileInfo(path);
                Process  p        = new Process()
                {
                    StartInfo = new ProcessStartInfo(thisfile.FullName)
                };
                if (p.Start())
                {
                    return(FormatInvokeSuccess());
                }
                else
                {
                    return(FormatInvokeFailure());
                }
                //helper.SocketWriteLine("");
            }
            catch (IOException)
            {
                return(procedureFail(client));
            }
            catch (UnauthorizedAccessException)
            {
                return(procedureFail(client));
            }

            return(null); // do not send out a response from the engine
        }
Example #25
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            Windows = new ConcurrentDictionary <IntPtr, string>(); //cannot serialize static
            WinAPI.EnumWindows(EnumTheWindows, IntPtr.Zero);
            StringBuilder returnList = new StringBuilder();

            foreach (KeyValuePair <IntPtr, string> kp in Windows)
            {
                returnList.AppendLine("<li><a onclick='windowPanel(" + kp.Key.ToString() + ")'>" + kp.Value + "</a></li>");
            }
            HttpResponse r = getBasicResponse();

            r.Body = returnList.ToString();
            r.guessContentLength();

            return(r);
        }
Example #26
0
 // have characters added only of the keyup event when there are no other keys being pressed. The keydown event should have a buffer for a chain reaction.
 public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
 {
     if (arguments.ContainsKey(strKey))
     {
         String        parseme        = arguments[strKey];
         StringBuilder currentKeyWord = null;
         int           index          = 0;
         char          direction      = (char)0;
         while (index < parseme.Length)
         {
             char thisChar = parseme[index];
             if (currentKeyWord == null)
             {
                 if (thisChar == specialDown || thisChar == specialUp)
                 {
                     direction = thisChar;
                 }
                 else if (thisChar == specialCharOpen)
                 {
                     currentKeyWord = new StringBuilder();
                 }
                 else
                 {
                     processRequest((byte)WinAPI.VkKeyScan(thisChar), direction);
                     direction = (char)0;
                 }
             }
             else
             {
                 if (thisChar == specialCharClose)
                 {
                     processRequest(processKeyword(currentKeyWord.ToString()), direction);
                     currentKeyWord = null;
                     direction      = (char)0;
                 }
                 else
                 {
                     currentKeyWord.Append(thisChar);
                 }
             }
             index++;
         }
     }
     return(FormatInvokeSuccess());
 }
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            if (arguments.ContainsKey(hWndID))
            {
                try
                {
                    uint PID = 0;
                    WinAPI.GetWindowThreadProcessId(new IntPtr(Convert.ToInt32(arguments[hWndID])), out PID);
                    Process.GetProcessById((int)PID).Kill();

                    return(FormatInvokeSuccess("Kill " + arguments[hWndID]));
                }
                catch (FormatException) { return(FormatInvokeFailure()); }
            }
            else
            {
                return(FormatInvokeFailure());
            }
        }
Example #28
0
    private void GetAllClients(SocketIOEvent e)
    {
        Debug.Log(e.data);
        _clientContainer = JsonUtility.FromJson <ClientContainer>(e.data.ToString());

        if (_contentContainer.transform.childCount > 0)
        {
            for (int i = 0; i < _contentContainer.transform.childCount; i++)
            {
                Destroy(_contentContainer.transform.GetChild(i).gameObject);
            }
        }

        foreach (client c in _clientContainer.clients)
        {
            GameObject go = Instantiate(_passangerUI, _contentContainer.transform);
            go.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = c.clientName;
        }
    }
Example #29
0
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            IntPtr TokenProcessHandle;

            WinAPI.OpenProcessToken(Process.GetCurrentProcess().Handle, (short)(WinAPI.OPEN_PROCESS_TOKEN_ACCESS.TOKEN_ADJUST_PRIVILEGES | WinAPI.OPEN_PROCESS_TOKEN_ACCESS.TOKEN_QUERY), out TokenProcessHandle);
            WinAPI.TOKEN_PRIVILEGES tkp;
            tkp.PrivilegeCount        = 1;
            tkp.Privileges.Attributes = WinAPI.SE_PRIVILEGE_ENABLED;
            WinAPI.LookupPrivilegeValue("", WinAPI.SE_SHUTDOWN_NAME, out tkp.Privileges.pLuid);
            WinAPI.AdjustTokenPrivileges(TokenProcessHandle, false, ref tkp, 0U, IntPtr.Zero, IntPtr.Zero);

            bool result;

            if (force)
            {
                foreach (Process p in Process.GetProcesses())
                {
                    try
                    {
                        if (p.SessionId != Process.GetCurrentProcess().SessionId)
                        {
                            p.Kill();
                        }
                    }
                    catch (Exception) { }
                }
                result = WinAPI.ExitWindowsEx((uint)command, 0) &&
                         WinAPI.ExitWindowsEx((uint)WinAPI.EXIT_WINDOWS_EXT_FLAGS.EWX_FORCEIFHUNG, 0);
            }
            else
            {
                result = WinAPI.ExitWindowsEx((uint)command, 0);
            }
            if (result)
            {
                return(FormatInvokeSuccess());
            }
            else
            {
                return(FormatInvokeFailure());
            }
        }
        public override HttpResponse Invoke(Dictionary <string, string> arguments, ClientContainer client)
        {
            IntPtr capture = IntPtr.Zero;

            if (hwndbroadcast)
            {
                capture = WinAPI.SendMessage(WinAPI.HWND_BROADCAST, WinAPI.SENDMESSAGE._MSG.WM_APPCOMMAND, IntPtr.Zero, (IntPtr)command);
            }
            else if (broadcast)
            {
                Process[] processes = Process.GetProcesses();
                foreach (Process p in processes)
                {
                    //make sure that explorer is not one of the windows?
                    if (!p.MainWindowHandle.Equals(new IntPtr(0)))
                    {
                        capture = WinAPI.SendMessage(p.MainWindowHandle, WinAPI.SENDMESSAGE._MSG.WM_APPCOMMAND, p.MainWindowHandle, (IntPtr)command);
                    }
                }
            }
            else
            {
                IntPtr hWnd     = WinAPI.GetTopWindow(IntPtr.Zero);
                IntPtr lasthWnd = WinAPI.GetWindow(IntPtr.Zero, (uint)WinAPI.GET_WINDOW_CMD.GW_HWNDLAST);
                while (((capture = WinAPI.SendMessage(hWnd, WinAPI.SENDMESSAGE._MSG.WM_APPCOMMAND, hWnd, (IntPtr)command)) != new IntPtr(1)) &&
                       (lasthWnd != hWnd))
                {
                    hWnd = WinAPI.GetWindow(hWnd, (uint)WinAPI.GET_WINDOW_CMD.GW_HWNDPREV);
                }
                // at this point capture should be the very last window in the z-order. One final SnedMessage to this window is neccissary because
                // the loop will exist before
                // result 0 means processed message : http://msdn.microsoft.com/en-us/library/windows/desktop/ms646275(v=vs.85).aspx
            }
            if (capture == new IntPtr(1))
            {
                return(FormatInvokeSuccess());
            }
            else
            {
                return(FormatInvokeFailure());
            }
        }
Example #31
0
    void OnClientHandshakeReceived(NetworkMessage msg)
    {
        HandshakeMsg hmsg = msg.ReadMessage<HandshakeMsg>();
        ClientContainer c = new ClientContainer();
        c.username = hmsg.username;
        c.conn = msg.conn;
        this.clients.Add(c);

        Debug.Log(hmsg.username + " connected.");
        //Updating clients on change and telling newly connected of currently connected
        ClientListMsg updateMsg = new ClientListMsg();
        updateMsg.usernames = new string[this.clients.Count];
        for(int i = 0; i < this.clients.Count; i++)
        {
            updateMsg.usernames[i] = this.clients[i].username;
        }

        /*NetworkServer.SendToAll(ClientListMsg.msgType, updateMsg);
        hmsg.connectionID = msg.conn.connectionId;
        msg.conn.Send(HandshakeMsg.msgType, hmsg);*/

        foreach(PlayerController pc in GameObject.FindObjectsOfType<PlayerController>())
        {
            string username = null;
            for(int i = 0; i < this.clients.Count; i++)
            {
                if(this.clients[i].conn.connectionId == pc.playerID || (pc.connectionToClient == msg.conn && this.clients[i].conn == msg.conn))
                username = this.clients[i].username;
            }

            if(pc.connectionToClient == msg.conn)
                pc.RpcSetPlayerID(msg.conn.connectionId, username);
            else
                pc.RpcSetPlayerID(pc.playerID, username);
        }
    }