using LitJson; using Sog; using System; using System.Collections.Generic; using System.Linq; using System.Text; using SimpleHttpServer; using ProtoCSStruct; using MySql.Data.MySqlClient; namespace Operation { [MenuMapping(MenuName.PLAYER_MANAGER,MenuIcon.PLAYER,1,PermissionCode.PLAYER_INFO_MANAGER)] public static class PlayerInfoOp { [RequestMapping("添加玩家指令",PermissionCode.INSERT_PLAYER_OP, toLog: true)] public static int OnInsertPlayerOpHttpReq(string httpApiCmd, JsonData builder, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId) { TraceLog.Trace("PlayerInfoOp.OnInsertPlayerOpHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId); string account = OperationServerUtils.GetAccount(query.GetValue("token")); if (account == null) { builder["ret"] = 6; builder["msg"] = "账号不存在或未登录"; return 6; } string uidList = query.GetValue("uidList"); long uid = query.GetValue("uid").Toint32(0); int type = query.GetValue("type").Toint32(0); string opUser = query.GetValue("opUser"); int opId = query.GetValue("opId").Toint32(0); int opType = query.GetValue("opType").Toint32(0); int opNum = query.GetValue("opNum").Toint32(0); string uniqueId = query.GetValue("uniqueId"); int paramInt = query.GetValue("paramInt").Toint32(0); string paramStr = query.GetValue("paramStr"); if (!string.IsNullOrEmpty(uidList)) { var uids = uidList.Split("|"); foreach (string uidStr in uids) { try { uid = long.Parse(uidStr); } catch (Exception ex) { TraceLog.Error("PlayerInfoOp.ProccessRequest error:{0}", ex.Message); builder["ret"] = 3; builder["msg"] = "操作失败,请检查参数!"; return 3; } } } TraceLog.Trace("PlayerInfoOp.OnInsertPlayerOpHttpReq account {0} ,uidList {1}, uid {2} type {3}, opUser {4} opId {5} opType {6} opNum {7} uniqueId {8} paramInt {9} paramStr {10}", account, uidList, uid, type, opUser, opId, opType, opNum, uniqueId, paramInt, paramStr); RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10(); data.Add(account); data.Add(uidList); data.Add(uid.ToString()); data.Add(type.ToString()); data.Add(opUser); data.Add(opId.ToString()); data.Add(opType.ToString()); data.Add(opNum.ToString()); data.Add(uniqueId.ToString()); data.Add(paramInt.ToString()); data.Add(paramStr); HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data); rsp.IsWaitFor = true; return 0; } public static int DoInsertPlayerOp(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator) { TraceLog.Trace("PlayerInfoOp.DoInsertPlayerOp HttpContextId {0}", req.HttpContextId); HttpRequestInfo m_request = null; LitJson.JsonData builder = new LitJson.JsonData(); try { var httpContextId = req.HttpContextId; m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == httpContextId); if (req.Data.Count < 11) { TraceLog.Error("PlayerInfoOp.DoInsertPlayerOp param error"); builder["ret"] = 2; builder["msg"] = "参数错误"; } else { string uidList = req.Data[1].ToString(); if (!string.IsNullOrEmpty(uidList)) { var uids = uidList.Split("|"); string errUidList = ""; foreach (string uidStr in uids) { long uid = long.Parse(uidStr); if (uid > 0) { if (!dbOperator.DBInsertPlayerOp(uid, int.Parse(req.Data[3].ToString()), req.Data[4].ToString(), int.Parse(req.Data[5].ToString()), int.Parse(req.Data[6].ToString()), int.Parse(req.Data[7].ToString()), req.Data[8].ToString(), int.Parse(req.Data[9].ToString()), req.Data[10].ToString(), builder)) { errUidList = errUidList + uidStr + ","; } } } if (errUidList != "") { builder["ret"] = 7; builder["msg"] = $"部分uid处理错误:{errUidList}"; } } else { long uid = long.Parse(req.Data[2].ToString()); if (!dbOperator.DBInsertPlayerOp(uid, int.Parse(req.Data[3].ToString()), req.Data[4].ToString(), int.Parse(req.Data[5].ToString()), int.Parse(req.Data[6].ToString()), int.Parse(req.Data[7].ToString()), req.Data[8].ToString(), int.Parse(req.Data[9].ToString()), req.Data[10].ToString(), builder)) { builder["ret"] = 7; builder["msg"] = "操作失败,请重试或者联系管理员处理!"; } } builder["ret"] = 0; builder["msg"] = "操作成功,等待游戏内处理!"; } } catch (Exception ex) { TraceLog.Error("PlayerInfoOp.DoInsertPlayerOp Error Msg {0}", ex.Message); } finally { if (m_request != null) { m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson(); m_request.ProcessEnd = true; } } TraceLog.Trace("PlayerInfoOp.DoInsertPlayerOp success httpContextId {0}", req.HttpContextId); return 0; } [RequestMapping("玩家操作查询",PermissionCode.SELECT_PLAYER_OP)] public static int OnSelectPlayerOpHttpReq(string httpApiCmd, JsonData builder, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId) { TraceLog.Trace("PlayerInfoOp.OnSelectPlayerOpHttpReq url {0} ,param count {1} ,httpContextId {2}", request.Url, query.Count, httpContextId); int pageSize = query.GetValue("pageSize").Toint32(0) == 0 ? 10 : query.GetValue("pageSize").Toint32(0); int pageIndex = query.GetValue("pageSize").Toint32(0) == 0 ? 1 : query.GetValue("pageIndex").Toint32(0); int type = query.GetValue("type").Toint32(0) == 0 ? 0 : query.GetValue("type").Toint32(0); string opUser = string.IsNullOrEmpty(query.GetValue("opUser")) ? "" : query.GetValue("opUser"); TraceLog.Trace("PlayerInfoOp.OnSelectPlayerOpHttpReq pageSize {0} ,pageIndex {1}, type {2}, opUser {3}", pageSize, pageIndex, type, opUser); RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10(); data.Add(pageSize.ToString()); data.Add(pageIndex.ToString()); data.Add(type.ToString()); data.Add(opUser); HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data); rsp.IsWaitFor = true; return 0; } public static int DoSelectPlayerOp(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator) { TraceLog.Trace("PlayerInfoOp.DoSelectPlayerOp HttpContextId {0}", req.HttpContextId); HttpRequestInfo m_request = null; LitJson.JsonData builder = new LitJson.JsonData(); try { var httpContextId = req.HttpContextId; m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == httpContextId); if (req.Data.Count < 4) { TraceLog.Error("PlayerInfoOp.DoSelectPlayerOp param error"); builder["ret"] = 2; builder["msg"] = "参数错误"; } else dbOperator.DBSelectPlayerOp(int.Parse(req.Data[0].ToString()), int.Parse(req.Data[1].ToString()), int.Parse(req.Data[2].ToString()), req.Data[3].ToString(), builder); } catch (Exception ex) { TraceLog.Error("PlayerInfoOp.DoSelectPlayerOp Error Msg {0}", ex.Message); } finally { if (m_request != null) { m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson(); m_request.ProcessEnd = true; } } TraceLog.Trace("PlayerInfoOp.DoSelectPlayerOp success httpContextId {0}", req.HttpContextId); return 0; } } }