You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

697 lines
27 KiB

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using LitJson;
using ProtoCSStruct;
using SimpleHttpServer;
using Sog;
namespace Operation
{
[MenuMapping(refc = typeof(PlayerInfoOp))]
class PlayerMonitor
{
[RequestMapping("玩家信息查询", PermissionCode.PLAYER_INFO_SEARCH, true)]
public static int OnPlayerMonitorHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp,
HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("PlayerMonitor.OnPlayerMonitorHttpReq Url{0},param count {1}, httpContextId {2}",
request.Url, query.Count, httpContextId);
int uid = query.GetValue("uid").Toint32(0);
string dbName = query.GetValue("dbName").ToString();
if (dbName == "AccountData")
{
SSGmQueryUserAccountInfoReq accountInfoReq = new SSGmQueryUserAccountInfoReq();
accountInfoReq.Id = httpContextId;
accountInfoReq.Account.SetString(query.GetValue("uid"));
accountInfoReq.AccountType = 1;
accountInfoReq.ReqType = (int)RoleReqType.SELECT_BASE_INFO;
//发送消息
OperationServerUtils.SendToDBServer((int)SSGameMsgID.GmQueryUserAccountinfoReq, ref accountInfoReq, 0,
0);
rsp.IsWaitFor = true;
return 0;
}
if (dbName == "MailData")
{
SSOperationSearchMailReq mailReq = new SSOperationSearchMailReq();
mailReq.Id = httpContextId;
mailReq.Uid = uid;
OperationServerUtils.SendToWorld((int)SSGameMsgID.OperationMailSearchReq, ref mailReq, uid, 0, "");
rsp.IsWaitFor = true;
return 0;
}
SSGmQueryUserRoleInfoReq req = new SSGmQueryUserRoleInfoReq();
req.Id = httpContextId;
req.Uid = (uint)uid;
req.AccountType = 0;
req.ReqType = (int)RoleReqType.SELECT_BASE_INFO;
if (dbName == "Dump")
{
DumpRoleData(uid,jsonData);
rsp.IsWaitFor = false;
return 0;
}
OperationServerUtils.SendToWorld((int)SSGameMsgID.GmQueryUserRoleReq, ref req, uid, 0, "");
rsp.IsWaitFor = true;
return 0;
}
public static void OnResMsg(uint id, JsonData payload, HttpResponse rsp, HttpRequest request,
HttpQueryParams query,
ref SSGmQueryUserRoletInfoRes res)
{
if (res.RoleBase.Uid == 0)
{
TraceLog.Error("PlayerMonitor.OnResMsg res.RoleBase.uid == 0! ");
payload["msg"] = "未查询到角色!";
payload["code"] = -1;
return;
}
payload["isOnline"] = OperationServerUtils.GetServerConfig().isOnline ? 1 : 0;
payload["code"] = 0;
rsp.IsWaitFor = false;
string modelName = query.GetValue("dbName").ToString();
payload["type"] = 0; // 0标准json 显示。1:类Json显示,3:表格显示
SaveRoleData(ref res);
switch (modelName)
{
case "RoleBase":
payload["type"] = 1;
payload["data"] = res.RoleBase.ToString();
break;
case "RoleData":
var fieldName = query.GetValue("fieldName");
payload["type"] = 1;
if (string.IsNullOrEmpty(fieldName))
{
payload["data"] = res.RoleData.ToString();
}
else
{
//支持最原始的数据模型查询结构,
var roleData = res.RoleData;
var types = typeof(DBRoleData);
var field = types.GetField(fieldName);
if (field != null)
{
var subPath = query.GetValue("subPath");
var data = field.GetValue(roleData);
var tailFiledName = fieldName;
var tailFieldSize = 1;
if (!string.IsNullOrEmpty(subPath) && subPath.Contains("."))
{
var subNameList = subPath.Split(".");
foreach (string subName in subNameList)
{
if (string.IsNullOrEmpty(subName))
{
break;
}
tailFiledName = subName;
tailFieldSize++;
var type = data.GetType();
if (subName.Contains('['))
{
//是一个结构数组
var index = subName.Replace("]", "");
index = index.Replace("[", "");
var dex = int.Parse(index, 0);
var method = type.GetMethod("Get");
data = method.Invoke(data, new object[1] { dex });
}
else
{
var subField = type.GetField(subName);
if (subField != null)
{
data = subField.GetValue(data);
}
}
}
}
payload["data"] = data.ToString();
payload["tailFiledName"] = tailFiledName;
payload["tailFieldSize"] = tailFieldSize;
var subTypes = GetSubFields(data.GetType(), data);
if (!subTypes.IsEmpty())
{
payload["subType"] = subTypes;
}
payload["isStruct"] = IsStruct(data.GetType());
}
}
break;
case "DropRateData":
payload["type"] = 1;
payload["data"] = res.DropRateData.ToString();
break;
case "TaskEXDataList":
payload["type"] = 3;
payload["data"] = ObjectUtils.parseToJson(res.RoleData.TaskEXData);
break;
case "DBPandoraActInfo":
RepeatedDBActInfo_32 list = res.RoleData.ActivityInfo;
JsonData pandoraData = new JsonData();
for (int i = 0; i < list.Count; i++)
{
pandoraData.Add(ObjectUtils.parseToJson(list[i]));
}
payload["data"] = pandoraData;
break;
case "HomeAd":
payload["data"] = ObjectUtils.parseToJson(res.RoleData.HomeAd);
break;
case "DBPopupGift":
var popupGift_16 = res.RoleData.PopupGift;
JsonData popupGiftData = new JsonData();
for (int i = 0; i < popupGift_16.Count; i++)
{
popupGiftData.Add(ObjectUtils.parseToJson(popupGift_16[i]));
}
payload["data"] = popupGiftData;
break;
case "SysUnlockData":
payload["type"] = 3;
payload["data"] = ObjectUtils.parseToJson(res.RoleData.SysUnlockData);
break;
case "Job":
payload["type"] = 3;
payload["data"] = ObjectUtils.parseToJson(res.RoleData.ExtData.Job);
break;
case "PandoraBag":
payload["type"] = 3;
payload["data"] = ObjectUtils.parseToJson(res.RoleData.PandoraBag);
break;
}
}
public static void SaveRoleData(ref SSGmQueryUserRoletInfoRes dataRes)
{
var uid = dataRes.RoleBase.Uid;
string filename = "./"+ uid + ".fdb";
if (File.Exists(filename))
{
File.Delete(filename);
}
int iRet = Sog.IO.FileDBSave.SaveToFile(ref dataRes, filename);
if (iRet != 0)
{
return;
}
return;
}
public static void DumpRoleData(int uid, JsonData payload)
{
string filename = "./" + uid + ".fdb";
if (!File.Exists(filename))
{
payload["ret"] = -1;
payload["msg"] = "data not found";
return;
}
Encoding shiftJis = Encoding.GetEncoding("shift_jis");
var bytes = Convert.ToBase64String(File.ReadAllBytes(filename));
payload["data"] = bytes;
payload["ret"] = 0;
}
static SSGmQueryUserRoletInfoRes sSGmQueryRes = new SSGmQueryUserRoletInfoRes();
static SSGmImportUserRoleInfoReq gmImportUserRoleInfoReq = new SSGmImportUserRoleInfoReq();
[RequestMapping("玩家信息导入", PermissionCode.IMPORT_PLAYER_ROLE_DATA)]
public static int OnImportRoleDataHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp,
HttpRequest request, HttpQueryParams query, uint httpContextId)
{
var config = OperationServerUtils.GetServerConfig();
if (config.isOnline)
{
jsonData["ret"] = -1;
jsonData["msg"] = "online is limit";
return 0;
}
var uid=query.GetValue("uid").Toint32();
var data = query.GetValue("data");
var bytes=Convert.FromBase64String(data);
//下载的是这个协议二进制,所以直接用这个协议数据反构建透传
sSGmQueryRes.Clear();
var input = new CodedInputStream(bytes);
sSGmQueryRes.ReadFrom(input);
sSGmQueryRes.RoleBase.Uid = uid;
gmImportUserRoleInfoReq.Clear();
gmImportUserRoleInfoReq.Uid = (uint)uid;
gmImportUserRoleInfoReq.Id = httpContextId;
gmImportUserRoleInfoReq.Data.CopyFrom(ref sSGmQueryRes);
//var req = new SSGmImportUserRoleInfoReq
//{
// Uid = (uint)uid,
// Id = httpContextId,
// Data = sSGmQueryRes
//};
rsp.IsWaitFor = true;
jsonData["ret"] = 0;
jsonData["msg"] = "success";
OperationServerUtils.SendToWorld((int)SSGameMsgID.GmImportUserRoleReq, ref gmImportUserRoleInfoReq, uid, 0, "");
return 0;
}
public static void OnImportRoleDataRes(uint serverID, StructPacket packet)
{
HttpRequestInfo m_request = null;
try
{
ref var res = ref packet.GetMessage<SSGmImportUserRoleInfoRes>();
var id = res.Id;
TraceLog.Debug("PlayerMonitor.OnImportRoleDataRes uid {0} ", id);
m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == id);
LitJson.JsonData builder = new LitJson.JsonData();
HttpQueryParams queryParams = new HttpQueryParams(m_request.Http.httpRequest.Url);
builder["ret"] = res.Ret;
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
}
catch (Exception ex)
{
TraceLog.Error("PlayerMonitor.OnImportRoleDataRes Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.ProcessEnd = true;
}
}
}
public static int OnGetRoleDataProp(string httpApiCmd, JsonData jsonData, HttpResponse rsp,
HttpRequest request, HttpQueryParams query, uint httpContextId)
{
var type = typeof(DBRoleData);
var subField = GetSubFields(type);
jsonData["data"] = subField;
jsonData["ret"] = 0;
return 0;
}
private static JsonData GetSubFields(Type type, object data = null)
{
JsonData json = new JsonData();
if (type == null)
{
return json;
}
var interfaceType = typeof(IStructMessage);
if (interfaceType.IsAssignableFrom(type))
{
var fields = type.GetFields();
foreach (var field in fields)
{
if (!field.IsPublic || field.IsStatic) //排除不需要的属性
{
continue;
}
if (field.Name is "Parser" or "SizeOf")
{
continue;
}
json.Add(field.Name);
}
}
if (IsStruct(type) && data != null)
{
var method = type.GetMethod("GetCount");
if (method == null)
{
return json;
}
var count = method.Invoke(data, Array.Empty<object>());
if (count == null)
{
return json;
}
int.TryParse(count.ToString(), out var result);
for (int i = 0; i < result; i++)
{
json.Add("[" + i + "]");
}
}
return json;
}
public static bool IsStruct(Type type)
{
return type.IsValueType && !type.IsEnum && !type.IsPrimitive;
}
[RequestMapping("玩家信息修改", PermissionCode.UPDATE_PLAYER_ROLE_DATA,toLog = true)]
public static int UpdateRoleDataHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp,
HttpRequest request, HttpQueryParams query, uint httpContextId)
{
jsonData["code"] = 0;
jsonData["ret"] = 0;
var uid = query.GetValue("uid").Toint32();
var newValue = query.GetValue("newValue");
var subPath = query.GetValue("subPath");
SSGmUpdateUserRoleInfoReq req = new SSGmUpdateUserRoleInfoReq();
req.Id = httpContextId;
req.Uid = (uint)uid;
req.SubFieldPath.SetString(subPath);
req.NewValue.SetString(newValue);
OperationServerUtils.SendToWorld((int)SSGameMsgID.GmUpdateUserRoleReq, ref req, uid, 0, "");
rsp.IsWaitFor = true;
return 0;
}
public static void OnUpdateRoleDataRes(uint serverID, StructPacket packet)
{
ref SSGmUpdateUserRoleInfoRes res = ref packet.GetMessage<SSGmUpdateUserRoleInfoRes>();
HttpRequestInfo m_request = null;
try
{
var id = (uint)res.Id;
TraceLog.Debug("PlayerMonitor.OnSearchMailRes reqId {0} ", id);
m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == id);
LitJson.JsonData builder = new LitJson.JsonData();
builder["code"] = res.Ret;
builder["ret"] = res.Ret;
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
}
catch (Exception ex)
{
TraceLog.Error("PlayerMonitor.OnSearchMailRes Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.ProcessEnd = true;
}
}
}
public static void OnSearchMailRes(uint serverID, StructPacket packet)
{
ref SSOperationSearchMailRes res = ref packet.GetMessage<SSOperationSearchMailRes>();
HttpRequestInfo m_request = null;
try
{
var id = (uint)res.Id;
TraceLog.Debug("PlayerMonitor.OnSearchMailRes reqId {0} ", id);
m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == id);
LitJson.JsonData builder = new LitJson.JsonData();
HttpQueryParams queryParams = new HttpQueryParams(m_request.Http.httpRequest.Url);
OnMailSearchRes(id, builder, m_request.Http.httpResponse, m_request.Http.httpRequest, queryParams,
ref res);
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
}
catch (Exception ex)
{
TraceLog.Error("PlayerMonitor.OnSearchMailRes Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.ProcessEnd = true;
}
}
}
public static void OnMailSearchRes(uint id, JsonData payload, HttpResponse rsp, HttpRequest request,
HttpQueryParams query, ref SSOperationSearchMailRes res)
{
if (res.Id == 0)
{
TraceLog.Error("PlayerMonitor.OnResMsg res.RoleBase.uid == 0! ");
payload["msg"] = "未查询到角色!";
payload["code"] = -1;
return;
}
var mails = res.Mails;
payload["type"] = 3;
JsonData jsonData = new JsonData();
for (int i = 0; i < mails.Count; i++)
{
var mail = mails[i];
JsonData box = new JsonData();
box["MailID"] = mail.MailID;
box["MailType"] = mail.MailType;
box["SenderUid"] = mail.SenderUid;
box["Title"] = mail.Title.ToString();
box["Content"] = mail.Content.ToString();
box["AddGoods"] = mail.AddGoods.ToString();
//box["AddCurrency"] = mail.AddCurrency.ToString();
box["Status"] = mail.Status;
box["SendTime"] = mail.SendTime;
jsonData.Add(box);
}
if (mails.Count > 0)
{
payload["data"] = jsonData;
}
else
{
payload["data"] = "";
}
payload["code"] = 0;
rsp.IsWaitFor = false;
}
public static void OnResMsg(uint id, JsonData payload, HttpResponse rsp, HttpRequest request,
HttpQueryParams query, ref SSGmQueryUserAccountInfoRes res)
{
if (res.Id == 0)
{
TraceLog.Error("PlayerMonitor.OnResMsg res.RoleBase.uid == 0! ");
payload["msg"] = "未查询到角色!";
payload["code"] = -1;
return;
}
payload["code"] = 0;
rsp.IsWaitFor = false;
string modelName = query.GetValue("dbName").ToString();
payload["type"] = 0; // 0标准json 显示。1:类Json显示
switch (modelName)
{
case "AccountData":
payload["type"] = 1;
payload["data"] = res.ToString();
break;
}
}
[RequestMapping("删除玩家邮件", PermissionCode.PLAYER_DELETE_MAIL, toLog: true)]
public static int OnDeletePlayerMailHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp,
HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("PlayerMonitor.OnPlayerMonitorHttpReq Url{0},param count {1}, httpContextId {2}",
request.Url, query.Count, httpContextId);
int uid = query.GetValue("uid").Toint32(0);
int mailId = query.GetValue("mailId").Toint32();
if (uid == 0 || mailId == 0)
{
jsonData["code"] = -1;
jsonData["msg"] = "输入错误";
return -1;
}
SSOperationDeleteMailReq ssreq = new SSOperationDeleteMailReq();
ssreq.Id = httpContextId;
ssreq.Uid = uid;
ssreq.MailId = mailId;
OperationServerUtils.SendToWorld((int)SSGameMsgID.OperationMailDeleteReq, ref ssreq, uid, 0, "");
rsp.IsWaitFor = true;
return 0;
}
public static void OnDeleteMailRes(uint serverID, StructPacket packet)
{
ref SSOperationDeleteMailRes res = ref packet.GetMessage<SSOperationDeleteMailRes>();
HttpRequestInfo m_request = null;
try
{
var id = (uint)res.Id;
TraceLog.Debug("PlayerMonitor.OnSearchMailRes reqId {0} ", id);
m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == id);
LitJson.JsonData builder = new LitJson.JsonData();
HttpQueryParams queryParams = new HttpQueryParams(m_request.Http.httpRequest.Url);
builder["code"] = res.Ret;
if (res.Ret == 0)
{
builder["msg"] = "删除成功";
}
else
{
builder["msg"] = "删除失败";
}
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
}
catch (Exception ex)
{
TraceLog.Error("PlayerMonitor.OnSearchMailRes Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.ProcessEnd = true;
}
}
}
[RequestMapping("解锁玩家周BP", PermissionCode.PLAYER_UNLOCK_WEEKLY_BP, toLog: true)]
public static int OnUnlockPlayerWeeklyBp(string httpApiCmd, JsonData jsonData, HttpResponse rsp,
HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("PlayerMonitor.OnUnlockPlayerWeeklyBp Url{0},param count {1}, httpContextId {2}",
request.Url, query.Count, httpContextId);
int uid = query.GetValue("uid").Toint32(0);
int ActID = query.GetValue("ActID").Toint32();
if (uid == 0 || ActID == 0)
{
jsonData["code"] = -1;
jsonData["msg"] = "输入错误";
return -1;
}
var config = ActivityDescMgr.Instance.GetConfig(ActID);
if (config == null)
{
jsonData["code"] = -1;
jsonData["msg"] = "输入错误";
return -1;
}
int itemid = int.MaxValue;
string account = OperationServerUtils.GetAccount(query.GetValue("token"));
if (account == null || itemid == int.MaxValue)
{
jsonData["ret"] = 6;
jsonData["msg"] = "账号不存在或未登录";
return 6;
}
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
data.Add(account);
data.Add("bp解锁");
data.Add("bp解锁");
data.Add("bp解锁");
data.Add(uid.ToString());
data.Add(itemid.ToString());
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
rsp.IsWaitFor = true;
return 0;
}
[RequestMapping("解锁玩家任务", PermissionCode.UPDATE_USER_TASK, toLog: true)]
public static int OnDoneTaskReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp,
HttpRequest request, HttpQueryParams query, uint httpContextId)
{
TraceLog.Trace("PlayerMonitor.OnUnlockPlayerWeeklyBp Url{0},param count {1}, httpContextId {2}",
request.Url, query.Count, httpContextId);
int uid = query.GetValue("uid").Toint32(0);
int taskId = query.GetValue("taskId").Toint32();
if (uid == 0 || taskId == 0)
{
jsonData["code"] = -1;
jsonData["msg"] = "输入错误";
return -1;
}
var config = QuestEXDescMgr.Instance.GetConfig(taskId);
if (config == null)
{
jsonData["code"] = -1;
jsonData["msg"] = "输入错误";
return -1;
}
SSOperationUpdateTaskReq req = new SSOperationUpdateTaskReq();
req.Id = httpContextId;
req.Uid = uid;
req.TaskId = taskId;
OperationServerUtils.SendToWorld((int)SSGameMsgID.OperationUpdateTaskReq, ref req, uid, 0, "");
rsp.IsWaitFor = true;
return 0;
}
public static int OnDoneTaskRes(uint remoteAppId, StructPacket packet, DBOperator dbOperator)
{
SSOperationUpdateTaskRes res = packet.GetMessage<SSOperationUpdateTaskRes>();
TraceLog.Trace("PlayerMonitor.OnDoneTaskRes HttpContextId {0}", res.Id);
HttpRequestInfo m_request = null;
LitJson.JsonData builder = new LitJson.JsonData();
try
{
var httpContextId = res.Id;
m_request = OperationServer.m_httpService.m_requestList.Find(f => f.Http.id == httpContextId);
if (res.Ret == 0)
{
builder["code"] = 0;
builder["msg"] = "发送成功";
}
else
{
builder["code"] = -1;
builder["msg"] = "发送失败";
}
}
catch (Exception ex)
{
TraceLog.Error("PlayerMonitor.OnDoneTaskRes Error Msg {0}", ex.Message);
}
finally
{
if (m_request != null)
{
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
m_request.ProcessEnd = true;
}
}
TraceLog.Trace("PlayerMonitor.OnDoneTaskRes success httpContextId {0}", res.Id);
return 0;
}
}
}