private WorkInfo assignWorker()
        {
            WorkInfo work = new WorkInfo();

            work.WordList = getBatch(batch_size);
            if (work.WordList.Count == 0)
            {
                return(null);
            }

            work.Id        = Guid.NewGuid();
            work.UsersList = userInfos;
            working.Add(work.Id, work);
            return(work);
        }
        protected override void TcpServerWork(StreamReader sr, StreamWriter sw)
        {
            bool hackInProgress = true;

            while (hackInProgress)
            {
                //TODO protocol:
                //indgående:
                //Forespørgelse på en workinfo: hack
                //Svar på hack: completed
                //Svar på password fundet : passwordfound
                //udgående:
                //



                //Console.WriteLine("listening for message");
                string message = sr.ReadLine();
                Console.WriteLine(message);

                switch (message)
                {
                case "hack":
                    WorkInfo w = assignWorker();
                    if (w != null)
                    {
                        string workinfo_string = JsonConvert.SerializeObject(w);
                        Console.WriteLine(w.WordList.Count + w.WordList[0]);
                        Console.WriteLine("Sending hack info!!");
                        sw.WriteLine(workinfo_string);
                        sw.Flush();
                        Console.WriteLine("hack send");
                    }
                    else
                    {
                        sw.WriteLine("nothing to hack");
                    }

                    break;

                case "passwordfound":
                    string passwordsfound = sr.ReadLine();
                    List <UserInfoClearText> userpassfound =
                        JsonConvert.DeserializeObject <List <UserInfoClearText> >(passwordsfound);

                    foreach (UserInfoClearText passwordmatch in userpassfound)
                    {
                        passwordmatches.Add(passwordmatch);



                        List <UserInfo> usersToRemove = new List <UserInfo>();

                        foreach (UserInfo user in userInfos)
                        {
                            if (user.Username == passwordmatch.UserName)
                            {
                                usersToRemove.Add(user);
                            }
                        }

                        foreach (UserInfo user in usersToRemove)
                        {
                            userInfos.Remove(user);
                        }
                    }

                    break;

                case "completed":
                    string completeInfo = sr.ReadLine();
                    Guid   id           = Guid.Parse(completeInfo);
                    working.Remove(id);
                    break;
                }

                if (working.Count == 0 && notdone.Count == 0 || userInfos.Count == 0)
                {
                    Console.WriteLine("----- Cracking Completed");
                    foreach (UserInfoClearText userinfo in passwordmatches)
                    {
                        Console.WriteLine(userinfo.ToString());
                    }
                    hackInProgress = false;
                }
            }
        }