示例#1
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) });
            });
        }
示例#2
0
        /// <summary>
        /// 增加或减少命值
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="SubTractValue"></param>
        /// <param name="isSub">时候减少</param>
        public void SetLifeValue(string userId, int SubTractValue, bool isSub = true)
        {
            string      sql   = "select * from life where userId = @userId";
            List <Life> lifes = MySqlExecuteTools.GetObjectResult <Life>(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });

            if (lifes.Count > 0)
            {
                Life life = MySqlExecuteTools.GetObjectResult <Life>(sql,
                                                                     new MySqlParameter[] { new MySqlParameter("@userId", userId) }).FirstOrDefault <Life>();


                if (life != null)
                {
                    if (isSub)
                    {
                        int subValue = life.lifeValue - SubTractValue;
                        if (subValue < 0)
                        {
                            subValue = 0;
                        }
                        sql = "update  life set lifeValue  =" + (subValue) + " where id = @id";
                    }
                    else
                    {
                        sql = "update  life set lifeValue  =" + (life.lifeValue + SubTractValue) + " where id = @id;";
                    }

                    MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@id", life.id) });
                }
            }
            else
            {
                Console.WriteLine(sql + " :is null");
            }
        }
示例#3
0
        public int CheckEnterButton(string usreId, string userType)
        {
            string sql = "";

            int runState = -1;

            //管理员
            if (userType.Equals("1"))
            {
                sql = "select * from grounp where userId = @userId";
                List <Grounp> ps = MySqlExecuteTools.GetObjectResult <Grounp>(sql, new MySqlParameter[] { new MySqlParameter("@userId", usreId) });

                if (ps == null || ps.Count == 0)
                {
                    return(-1);
                }
                Grounp p = ps[0];
                runState = p.runState;
            }
            else
            {
                Grounp p = GetGrounpByPlayer(int.Parse(usreId));
                if (p == null)
                {
                    return(-1);
                }
                runState = p.runState;
            }

            return(runState);
        }
示例#4
0
        public List <int> SearchGrounpListByUser(int userId)
        {
            string        sql  = "select * from grounp where userId = @userId and runState =0 and fenceLon>0  ORDER BY id DESC";
            List <Grounp> list = MySqlExecuteTools.GetObjectResult <Grounp>(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });

            return(list.Select(a => a.id).ToList <int>());
        }
示例#5
0
        protected List <Room> SearchAllRoom()
        {
            string      sql    = "select * from room";
            List <Room> result = MySqlExecuteTools.GetObjectResult <Room>(sql, null);

            return(result);
        }
示例#6
0
        /// <summary>
        /// 通过grounp查询room
        /// </summary>
        /// <param name="grounpId"></param>
        /// <returns></returns>
        protected List <Room> SearchRoomListByGrounp(string grounpId, string userId = "-1")
        {
            string      sql    = "select * from room where grounpId = @grounpId ORDER BY id ASC";
            List <Room> result = MySqlExecuteTools.GetObjectResult <Room>(sql,
                                                                          new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            result.ForEach((item) => {
                sql       = "select * from room_user where room_id = @room_id ";
                int count = MySqlExecuteTools.GetCountResult(sql,
                                                             new MySqlParameter[] { new MySqlParameter("@room_id", item.id) });
                item.userCount = count;

                //是玩家的话
                if (!userId.Equals("-1"))
                {
                    sql = "select * from room_user where room_id = @room_id  and user_id = @user_id";

                    count = MySqlExecuteTools.GetCountResult(sql,
                                                             new MySqlParameter[] { new MySqlParameter("@room_id", item.id), new MySqlParameter("@user_id", userId) });
                    if (count > 0)
                    {
                        item.isCurrentUser = true;
                    }
                }
            });

            return(result);
        }
示例#7
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("");
            }
        }
