A little before 1 a.m. on Feb. 10, 2017, an analyst working the night shift on the third floor of a stately stone building in central London saw his computer light up with alerts.

There was a sudden influx of unusual betting in sportsbooks from the Caribbean to Asia. One of the largest underdogs in the NBA that night (at 12 points) was getting unexpected action to win. Within moments the monitors at Sportradar AG -- a large European-based gambling services company that has a contract with the NBA to watch more than 550 international sportsbooks -- had flagged it as possible match fixing.

The target was the Cleveland Cavaliers.

The analyst went to work and within a minute or two found what he believed to be the source, a tweet from ESPN reporter Royce Young revealing that LeBron James, Kyrie Irving and Kevin Love were all going to play that night in Oklahoma City after Cavs coach Tyronn Lue had previously announced they'd all skip the game to rest. Sportradar issued an all clear, and casinos around the globe scrambled to reset the lines. Within 10 minutes, the game was a pick 'em.

Moments like these have been part of an intense legislative battle across the nation over the past six months. Mostly behind the scenes but occasionally in open sessions, the NBA and Major League Baseball have partnered in a fight that neither could've even dreamed about over the past few decades: a battle to protect their leagues' integrity while also getting their hands on a piece of what could be a new ocean of gambling money in the United States.

The Supreme Court ruling Monday opened the door for states outside Nevada to legalize widespread sports gambling, an action that is expected to lead to billions of dollars moving from illegal sportsbooks to new or expanded legal operations.

Since last June when the court agreed to hear the case, more than 20 states have taken up versions of bills aimed at taking advantage of a favorable ruling. Four states -- New Jersey, Pennsylvania, Mississippi and West Virginia -- have passed bills that could see them begin taking bets in a short time.

The NBA and MLB have been on the ground in all of these states as they combine resources to lobby to get language that would assure them of a gambling revenue stream for years to come. They've hired high-priced lobbying firms, submitted written statements and sent executives to testify in statehouses.

All the pro sports leagues, including the PGA Tour and the NCAA, have been involved, but it has been the NBA and MLB that have been the tip of the spear. And first in the firing line for those pushing back and the desire for a cut of the new proceeds.

In January, NBA vice president Dan Spillane started an uproar when he appeared before the New York state legislature and asked for leagues to get a 1 percent cut off the top from all sports wagers were it to be legalized. Spillane said the NBA would be deserving of the money because it would have to pay for "integrity" services -- like the arrangement the league has with Sportradar -- to watch for match fixing or other betting irregularities that could threaten the game.

In the months since, Spillane and his counterpart at MLB, vice president Bryan Seeley, have crisscrossed the country to pitch similar language to legislatures.

"It is reasonable for those who reap the profits to compensate the sports league in recognition of the billions of dollars the leagues invest to create a compelling product," Seeley told Kansas lawmakers as he angled for a favorable bill there in March. "As well as the risk to reputation and integrity that accompanies sports betting."

Legal sports betting could present new challenges for the NBA and other leagues. David Purdum

Casinos, gambling lobbyists and some legislators protested what was branded as the NBA's request for an "integrity fee." Last year, Nevada sportsbooks had a 5.1 percent profit margin, according to figures released by the state's gaming control board. Over the past 10 years, Nevada sportsbooks have averaged 5.3 percent annual profit margin, according to a study by UNLV's Center for Gaming Research.

Therefore, asking for a 1 percent cut of bets would represent almost 20 percent cut of the profit if new sportsbooks across the nation see the same margins as Nevada. Lobbyists for casinos have told state legislators that such a fee would have to be passed on to customers in the form of less favorable odds on bets and leave them uncompetitive with the illegal sports wagering market they are trying to eliminate. Opponents have also pointed out the NBA and NFL have held games in London for years -- MLB is planning games there -- and have integrity operations in place already.

"It will place brick-and-mortar gaming and racing venues at a significant economic and competitive disadvantage," Whitney Damron, a lawyer for Kansas casinos, told the state's House of Representatives in response to the NBA and MLB's effort there. "This will prevent the state from realizing the full benefits of gaming legislation."

The NBA has disputed the math, saying a larger legal market would create a better margin for casinos. The leagues have also actively pushed for betting to be made more widely available on cell phones and to make it easy to register to gamble that way, which would potentially limit how much current casinos could get in on the new market.

As the Supreme Court debated its ruling after hearing oral arguments in December, the NBA and MLB reacted to the pushback by starting to maneuver and altered the pitch to states. The leagues backed down from the 1 percent ask. In New York, where a sports gambling bill is currently in committee, a compromise got legislators to insert language for a 0.25 percent cut of bets to the leagues.

In the meantime, the leagues distanced themselves from the term "integrity fee." Over All-Star Weekend in February, NBA commissioner Adam Silver tried to change the rhetoric when he said the leagues were owed a "royalty" for their long-term investment in creating games on which people want to wager.

"These are our games ... the backbone of the whole business of sports betting, and we think it makes sense for us to be compensated," the NBA's Spillane said during a panel discussion in Las Vegas in April. "You can't have sports betting without our game. ... We think it's reasonable for us to be compensated for that input just like every other supplier."

A surprise battleground in this fight has been West Virginia, a small state with no pro sports teams and only five casinos currently. The state legislature passed a bill in March without a fee for sports leagues that would go into effect after the Supreme Court ruling. MLB commissioner Rob Manfred publicly pressured Gov. Jim Justice to veto the bill. Justice didn't and it became provisional law.

But the NBA and MLB continued to lobby Justice, whose family owns The Greenbrier Resort, where one of the state's casinos is located and where an annual PGA Tour event is held. Last week the governor announced he'd reached a deal with the leagues and the state's lottery commission that would send money to the leagues, including the PGA Tour. ESPN reported the deal would also send money to Marshall and West Virginia, the state's two Division I universities.

Lawmakers disputed the legality of the agreement and the process is still playing out. How it ends up might turn out to be a precedent for other states, which is why the NBA and MLB have spent so much time trying to leverage a favorable deal in an otherwise small market.

In addition to trying to get the fee built into new laws, the NBA and MLB have attempted to get lawmakers to mandate that casinos buy real-time data from the leagues themselves. Much of the new betting market is expected to be in the form of in-game wagers, which makes real-time information vital. Leagues want to turn this into a profit center and have been preparing to do so.

In addition to monitoring wagering overseas, this season the NBA started a new deal with Sportradar for data services. It's a multimillion-dollar deal that allows Sportradar to sell the NBA's official real-time data to casinos around the world.

As all of this has played out, the players' unions for the pro sports leagues have been monitoring the lobbying efforts. Recently the National Basketball Players' Association hosted a symposium of sorts with representatives from the NFLPA, MLBPA and NHLPA. The four groups released a joint statement requesting a seat at the table as new laws and revenues are understood and divided.

"The time has come to address not just who profits from sports gambling, but also the costs," the statement read. "Betting on sports may become widely legal, but we cannot allow those who have lobbied the hardest for sports gambling to be the only ones controlling how it would be ushered into our businesses."

No matter how it shakes out, American professional sports and how fans consume and interact with them are about to change. And the NBA and MLB have been working tirelessly to construct a way to profit from it.

"The leagues kept their distance ... when sports betting was put in place decades ago," Spillane said last month in Vegas. "That was the wrong move. We're not going to make that mistake again. We are going to be engaged in the process."

ESPN.com gambling writer David Purdum and contributor Ryan Rodenberg contributed to this report. ESPN has a deal with Sportradar to provide odds.