Example #1
0
        public void GiveCurrentWordVariant(Guid token, string word)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("GiveCurrentWordVariant userId=" + user.Id);
            RoomControll.GiveCurrentWordVariant(user, word);
        }
Example #2
0
        public void SetPrimaryWord(Guid token, string primaryWord)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("SetPrimaryWord userId=" + user.Id);
            RoomControll.SetPrimaryWord(user, primaryWord);
        }
Example #3
0
        public void AskQuestion(Guid token, string question, string word)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("AskQuestion userId=" + user.Id);
            RoomControll.AskQuestion(user, question, word);
        }
Example #4
0
        public void VoteForPlayerWord(Guid token, int wordId, bool up)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("VoteForPlayerWord userId=" + user.Id + " word=" + wordId + (up ? "up" : "down"));
            RoomControll.VoteForPlayerWord(user, wordId, up);
        }
Example #5
0
        public void Logoff(Guid token)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("Logoff userId=" + user.Id);
            RoomControll.DeleteOnlineUser(user);
        }
Example #6
0
        public GameState GetState(Guid token)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("GetState asked userId=" + user.Id);
            return(RoomControll.GetState(user));
        }
Example #7
0
        public void VoteForChiefWord(Guid token, bool up)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("VoteForChiefWord userId=" + user.Id + (up ? "up" : "down"));
            RoomControll.VoteForChifWord(user, up);
        }
Example #8
0
        public void BroadcastMessage(GameMessage message)
        {
            var deadUsers = new List <User>();

            lock (gameState)
            {
                foreach (var user in gameState.Users)
                {
                    try
                    {
                        user.Callback.Notify(message);
                    }
                    catch (CommunicationException e)
                    {
                        // assume that client is down. we can't logof it now - deadlock
                        LogSaver.Log(e.Message);
                        deadUsers.Add(user);
                    }
                    catch (Exception e)
                    {
                        LogSaver.Log("FAIL!! mysterious callback exception: " + e.Message);
                    }
                }
            }

            // logoff all deadUsers
            foreach (var deadUser in deadUsers)
            {
                LogSaver.Log("User " + deadUser.Id + " is dead. Logoff");
                RoomControll.DeleteOnlineUser(deadUser);
            }
        }
Example #9
0
        public void GiveChiefWord(Guid token, string word)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("GiveChiefWord userId=" + user.Id);
            RoomControll.GiveChiefWord(user, word);
        }
Example #10
0
        public void LeaveRoom(Guid token)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("User " + user.Id + "leave room");
            RoomControll.UserLeaveRoom(user);
        }
Example #11
0
        public void AddRoom(Guid token, string roomName)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("AddRoom userId=" + user.Id + " roomName=" + roomName);

            RoomControll.AddRoom(roomName);
        }
Example #12
0
        public void GotoRoom(Guid token, int roomId)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("GotoRoom userId=" + user.Id + " to room " + roomId);

            RoomControll.GotoRoom(user, roomId);
        }
Example #13
0
        public List <Room> GetRoomsList(Guid token)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("GetRoomsList userId=" + user.Id);

            return(RoomControll.GetRoomsList(user));
        }
Example #14
0
        public void StartGame(Guid token)
        {
            var user = RoomControll.GetUserByToken(token);

            LogSaver.Log("Start Game userId=" + user.Id);
            //ведущим становится взывавший эту операцию (пока пусть так будет)
            user.role = User.Role.Host;
            RoomControll.StartGame(user);
        }
Example #15
0
        public static void LogoffUser(User user)
        {
            User        us  = RoomControll.GetUserByName(user.Name);
            GameMessage msg = new GameMessage();

            msg = GameMessage.LogoffUser();
            DeleteOnlineUser(us);
            try { us.Callback.Notify(msg); }
            catch { }
        }
Example #16
0
        public void ReceiveChatMessage(Guid token, string message)
        {
            var user = RoomControll.GetUserByToken(token);

            if (message == "")
            {
                return;
            }
            LogSaver.Log("Chat message from " + user.Name + ": " + message);
            RoomControll.BroadcastChatMessageToRoom(user, message);
        }
Example #17
0
        static void Main(string[] args)
        {
            // TODO: remove this and do normal room management
            RoomControll.AddRoom("Lobby");
            RoomControll.AddRoom("First and only room");

            var service = new ServiceHost(typeof(GameService));

            service.Open();
            LogSaver.Log("Server started");
            Console.ReadLine();
            service.Close();
            LogSaver.Log("Server shut down");
        }
Example #18
0
        public static void AddOnlineUser(User user)
        {
            lock (OnlineUsers)
            {
                if (RoomControll.CheckUser(user.Name))
                {
                    LogoffUser(user);
                }
                OnlineUsers.Add(user);
            }

            // assign user to lobby
            user.RoomId = 0;
            Rooms[0].EnterRoom(user);
        }
        public static UserData LoginUser(string name, string password)
        {
            User user;

            lock (syncObject) //добавлено чтобы не путать OperatinContext, хотя не понятно насколько работает
            {
            #if DEBUG
                user = new User(userCnt, name);
                ++userCnt;
            #else
                user = DBAccess.CheckUser(name, password);
            #endif

                if (user.Id != -1)
                {
                    RoomControll.AddOnlineUser(user);
                }
            }


            return(new UserData(user));
        }