public int CheckEnterButton(string usreId, string userType) { string sql = ""; int runState = -1; //管理员 if (userType.Equals("1")) { sql = "select * from grounp where userId = @userId"; List <Grounp> ps = MySqlExecuteTools.GetObjectResult <Grounp>(sql, new MySqlParameter[] { new MySqlParameter("@userId", usreId) }); if (ps == null || ps.Count == 0) { return(-1); } Grounp p = ps[0]; runState = p.runState; } else { Grounp p = GetGrounpByPlayer(int.Parse(usreId)); if (p == null) { return(-1); } runState = p.runState; } return(runState); }
private void SetFence() { string grounpId = root.GetComponentInChildren <ListView>().selectGameId; Grounp grounp = ListData.FindGrounpByKey(root.GetComponentInChildren <ListView>().selectGameId); RestFulProxy.SearchState(grounpId, (result) => { result = result.Trim('"'); if (result.Equals("1")) { PlayerPrefs.SetString("grounpId", grounpId); if (grounp != null) { PlayerPrefs.SetFloat("fenceLon", grounp.fenceLon); PlayerPrefs.SetFloat("fenceLat", grounp.fenceLat); PlayerPrefs.SetInt("fenceRadius", grounp.fenceRadius); } SceneTools.instance.LoadScene("Fence"); } else { root.GetComponent <RootEditGameView>().errorMessage.ShowMessage( grounp.name + "游戏已启动,无法再次进行编辑器电子围栏", SoundType.Error); } }); }
//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 Grounp GetGrounpByRoomId(int roomID) { Grounp grounp = null; roomGrounp.TryGetValue(roomID, out grounp); return(grounp); }
private void SetGrounpName() { gameId = GetComponentInParent <RootJoinRoomView>().GetComponentInChildren <ListView>().selectGameId; Grounp grounp = ListData.FindGrounpByKey(gameId); if (grounp != null) { GameName.text = grounp.name; } }
private void CreateGroupRoomDic(List <Room> roomList) { this.roomList = roomList; roomGrounp.Clear(); roomList.ForEach((item) => { Grounp p = SearchGrounpDao.GetGrounpById(item.grounpId.ToString()); roomGrounp.Add(item.id, p); }); // Console.WriteLine(Utils.CollectionsConvert.ToJSON(roomGrounp)); // Logger.Debug(Utils.CollectionsConvert.ToJSON(roomGrounp)); }
/// <summary> /// 定时发送经纬度数据 /// </summary> /// <param name="state"></param> private void SendMapDataCallBack(object state) { try { tmrsendPostion.Change(Timeout.Infinite, Timeout.Infinite); ConcurrentDictionary <PubgSession, SessionItem> dic = PubgSession.mOnLineConnections; mapDataPushBusiness.CreateGPSRoomDic(); foreach (PubgSession session in dic.Keys) { SessionItem sessionItem = null; dic.TryGetValue(session, out sessionItem); if (sessionItem != null && !string.IsNullOrEmpty(sessionItem.gpsItem.userName)) { List <GPSItem> gpsList = mapDataPushBusiness.GetGpsListByUser(sessionItem.gpsItem); int roomId = mapDataPushBusiness.GetRoomByUser(sessionItem.gpsItem.userId, sessionItem.gpsItem.userType); Dictionary <string, object> dataDic = new Dictionary <string, object>(); Grounp grounp = mapDataPushBusiness.GetGrounpByRoomId(roomId); //玩家增加房间和生命值 if (sessionItem.gpsItem.userType == 0) { Room room = mapDataPushBusiness.GetRoomById(roomId); dataDic.Add("room", room); Life life = registerDao.GetLifeById(sessionItem.gpsItem.userId); dataDic.Add("life", life); } else { dataDic.Add("room", null); dataDic.Add("life", null); } dataDic.Add("grounp", grounp); dataDic.Add("gpsData", gpsList); string resultJson = Utils.CollectionsConvert.ToJSON(dataDic); //Logger.Debug(resultJson); string data = "ShowPosition" + Constant.START_SPLIT + resultJson + "\r\n"; session.Send(data); } } } catch (Exception e) { Logger.InfoFormat("更新位置异常::{0}", e.Message); tmrsendPostion.Dispose(); tmrsendPostion = new System.Threading.Timer(SendMapDataCallBack, null, IntervalSendPostion, IntervalSendPostion); Console.WriteLine("位置更新异常信息:" + e.Message); } finally { tmrsendPostion.Change(IntervalSendPostion, IntervalSendPostion); } }
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)); }
/// <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 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(); }
public object ExecuteCommand(string body, string[] parameter) { Dictionary <string, object> resultDic = Utils.CollectionsConvert.ToObject <Dictionary <string, object> >(body); string gpsJson = Utils.CollectionsConvert.ToJSON(resultDic["gpsData"]); List <GPSItem> gpsItems = Utils.CollectionsConvert.ToObject <List <GPSItem> >(gpsJson); string grounpJson = Utils.CollectionsConvert.ToJSON(resultDic["grounp"]); Grounp grounp = Utils.CollectionsConvert.ToObject <Grounp>(grounpJson); string roomJson = Utils.CollectionsConvert.ToJSON(resultDic["room"]); Room room = Utils.CollectionsConvert.ToObject <Room>(roomJson); string lifeJson = Utils.CollectionsConvert.ToJSON(resultDic["life"]); Life life = Utils.CollectionsConvert.ToObject <Life>(lifeJson); if (grounp == null) { grounp = new Grounp(); } //if (gpsItems==null || gpsItems.Count==0) //{ // // MessageShow.instance.ShowMesage("发送数据为空"); // return null; //} GPSItem currentUser = null; for (int i = 0; gpsItems != null && i < gpsItems.Count; i++) { if (gpsItems[i].userId.Equals(LoginInfo.Userinfo.id)) { gpsItems[i].color = colors[0]; currentUser = gpsItems[i]; } else { gpsItems[i].color = colors[1]; } } if (currentUser == null) { currentUser = new GPSItem(); float lat = Input.location.lastData.latitude; float lon = Input.location.lastData.longitude; double[] datas = GPSTools.gps84_To_Gcj02(lat, lon); currentUser.lat = datas[0]; currentUser.lon = datas[1]; currentUser.userId = LoginInfo.Userinfo.id; currentUser.userName = LoginInfo.Userinfo.name; currentUser.userType = 1; } Dictionary <string, object> result = new Dictionary <string, object>(); result.Add("currentUser", currentUser); result.Add("gpsData", gpsItems); result.Add("grounp", grounp); result.Add("room", room); result.Add("life", life); result.Add("ip", Config.parse("ServerIP")); string sendJson = Utils.CollectionsConvert.ToJSON(result); //Debug.Log(sendJson); ShowMapPoint.instacne.Show(Utils.CollectionsConvert.ToJSON(sendJson)); return(null); }