示例#8
0
        /// <summary>
        /// 设置grounp运行状态
        /// </summary>
        /// <param name="grounpId"></param>
        /// <returns></returns>
        public string UpdateState(string grounpId)
        {
            string        sql    = "select * from grounp where id = @grounpId";
            List <Grounp> result = MySqlExecuteTools.GetObjectResult <Grounp>(sql,
                                                                              new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            if (result.Count == 1)
            {
                if (result[0].fenceLat <= 0)
                {
                    return("电子围栏尚未设置,无法启动游戏!");
                }
                //查询grounp下room 的状态
                sql = "select * from room where grounpId = @grounpId and  runState = -1";
                int resultCount = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });
                if (resultCount > 0)
                {
                    return("该游戏的队员尚未准备就绪,无法启动游戏");
                }
            }
            else
            {
                return("非法操作");
            }

            sql = "update  grounp set runState =0  where id = @grounpId;";
            MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            //推送给该组的其他玩家更新状态

            publishPlayerState.SendUserListByAdmin(result[0].userId, PublishPlayerState.Update_Command);

            return("0");
        }
示例#9
0
        /// <summary>
        /// 更新范围
        /// </summary>
        /// <param name="frequency"></param>
        public void UpdateFenceScope(int frequency)
        {
            string        sql  = "select * from grounp where runState =0 and fenceLon>0 ORDER BY id DESC";
            List <Grounp> list = MySqlExecuteTools.GetObjectResult <Grounp>(sql, null);

            list.ForEach((grounp) => {
                if (grounp.fenceRadius > 0)
                {
                    int everyCount = grounp.fenceTotalRadius / (grounp.playerTime * 60 / frequency);
                    sql            = "update  grounp set fenceRadius = '" + (grounp.fenceRadius - everyCount) +
                                     "',remainTime='" + (grounp.remainTime - frequency) + "' where id = @grounpId;";
                    MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounp.id) });
                }
                else
                {
                    sql = "update  grounp set fenceRadius = 2000,fenceTotalRadius=2000," +
                          "runState = -1,fenceLon=-1,fenceLat=-1,remainTime='" + (grounp.playerTime * 60) + "' where id = @grounpId;";
                    MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounp.id) });

                    //保存战绩,复位生命值
                    scoreDao.SaveScoreResetLife(grounp.id);

                    //向管理员和玩家通知游戏结束
                    publishPlayerState.SendSingleUserMessage(grounp.userId, PublishPlayerState.Game_Over);
                    publishPlayerState.SendUserListByAdmin(grounp.userId, PublishPlayerState.Game_Over);



                    //更新room和roomUser状态
                    UpdateRoomAndUserState(grounp.id);
                }
            });

            joinRoomDao.GetAllRoom();
        }
示例#10
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("");
        }
示例#11
0
        public void CheckCode(PubgSession session, string body, string code, string userId, string userType, string
                              deviceUniqueIdentifier, string plat, string system)
        {
            string           sql    = "select * from code where name = @name and userType = @userType";
            List <CodeModel> result = MySqlExecuteTools.GetObjectResult <CodeModel>(sql,
                                                                                    new MySqlParameter[] { new MySqlParameter("@name", code), new MySqlParameter("@userType", userType) });
            DataResult dataResult = new DataResult();

            //不存在
            if (result.Count == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "授权码输入有误,请重试!";
            }

            else
            {
                CheckCountOrDateTime(result[0], dataResult, deviceUniqueIdentifier, plat, system, userId);
            }
            //save machine
            if (dataResult.result == 0)
            {
                SaveMachineCode(result[0], deviceUniqueIdentifier, plat, system, userId);
            }

            session.Send(GetSendData(dataResult, body));
        }
示例#12
0
        /// <summary>
        /// 通过管理员获取下所有的room
        /// </summary>
        /// <param name="adminUser"></param>
        /// <returns></returns>
        public List <Room> GetRoomListByAdmin(int adminUser)
        {
            string      sql    = "select r.* from room  r join grounp p on p.id = r.grounpId where p.userId = @userId";
            List <Room> result = MySqlExecuteTools.GetObjectResult <Room>(sql,
                                                                          new MySqlParameter[] { new MySqlParameter("@userId", adminUser) });

            return(result);
        }
