示例#1
0
文件: Room.cs 项目: blindsight/Talker
        public static List<Room> GetAllRooms()
        {
            List<Room> rooms = new List<Room>();

            using (MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString)) {
                using(MySqlCommand cmd = new MySqlCommand("SELECT * FROM rooms", conn)) {
                    cmd.Connection.Open();

                    MySqlDataReader roomReader = cmd.ExecuteReader();

                    while(roomReader.Read()) { //TODO should the while be used if only one row?
                        Room newRoom = new Room();
                        newRoom.Id = long.Parse(roomReader["roomId"].ToString());
                        newRoom.Name = roomReader["name"].ToString();
                        newRoom.Desc = roomReader["desc"].ToString(); //todo: should try parse be used for safety?
                        newRoom.Topic = roomReader["topic"].ToString();

                        //TODO: could add total users entered and left or something for stats?
                        rooms.Add(newRoom);
                    }

                    cmd.Connection.Close();
                }
            }

            return rooms;
        }
示例#2
0
文件: User.cs 项目: blindsight/Talker
        public void ChangeRoom(Room newRoom)
        {
            //take the user out of the room so that write to room is faster.
            this.Room.Users.Remove(this);
            this.Room = newRoom;
            this.Room.Users.Add(this);

            //TODO: find a better way to do this
            Server.CommandList.ForEach(delegate(ICommand command) {
                if(command.Name.Equals("look")) {
                    UserInput newInput = new UserInput(this, "look");
                    command.Run(newInput);
                }
            });
        }