Esempio n. 1
0
        public IActionResult LeechPower(string name, FactionName factionName, int power, FactionName leechFactionName, bool isLeech, bool?isPwFirst)
        {
            if (ServerStatus.IsStopSyntax == true)
            {
                return(Redirect("/home/serverdown"));
            }
            var task = _userManager.GetUserAsync(HttpContext.User);

            Task[] taskarray = new Task[] { task };
            Task.WaitAll(taskarray, millisecondsTimeout: 1000);
            var faction = GameMgr.GetGameByName(name).FactionList.Find(x => x.FactionName.ToString().Equals(name));
            var leech   = isLeech ? "leech" : "decline";

            var syntax = string.Format("{0}:{1} {2} from {3}", factionName, leech, power, leechFactionName);

            if (isPwFirst.HasValue)
            {
                var pwFirst = isPwFirst.GetValueOrDefault() ? "pw" : "pwt";
                syntax = syntax + " " + pwFirst;
            }
            GaiaGame gaiaGame = GameMgr.GetGameByName(name);

            try
            {
                //GameMgr.WriteUserActionLog(syntax, task.Result.UserName);
            }
            catch { }
            gaiaGame.Syntax(syntax, out string log, dbContext: this.dbContext);
            //如果是即时制游戏,进行通知
            if (gaiaGame.IsSocket)
            {
                NoticeWebSocketMiddleware.GameActive(gaiaGame, HttpContext.User);
            }
            return(Redirect("/home/viewgame/" + System.Net.WebUtility.UrlEncode(name)));
        }