示例#13
0
        public Life GetLifeById(int userId)
        {
            string sql  = "select * from life where userId = @userId";
            Life   life = MySqlExecuteTools.GetObjectResult <Life>(sql,
                                                                   new MySqlParameter[] { new MySqlParameter("@userId", userId) }).FirstOrDefault <Life>();

            return(life);
        }
示例#14
0
        /// <summary>
        /// 查询所有的队
        /// </summary>
        /// <returns></returns>
        private List <Grounp> GetAllRoom(int userId)
        {
            string        sql    = "select * from gronp where userId = @userId";
            List <Grounp> result = MySqlExecuteTools.GetObjectResult <Grounp>(sql,
                                                                              new MySqlParameter[] { new MySqlParameter("@userId", userId) });

            return(result);
        }
示例#15
0
 protected Grounp GetGrounpByPlayer(int player)
 {
     string sql = "select p.* 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=" + player;
     List<Grounp> ps = MySqlExecuteTools.GetObjectResult<Grounp>(sql, null);
     if (ps.Count > 0)
     {
         return ps.FirstOrDefault<Grounp>();
     }
     return null;
 }
示例#16
0
        public static Grounp GetGrounpById(string grounpId)
        {
            string        sql    = "select * from grounp where id = @grounpId ORDER BY id DESC";
            List <Grounp> result = MySqlExecuteTools.GetObjectResult <Grounp>(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            if (result.Count == 1)
            {
                return(result[0]);
            }

            return(null);
        }
示例#17
0
        public int IsEditRoom(string roomId, string userId)
        {
            string      sql      = "select *  from room where id = @id and userId = @userId";
            List <Room> roomList = MySqlExecuteTools.GetObjectResult <Room>(sql,
                                                                            new MySqlParameter[] { new MySqlParameter("@id", roomId), new MySqlParameter("@userId", userId) });

            if (roomList.Count > 0)
            {
                return(0);
            }

            return(-1);
        }
示例#18
0
        public string GetLeaderAuthority(string userId)
        {
            string      sql      = "select * from room where userId = @userId";
            List <Room> roomList = MySqlExecuteTools.GetObjectResult <Room>(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });

            if (roomList != null && roomList.Count > 0)
            {
                return("1");
            }
            else
            {
                return("0");
            }
        }
示例#19
0
        public void SearchAllGrounp(PubgSession session, string body, string keyName, string userId, string userType)
        {
            Logger.InfoFormat("查询所有的游戏:{0}", keyName);
            List <Grounp> result = null;

            if (keyName.Equals("-1"))
            {
                string sql = "select * from grounp  ORDER BY id DESC";
                result = MySqlExecuteTools.GetObjectResult <Grounp>(sql, null);
            }
            else
            {
                string sql = "select * from grounp where name like '%" + keyName + "%' ORDER BY id DESC";
                result = MySqlExecuteTools.GetObjectResult <Grounp>(sql, null);
            }

            result.ForEach((item) => {
                if (item.fenceLat > 0)
                {
                    item.isDefence = true;
                }
            });
            //管理员
            if (userType.Equals("1"))
            {
                Grounp grounp = result.Where((item) => item.userId == int.Parse(userId)).FirstOrDefault <Grounp>();
                result.Remove(grounp);
                result.Insert(0, grounp);
            }

            else
            {
                //当前的grounp显示top
                Grounp p = GetGrounpByPlayer(int.Parse(userId));
                if (p != null)
                {
                    Grounp grounp = result.Where((item) => item.id == p.id).FirstOrDefault <Grounp>();
                    result.Remove(grounp);
                    result.Insert(0, grounp);
                }
            }

            DataResult dataResult = new DataResult();

            dataResult.result = 0;
            dataResult.data   = result;
            session.Send(GetSendData(dataResult, body));
        }
示例#20
0
        private void DeleteRoom(string grounpId)
        {
            string      sql    = "select * from room where grounpId = @grounpId";
            List <Room> result = MySqlExecuteTools.GetObjectResult <Room>(sql,
                                                                          new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            result.ForEach((item) => {
                int roomId = item.id;
                // 删除房间信息
                string deleteGronpSql = "delete  from room  where id = @roomId";
                MySqlExecuteTools.GetCountResult(deleteGronpSql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) });

                //删除房间和用户的关联表
                string delete_grounp_userSql = "delete  from  room_user  where room_id = @roomId";
                MySqlExecuteTools.GetCountResult(delete_grounp_userSql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) });
            });
        }
