Exemple #1
0
        public void Enqueue(Kv kv)
        {
            int gameID = kv.GetInt32("GameID");

            if (consumers.ContainsKey(gameID))
            {
                if (gameID > 0 && consumers[gameID].Game != null)
                {
                    MethodNameE mn = (MethodNameE)kv.GetInt32("MethodName");

                    if (consumers[gameID].Game.Flags.IsNotReady && mn != MethodNameE.RestartGame && mn != MethodNameE.RestartGameWithSetup &&
                        mn != MethodNameE.WriteChatMessage && mn != MethodNameE.ForceLogoff)
                    {
                        return;
                    }
                }
                consumers[gameID].ConsumeMessage(kv);
            }
            else
            {
                if (!queues.ContainsKey(gameID))
                {
                    queues.Add(gameID, new Queue <Kv>());
                }

                queues[gameID].Enqueue(kv);
            }
        }
Exemple #2
0
        public DataTable GetRankInfo()
        {
            int       userID = Kv.GetInt32("UserID");
            DataTable dt     = User.GetRankInfo(Kv.Cxt, userID);
            Kv        Kv1    = new Kv();

            Kv1.DataTable = dt;
            return(Kv1.DataTable);
        }
        public void UpdateGame()
        {
            App.Model.Db.Game item = new App.Model.Db.Game(base.Kv.Cxt, Kv.GetInt32("GameID"));

            if (!string.IsNullOrEmpty(Kv.Get("GameXml")))
            {
                item.GameXml = Kv.Get("GameXml");
            }

            item.GameResultID = Kv.GetInt32("GameResult");
            item.GameFlags    = Kv.Get("GameFlags");
            item.Save();
        }
