示例#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
        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));
        }
示例#3
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));
        }