示例#21
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("");
        }
示例#22
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();
        }
示例#23
0
        /// <summary>
        /// 通过管理员查询房间和用户列表
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public string GetRoomUserTreeData(string adminUserId)
        {
            string      sql      = "select r.* from grounp p JOIN room r on p.id = r.grounpId where p.userId =@userId";
            List <Room> roomList = MySqlExecuteTools.GetObjectResult <Room>(sql, new MySqlParameter[] { new MySqlParameter("@userId", adminUserId) });

            if (roomList.Count == 0)
            {
                Logger.Debug("GetRoomUserTreeData is null");
                return("");
            }

            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            roomList.ForEach((room) => {
                Dictionary <string, object> roomDic = new Dictionary <string, object>();
                roomDic.Add("id", room.id);
                roomDic.Add("name", room.name);

                List <Dictionary <string, object> > userListDic = new List <Dictionary <string, object> >();


                sql = "SELECT u.id,u.name from room_user ru JOIN `user` u  on ru.user_id = u.id where ru.room_id = @roomId";
                List <object> list = MySqlExecuteTools.GetMuchFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", room.id) });

                list.ForEach((item) => {
                    Dictionary <string, object> userDic = new Dictionary <string, object>();
                    List <object> userList = (List <object>)item;

                    string _userId  = userList[0].ToString();
                    string userName = userList[1].ToString();
                    userDic.Add("id", _userId);
                    userDic.Add("name", userName);
                    userListDic.Add(userDic);
                });
                roomDic.Add("child", userListDic);
                result.Add(roomDic);
            });

            string resultStr = Utils.CollectionsConvert.ToJSON(result);

            resultStr = resultStr.Replace("\\", "");
            Logger.Debug(resultStr);
            return(resultStr);
        }
示例#24
0
        private List <UserName> GetUserList(List <Room_User> roomUserList)
        {
            List <string> ids = new List <string>();

            roomUserList.ForEach((item) => {
                ids.Add(item.user_id.ToString());
            });

            string          result     = StrUtil.ConnetString(ids, ",");
            string          sql        = "select * from user where id in  (" + result + ")";
            List <UserName> resultData = MySqlExecuteTools.GetObjectResult <UserName>(sql, null);

            resultData.ForEach((user) => {
                int runState  = roomUserList.Where((item) => item.user_id == user.id).FirstOrDefault <Room_User>().runState;
                user.runState = runState;
            });

            return(resultData);
        }
示例#25
0
        public string SearchScoreGrounpId(int grounpId)
        {
            //string sql = "select count(*) from room_user where room_id = @roomId";

            //List<object> list = MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) });
            ////查出数量room下的玩家人数
            //if (list.Count > 0)
            //{
            //    int count = int.Parse((MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) })[0].ToString()));


            // string   sql = "select * from score where roomId = @roomId  order by createTime desc limit 0," + count;

            string       sql       = "select * from score where grounpId = @grounpId  order by lifeValue desc";
            List <Score> scoreLsit = MySqlExecuteTools.GetObjectResult <Score>(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });
            string       result    = Utils.CollectionsConvert.ToJSON(scoreLsit);

            return(result);
        }
