Esempio n. 1
0
        public void AcceptChiefWord(User user, string word)
        {
            if (user.role != User.Role.Host)
            {
                LogSaver.Log("!!! AcceptChiefWord invoked user " + user.Id + " role " + user.role.ToString());
                GameException.Throw("Вы не можете так делать");
            }

            lock (gameState)
            {
                if (gameState.UsedWords.Contains(word))
                {
                    GameException.Throw("Это слово уже использовалось");
                }

                if (!word.StartsWith(gameState.PrimaryWordKnownLetters))
                {
                    GameException.Throw("Слово должно начинаться с открытых букв");
                }
                if (word == gameState.PrimaryWord)
                {
                    GameException.Throw("Так ты спалишь загаданное слово!");
                }

                gameState.PrepareForVoting(1);
                gameState.ChiefWord = word;
                BroadcastMessage(GameMessage.WeHaveChiefWord(word));
                ChangeState(GameState.State.VotingForHostWord);
            }
        }
Esempio n. 2
0
        //Connect to DB with query
        public static User CheckUser(string username, string password)
        {
            string sql = "SELECT * FROM Users WHERE [Имя]='" + username + "'"; //SQL-query

            //connection options
            string          connectionString = "Provider=Microsoft.Ace.OLEDB.12.0;" + "Data Source= Users.accdb";
            OleDbConnection connection       = new OleDbConnection(connectionString);

            connection.Open();
            OleDbCommand    command    = new OleDbCommand(sql, connection);
            OleDbDataReader dataReader = command.ExecuteReader();

            //check results
            if (dataReader.Read())
            {
                if (dataReader["Пароль"].ToString() == SHA512Hash(password))
                {
                    return(new User(Convert.ToInt32(dataReader["Код"]), username));
                }
            }

            // If autorization failed
            GameException.Throw("Incorrect password!");
            return(new User(-1, "Error"));
        }
Esempio n. 3
0
        public static void Throw(string message)
        {
            var exception = new GameException {
                Message = message
            };

            throw new FaultException <GameException>(exception);
        }
Esempio n. 4
0
        public void VoteForChiefWord(User user, bool up)
        {
            lock (gameState)
            {
                if (user.role == User.Role.Host)
                {
                    GameException.Throw("Вы не можете голосовать");
                }

                gameState.votings[0].Vote(user, up);
            }
        }
Esempio n. 5
0
        public void VoteForPlayerWord(User user, int wordId, bool up)
        {
            lock (gameState)
            {
                if (user.role != User.Role.None)
                {
                    GameException.Throw("Вы не можете голосовать");
                }

                gameState.votings[wordId].Vote(user, up);
            }
        }
Esempio n. 6
0
        public void AcceptPrimaryWord(User user, string primaryWord)
        {
            if (user.role != User.Role.Host)
            {
                LogSaver.Log("!!! AcceptPrimaryWord invoked user " + user.Id + " role " + user.role.ToString());
                GameException.Throw("Вы не можете этого делать!");
            }

            lock (gameState)
            {
                gameState.PrimaryWord = primaryWord.ToLower();
                BroadcastMessage(GameMessage.PrimaryWordGiven(gameState.PrimaryWord));
                ChangeState(GameState.State.HaveNoCurrentWord);
            }
        }
Esempio n. 7
0
        public static void AddRoom(string name)
        {
            if (Rooms.Values.Any(p => p.Name == name))
            {
                GameException.Throw("Комната с таким именем уже есть");
            }

            var newRoomId = roomsCount;

            Interlocked.Increment(ref roomsCount);
            Rooms.TryAdd(newRoomId, new Room(newRoomId, name));
            GameMessage message = GameMessage.AddedRoom(name, newRoomId);

            Rooms[0].BroadcastMessage(message);
        }
Esempio n. 8
0
        public static void GotoRoom(User user, int roomId)
        {
            if (!Rooms.ContainsKey(roomId))
            {
                LogSaver.Log("!?! Trying to go to nonexistent room " + roomId + " userId=" + user.Id);
                GameException.Throw("Комнаты с таким номером нет");
            }

            if (roomId == user.RoomId)
            {
                return;
            }

            Rooms[user.RoomId].LeaveRoom(user);
            user.RoomId = roomId;
            Rooms[roomId].EnterRoom(user);
        }
