コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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");
            }
        }
コード例 #5
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");
            }
        }
コード例 #6
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);
        }
コード例 #7
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));
        }
コード例 #8
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);
            }
        }
コード例 #9
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) });
            });
        }
コード例 #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 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));
        }
コード例 #11
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("");
        }
コード例 #12
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();
        }
コード例 #13
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));
        }
コード例 #14
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);
        }
コード例 #15
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);
        }
コード例 #16
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);
        }
コード例 #17
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);
        }
コード例 #18
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);
                });
            });
        }
コード例 #19
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);
        }
コード例 #20
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);
        }
コード例 #21
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);
        }
コード例 #22
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));
        }
コード例 #23
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");
        }
コード例 #24
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);
        }
コード例 #25
0
        /// <summary>
        /// 更新user的状态
        /// </summary>
        private void UpdateRoomUserState(string userID)
        {
            string sql = "update room_user set runState = 0  where user_id = " + userID;

            MySqlExecuteTools.AddOrUpdate(sql);
        }
コード例 #26
0
        public void UpdateLifeValue(int lifeValue, int bulletCountValue, string userId)
        {
            string sql = "update life set lifeValue = '" + lifeValue + "', bulletCount = '" + bulletCountValue + "' where userId = " + userId;

            MySqlExecuteTools.AddOrUpdate(sql);
        }
コード例 #27
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));
        }
コード例 #28
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));
            }
        }
コード例 #29
0
        //====================================================================
        //玩家: 没有启动的时候不刷新
        //启动的时候刷新
        //队长的话, 不断刷新
        //管理员刷新,变化推送。
        //======================================================================
        public string SetUserRoomState(string userID)
        {
            //是否有房间创建
            string      sql      = "select * from room where userId = @userId";
            List <Room> roomList = MySqlExecuteTools.GetObjectResult <Room>(sql,
                                                                            new MySqlParameter[] { new MySqlParameter("@userId", int.Parse(userID)) });

            //普通玩家
            if (roomList.Count == 0)
            {
                //更新玩家状态
                UpdateRoomUserState(userID);

                //该队中其他玩家,不包括玩家
                List <int> userList = GetUserListBySingleUser(int.Parse(userID));
                if (userList.Count > 0)
                {
                    publishPlayerState.PublishPlayerList(userList);
                }

                //推送给队长
                int adminUser = FindLeaderByPlayer(int.Parse(userID));
                publishPlayerState.SendSingleUserMessage(adminUser, PublishPlayerState.Update_Command);
                return("0");
            }
            //队长玩家
            else
            {
                Room room = roomList.FirstOrDefault <Room>();

                sql = "select * from room_user where room_id = @room_id";
                List <Room_User> room_UserList = MySqlExecuteTools.GetObjectResult <Room_User>(sql,
                                                                                               new MySqlParameter[] { new MySqlParameter("@room_id", room.id) });
                //房间里没有其他玩家加入
                if (room_UserList.Count == 1)
                {
                    return("-2");
                }

                bool isFinished = CheckOtherPlayerState(room_UserList, int.Parse(userID));
                //完成
                if (isFinished)
                {
                    //更新玩家状态
                    UpdateRoomUserState(userID);

                    //更新room状态
                    UpdateRoomState(userID, room);

                    //推送给队长自己
                    publishPlayerState.PubilshLoaderSelf(int.Parse(userID));
                    //推送管理员
                    publishPlayerState.PublishAdmin(room);
                    //推送给其他玩家
                    List <int> userIdList = GetOtherUserByLeader(userID);
                    if (userIdList != null && userIdList.Count > 0)
                    {
                        publishPlayerState.PublishPlayerList(userIdList);
                    }

                    return("0");
                }
                // 未完成
                else
                {
                    return("-1");
                }
            }
        }
コード例 #30
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();
        }