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.
481 lines
18 KiB
481 lines
18 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text.RegularExpressions;
|
|
using LitJson;
|
|
using Newtonsoft.Json.Linq;
|
|
using ProtoCSStruct;
|
|
using SimpleHttpServer;
|
|
using Sog;
|
|
|
|
namespace Operation
|
|
{
|
|
[MenuMapping(refc = typeof(SendEmail))]
|
|
public class GameData
|
|
{
|
|
[RequestMapping("查找道具", PermissionCode.ITEM_SEARCHG)]
|
|
public static int OnGetItemListHttpReq(string httpApiCmd, JsonData jsondata, HttpResponse rsp,
|
|
HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
var goodsType = query.GetValue("type").Toint32((int)GoodsType.Items);
|
|
|
|
JsonData data1 = new JsonData();
|
|
switch (goodsType)
|
|
{
|
|
case (int)GoodsType.Items:
|
|
{
|
|
foreach (var item in ItemDescMgr.Instance.ItemTable)
|
|
{
|
|
string nameKey = string.Format("item{0}", item.Value.itemID);
|
|
var lang = LanguageDescMgr.Instance.GetConfig(nameKey);
|
|
if (lang != null)
|
|
{
|
|
nameKey = lang.ZH;
|
|
}
|
|
|
|
data1[string.Concat(item.Value.itemID)] = nameKey + "_" + item.Value.itemID;
|
|
}
|
|
}
|
|
break;
|
|
case (int)GoodsType.Equipment:
|
|
{
|
|
foreach (var item in EquipDescMgr.Instance.ItemTable)
|
|
{
|
|
var equipId = item.Value.id;
|
|
data1[equipId + ""] = equipId;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case (int)GoodsType.EquipSkin:
|
|
{
|
|
foreach (var item in RoleModelDescMgr.Instance.ItemTable)
|
|
{
|
|
var id = item.Value.id;
|
|
data1[id + ""] = item.Value.id;
|
|
}
|
|
}
|
|
break;
|
|
case (int)GoodsType.Gem:
|
|
{
|
|
foreach (var item in GemDescMgr.Instance.ItemTable)
|
|
{
|
|
var id = item.Value.id;
|
|
data1[id + ""] = item.Value.id;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
jsondata["data"] = data1;
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
[RequestMapping("查找道具价值", PermissionCode.COST_PLAYER_ITEM, true)]
|
|
public static int OnGetItemCostHttpReq(string httpApiCmd, JsonData jsondata, HttpResponse rsp,
|
|
HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
|
|
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
|
|
rsp.IsWaitFor = true;
|
|
return 0;
|
|
}
|
|
|
|
public static int DoOnGetItemCostHttpRes(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);
|
|
dbOperator.DbSelectItemCostAll(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;
|
|
}
|
|
|
|
[RequestMapping("添加道具价值", PermissionCode.ADD_COST_ITEM)]
|
|
public static int OnInsertItemCostHttpReq(string httpApiCmd, JsonData jsondata, HttpResponse rsp,
|
|
HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
|
|
int itemId = query.GetValue("itemId").Toint32(0) == 0 ? 10 : query.GetValue("itemId").Toint32(0);
|
|
float cn = query.GetValue("cnCost").ToFloat(0) == 0 ? 1 : query.GetValue("cnCost").ToFloat(0);
|
|
float kr = query.GetValue("krCost").ToFloat(0) == 0 ? 1 : query.GetValue("krCost").ToFloat(0);
|
|
float jp = query.GetValue("jpCost").ToFloat(0) == 0 ? 1 : query.GetValue("jpCost").ToFloat(0);
|
|
float en = query.GetValue("enCost").ToFloat(0) == 0 ? 1 : query.GetValue("enCost").ToFloat(0);
|
|
data.Add(itemId.ToString());
|
|
data.Add(cn.ToString());
|
|
data.Add(kr.ToString());
|
|
data.Add(jp.ToString());
|
|
data.Add(en.ToString());
|
|
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
|
|
rsp.IsWaitFor = true;
|
|
return 0;
|
|
}
|
|
|
|
public static int DoOnInsertItemCost(string httpApiCmd, SSHttpApiDbReq req, DBOperator dbOperator)
|
|
{
|
|
TraceLog.Trace("GameData.DoOnInsertItemCost 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("GameData.DoOnInsertItemCost param error");
|
|
builder["ret"] = 2;
|
|
builder["msg"] = "参数错误";
|
|
}
|
|
else
|
|
{
|
|
dbOperator.DbInsertItemCost(builder, int.Parse(req.Data[0].ToString()),
|
|
float.Parse(req.Data[1].ToString()), float.Parse(req.Data[3].ToString()),
|
|
float.Parse(req.Data[3].ToString()), float.Parse(req.Data[3].ToString()));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TraceLog.Error("GameData.DoOnInsertItemCost Error Msg {0}", ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
if (m_request != null)
|
|
{
|
|
m_request.Http.httpResponse.ContentAsUTF8 = builder.ToJson();
|
|
m_request.ProcessEnd = true;
|
|
}
|
|
}
|
|
|
|
TraceLog.Trace("PlayerInfoOp.DoOnInsertItemCost success httpContextId {0}", req.HttpContextId);
|
|
|
|
return 0;
|
|
}
|
|
|
|
[RequestMapping("删除道具价值", PermissionCode.DELETE_COST_ITEM)]
|
|
public static int OnDeleteItemCostHttpReq(string httpApiCmd, JsonData jsondata, HttpResponse rsp,
|
|
HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
RepeatedFixedStructString128_10 data = new RepeatedFixedStructString128_10();
|
|
int itemId = query.GetValue("itemId").Toint32(0) == 0 ? 10 : query.GetValue("itemId").Toint32(0);
|
|
data.Add(itemId.ToString());
|
|
HttpApiRootHandler.FillHttpApiDbReq2MessageTaskDistributor(httpApiCmd, httpContextId, ref data);
|
|
rsp.IsWaitFor = true;
|
|
return 0;
|
|
}
|
|
|
|
public static int DoOnDeleteItemCost(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 < 1)
|
|
{
|
|
TraceLog.Error("PlayerInfoOp.DoSelectPlayerOp param error");
|
|
builder["ret"] = 2;
|
|
builder["msg"] = "参数错误";
|
|
}
|
|
else
|
|
{
|
|
dbOperator.DbDeleteItemCost(builder, int.Parse(req.Data[0].ToString()));
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
|
|
|
|
[RequestMapping("数值配置查询", PermissionCode.SELECT_GAME_DATA, true, ignored: true)]
|
|
public static int OnGetGameDataConfigHttpReq(string httpApiCmd, JsonData jsondata, HttpResponse rsp,
|
|
HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
OperationServer.UpdateCurrency();
|
|
var name = query.GetValue("name");
|
|
if (string.IsNullOrEmpty(name))
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
var targetKey = query.GetValue("targetKey");
|
|
var targetValue = query.GetValue("targetValue");
|
|
|
|
name += ".bin";
|
|
jsondata["ret"] = 0;
|
|
var mgr = GameConfigMgr.Instance.GetConfigMgr(name);
|
|
jsondata["data"] = GetData(jsondata, mgr, targetKey, targetValue);
|
|
return 1;
|
|
}
|
|
|
|
|
|
public static JsonData GetData(JsonData jsondata, IConfigManager mgr, string targetKey = "",
|
|
string targetValue = "")
|
|
{
|
|
var type = mgr.GetType();
|
|
var prps = type.GetProperties();
|
|
|
|
JsonData data = new JsonData();
|
|
foreach (var prp in prps)
|
|
{
|
|
var pv = prp.GetValue(mgr);
|
|
if (pv == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (pv.GetType().FullName == mgr.GetType().FullName)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
if (!prp.PropertyType.IsGenericType ||
|
|
prp.PropertyType.GetGenericTypeDefinition() != typeof(SortedList<,>))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// 如果属性是 SortedList<TKey, TValue>,获取键值对
|
|
if (prp.GetValue(mgr) is not IDictionary sortedListValue)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var dog = 0;
|
|
foreach (DictionaryEntry entry in sortedListValue)
|
|
{
|
|
var descObj = entry.Value;
|
|
if (descObj == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var descType = descObj.GetType();
|
|
var descps = descType.GetProperties();
|
|
if (descType.Name.Contains("Desc"))
|
|
{
|
|
Build(data, descps, descObj, targetKey, targetValue);
|
|
jsondata["count"] = descps.Length;
|
|
}
|
|
|
|
if (descObj is not IDictionary subSortListValue)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
foreach (DictionaryEntry subEnt in subSortListValue)
|
|
{
|
|
var subDescObj = subEnt.Value;
|
|
if (subDescObj == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var subDescType = subDescObj.GetType();
|
|
var subDescps = subDescType.GetProperties();
|
|
if (subDescType.Name.Contains("Desc"))
|
|
{
|
|
Build(data, subDescps, subDescObj, targetKey, targetValue);
|
|
jsondata["count"] = subDescps.Length;
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
public static int OnGetGameDataConfigNamesHttpReq(string httpApiCmd, JsonData jsondata, HttpResponse rsp,
|
|
HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
List<string> list = GameConfigMgr.Instance.GetConfigNames();
|
|
JsonData json = new JsonData();
|
|
foreach (var name in list)
|
|
{
|
|
json.Add(name.Split(".")[0]);
|
|
}
|
|
|
|
jsondata["data"] = json;
|
|
jsondata["code"] = 0;
|
|
jsondata["ret"] = 0;
|
|
return 1;
|
|
}
|
|
|
|
public static void Build(JsonData data, PropertyInfo[] descPropertyInfos, object descObj, string targetKey,
|
|
string targetValue)
|
|
{
|
|
var json = new JsonData();
|
|
foreach (var propertyInfo in descPropertyInfos)
|
|
{
|
|
var filedKey = propertyInfo.Name;
|
|
bool filterValue = false;
|
|
if (!string.IsNullOrEmpty(targetKey))
|
|
{
|
|
if (targetKey == filedKey)
|
|
{
|
|
filterValue = true;
|
|
}
|
|
}
|
|
|
|
var filedVal = propertyInfo.GetValue(descObj);
|
|
if (filedVal == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (ReferenceEquals(filedVal, ""))
|
|
{
|
|
json[filedKey] = "";
|
|
}
|
|
else
|
|
{
|
|
var empty = string.Empty;
|
|
switch (filedVal)
|
|
{
|
|
case int:
|
|
{
|
|
var obj = int.Parse(filedVal.ToString() ?? empty);
|
|
if (filterValue && !string.IsNullOrEmpty(targetValue) && obj != int.Parse(targetValue))
|
|
{
|
|
return;
|
|
}
|
|
|
|
json[filedKey] = obj;
|
|
}
|
|
break;
|
|
case long:
|
|
{
|
|
var obj = long.Parse(filedVal.ToString() ?? empty);
|
|
if (filterValue && !string.IsNullOrEmpty(targetValue) && obj != long.Parse(targetValue))
|
|
{
|
|
return;
|
|
}
|
|
|
|
json[filedKey] = obj;
|
|
}
|
|
break;
|
|
case double:
|
|
{
|
|
var obj = double.Parse(filedVal.ToString() ?? string.Empty);
|
|
if (filterValue && !string.IsNullOrEmpty(targetValue) &&
|
|
Math.Abs(obj - double.Parse(targetValue)) != 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
json[filedKey] = obj;
|
|
}
|
|
|
|
break;
|
|
case float:
|
|
{
|
|
var obj = float.Parse(filedVal.ToString() ?? string.Empty);
|
|
if (filterValue && !string.IsNullOrEmpty(targetValue) &&
|
|
Math.Abs(obj - float.Parse(targetValue)) != 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
json[filedKey] = obj;
|
|
}
|
|
|
|
break;
|
|
case string:
|
|
{
|
|
var obj = filedVal.ToString();
|
|
if (filterValue && !string.IsNullOrEmpty(targetValue) && obj != targetValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
json[filedKey] = obj;
|
|
}
|
|
break;
|
|
case JArray array:
|
|
{
|
|
json[filedKey] = array.ToString();
|
|
break;
|
|
}
|
|
case JObject jObject:
|
|
{
|
|
json[filedKey] = jObject.ToString();
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
var obj = filedVal.ToJsonstr();
|
|
json[filedKey] = obj;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
data.Add(json);
|
|
}
|
|
|
|
|
|
static string GetComment(MemberInfo memberInfo)
|
|
{
|
|
// 获取字段的注释
|
|
var commentRegex = new Regex(@"//\s*([^\r\n]*)");
|
|
var sourceFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
|
|
memberInfo.Module.Name.Replace(".dll", ".cs"));
|
|
var lines = File.ReadAllLines(sourceFile);
|
|
|
|
foreach (var line in lines)
|
|
{
|
|
var match = commentRegex.Match(line);
|
|
if (match.Success)
|
|
{
|
|
return match.Groups[1].Value.Trim();
|
|
}
|
|
}
|
|
|
|
return "N/A";
|
|
}
|
|
}
|
|
}
|