Esempio n. 9
0
        public void AcceptCurrentWordVariant(User user, string word)
        {
            if (user.role != User.Role.None)
            {
                LogSaver.Log("!!! AcceptCurrentWordVariant invoked user " + user.Id + " role " + user.role.ToString());
                GameException.Throw("Вы не можете так делать");
            }

            bool epicWin = false; // угадал primaryWord

            lock (gameState)
            {
                if (gameState.UsedWords.Contains(word))
                {
                    GameException.Throw("Это слово уже использовалось");
                }

                if (!word.StartsWith(gameState.PrimaryWordKnownLetters))
                {
                    GameException.Throw("Слово должно начинаться с открытых букв");
                }

                if (word == gameState.PrimaryWord)
                {
                    epicWin = true;
                }
                else
                {
                    gameState.VarOfCurWord = word;
                    user.role = User.Role.Contacter;
                }
            }

            if (epicWin)
            {
                ResetRoles();
                ChangeState(GameState.State.GameOver);
            }
            else
            {
                BroadcastMessage(GameMessage.UserRoleChangedMessage(user, User.Role.Contacter));
                BroadcastMessage(GameMessage.VarOfCurWordChangedMessage(word));
                ChangeState(GameState.State.HaveCurrentWordVariant);
            }
        }
Esempio n. 10
0
        public void Vote(User user, bool up)
        {
            if (VotedUsers.Contains(user.Id))
            {
                GameException.Throw("Вы не можете голосовать дважды");
            }

            if (up)
            {
                VotesUp++;
            }
            else
            {
                VotesDown++;
            }

            VotedUsers.Add(user.Id);
        }
Esempio n. 11
0
        public void AcceptQuestion(User user, string question, string word)
        {
            if (user.role != User.Role.None)
            {
                LogSaver.Log("!!! AcceptQuestion invoked user " + user.Id + " role " + user.role.ToString());
                GameException.Throw("Вы не можете этого делать!");
            }

            bool epicWin = false; //угадал primaryWord

            lock (gameState)
            {
                gameState.Question = question;

                if (!word.StartsWith(gameState.PrimaryWordKnownLetters))
                {
                    GameException.Throw("Слово должно начинаться с открытых букв");
                }

                if (word == gameState.PrimaryWord)
                {
                    epicWin = true;
                }
                else
                {
                    gameState.CurrentWord = word;
                    user.role             = User.Role.Qwestioner;
                }
            }

            if (epicWin)
            {
                ResetRoles();
                ChangeState(GameState.State.GameOver);
            }
            else
            {
                BroadcastMessage(GameMessage.QuestionAsked(question, word));
                BroadcastMessage(GameMessage.UserRoleChangedMessage(user, User.Role.Qwestioner));
                ChangeState(GameState.State.HaveCurrentWord);
            }
        }
Esempio n. 12
0
        //Registration. If username already busy - return -1;
        public static int UserReg(string username, string password)
        {
            string          sql = "SELECT * FROM Users WHERE [Имя]='" + CheckWord(username) + "'"; //SQL-query
            string          connectionString = "Provider=Microsoft.Ace.OLEDB.12.0;" + "Data Source= Users.accdb";
            OleDbConnection connection       = new OleDbConnection(connectionString);

            connection.Open();
            OleDbCommand    command    = new OleDbCommand(sql, connection);
            OleDbDataReader dataReader = command.ExecuteReader();

            if (dataReader.Read())
            {
                GameException.Throw("This name is already registred");
                return(-1);
            }
            sql     = "INSERT INTO [Users] ([Имя],[Пароль]) VALUES ('" + CheckWord(username) + "','" + CheckWord(SHA512Hash(password)) + "')";
            command = new OleDbCommand(sql, connection);
            command.ExecuteNonQuery();

            return(0);
        }
Esempio n. 13
0
 public static void Throw(string message)
 {
     var exception = new GameException { Message = message };
     throw new FaultException<GameException>(exception);
 }