Esempio n. 1
0
        public string GetRoomLifeInfoByUser(string userId)
        {
            //只考虑玩家
            int roomId = GetRoomIdByUser(int.Parse(userId));

            string sql = "select user_id from room_user where room_id = @roomId";
            //获取用户列表
            List <object> list = MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) });


            if (list.Count > 0)
            {
                List <string> resultStr = new List <string>();
                list.ForEach((id) =>
                {
                    resultStr.Add(id.ToString());
                });
                string result = StrUtil.ConnetString(resultStr, ",");
                sql = "select * from life where userId in  (" + result + ")";
                List <Life> lifes = MySqlExecuteTools.GetObjectResult <Life>(sql, null);
                lifes.ForEach((life) =>
                {
                    life.userName = MySqlExecuteTools.GetSingleFieldResult("select name from user  where id = @id", new MySqlParameter[] { new MySqlParameter("@id", life.userId) })[0].ToString();
                });

                return(Utils.CollectionsConvert.ToJSON(lifes));
            }
            else
            {
                return("");
            }
        }
Esempio n. 2
0
        private int GrounpIdByUser(int userId, string userType)
        {
            int           gournpID  = -1;
            List <object> grounpIds = null;

            //玩家
            if (userType.Equals("0"))
            {
                string sql = "select grounpId from score where userId = @userId";
                grounpIds = MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });

                if (grounpIds.Count > 0)
                {
                    gournpID = (int)grounpIds[0];
                }
            }
            //管理员
            else
            {
                string sql = "select id from grounp where userId = @userId";
                grounpIds = MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });
                if (grounpIds.Count > 0)
                {
                    gournpID = (int)grounpIds[0];
                }
            }
            return(gournpID);
        }
Esempio n. 3
0
        public void SaveScoreResetLife(int grounpId)
        {
            string sql = "select  l.* from room r join room_user ru on r.id = ru.room_id join life l on ru.user_id = l.userId where r.grounpId = @grounpId";

            List <Life> lifeList = MySqlExecuteTools.GetObjectResult <Life>(sql,
                                                                            new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            lifeList.ForEach((life) =>
            {
                //查询roomid

                int roomId = GetRoomIdByUser(life.userId);

                //查询userName
                sql             = "select name from user where id = @user_id";
                string userName = MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@user_id", life.userId) })[0].ToString();
                if (life.lifeValue < 0)
                {
                    life.lifeValue = 0;
                }
                //插入值
                sql = "insert into score(createTime,bulletCount,lifeValue,fightScore,roomId,grounpId,userId,userName) " +
                      "values('" + TimeUtils.GetCurrentTimestamp() + "','" + life.bulletCount + "','" + life.lifeValue + "'" +
                      ",'" + life.fightScore + "','" + roomId + "','" + grounpId + "','" + life.userId + "','" + userName + "')";
                MySqlExecuteTools.GetAddID(sql);


                //复位life的生命值

                sql = "update life set bulletCount = 80,lifeValue=50,fightScore=35  where id = @id;";
                MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@id", life.id) });
            });
        }
Esempio n. 4
0
        public string GetRemainTime(string userId, string userType)
        {
            userId   = userId.Trim();
            userType = userType.Trim();
            Console.WriteLine("userId={0},userType={1}", userId, userType);
            string sql = "";

            //管理员
            if (userType.Equals("1"))
            {
                sql = "select * from grounp where userId = @userId  and runState = 0";
                List <Grounp> pList = MySqlExecuteTools.GetObjectResult <Grounp>(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });
                if (pList.Count > 0)
                {
                    return(pList[0].remainTime.ToString());
                }
            }
            //玩家
            else
            {
                sql = "select p.remainTime from grounp p JOIN room r on p.id = r.grounpId join room_user ru on r.id = ru.room_id where ru.user_id =" + userId;
                List <object> list = MySqlExecuteTools.GetSingleFieldResult(sql, null);
                if (list != null && list.Count > 0)
                {
                    return(list[0].ToString());
                }
            }


            return("");
        }
Esempio n. 5
0
        public int FindLeaderByPlayer(int userId)
        {
            string        sql        = "select r.userId from room_user ru  left join room r on r.id = ru.room_id where ru.user_id =  " + userId;
            List <object> dataResult = MySqlExecuteTools.GetSingleFieldResult(sql, null);

            List <int> userIdList = new List <int>();

            dataResult.ForEach((item) => {
                userIdList.Add((int)item);
            });
            return(userIdList[0]);
        }
Esempio n. 6
0
        private int GetRoomIdByUser(int userId)
        {
            string        sql    = "select room_id from room_user where user_id = @user_id";
            List <object> result = MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@user_id", userId) });

            if (result.Count > 0)
            {
                int roomId = int.Parse(result[0].ToString());

                return(roomId);
            }
            return(-1);
        }
