public void Add(PubgSession session, string body, int grounpId, int userId) { bool result = CheckGrounpCount(grounpId); DataResult dataResult = new DataResult(); if (result) { string sql = "insert into grounp_user(grounp_id,user_id) " + "values('" + grounpId + "','" + userId + "')"; int count = MySqlExecuteTools.AddOrUpdate(sql); if (count > 0) { dataResult.result = 0; dataResult.resean = "组队成功"; } else { dataResult.result = 1; dataResult.resean = "操作失败,请重试."; } } else { dataResult.result = 1; dataResult.resean = "该队用户已满,请重试."; } session.Send(GetSendData(dataResult, body)); }
private void SaveMachineCode(CodeModel codeModel, string deviceUniqueIdentifier, string plat, string system, string userId) { string sql = "insert into machine(codeid,deviceUniqueIdentifier,plat,system,userId) " + "values('" + codeModel.id + "','" + deviceUniqueIdentifier + "','" + plat + "','" + system + "','" + userId + "')"; MySqlExecuteTools.AddOrUpdate(sql); }
/// <summary> /// 更新room状态 /// </summary> /// <param name="userID"></param> private void UpdateRoomState(string userID, Room room) { //更新room状态 string sql = "update room set runState = 0 " + " where userId = " + userID; MySqlExecuteTools.AddOrUpdate(sql); //推送给管理员 }
/// <summary> /// 创建房间 /// </summary> /// <param name="num">创建分队色数量</param> /// <param name="roomid">房间id</param> private void CreateRoom(int num, long roomid, string defaultCheckCode = "123456") { for (int i = 0; i < num; i++) { string sql = "insert into room(grounpId,code,name,checkCode) " + "values('" + roomid + "','" + (i + 1) + "','" + "房间" + (i + 1) + "','" + defaultCheckCode + "')"; MySqlExecuteTools.AddOrUpdate(sql); } }
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); } }
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)); }
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); }); }); }
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"); }
/// <summary> /// 更新user的状态 /// </summary> private void UpdateRoomUserState(string userID) { string sql = "update room_user set runState = 0 where user_id = " + userID; MySqlExecuteTools.AddOrUpdate(sql); }
public void UpdateLifeValue(int lifeValue, int bulletCountValue, string userId) { string sql = "update life set lifeValue = '" + lifeValue + "', bulletCount = '" + bulletCountValue + "' where userId = " + userId; MySqlExecuteTools.AddOrUpdate(sql); }
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)); }
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(); }