示例#1
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);
        }
示例#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
        /// <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");
        }
示例#4
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();
        }
示例#5
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) });
            });
        }
示例#6
0
        //public void AddGrounp(PubgSession session, string body, string grounpName,string playerTime, string userId,string area="shanxi")
        //{
        //    Logger.InfoFormat("创建队:{0}", grounpName);
        //    DataResult dataResult = new DataResult();
        //    string sql = "select * from grounp where userId = @userId";
        //    List<Grounp> result = MySqlExecuteTools.GetObjectResult<Grounp>(sql,
        //      new MySqlParameter[] { new MySqlParameter("@userId", userId) });

        //    if(result.Count>= createGrounpCount)
        //    {
        //        dataResult.result = 1;
        //        dataResult.resean = "您的权限最多创建"+ createGrounpCount + "个分队,请检查后重试。";
        //        session.Send(GetSendData(dataResult, body));

        //        return;
        //    }

        //    sql = "select * from grounp where name = @name and userId = @userId";
        //     result = MySqlExecuteTools.GetObjectResult<Grounp>(sql,
        //       // new MySqlParameter[] { new MySqlParameter("@name", roomName), new MySqlParameter("@area", room.area.Trim())});
        //       new MySqlParameter[] { new MySqlParameter("@name", grounpName), new MySqlParameter("@userId", userId) });

        //    if (result.Count >0)
        //    {
        //        dataResult.result = 1;
        //        dataResult.resean = "队名称已存在,请检查后重试。";
        //    }
        //    else
        //    {
        //        //创建房间
        //        sql = "insert into grounp(name,runState,playerTime,area,userId) " +
        //            "values('" + grounpName + "','-1','" + playerTime + "','" + area + "','" + userId + "')";
        //        long roomid = MySqlExecuteTools.GetAddID(sql);
        //        if(roomid!=-1)
        //        {
        //            //创建房间
        //            CreateRoom(roomCount, roomid);

        //            dataResult.result = 0;
        //            dataResult.data = null;
        //        }
        //        else
        //        {
        //            dataResult.result = 1;
        //            dataResult.data ="创建失败,请重试!";
        //        }

        //    }
        //    if(dataResult.result == 0)
        //    {
        //        joinRoomDao.GetAllRoom();
        //    }
        //    session.Send(GetSendData(dataResult, body));
        //}

        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="session"></param>
        /// <param name="body"></param>
        /// <param name="id">roomid</param>
        /// <param name="userId">用户id</param>
        //public void DeleteGrounp(PubgSession session, string body, string  grounpId)
        //{

        //    DataResult dataResult = new DataResult();
        //    //查询能否删除

        //    List<Room> roomList = SearchRoomListByGrounp(grounpId);
        //    if(roomList==null || roomList.Count==0)
        //    {
        //        dataResult.result = 1;
        //        dataResult.resean = "非法操作,无法进行删除。";
        //        session.Send(GetSendData(dataResult, body));
        //        return;
        //    }

        //    foreach(Room item in roomList)
        //    {
        //        List<Room_User> roomUserList = SearchSingleGrounpCommon(item.id.ToString());
        //        if (roomUserList.Count > 0)
        //        {
        //            dataResult.result = 1;
        //            dataResult.resean = "该房间下存在用户,无法进行删除。";
        //            session.Send(GetSendData(dataResult, body));

        //            return;
        //        }
        //    }

        //    //开始删除队信息
        //   string sql = "delete  from grounp where id = @grounpId";
        //   MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });
        //   dataResult.result = 0;
        //    //删除房间的相关数据
        //    DeleteRoom(grounpId);
        //    if (dataResult.result == 0)
        //    {
        //        joinRoomDao.GetAllRoom();
        //    }
        //    session.Send(GetSendData(dataResult, body));
        //}

        /// <summary>
        /// 更新房间
        /// </summary>
        /// <param name="session"></param>
        /// <param name="body"></param>
        /// <param name="room"></param>
        public void UpdateGrounp(PubgSession session, string body, string grounpId, string grounpName, string checkCode, string playerTime)
        {
            DataResult dataResult = new DataResult();
            Grounp     p          = SearchGrounpDao.GetGrounpById(grounpId);

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


            //更新队
            string sql = "update grounp set name = '" + grounpName + "', playerTime = '" + playerTime +
                         "', checkCode = '" + checkCode + "', remainTime = '" + (int.Parse(playerTime) * 60) + "' where id = @grounpId";

            MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });


            //更新分队信息
            dataResult.result = 0;
            session.Send(GetSendData(dataResult, body));
        }
