processMsg conn client (JoinRoom rid) = do
  client' <- refreshClient conn client
  let r = clientRoomId client'
  case r of 
    Just oldRid -> do
        -- client leaves a room and joins one
        case (oldRid == rid) of
          True -> return [] -- no-op
          False -> do
            execute conn "update clients set room_id = ? where client_id = ?" (rid, (clientId client))
            rleft <- liftM makeUpdatedRoom $ findRoom conn oldRid 
            rjoined <- liftM makeUpdatedRoom $ findRoom conn rid
            return [rleft $ ExitRoom (tupClient client'), rjoined $ EnterRoom (tupClient client')]
    Nothing -> do
        execute conn "update clients set room_id = ? where client_id = ?" (rid, (clientId client))
        r <- liftM makeUpdatedRoom $ findRoom conn rid
        return [r $ EnterRoom (tupClient client')]
processMsg conn client (JoinRoom rid) = do
  client' <- refreshClient conn client
  let r = clientRoomId client'
  case r of 
    Just oldRid -> do
        -- client leaves a room and joins one
        case (oldRid == rid) of
          True -> return [] -- no-op
          False -> do
            execute conn "update clients set room_id = ? where client_id = ?" (rid, (clientId client))
            rleft <- liftM makeUpdatedRoom $ findRoom conn oldRid 
            rjoined <- liftM makeUpdatedRoom $ findRoom conn rid
            return [rleft $ ExitRoom (tupClient client'), rjoined $ EnterRoom (tupClient client')]
    Nothing -> do
        execute conn "update clients set room_id = ? where client_id = ?" (rid, (clientId client))
        r <- liftM makeUpdatedRoom $ findRoom conn rid
        return [r $ EnterRoom (tupClient client')]
processMsg conn client (JoinRoom rid) = do
  client' <- refreshClient conn client
  let r = clientRoomId client'
  case r of 
    Just oldRid -> do
        -- client leaves a room and joins one
        case (oldRid == rid) of
          True -> return [] -- no-op
          False -> do
            execute conn "update clients set room_id = ? where client_id = ?" (rid, (clientId client))
            rleft <- liftM makeUpdatedRoom $ findRoom conn oldRid 
            rjoined <- liftM makeUpdatedRoom $ findRoom conn rid
            return [rleft $ ExitRoom (tupClient client'), rjoined $ EnterRoom (tupClient client')]
    Nothing -> do
        execute conn "update clients set room_id = ? where client_id = ?" (rid, (clientId client))
        r <- liftM makeUpdatedRoom $ findRoom conn rid
        return [r $ EnterRoom (tupClient client')]