Exemple #4
0
        public DataTable GetUserInfoByUserID()
        {
            int       userID = Kv.GetInt32("UserID");
            DataTable dt     = User.GetUserInfoByUserID(Kv.Cxt, userID);
            Kv        Kv1    = new Kv();

            Kv1.DataTable = dt;

            if (Kv1.DataTable.Rows.Count > 0)
            {
                DataColumn dc = new DataColumn("UserImage");
                Kv1.DataTable.Columns.Add(dc);
                Kv1.DataTable.Rows[0]["UserImage"] = GetUserImage(Ap.WebFolderUserImages + userID);
            }
            return(Kv1.DataTable);
        }
        public DataSet AddGame(bool isOfferedReMatch)
        {
            try
            {
                #region Get Game Data

                int challengeID         = Kv.GetInt32("ChallengeID");
                int currentUserID       = Kv.GetInt32(StdKv.CurrentUserID); //opponent user id //using StdKv.CurrentUserID because of some reason -----base.Kv.Cxt.CurrentUserID
                int opponentChessTypeID = Kv.GetInt32("ChessTypeID");

                DataSet gds = App.Model.Db.Game.GetGameData(challengeID, currentUserID, opponentChessTypeID, isOfferedReMatch);
                if (gds.Tables.Count < 2)
                {
                    return(null);
                }

                gds.Tables[0].TableName = "Challenge";
                gds.Tables[1].TableName = "Users";
                gds.Tables[2].TableName = "UserGameTypes";
                gds.Tables[3].TableName = "Engines";

                if (gds.Tables.Count > 4)
                {
                    gds.Tables[4].TableName = "TournamentMatch";
                    gds.Tables[5].TableName = "Tournament";
                }

                Challenge c  = new Challenge(base.Kv.Cxt, gds.Tables["Challenge"].Rows[0]);
                Users     us = new Users(base.Kv.Cxt, gds.Tables["Users"]);

                User uc = us[0];
                User uo = us[1];

                //if (currentUserID == uc.UserID)
                //{
                //    if (uo.UserStatusIDE == UserStatusE.Playing || uo.UserStatusIDE == UserStatusE.Gone || uo.UserStatusIDE == UserStatusE.Kibitzer)
                //    {
                //        return null;
                //    }
                //}
                //else
                //{
                //    if (uc.UserStatusIDE == UserStatusE.Playing || uc.UserStatusIDE == UserStatusE.Gone || uc.UserStatusIDE == UserStatusE.Kibitzer)
                //    {
                //        return null;
                //    }
                //}

                UserGameTypes ugts = new UserGameTypes(base.Kv.Cxt, gds.Tables["UserGameTypes"]);
                UserGameType  ugtc = new UserGameType();
                UserGameType  ugto = new UserGameType();

                switch (ugts.Count)
                {
                case 1:
                    ugtc = ugts[0];
                    break;

                case 2:
                    ugtc = ugts[0];
                    ugto = ugts[1];
                    break;
                }

                if (c.ChallengerUserID != ugtc.UserID)
                {
                    UserGameType ugtt = ugtc;
                    ugtc = ugto;
                    ugto = ugtt;
                }

                if (c.ChallengerUserID != uc.UserID)
                {
                    User ut = uc;
                    uc = uo;
                    uo = ut;
                }

                #endregion

                #region Save Game
                SqlTransaction    t    = null;
                App.Model.Db.Game item = new App.Model.Db.Game();

                if (c.ChessTypeIDE == ChessTypeE.Engine || c.ChessTypeIDE == ChessTypeE.Centaur)
                {
                    if (ugtc.EloRating == 0)
                    {
                        ugtc.EloRating = 2200;
                    }
                }
                else
                {
                    if (ugtc.EloRating == 0)
                    {
                        ugtc.EloRating = 1500;
                    }
                }

                if ((ChessTypeE)opponentChessTypeID == ChessTypeE.Engine || (ChessTypeE)opponentChessTypeID == ChessTypeE.Centaur)
                {
                    if (ugto.EloRating == 0)
                    {
                        ugto.EloRating = 2200;
                    }
                }
                else
                {
                    if (ugto.EloRating == 0)
                    {
                        ugto.EloRating = 1500;
                    }
                }


                try
                {
                    switch (c.ColorIDE)
                    {
                    //case ColorE.Autometic:
                    case ColorE.White:
                        item.WhiteUserID      = ugtc.UserID == 0 ? c.ChallengerUserID : ugtc.UserID;
                        item.BlackUserID      = ugto.UserID == 0 ? currentUserID : ugto.UserID;
                        item.EloWhiteBefore   = ugtc.EloRating;
                        item.EloBlackBefore   = ugto.EloRating;
                        item.WhiteEngineID    = uc.EngineID;
                        item.BlackEngineID    = uo.EngineID;
                        item.WhiteChessTypeID = c.ChessTypeID;
                        item.BlackChessTypeID = opponentChessTypeID;
                        break;

                    case ColorE.Black:
                        item.BlackUserID      = ugtc.UserID == 0 ? c.ChallengerUserID : ugtc.UserID;
                        item.WhiteUserID      = ugto.UserID == 0 ? currentUserID : ugto.UserID;
                        item.EloBlackBefore   = ugtc.EloRating;
                        item.EloWhiteBefore   = ugto.EloRating;
                        item.BlackEngineID    = uc.EngineID;
                        item.WhiteEngineID    = uo.EngineID;
                        item.WhiteChessTypeID = opponentChessTypeID;
                        item.BlackChessTypeID = c.ChessTypeID;
                        break;
                    }

                    item.IsRated = c.IsRated;
                    item.IsChallengerSendsGame = c.IsChallengerSendsGame;
                    item.ChallengeID           = c.ChallengeID;
                    item.GameResultIDE         = GameResultE.InProgress;
                    item.GameTypeID            = c.GameTypeID;
                    item.StartDate             = DateTime.Now;
                    item.TimeMin        = c.TimeMin;
                    item.GainPerMoveMin = c.GainPerMoveMin;
                    item.RoomID         = c.RoomID;
                    item.GameXml        = "";
                    if (c.TournamentMatchID != 0)
                    {
                        item.TournamentMatchID = c.TournamentMatchID;
                    }

                    t = SqlHelper.BeginTransaction(Config.ConnectionString);

                    Challenges.UpdateAllChallenges(t, c.ID, currentUserID, c.ChallengerUserID);

                    item.Save(t);

                    SqlHelper.CommitTransaction(t);
                }
                catch (Exception ex)
                {
                    SqlHelper.RollbackTransaction(t);
                    //throw ex;
                    Log.Write(base.Kv.Cxt, ex);
                }
                #endregion

                #region Return Game DataSet
                item.DataRow.Table.TableName = "Game";
                gds.Tables.Add(item.DataRow.Table.Copy());

                gds.Tables.Remove("UserGameTypes");

                return(gds);

                #endregion
            }
            catch (Exception ex)
            {
                Log.Write(Kv.Cxt, ex);
                return(null);
            }
        }
Exemple #6
0
 public static int GetInt32(SysKv sysKv)
 {
     return(Kv.GetInt32(SysKv, sysKv.ToString()));
 }
Exemple #7
0
 public int GetInt32(StdKv key)
 {
     return(Kv.GetInt32(DataTable, key.ToString()));
 }
Exemple #8
0
 public int GetInt32(string key)
 {
     return(Kv.GetInt32(DataTable, key));
 }