//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)); }
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)); }
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)); }
/// <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)); }
public void SearchSingleRoom(PubgSession session, string body, string roomId) { Logger.InfoFormat("查询room下的user:{0}", roomId); DataResult dataResult = new DataResult(); dataResult.result = 0; dataResult.data = GetUserList(SearchSingleGrounpCommon(roomId)); 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 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(); }
public void SearchSingleGrounp(PubgSession session, string body, string grounpId, string userId) { Logger.InfoFormat("查询单队下的房间:{0}", grounpId); DataResult dataResult = new DataResult(); dataResult.result = 0; dataResult.data = SearchRoomListByGrounp(grounpId, userId); session.Send(GetSendData(dataResult, body)); }
public void StartSendChatMessage(string content, string userName, PubgSession session) { Dictionary <string, string> _dic = new Dictionary <string, string>(); _dic.Add("time", TimeUtils.GetCurrentFormatTime()); _dic.Add("content", content); _dic.Add("name", userName); string resultJson = Utils.CollectionsConvert.ToJSON(_dic); string data = "SendMessage" + Constant.START_SPLIT + resultJson + "\r\n"; session.Send(data); }
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)); }
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)); }
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)); }
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(); }