public BitPoker.Models.Contracts.Table Get(Guid id) { using (BitPoker.Repository.ITableRepository repo = Repository.Factory.GetTableRepository()) { return(repo.Find(id)); } }
public void AddSmallBlind(BitPoker.Models.Messages.ActionMessage message) { if (message != null) { //Is the blind the correct amount? var table = tableRepo.Find(message.TableId); if (table != null && message.Action == "POST SMALL BLIND" && message.Amount == table.BigBlind) { //handRepo.AddMessage(message); } else { throw new ArgumentException(); } } }
public async Task <BitPoker.Models.Messages.BuyInResponse> Post(BitPoker.Models.Messages.BuyInRequest buyInRequest) { //if (!base.Verify(buyInRequest.BitcoinAddress, buyInRequest.ToString(), buyInRequest.Signature)) //{ // throw new Exceptions.SignatureNotValidException(); //} BitPoker.Models.Messages.BuyInResponse response = new BitPoker.Models.Messages.BuyInResponseMessage() { TimeStamp = DateTime.UtcNow }; var table = tableRepo.Find(buyInRequest.TableId); if (table != null) { //Is seat empty? table.Players[0] = new BitPoker.Models.TexasHoldemPlayer() { //BitcoinAddress = buyInRequest.BitcoinAddress, Stack = buyInRequest.Amount, //Position = buyInRequest.Seat, //Assume no hand played for this mock IsBigBlind = false, IsDealer = true, IsSmallBlind = false, IsTurnToAct = false, }; tableRepo.Update(table); if (table.Players.Count >= table.MinPlayers) { //DEAL BitPoker.Models.IPlayer smallBind = table.Players.OrderBy(p => p.Position).FirstOrDefault(); BitPoker.Models.Messages.ActionMessage smallBlindRequest = new BitPoker.Models.Messages.ActionMessage() { Action = "POST SMALL BLIND", //TimeStamp = DateTime.UtcNow, TableId = buyInRequest.TableId }; String json = JsonConvert.SerializeObject(smallBlindRequest); StringContent requestContent = new StringContent(json, Encoding.UTF8, "application/json"); using (HttpClient httpClient = new HttpClient()) { using (HttpResponseMessage responseMessage = await httpClient.PostAsync(smallBind.IPAddress, requestContent)) { if (responseMessage.IsSuccessStatusCode) { String responseContent = await responseMessage.Content.ReadAsStringAsync(); } else { throw new InvalidOperationException(); } } } //// //const String alice_wif = "93Loqe8T3Qn3fCc87AiJHYHJfFFMLy6YuMpXzffyFsiodmAMCZS"; //NBitcoin.BitcoinSecret alice_secret = new NBitcoin.BitcoinSecret(alice_wif, NBitcoin.Network.TestNet); //NBitcoin.BitcoinAddress alice_address = alice_secret.GetAddress(); ////response.Table = table; ////Create players //BitPoker.Models.PlayerInfo[] players = new BitPoker.Models.PlayerInfo[2]; //players[0] = new BitPoker.Models.PlayerInfo() { BitcoinAddress = alice_address.ToString(), UserAgent = "Bitpoker 0.1", IPAddress = "https://bitpoker.azurewebsites.net/api" }; //players[1] = new BitPoker.Models.PlayerInfo() { BitcoinAddress = buyInRequest.BitcoinAddress }; ////Alice in seat 0, you in the sb ////response.Players[0] = new BitPoker.Models.PlayerInfo() { BitcoinAddress = alice_address.ToString(), UserAgent = "Bitpoker 0.1", IPAddress = "https://bitpoker.azurewebsites.net/api" }; ////response.Players[1] = new BitPoker.Models.PlayerInfo() { BitcoinAddress = buyInRequest.BitcoinAddress }; ////Alice pub key //const String alice_pub_key = "041FA97EFD760F26E93E91E29FDDF3DDDDD3F543841CF9435BDC156FB73854F4BF22557798BA535A3EE89A62238C5AFC7F8BF1FA0985DC4E1A06C25209BAB78BD1"; //Byte[] alicePubKeyAsBytes = NBitcoin.DataEncoders.Encoders.Hex.DecodeData(alice_pub_key); //NBitcoin.PubKey alicePubKey = new NBitcoin.PubKey(alicePubKeyAsBytes); //NBitcoin.PubKey userKey = new NBitcoin.PubKey(buyInRequest.PubKey); //var scriptPubKey = NBitcoin.PayToMultiSigTemplate.Instance.GenerateScriptPubKey(2, new[] { alicePubKey, userKey }); ////As its heads up, create the first hand and deck //BitPoker.Models.Hand hand = new BitPoker.Models.Hand(players); } return(response); } else { throw new Exceptions.TableNotFoundException(); } }
public BitPoker.Models.Hand Post(BitPoker.Models.Messages.DealRequest request) { var table = tableRepo.Find(request.TableId); if (table != null) { BitPoker.Models.Hand hand = new BitPoker.Models.Hand() { Deck = request.Deck }; //todo: change to position var sb = table.Peers[0]; const String alice_wif = "93Loqe8T3Qn3fCc87AiJHYHJfFFMLy6YuMpXzffyFsiodmAMCZS"; NBitcoin.BitcoinSecret alice_secret = new NBitcoin.BitcoinSecret(alice_wif, NBitcoin.Network.TestNet); NBitcoin.BitcoinAddress alice_address = alice_secret.GetAddress(); const String alice_pubkey = "041fa97efd760f26e93e91e29fddf3ddddd3f543841cf9435bdc156fb73854f4bf22557798ba535a3ee89a62238c5afc7f8bf1fa0985dc4e1a06c25209bab78bd1"; BitPoker.Models.Messages.ActionMessage smallBlind = new BitPoker.Models.Messages.ActionMessage() { //Id = new Guid("4bc7f305-aa16-450a-a3be-aad8fba7f425"), Index = 0, Action = "SMALL BLIND", Amount = table.SmallBlind, //BitcoinAddress = sb.BitcoinAddress, HandId = hand.Id, //PublicKey = alice_pubkey, TableId = request.TableId }; //smallBlind.Signature = alice_secret.PrivateKey.SignMessage(smallBlind.ToString()); //hand.AddMessage(smallBlind); //var bb = table.Players[1]; //const String bob_wif = "91yMBYURGqd38spSA1ydY6UjqWiyD1SBGJDuqPPfRWcpG53T672"; //NBitcoin.BitcoinSecret bob_secret = new NBitcoin.BitcoinSecret(bob_wif, NBitcoin.Network.TestNet); //NBitcoin.BitcoinAddress bob_address = bob_secret.GetAddress(); //const String bob_pubkey = "04f48396ac675b97eeb54e57554827cc2b937c2dae285a9198f9582b15c920d91309bc567858dc63357bcd5d24fd8c041ca55de8bae62c7315b0ba66fe5f96c20d"; ////NBitcoin.Crypto.Hashes.SHA256(NBitcoin.DataEncoders.Encoders.ASCII.(smallBlind.ToString())); //Byte[] hash = NBitcoin.Crypto.Hashes.SHA256(NBitcoin.DataEncoders.Encoders.ASCII.DecodeData(smallBlind.ToString())); //BitPoker.Models.Messages.ActionMessage bigBlind = new BitPoker.Models.Messages.ActionMessage() //{ // Id = new Guid("d10cc043-4df3-4d41-8b31-8dd573824c8b"), // Index = 1, // Action = "BIG BLIND", // Amount = table.BigBlind, // BitcoinAddress = bb.BitcoinAddress, // HandId = hand.Id, // PreviousHash = NBitcoin.DataEncoders.Encoders.ASCII.EncodeData(hash), // PublicKey = bob_pubkey, // TableId = request.TableId //}; //bigBlind.Signature = bob_secret.PrivateKey.SignMessage(bigBlind.ToString()); //hand.AddMessage(bigBlind); this.handRepo.Add(hand); return(hand); } else { throw new ArgumentException(); } }