示例#7
0
        /// <summary>
        /// code存在
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        private int GetCodeMachineCount(string code)
        {
            string sql = "select * from machine where codeid = @code";

            int result = MySqlExecuteTools.GetCountResult(sql,
                                                          new MySqlParameter[] { new MySqlParameter("@code", code) });

            return(result);
        }
        private bool CheckGrounpCount(int grounpId, int num = 5)
        {
            string sql   = "select * from grounp_user where grounp_id = @grounpId";
            int    count = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            if (count < num + 1)
            {
                return(true);
            }

            return(false);
        }
示例#9
0
        public string SearchState(string grounpId)
        {
            // throw new NotImplementedException();
            string sql   = "select * from grounp where id = @grounpId  and runState = 0";
            int    count = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            if (count > 0)
            {
                return("0");
            }
            else
            {
                return("1");
            }
        }
示例#10
0
        /// <summary>
        /// 机器码和code存在在
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        private bool IsExistCodeMachine(string code, string deviceUniqueIdentifier)
        {
            string sql = "select * from machine where codeid = @code and deviceUniqueIdentifier = @deviceUniqueIdentifier";

            int result = MySqlExecuteTools.GetCountResult(sql,
                                                          new MySqlParameter[] { new MySqlParameter("@code", code),
                                                                                 new MySqlParameter("@deviceUniqueIdentifier", deviceUniqueIdentifier) });

            if (result > 0)
            {
                return(true);
            }

            return(false);
        }
示例#11
0
        private void SaveMachineCode(int codeid, string deviceUniqueIdentifier, string plat, string system)
        {
            string sql = "select * from machine where codeid = @code and deviceUniqueIdentifier = @deviceUniqueIdentifier";

            int result = MySqlExecuteTools.GetCountResult(sql,
                                                          new MySqlParameter[] { new MySqlParameter("@code", codeid),
                                                                                 new MySqlParameter("@deviceUniqueIdentifier", deviceUniqueIdentifier) });

            //保存
            if (result == 0)
            {
                sql = "insert into machine(codeid,deviceUniqueIdentifier,plat,system) " +
                      "values('" + codeid + "','" + deviceUniqueIdentifier + "','" + plat + "','" + system + "')";
                MySqlExecuteTools.AddOrUpdate(sql);
            }
        }
示例#12
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) });
            });
        }
示例#13
0
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="session"></param>
        /// <param name="body"></param>
        /// <param name="id">roomid</param>
        /// <param name="userId">用户id</param>
        public void DeleteRoom(PubgSession session, string body, string roomId, string userId)
        {
            DataResult dataResult = new DataResult();

            //判断当前用户是具有删除的权限

            string sql = "select * from room where id = @room_id and userId = @userId";

            int roomCount = MySqlExecuteTools.GetCountResult(sql,
                                                             new MySqlParameter[] { new MySqlParameter("@room_id", roomId), new MySqlParameter("@userId", userId) });

            if (roomCount == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "操作错误,无删除权限";
                session.Send(GetSendData(dataResult, body));
                return;
            }


            sql = "select * from room_user where room_id = @room_id and user_id <>  @userId";
            int countResult = MySqlExecuteTools.GetCountResult(sql,
                                                               new MySqlParameter[] { new MySqlParameter("@room_id", roomId), new MySqlParameter("@userId", userId) });

            if (countResult > 0)
            {
                dataResult.result = 1;
                dataResult.resean = "战队下有玩家用户,无法进行删除";
                session.Send(GetSendData(dataResult, body));
                return;
            }

            //删除队长创建的room
            sql = "delete from room  where id = @id";
            MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@id", roomId) });

            //删除room_user

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

            dataResult.result = 0;
            //查询能否删除
            session.Send(GetSendData(dataResult, body));
        }
