コード例 #1
0
ファイル: LobbyViewModel.cs プロジェクト: zilveer/BitPoker
        public void AddNewTable(UInt64 smallBlind, UInt64 bigBlind, UInt64 minBuyIn, UInt64 maxBuyIn, Int16 minPlayers, Int16 maxPlayers)
        {
            BitPoker.Models.Contracts.Table table = new BitPoker.Models.Contracts.Table()
            {
                SmallBlind     = smallBlind,
                BigBlind       = bigBlind,
                MinBuyIn       = minBuyIn,
                MaxBuyIn       = maxBuyIn,
                MinPlayers     = minPlayers,
                MaxPlayers     = maxPlayers,
                NetworkAddress = "p2p"
            };

            if (!table.IsValid())
            {
                throw new AggregateException("Invalid table params");
            }

            //Check for duplicates
            using (BitPoker.Repository.ITableRepository tableRepo = new BitPoker.Repository.LiteDB.TableRepository(@"poker.db"))
            {
                tableRepo.Add(table);
                tableRepo.Save();
            }
        }
コード例 #2
0
ファイル: LobbyViewModel.cs プロジェクト: zilveer/BitPoker
        public void JoinTable(Guid tableId)
        {
            using (BitPoker.Repository.ITableRepository tableRepo = new BitPoker.Repository.LiteDB.TableRepository(@"poker.db"))
            {
                IRequest request = new RPCRequest();
                var      table   = tableRepo.Find(tableId);

                JoinTableRequest method = new JoinTableRequest()
                {
                };

                request.Method = request.GetType().Name;
                request.Params = request;

                //send
                String json = Newtonsoft.Json.JsonConvert.SerializeObject(request);
                Backend.SendRequest(request);
            }
        }
コード例 #3
0
ファイル: LobbyViewModel.cs プロジェクト: zilveer/BitPoker
        /// <summary>
        /// Display messages and peform any actions
        /// </summary>
        /// <param name="composite"></param>
        public void ProcessMessage(CompositeType composite)
        {
            IRequest request = Newtonsoft.Json.JsonConvert.DeserializeObject <RPCRequest>(composite.Message);

            this.InComingRequests.Add(request);
            this.LastMessage = composite.Message;

            switch (request.Method)
            {
            case "NewPeer":
                NewPeerRequest newPeer = Newtonsoft.Json.JsonConvert.DeserializeObject <NewPeerRequest>(request.Params.ToString());
                NetworkPlayers.Add(newPeer.Player);

                break;

            case "NewTable":     //Peer has announced a new table

                BitPoker.Models.Contracts.Table newTable = Newtonsoft.Json.JsonConvert.DeserializeObject <BitPoker.Models.Contracts.Table>(request.Params.ToString());
                TableViewModel newTableViewModel         = new TableViewModel(newTable);
                //this.Tables.Add(newTableViewModel);

                break;

            case "GetTables":     //Give me your tables

                using (BitPoker.Repository.ITableRepository tableRepo = new BitPoker.Repository.LiteDB.TableRepository("data.db"))
                {
                    IEnumerable <BitPoker.Models.Contracts.Table> tables = tableRepo.All();

                    //now send
                    IResponse response = new RPCResponse()
                    {
                        Id     = request.Id,
                        Result = tables
                    };

                    this.SentRequests.Add(request);
                    Backend.SendResponse(response);

                    break;
                }

            case "GetTablesResponse":     //Add resultant tables
                GetTablesResponse tableResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <GetTablesResponse>(request.Params.ToString());

                foreach (BitPoker.Models.Contracts.Table table in tableResponse.Tables)
                {
                    //TableViewModel tableViewModel = new TableViewModel(table);
                    this.Tables.Add(table);
                }

                break;

            case "ActionMessage":
                ActionMessage actionMessage = Newtonsoft.Json.JsonConvert.DeserializeObject <ActionMessage>(request.Params.ToString());

                //actionMessage.HandId;

                break;
            }
        }