Esempio n. 7
0
        /// <summary>
        /// room查询管理员
        /// </summary>
        /// <param name="roomId"></param>
        /// <returns></returns>
        public int GetGrounpAdminByRoom(int roomId)
        {
            string sql    = "select p.userId from room r join grounp p on p.id = r.grounpId and r.id = @roomid";
            int    userId = -1;

            object result = MySqlExecuteTools.GetSingleFieldResult(sql,
                                                                   new MySqlParameter[] { new MySqlParameter("@roomid", roomId) }).FirstOrDefault <object>();

            if (result != null)
            {
                userId = (int)result;
            }
            return(userId);
        }
Esempio n. 8
0
        /// <summary>
        /// 通过admin获取roomUserList
        /// </summary>
        /// <returns></returns>
        public List <int> GetRoomUserListByAdmin(int adminUserID)
        {
            string sql = " select ru.user_id from room r join grounp p join room_user ru on p.id = r.grounpId and r.id = ru.room_id and p.userId = @userId";

            List <object> dataResult = MySqlExecuteTools.GetSingleFieldResult(sql,
                                                                              new MySqlParameter[] { new MySqlParameter("@userId", adminUserID) });
            List <int> result = new List <int>();

            dataResult.ForEach((item) => {
                result.Add((int)item);
            });

            return(result);
        }
Esempio n. 9
0
        public string GetPlayerInfoByUser(string userId)
        {
            string      sql   = "select * from life where userId =@userId";
            List <Life> lifes = MySqlExecuteTools.GetObjectResult <Life>(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });

            if (lifes != null && lifes.Count > 0)
            {
                Life life = lifes[0];
                life.userName = MySqlExecuteTools.GetSingleFieldResult("select name from user  where id = @id",
                                                                       new MySqlParameter[] { new MySqlParameter("@id", life.userId) })[0].ToString();

                string json = Utils.CollectionsConvert.ToJSON(life);
                Logger.Debug(json);
                return(json);;
            }
            Logger.Debug("GetPlayerInfoByUser back is null");
            return("");
        }
Esempio n. 10
0
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="session"></param>
        /// <param name="body"></param>
        /// <param name="id">roomid</param>
        /// <param name="userId">用户id</param>
        public void ExitRoom(PubgSession session, string body, string roomId, string userId, string userName)
        {
            string           sql             = "select * from room_user where user_id = @user_id";
            List <Room_User> grounp_UserList = MySqlExecuteTools.GetObjectResult <Room_User>(sql,
                                                                                             new MySqlParameter[] { new MySqlParameter("@user_id", userId) });
            DataResult dataResult = new DataResult();

            if (grounp_UserList.Count == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "非法操作";
                session.Send(GetSendData(dataResult, body));
                return;
            }


            Grounp p = GetGrounpByPlayer(int.Parse(userId));

            if (p != null && p.runState == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "游戏运行中,无法退出战队。";
                session.Send(GetSendData(dataResult, body));
                return;
            }


            // 删除之前提示
            sql = "select name from room where id=" + roomId;
            string rommName = MySqlExecuteTools.GetSingleFieldResult(sql, null)[0].ToString();

            publishTipsMessage.JoinAndExitLeader(userName, int.Parse(userId), rommName, false);



            sql = "delete from room_user  where id = @id";
            MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@id", grounp_UserList[0].id) });

            dataResult.result = 0;
            session.Send(GetSendData(dataResult, body));

            //刷新缓存数据
            GetRoomUserData();
        }
Esempio n. 11
0
        /// <summary>
        /// 通过队长查询其他同队的用户
        /// </summary>
        /// <returns></returns>
        public List <int> GetOtherUserByLeader(string leaderUserId)
        {
            string sql = "select ru.user_id from room r join room_user ru on r.userId =  " + leaderUserId +
                         " and ru.user_id <>" + leaderUserId + " and r.id = ru.room_id";

            List <object> dataResult = MySqlExecuteTools.GetSingleFieldResult(sql, null);

            if (dataResult == null)
            {
                Console.WriteLine(sql + "查询结果为空");
                return(null);
            }
            List <int> userIdList = new List <int>();

            dataResult.ForEach((item) => {
                userIdList.Add((int)item);
            });

            return(userIdList);
        }
Esempio n. 12
0
        /// <summary>
        /// /// <summary>
        /// 通过一个玩家获取同队的其他玩家,
        /// </summary>
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="isState">并且状态准备好</param>
        /// <returns></returns>
        public List <int> GetUserListBySingleUser(int userId, bool isState = true)
        {
            string sql = " select ru.user_id from room_user ru  " +
                         "left join room r on r.id = ru.room_id   and ru.user_id = " + userId + " where  ru.runState=0";

            if (!isState)
            {
                sql = " select ru.user_id from room_user ru  " + "left join room r on r.id = ru.room_id   and ru.user_id = " + userId;
            }

            List <object> dataResult = MySqlExecuteTools.GetSingleFieldResult(sql, null);

            if (dataResult == null)
            {
                return(null);
            }
            List <int> userIdList = new List <int>();

            dataResult.ForEach((item) => {
                userIdList.Add((int)item);
            });

            return(userIdList);
        }
