Example #1
0
        public void unreserve(Client c, string tableId)
        {
            NoLimitHoldem table = find(tableId);

            if (table == null)
            {
                return;
            }
            string test = c.reservedTables.Find(delegate(string str) { return(str == tableId); });

            if (test == null)
            {
                return;
            }
            c.reservedTables.Remove(tableId);
            int i = 0;

            for (i = 0; i < table.tableData.reservedUserName.Length; i++)
            {
                if (table.tableData.reservedUserName[i] == c.Username)
                {
                    table.tableData.reservedUserName[i] = null;
                }
            }
            table.TableRelease(
                new string[] { "type", "msgtype", "pos", "tableId" },
                new string[] { "srvmsg", "ursv", i.ToString(), table.tableId }
                );
        }
Example #2
0
        public void reserve(Client c, string tableId, int pos)
        {
            //we should start a timer for 30 second after it we should delete him
            NoLimitHoldem table = find(tableId);

            if (table == null)
            {
                return;
            }
            if (pos >= table.seatsCount)
            {
                return;
            }
            if (c.sittedTables.Find(delegate(string str) { return(str == tableId); }) != null)
            {
                c.send(
                    new string[] { "type", "msgtype", "message" },
                    new string[] { "srvmsg", "error", "Sorry.. You already siited down on this table" }
                    );
                return;
            }

            object myObj = c.reservedTables.Find(delegate(string str) { return(str == tableId); });

            if (myObj != null) // he reserve a seat on this table later or not
            {
                return;
            }
            if (table.tableData.reservedUserName[pos] != null || !table.isVacant(pos))//some one reserve this seat or seat on it he can not seat here
            {
                return;
            }

            c.reservedTables.Add(tableId);
            table.tableData.reservedUserName[pos] = c.Username;

            ThreadStart timer = new ThreadStart(delegate() {
                table.TableRelease(
                    new string[] { "type", "msgtype", "pos", "username", "tableId" },
                    new string[] { "srvmsg", "rsv", pos.ToString(), c.Username, table.tableId }
                    );
                c.send(
                    new string[] { "type", "msgtype", "pos", "username", "tableId", "minBuyIn", "maxBuyIn" },
                    new string[] { "srvmsg", "rsvShow", pos.ToString(), c.Username, table.tableId, table.minBuyin.ToString(), table.maxBuyin.ToString() }
                    );
                int seconds    = 30;
                int counter    = 0;
                string checker = c.reservedTables.Find(delegate(string str) { return(str == tableId); });
                while (seconds > 0 && checker != null && c.isAvailable)//here i think we have a bug .... check it later mamal
                {
                    checker = c.reservedTables.Find(delegate(string str) { return(str == tableId); });
                    Thread.Sleep(100);
                    if (checker == null)
                    {
                        break;
                    }
                    counter += 100;
                    if (counter == 1000)
                    {
                        seconds--;
                        counter = 0;
                        if (c.reservedTables.Find(delegate(string str) { return(str == tableId); }) == null)
                        {
                            break;
                        }
                        table.TableRelease(
                            new string[] { "type", "msgtype", "pos", "timeExist", "tableId" },
                            new string[] { "srvmsg", "rsvTime", pos.ToString(), seconds.ToString(), table.tableId }
                            );
                    }
                }
                // time out or disconnect or cancel
                table.TableRelease(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "ursv", table.tableId, pos.ToString() }
                    );
                c.send(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "unrsv", table.tableId, pos.ToString() }
                    );
                c.reservedTables.Remove(tableId);
                table.tableData.reservedUserName[pos] = null;
            });
            Thread th = new Thread(timer);

            th.Start();
        }
Example #3
0
        //private static void updateData()
        //{
        //    // create cash games
        //    string TableName, TableID;
        //    int SeatsCount, LastId = 0, BigBlind, MaxBuyin, MinBuyin;
        //    do
        //    {


        //        TableName = DB.get("TableName", "CashgameTables", new string[] { "id", ">", LastId.ToString() });
        //        if (TableName != "")
        //        {
        //            LastId = Int32.Parse(DB.get("id", "CashgameTables", new string[] { "TableName", "=", TableName }));
        //            TableID = DB.get("TableID", "CashgameTables", new string[] { "id", "=", LastId.ToString() });
        //            SeatsCount = Int32.Parse(DB.get("SeatsCount", "CashgameTables", new string[] { "id", "=", LastId.ToString() }));
        //            MaxBuyin = Int32.Parse(DB.get("MaxBuyin", "CashgameTables", new string[] { "id", "=", LastId.ToString() }));
        //            MinBuyin = Int32.Parse(DB.get("MinBuyin", "CashgameTables", new string[] { "id", "=", LastId.ToString() }));
        //            BigBlind = Int32.Parse(DB.get("BigBlind", "CashgameTables", new string[] { "id", "=", LastId.ToString() }));

        //            int last = cashTables.Length;
        //            Array.Resize(ref cashTables, last + 1);
        //            cashTables[last] = new CashGameTable(TableID, TableName, SeatsCount, MinBuyin, MaxBuyin, BigBlind);
        //        }
        //    } while (TableName != "");

        //    // create tournments

        //    // create sits and goes

        //    // add players to tournoments
        //}

        /////////////////////////
        // here we write some function to check data and then call function for each table
        ////////////////////////
        public void SitDown(Client c, string tableId, int chip, int pos)
        {
            if (!c.isAvailable)
            {
                return;
            }
            NoLimitHoldem table = find(tableId);

            if (table == null)
            {
                c.Kill(); return;
            }
            //checking inputs
            if (chip > table.maxBuyin || chip < table.minBuyin)
            {
                c.send(
                    new string[] { "type", "msgtype", "tableId", "message" },
                    new string[] { "srvmsg", "error", table.tableId, "Please buy chips between Minimum buyin and Maximum buyin. " }
                    );
                table.TableRelease(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "ursv", table.tableId, pos.ToString() }
                    );
                c.send(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "unrsv", table.tableId, pos.ToString() }
                    );
                return;
            }
            if (!table.isVacant(pos))
            {
                c.send(
                    new string[] { "type", "msgtype", "tableId", "message" },
                    new string[] { "srvmsg", "error", table.tableId, "Sorry.. Can not sit down here" }
                    );
                table.TableRelease(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "ursv", table.tableId, pos.ToString() }
                    );
                c.send(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "unrsv", table.tableId, pos.ToString() }
                    );
                return;
            }
            if (c.decBalance(chip) == -1)
            {
                c.send(
                    new string[] { "type", "msgtype", "tableId", "message" },
                    new string[] { "srvmsg", "error", table.tableId, "Sorry.. You don't have enought balance to sit on table.\n Please deposit and try again." }
                    );
                table.TableRelease(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "ursv", table.tableId, pos.ToString() }
                    );
                c.send(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "unrsv", table.tableId, pos.ToString() }
                    );
                return;
            }
            if (c.sittedTables.Find(delegate(string str) { return(str == tableId); }) != null)
            {
                c.send(
                    new string[] { "type", "msgtype", "tableId", "message" },
                    new string[] { "srvmsg", "error", table.tableId, "Sorry.. You already sited down on this table" }
                    );
                table.TableRelease(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "ursv", table.tableId, pos.ToString() }
                    );
                c.send(
                    new string[] { "type", "msgtype", "tableId", "pos" },
                    new string[] { "srvmsg", "unrsv", table.tableId, pos.ToString() }
                    );
                return;
            }
            if (table.tableData.reservedUserName[pos] != c.Username)
            {
                //the player didn't reserved the table after
                c.Kill();
                return;
            }
            table.sitDown(c, chip, pos);
        }