示例#26
0
        private void UpdateRoomAndUserState(int grounpId)
        {
            string      sql      = "select * from room where grounpId = @grounpId";
            List <Room> roomList = MySqlExecuteTools.GetObjectResult <Room>(sql,
                                                                            new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            roomList.ForEach((room) => {
                //更新room状态
                sql = "update  room set runState = -1  where  id = " + room.id;
                MySqlExecuteTools.AddOrUpdate(sql);

                sql = "select * from room_user where room_id = @room_id";
                List <Room_User> roomUserList = MySqlExecuteTools.GetObjectResult <Room_User>(sql,
                                                                                              new MySqlParameter[] { new MySqlParameter("@room_id", room.id) });
                roomUserList.ForEach((roomUser) => {
                    sql = "update  room_user set runState = -1  where  id = " + roomUser.id;
                    MySqlExecuteTools.AddOrUpdate(sql);
                });
            });
        }
示例#27
0
        /// <summary>
        /// 通过room查询user,如果存在userid,将其排除
        /// </summary>
        /// <param name="grounpId"></param>
        /// <returns></returns>
        public List <Room_User> SearchSingleGrounpCommon(string roomId, int userID = -1)
        {
            List <Room_User> result = null;

            if (userID != -1)
            {
                string sql = "select * from room_user where room_id = @room_id and user_id <> @userId";
                result = MySqlExecuteTools.GetObjectResult <Room_User>(sql,
                                                                       new MySqlParameter[] { new MySqlParameter("@room_id", roomId), new MySqlParameter("@userId", userID) });
            }
            else
            {
                string sql = "select * from room_user where room_id = @room_id";
                result = MySqlExecuteTools.GetObjectResult <Room_User>(sql,
                                                                       new MySqlParameter[] { new MySqlParameter("@room_id", roomId) });
            }


            return(result);
        }
示例#28
0
        public static void TestLogin(string username, string password)
        {
            //  MySqlCommand cmd = new MySqlCommand("select * from user where username = @username and password = @password", MySQLHelp.Instance.GetSqlConn);
            //  cmd.Parameters.AddWithValue("username", username);
            //  cmd.Parameters.AddWithValue("password", password);
            //  MySqlDataReader  reader = cmd.ExecuteReader();
            //  int result = 0;
            //  while (reader.Read())
            //  {
            //      if (reader.HasRows)
            //      {
            //          result = result + 1;
            //      }
            //  }
            //Console.WriteLine("count={0}", result);

            //  Console.ReadKey();
            //  Console.WriteLine();g
            string sql = "select * from code";

            MySqlExecuteTools.GetObjectResult <CodeModel>(sql, null);
        }
示例#29
0
        public void CheckLogin(PubgSession session, string body, string username, string password)
        {
            Logger.InfoFormat("用户登陆验证:{0}", username);
            string          sql    = "select * from user where telephone = @username and password = @password";
            List <UserName> result = MySqlExecuteTools.GetObjectResult <UserName> (sql,
                                                                                   new MySqlParameter[] { new MySqlParameter("@username", username), new MySqlParameter("@password", password) });

            DataResult dataResult = new DataResult();

            if (result.Count == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "账号或密码有误,请重试!";
            }
            else
            {
                bool isLogin = CheckIsLogin(result[0].id.ToString());
                if (isLogin)
                {
                    dataResult.result = 1;
                    dataResult.resean = "该账号已在线,不能重复登录,请重试!";
                }
                else
                {
                    dataResult.result = 0;

                    UserName userName = result[0];
                    sql = "select * from room where userId = @userId";
                    int count = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@userId", userName.id) });
                    if (count > 0)
                    {
                        userName.isLeader = true;
                    }
                    dataResult.data = userName;
                }
            }
            session.Send(GetSendData(dataResult, body));
        }
示例#30
0
        public string AddPlayerLife(string userId, string addLifeValue, string currentUser)
        {
            string sql          = "select * from life  where userId = @userId";
            Life   currrentlife = MySqlExecuteTools.GetObjectResult <Life>(sql,
                                                                           new MySqlParameter[] { new MySqlParameter("@userId", currentUser) })[0];

            if (currrentlife.lifeValue < int.Parse(addLifeValue))
            {
                return("1");
            }
            Life addlife = MySqlExecuteTools.GetObjectResult <Life>(sql,
                                                                    new MySqlParameter[] { new MySqlParameter("@userId", userId) })[0];


            sql = "update life set lifeValue = '" + (addlife.lifeValue + int.Parse(addLifeValue)) + "' where userId = " + userId;
            MySqlExecuteTools.GetCountResult(sql);

            sql = "update life set lifeValue = '" + (currrentlife.lifeValue - int.Parse(addLifeValue)) + "' where userId = " + currentUser;
            MySqlExecuteTools.AddOrUpdate(sql);


            return("0");
        }