Beispiel #1
0
 public Message(DateTime time, User sender, string message)
 {
     Time = time;
     Sender = sender;
     Msg = message;
 }
Beispiel #2
0
        public bool Login(string user, string pass)
        {
            /*
            // Regisztráció debug
            database.dbUserSet.Add(new dbUserSet() { name = user, pass = pass, email = "", goodanswers = 0, played = 0, questions = 0, win = 0 });
            database.SaveChanges();
            */

            bool userfound = false;
            try
            {
                userfound = (from users in database.dbUserSet
                             where users.name.Equals(user) && users.pass.Equals(pass)
                             select users).Count().Equals(1);
            }
            catch (Exception)
            {
            }
            // debug, adminra belép
            if (onlineUsers.Exists(x => x.Name.Equals(user)))
            {
                Logger.log(Errorlevel.INFO, user + " tried to log in twice");
                return false;
            }
            else if (user.Length < 10 || userfound)
            {
                User login = new User(user);
                onlineUsers.Add(login);

                Logger.log(Errorlevel.INFO, user + " logged in");
                return true;
            }
            else
            {
                Logger.log(Errorlevel.INFO, (String.IsNullOrEmpty(user) ? "NULL OR EMPTY" : user) + " failed to log in");
                return false;
            }
        }
Beispiel #3
0
 public bool Answer(User user, int id)
 {
     user.State = States.IDLE;
     if (id == 0)
     {
         user.AnswerResult = new AnswerResult() { Answer = true, Time = DateTime.Now };
         return true;
     }
     else
     {
         user.AnswerResult = new AnswerResult() { Answer = false, Time = DateTime.Now };
         return false;
     }
 }
Beispiel #4
0
 public void addUser(User user)
 {
     if (Players.Count <= Room.MAXPLAYERS)
     {
         user.Color = playercolors[Players.Count];
         Players.Add(user);
     }
     else throw new OverflowException("Too much users in " + Name + " room!");
 }
Beispiel #5
0
        private void turn(object sender, DoWorkEventArgs e)
        {
            int turn = 0;
            do
            {
                actualPlayer = null;
                actualCell = null;

                question = new Question(IQService.database.dbQuestionSet.OrderBy(r => Guid.NewGuid()).First());
                selectNextMove();

                Stopwatch stopper = new Stopwatch();
                stopper.Start();
                // Lépésre vár
                while (stopper.ElapsedMilliseconds < turnTimeout && actualCell == null) Thread.Sleep(IQService.Pingperiod);

                if (actualCell != null)
                {

                    actualCell.Owner.State = States.ANSWER;

                    stopper.Restart();
                    while (stopper.ElapsedMilliseconds < turnTimeout &&
                        (actualPlayer.State == States.ANSWER ||
                        (actualCell.Owner.State == States.ANSWER && actualCell.Owner.Name != null)))
                    {
                        Thread.Sleep(IQService.Pingperiod);
                    }

                    // Lejárt az idő: a válasz rossz
                    if (actualPlayer.AnswerResult == null)
                        actualPlayer.AnswerResult = new AnswerResult() { Answer = false, Time = DateTime.Now };
                    if (actualCell.Owner.AnswerResult == null)
                        actualCell.Owner.AnswerResult = new AnswerResult() { Answer = false, Time = DateTime.Now };

                    if (actualPlayer.AnswerResult.Answer == false || actualPlayer.AnswerResult.Time > actualCell.Owner.AnswerResult.Time)
                    {
                        // Védő nyert
                        actualCell.Owner.Point += 10;
                        actualPlayer.Point -= 10;
                    }
                    else
                    {
                        // Támadó nyert
                        actualCell.Owner.Point -= 10;
                        actualPlayer.Point += 10;
                        actualCell.Owner = actualPlayer;
                    }

                    actualCell.Owner.State = States.IDLE;
                    actualCell.Owner.AnswerResult = null;
                }
                actualPlayer.State = States.IDLE;
                actualPlayer.AnswerResult = null;
                turn++;
            } while (turn < maxturns);

            // Játék vége
            foreach (User u in Players)
            {
                u.State = States.FINISHED;
            }
            Thread.Sleep(IQService.Timeout);
            finished = true;
        }
Beispiel #6
0
        public void selectNextMove()
        {
            foreach (User u in Players) u.State = States.IDLE;
            if (rollable == null || rollable.Count == 0)
            {
                rollable = new List<User>();
                rollable.AddRange(Players);
            }

            int r = IQService.rand.Next(rollable.Count);
            actualPlayer = rollable[r];
            rollable.RemoveAt(r);

            actualPlayer.State = States.MOVE;
        }
Beispiel #7
0
        public void selectNextMove()
        {
            foreach (User u in Players) u.State = States.IDLE;
            if (rollable == null || rollable.Count == 0)
            {
                rollable = new List<User>();
                rollable.AddRange(Players);
            }

            int r = IQService.rand.Next(rollable.Count);

            if (IQService.Debug)
            {
                int debug = -1;
                debug = rollable.FindIndex(x => x.Name.Equals("debug"));
                if (debug != -1) r = debug;
            }

            actualPlayer = rollable[r];
            rollable.RemoveAt(r);

            actualPlayer.State = States.MOVE;
        }