Esempio n. 13
0
        public void JoinRoom(PubgSession session, string body, string checkCode, string grounpId,
                             string roomId, string userId, string userName)
        {
            Logger.InfoFormat("加入队:{0},{1}", roomId, userId);
            string           sql             = "select * from room_user where user_id = @user_id";
            List <Room_User> grounp_UserList = MySqlExecuteTools.GetObjectResult <Room_User>(sql,
                                                                                             new MySqlParameter[] { new MySqlParameter("@user_id", userId) });
            DataResult dataResult = new DataResult();

            if (grounp_UserList.Count > 0)
            {
                dataResult.result = 1;
                dataResult.resean = "您已经加入房间,不能重复。";
                session.Send(GetSendData(dataResult, body));
                return;
            }

            //校验checkcode是否正确

            sql = "select * from room where id = @roomId and checkCode = @checkCode";

            int countResult = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId), new MySqlParameter("@checkCode", checkCode) });

            if (countResult == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "进入房间的密码不正确,请重试。";
                session.Send(GetSendData(dataResult, body));
                return;
            }


            Grounp p = SearchGrounpDao.GetGrounpById(grounpId);

            if (p != null && p.runState == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "游戏运行中,无法加入战队。";
                session.Send(GetSendData(dataResult, body));
                return;
            }
            sql = "select * from room where id = @roomId";

            List <Room> roomList = MySqlExecuteTools.GetObjectResult <Room>(sql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) });

            if (roomList.Count == 1 && roomList[0].runState == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "该战队已经准备就绪,无法加入,请重试。";
                session.Send(GetSendData(dataResult, body));
                return;
            }

            //grounp_UserList = SearchSingleGrounpCommon(roomId);

            //if (grounp_UserList.Count> maxNum)
            //{
            //    dataResult.result = 1;
            //    dataResult.resean = "房间人数加入已满,请重试。";
            //}
            //else
            //{
            sql = "insert into room_user(room_id,user_id) " + "values('" + roomId + "','" + userId + "')";
            MySqlExecuteTools.AddOrUpdate(sql);
            dataResult.result = 0;

            //推送数据
            sql = "select name from room where id=" + roomId;
            string rommName = MySqlExecuteTools.GetSingleFieldResult(sql, null)[0].ToString();

            publishTipsMessage.JoinAndExitLeader(userName, int.Parse(userId), rommName, true);


            // }
            session.Send(GetSendData(dataResult, body));
            GetRoomUserData();
        }
Esempio n. 14
0
        /// <summary>
        /// 查询成绩
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="currentScore">0,为当前</param>
        ///  <param name="isPlayerOrder">是否查询结果为玩家排行</param>
        public string SearchScore(int userId, string userType, bool isPlayerOrder = true, int currentScore = 0)
        {
            //只考虑玩家
            int    roomId = GetRoomIdByUser(userId);
            string sql    = "";

            //玩家的排行
            if (isPlayerOrder)
            {
                int grounpID = GrounpIdByUser(userId, userType);
                if (grounpID == -1)
                {
                    return("");
                }
                return(SearchScoreGrounpId(grounpID));
            }
            //room的排行
            else
            {
                int grounpId = -1;
                //玩家
                if (userType.Equals("0"))
                {
                    sql = "select grounpId from room where id = @roomId";

                    List <object> list = (MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) }));
                    if (list == null || list.Count == 0)
                    {
                        return("");
                    }
                    grounpId = (int)(list[0]);
                }
                else
                {
                    sql      = "select id from grounp where userId = @userId";
                    grounpId = (int)(MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) })[0]);
                }


                sql = "select * from room where grounpId = @grounpId";
                //获取分组的
                List <Room>  rooms  = MySqlExecuteTools.GetObjectResult <Room>(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });
                List <Score> scores = new List <Score>();
                rooms.ForEach((room) =>
                {
                    //求平均值
                    sql = " select avg(bulletCount),avg(lifeValue) as lv,avg(fightScore),createTime from score   where roomId = " + room.id + "  order by lv desc";
                    List <object> result = (List <object>)(MySqlExecuteTools.GetMuchFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", room.id) })[0]);
                    int bulletCount      = 0;
                    if (result[0] != DBNull.Value)
                    {
                        bulletCount = Convert.ToInt16(result[0]);
                    }

                    int lifeValue = 0;
                    if (result[1] != DBNull.Value)
                    {
                        lifeValue = Convert.ToInt16(result[1]);
                    }

                    int fightScore = 0;

                    if (result[2] != DBNull.Value)
                    {
                        fightScore = Convert.ToInt16(result[2]);
                    }
                    int createTime = 0;
                    if (result[3] != DBNull.Value)
                    {
                        createTime = int.Parse(result[3].ToString());
                    }

                    Score score       = new Score();
                    score.bulletCount = bulletCount;
                    score.lifeValue   = lifeValue;
                    score.fightScore  = fightScore;
                    score.userName    = room.name;
                    score.createTime  = createTime;
                    scores.Add(score);
                });

                return(Utils.CollectionsConvert.ToJSON(scores));
            }
        }