示例#14
0
        public void RegisterUser(PubgSession session, string body, string telephone, string password,
                                 string name, string icon, string checkCode, string userType)
        {
            // Logger.InfoFormat("新的客户端断开:{0}", session.RemoteEndPoint);


            string sql    = "select * from user where telephone = @telephone";
            int    result = MySqlExecuteTools.GetCountResult(sql,
                                                             new MySqlParameter[] { new MySqlParameter("@telephone", telephone) });

            DataResult dataResult = new DataResult();

            if (result > 0)
            {
                dataResult.result = 1;
                dataResult.resean = "手机号码已注册,请重试";
            }
            else
            {
                int type = Convert.ToInt32(userType);
                dataResult.result = 0;

                sql = "insert into user(password,name ,telephone,image,type) " +
                      "values('" + password + "','" + name + "','" + telephone + "','" + icon + "','" + type + "')";
                long newuserId = MySqlExecuteTools.GetAddID(sql);

                //玩家,增加生命信息
                if (type == 0)
                {
                    sql = "insert into life(userId) " +
                          "values('" + newuserId + "')";
                    MySqlExecuteTools.AddOrUpdate(sql);
                }
                //管理员,增加一条grounp数据
                if (type == 1)
                {
                    sql = "insert into grounp(name,userId) " +
                          "values('" + name + "','" + newuserId + "')";
                    MySqlExecuteTools.AddOrUpdate(sql);
                }
            }

            session.Send(GetSendData(dataResult, body));
        }
示例#15
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();
        }
示例#16
0
        public int Save(string json)
        {
            string[] strs = json.Split('|');

            string grounpId = strs[0];

            string fenceLon = strs[1];

            string fenceLat = strs[2];

            string fenceRadius = strs[3];

            string sql = "update  grounp set fenceLon = '" + fenceLon + "', fenceLat = '" + fenceLat +
                         "', fenceRadius = '" + fenceRadius + "', fenceTotalRadius = '" + fenceRadius + "' where id = @grounpId;";
            int count = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });

            // Console.WriteLine(count);
            joinRoomDao.GetAllRoom();
            return(0);
        }
示例#17
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));
        }
示例#18
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");
        }
示例#19
0
        public void CreateEditRoom(PubgSession session, string body, string grounpId, string gamePassword, string roomId,
                                   string roomName, string checkCode, string userId)
        {
            Logger.InfoFormat("创建编辑房间:{0},{1},{2},{3}", grounpId, roomId, roomName, checkCode);
            DataResult dataResult = new DataResult();
            string     sql        = "select * from grounp where id = @id and checkCode = @checkCode";
            int        result     = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@id", grounpId), new MySqlParameter("@@checkCode", gamePassword) });

            if (result == 0)
            {
                dataResult.result = 1;
                dataResult.resean = "游戏密码错误,操作失败";
                session.Send(GetSendData(dataResult, body));
                return;
            }
            //ADD
            if (roomId.Equals("-1"))
            {
                //每个用户只能创建一个房间

                sql = "select * from room where userId = @userId";

                int roomCount = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });
                if (roomCount >= 1)
                {
                    dataResult.result = 1;
                    dataResult.resean = "创建失败,每个队长只能创建一个战队";
                    session.Send(GetSendData(dataResult, body));
                    return;
                }
                //不能加入其他队还进行队的创建

                sql = "select * from room_user where user_id = @userId";

                roomCount = MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) });
                if (roomCount > 0)
                {
                    dataResult.result = 1;
                    dataResult.resean = "创建失败,您已经加入战队,无法再次创建";
                    session.Send(GetSendData(dataResult, body));
                    return;
                }

                //创建房间
                sql = "insert into room(grounpId,name,checkCode,userId) " +
                      "values('" + grounpId + "','" + roomName + "','" + checkCode + "','" + userId + "')";
                long newRoomId = MySqlExecuteTools.GetAddID(sql);

                //用户加入到该房间
                sql = "insert into room_user(room_id,user_id) " + "values('" + newRoomId + "','" + userId + "')";
                MySqlExecuteTools.AddOrUpdate(sql);
            }
            //更新
            else
            {
                sql = "update room set name = '" + roomName + "', checkCode = '" + checkCode + "' where id = @roomid;";
                MySqlExecuteTools.GetCountResult(sql, new MySqlParameter[] { new MySqlParameter("@roomid", roomId) });
            }

            dataResult.result = 0;
            session.Send(GetSendData(dataResult, body));
        }
示例#20
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();
        }