Example #1
0
        public Models.IResponse Post(Models.IRequest model)
        {
            if (model.Method == "AddPlayer")
            {
                Models.Messages.RPCResponse      response = new Models.Messages.RPCResponse();
                Models.Messages.AddPlayerRequest request  = model.Params as Models.Messages.AddPlayerRequest;

                //need to include timestamp too
                Boolean valid = true; //base.Verify(request.BitcoinAddress, model.Id.ToString(), model.Signature);

                if (valid)
                {
                    //PlayerRepo.Add(request.Player);
                    return(response);
                }
                else
                {
                    response.Error = "invalid siganture";
                    return(response);
                }
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        public Models.IResponse Get(Models.IRequest request)
        {
            Models.Messages.RPCResponse response = new Models.Messages.RPCResponse()
            {
                Id = request.Id
            };

            switch (request.Method.ToUpper())
            {
            //Get peers that user knows about
            case "GetPeers":
                response.Result = PlayerRepo.All();
                break;

            //Get my tables
            case "GetTables":
                response.Result = TableRepo.All();
                break;

            case "GetHands":
                throw new NotImplementedException();

            //break;
            default:
                response.Error = new Models.Messages.Code()
                {
                    code    = "-32601",
                    message = "method not found"
                };
                break;
            }

            return(response);
        }
Example #3
0
        public Models.IResponse Get(Models.IRequest request)
        {
            Models.Messages.RPCResponse response = new Models.Messages.RPCResponse()
            {
                Id = request.Id
            };

            switch (request.Method.ToUpper())
            {
            case "GetInfo":
                base.Log        = String.Format("Getinfo called by {0}", request.Id);
                response.Result = new Models.Peer()
                {
                    LastSeen = DateTime.UtcNow
                };
                break;

            //case "GetPeers":
            //    response.Result = PlayerRepo.All();
            //    break;
            //case "GetTables":
            //    response.Result = TableRepo.All();
            //    break;
            case "GetHands":
                throw new NotImplementedException();

            //break;
            default:
                response.Error = new Models.Messages.Code()
                {
                    code    = "-32601",
                    message = "method not found"
                };
                break;
            }

            return(response);
        }
Example #4
0
        public void Post(Models.IRequest request)
        {
            //if (request.Method == "AddTableRequest")
            switch (request.Method)
            {
            case "AddTableRequest":
                Models.Messages.AddTableRequest addTableRequest = request.Params as Models.Messages.AddTableRequest;

                Boolean valid = true;     //!base.Verify(addTableRequest.BitcoinAddress, addTableRequest.ToString(), request.Signature
                if (!valid)
                {
                    //throw new Exceptions.SignatureNotValidException();
                    throw new Exception();
                }
                else
                {
                    TableRepo.Add(addTableRequest.Table);
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #5
0
        public Models.IResponse Post(Models.IRequest request)
        {
            //Models.Messages.RPCResponse response = new Models.Messages.RPCResponse()
            //{
            //    Id = id.Id
            //};

            throw new NotImplementedException();

            //try
            //{
            //    switch (request.Method.ToUpper())
            //    {
            //        case "GETTABLES":
            //            response.Result = TableRepo.All();
            //            break;
            //        case "JOINTABLE":
            //            Models.Messages.JoinTableRequest joinTableRequest = request.Params as Models.Messages.JoinTableRequest;
            //            response.Result = JoinTable(joinTableRequest);
            //            break;
            //        case "BUYIN":
            //            Models.Messages.BuyInRequest buyInRequest = request.Params as Models.Messages.BuyInRequest;
            //            response.Result = BuyIn(buyInRequest);
            //            break;
            //        case "SHUFFLE":
            //            response.Result = Shuffle();
            //            break;
            //        case "DEAL":
            //            Models.Messages.DealRequest dealRequest = request.Params as Models.Messages.DealRequest;
            //            break;
            //        case "SMALLBLIND":
            //        case "SB":
            //            var smallBlindRequest = request.Params as Models.Messages.ActionMessage;
            //            response.Result = ProcessSmallBlind(smallBlindRequest);
            //            break;
            //        case "BIGBLIND":
            //        case "BB":
            //            var bigBlindRequest = request.Params as Models.Messages.ActionMessage;
            //            response.Result = ProcessBigBlind(bigBlindRequest);
            //            break;
            //        default:
            //            response.Error = new Models.Messages.Code()
            //            {
            //                code = "-32601",
            //                message = "method not found"
            //            };
            //            break;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    response.Error = ex.Message;
            //}



            //NOTE:  THIS IS WHERE THE STUB AI LOGIC SHOULD EXIST.
            //
            //if (MemoryCache.Default.Contains(message.TableId.ToString()))
            //{
            //    Models.Hand.Table table = (Models.Hand.Table)MemoryCache.Default[message.TableId.ToString()];

            //    if (table != null)
            //    {
            //        ////Alice pub key
            //        //String key = "041FA97EFD760F26E93E91E29FDDF3DDDDD3F543841CF9435BDC156FB73854F4BF22557798BA535A3EE89A62238C5AFC7F8BF1FA0985DC4E1A06C25209BAB78BD1";
            //        //Byte[] aliceKeyAsBytes = NBitcoin.DataEncoders.Encoders.Hex.DecodeData(key);
            //        //NBitcoin.PubKey aliceKey = new NBitcoin.PubKey(aliceKeyAsBytes);

            //        //Byte[] userKeyAsBytes = NBitcoin.DataEncoders.Encoders.Hex.DecodeData(buyInRequest.PubKey);
            //        //NBitcoin.PubKey userKey = new NBitcoin.PubKey(userKeyAsBytes);

            //        //var scriptPubKey = NBitcoin.PayToMultiSigTemplate.Instance.GenerateScriptPubKey(2, new[] { aliceKey, userKey });
            //    }
            //}

            //BitcoinPubKeyAddress address = new BitcoinPubKeyAddress(request.BitcoinAddress);
            //bool verified = address.VerifyMessage(request.ToString(), request.Signature);

            //if (verified != true)
            //{
            //    throw new Exceptions.SignatureNotValidException();
            //}



            //return response;
        }