Esempio n. 2
0
        public override void InvokeAction()
        {
            var gamelist = GameMgr.GetAllGameName();

            foreach (var item in gamelist)
            {
                GaiaGame gaiaGame = GameMgr.GetGameByName(item);
                //删除结束游戏
                if (gaiaGame.GameStatus.stage == Stage.GAMEEND)
                {
                    GameMgr.RemoveAndBackupGame(item);
                    continue;
                }

                //判断上次行动时间是否大于设置drop时间

                int hours = gaiaGame.dropHour == 0 ? 240 : gaiaGame.dropHour;
#if false
                hours = 10;
#endif

                if (DateTime.Now.AddDays(-hours / 24) > gaiaGame.LastMoveTime)
                {
                    //GameMgr.RemoveAndBackupGame(item);
                    //不需要备份直接删除
                    //GameMgr.DeleteOneGame(item);

                    //记录用户drop 次数
                    //drop
                    String userName = gaiaGame.GetCurrentUserName();
                    //如果没有用户
                    //或者时2人游戏
                    //没有用户
                    //用户数量不等
                    //第0回合
                    //一场多个用户
                    if (String.IsNullOrEmpty(userName) || gaiaGame.UserCount == 2 || gaiaGame.UserGameModels == null ||
                        gaiaGame.UserGameModels.Count != gaiaGame.UserCount || gaiaGame.GameStatus.RoundCount == 0 ||
                        gaiaGame.UserGameModels.FindAll(user => user.username == userName).Count > 1)
                    {
                        GameMgr.DeleteOneGame(item);
                        continue;
                    }
                    else
                    {
                        try
                        {
                            Faction faction = gaiaGame.FactionList.SingleOrDefault((Faction fac) => fac.UserName == userName);
                            gaiaGame.Syntax(faction.FactionName.ToString() + ":drop", out string _, "", null);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public string Syntax(string name, string syntax, string factionName)
        {
            if (ServerStatus.IsStopSyntax == true)
            {
                return("error:" + "服务器维护中");
            }

            var task = _userManager.GetUserAsync(HttpContext.User);

            Task[] taskarray = new Task[] { task };
            Task.WaitAll(taskarray, millisecondsTimeout: 1000);
            if (task.Result != null)
            {
                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(syntax))
                {
                    return("error:空语句");
                }
                else if (syntax.Contains("drop"))
                {
                    return("error:系统命令");
                }

                if (!string.IsNullOrEmpty(factionName))
                {
                    syntax = string.Format("{0}:{1}", factionName, syntax);
                }
                //游戏结束,发送邮件赋值,
                GaiaCore.Gaia.Game.DbGameSave._emailSender = this._emailSender;
                //执行命令
                GaiaGame gaiaGame = GameMgr.GetGameByName(name);
                try
                {
                    GameMgr.WriteUserActionLog(syntax, task.Result.UserName);
                }
                catch {
                    _logger.LogInformation(syntax);
                }
                gaiaGame.Syntax(syntax, out string log, task.Result.UserName, dbContext: this.dbContext);
                if (!string.IsNullOrEmpty(log))
                {
                    return("error:" + log);
                }
                else
                {
                    //如果是即时制游戏,进行通知
                    if (gaiaGame.IsSocket)
                    {
                        NoticeWebSocketMiddleware.GameActive(gaiaGame, HttpContext.User);
                    }
                    return("ok");
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "没有获取到用户名");
                return("error:未登入用户");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 跳过回合
        /// </summary>
        public void SkipRound(string id, int round = 6)
        {
            GaiaGame gaiaGame = GameMgr.GetGameByName(id);

            for (int i = gaiaGame.GameStatus.RoundCount; i < 6; i++)
            {
                for (int count = 0; count < gaiaGame.UserCount; count++)
                {
                    gaiaGame.Syntax(
                        string.Format("{1}:pass {0}", gaiaGame.RBTList[0].name,
                                      gaiaGame.FactionList[gaiaGame.GameStatus.PlayerIndex].FactionName), out string log, dbContext: this.dbContext);
                }
            }
        }
Esempio n. 5
0
        public async Task <JsonResult> DropFaction(string id, string factionName = null)
        {
            GaiaGame gaiaGame = GameMgr.GetGameByName(id);

            gaiaGame.Syntax(factionName + ":drop", out string log, "", dbContext);
            return(new JsonResult(new GaiaProject.Models.Data.UserFriendController.JsonData
            {
                data = "",
                info = new GaiaProject.Models.Data.UserFriendController.Info
                {
                    state = 200
                }
            }));
        }
Esempio n. 6
0
        /// <summary>
        /// 创建游戏
        /// </summary>
        /// <param name="name"></param>
        /// <param name="username"></param>
        /// <param name="result"></param>
        /// <param name="MapSelection"></param>
        /// <param name="seed"></param>
        /// <param name="isTestGame"></param>
        /// <param name="isSocket"></param>
        /// <param name="IsRotatoMap"></param>
        /// <param name="version"></param>
        /// <returns></returns>

        private static bool CreateNewGame(string name, string[] username, out GaiaGame result, string MapSelection, int seed = 0, bool isTestGame = false, bool isSocket = false, bool IsRotatoMap = false, int version = 3)
        {
            if (m_dic.ContainsKey(name))
            {
                result = null;
                return(false);
            }
            else
            {
                seed               = seed == 0 ? RandomInstance.Next(int.MaxValue) : seed;
                result             = new GaiaGame(username, name);
                result.IsTestGame  = isTestGame;
                result.GameName    = name;        //游戏名称
                result.IsSocket    = isSocket;    //即时制
                result.IsRotatoMap = IsRotatoMap; //旋转地图
                result.version     = version;

                //开局的两条命令
                result.Syntax(GameSyntax.setupmap + " " + MapSelection, out string log);
                result.Syntax(GameSyntax.setupGame + seed, out log);
                m_dic.Add(name, result);
                return(true);
            }
        }
Esempio n. 7
0
        private static GaiaGame RestoreGameWithActionLog(KeyValuePair <string, GaiaGame> item, Func <string, bool> DebugInvoke = null, bool isTodict = true, int?row = null)
        {
            var gg = new GaiaGame(item.Value.Username, item.Value.GameName);

            gg.IsTestGame  = item.Value.IsTestGame;        //测试
            gg.IsSocket    = item.Value.IsSocket;          //即使制度
            gg.IsRotatoMap = item.Value.IsRotatoMap;       //旋转地图
            gg.IsSaveToDb  = item.Value.IsSaveToDb;        //是否保存数据
            gg.dbContext   = item.Value.dbContext;         //数据源

            gg.UserGameModels = item.Value.UserGameModels; //恢复设置

            if (item.Value.version == 0)
            {
                gg.version = 1;
            }
            else
            {
                gg.version = item.Value.version;
            }

            //设置用户信息
            gg.SetUserInfo();

            try
            {
                int rowIndex = 1;
                foreach (var str in item.Value.UserActionLog.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (str.Contains("Xenos:build I3"))
                    {
                        int a = 1;
                    }
                    gg.Syntax(str, out string log);
                    if (!string.IsNullOrEmpty(log))
                    {
                        if (DebugInvoke != null)
                        {
                            DebugInvoke.Invoke(item.Key + ":" + log);
                        }
                        System.Diagnostics.Debug.WriteLine(item.Key + ":" + log);
                        break;
                    }
                    else
                    {
                        //System.Diagnostics.Debug.WriteLine(str);
                    }
                    if (row != null)
                    {
                        //相等,终止恢复
                        if (rowIndex == row)
                        {
                            break;
                        }
                        else
                        {
                            rowIndex++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (DebugInvoke != null)
                {
                    DebugInvoke.Invoke(item.Key + ":" + ex.ToString());
                }
                System.Diagnostics.Debug.WriteLine(item.Key + ":" + ex.ToString());
            }
            //上次时间
            gg.LastMoveTime = item.Value.LastMoveTime;


            //需要加载到内存
            if (isTodict)
            {
                //如果是结束的游戏,跳过
                if (item.Value.GameStatus.stage == Stage.GAMEEND)
                {
                }
                else//其它
                {
                    if (m_dic.ContainsKey(item.Key))
                    {
                        m_dic[item.Key] = gg;
                    }
                    else
                    {
                        m_dic.Add(item.Key, gg);
                    }
                }
            }
            else
            {
//                if (m_dic.ContainsKey(item.Key))
//                {
//                    m_dic.Remove(item.Key);
//                }
            }
            return(gg);
        }