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.
421 lines
14 KiB
421 lines
14 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
using Sog;
|
|
using System.Net.Http;
|
|
using LitJson;
|
|
using SimpleHttpServer;
|
|
|
|
using ProtoCSStruct;
|
|
using System.Reflection;
|
|
using System.Dynamic;
|
|
using Sog.Crypto;
|
|
using System.Web;
|
|
using System.Text.Json;
|
|
using System.Text;
|
|
|
|
namespace Operation
|
|
{
|
|
public class hero
|
|
{
|
|
public int id { get; set; }
|
|
public string name { get; set; }
|
|
public int race { get; set; }
|
|
}
|
|
|
|
public class myRoleData
|
|
{
|
|
public string role_name;
|
|
|
|
public string cpUid;
|
|
// 确认一下输入的服务器Id,和实际查询到的服务器id不同,是否成功返回
|
|
public string server_id;
|
|
|
|
public string cpExt;
|
|
|
|
public string cUid;
|
|
|
|
public string cid;
|
|
}
|
|
|
|
public class UidRelm
|
|
{
|
|
public int uid;
|
|
public int realmId;
|
|
}
|
|
|
|
[MenuMapping(refc = typeof(PlayerInfoOp))]
|
|
public class SelectRole
|
|
{
|
|
public static int OnSelectHerosHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
TraceLog.Trace("SelectRole.OnSelectHerosHttpReq Url{0},param count {1}", request.Url, query.Count);
|
|
|
|
JsonData msgdata = new JsonData();
|
|
jsonData["data"] = msgdata;
|
|
msgdata.Add("");
|
|
msgdata.Clear();
|
|
|
|
return 0;
|
|
}
|
|
|
|
[RequestMapping("hero_skin",PermissionCode.SELECT_HERO_SKIN)]
|
|
public static int OnSelectHeroSkinHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
TraceLog.Trace("SelectRole.OnSelectHeroSkinHttpReq Url{0},param count {1}", request.Url, query.Count);
|
|
|
|
JsonData msgdata = new JsonData();
|
|
jsonData["data"] = msgdata;
|
|
msgdata.Add("");
|
|
msgdata.Clear();
|
|
|
|
return 0;
|
|
}
|
|
|
|
private static void GetResData(Dictionary<string, object> man, FieldInfo[] fieldInfos, object res)
|
|
{
|
|
//dynamic obj =new ExpandoObject();
|
|
|
|
foreach (var Fd in fieldInfos)
|
|
{
|
|
if (Fd.Name.StartsWith("Repeated") || Fd.Name == "FixedElementField")
|
|
{
|
|
continue;
|
|
}
|
|
if (Fd.FieldType.IsArray)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//基础类型直接写入值
|
|
if (Fd.FieldType.IsPrimitive)
|
|
{
|
|
if (!man.ContainsKey(Fd.Name))
|
|
{
|
|
man.Add(Fd.Name, Fd.GetValue(res));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// ProtoCSStruct.RepeatedDBIDValue_32 +< Buffer > e__FixedBuffer.FixedElementField
|
|
|
|
var vla = res.GetType().GetField(Fd.Name).GetValue(res);
|
|
//字符类型获取字符写入
|
|
if (Fd.FieldType == typeof(FixedStructString32) || Fd.FieldType == typeof(FixedStructString16))
|
|
{
|
|
man.Add(Fd.Name, Fd.FieldType.GetMethod("GetString").Invoke(vla, null));
|
|
}
|
|
//自定义结构继续递归
|
|
else
|
|
{
|
|
var sss = new Dictionary<string, object>();
|
|
GetResData(sss, Fd.FieldType.GetFields(), vla);
|
|
man.Add(Fd.Name, sss);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//收到回包时调用这个
|
|
public static void OnResMsg(uint id, JsonData jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, ref SSGmQueryUserRoletInfoRes res)
|
|
{
|
|
if(res.RoleBase.Uid == 0)
|
|
{
|
|
jsondata["msg"] = "failed!";
|
|
jsondata["code"] = -1;
|
|
return;
|
|
}
|
|
|
|
JsonData rdata = new JsonData();
|
|
|
|
rdata["role_id"] = res.RoleBase.Uid;
|
|
rdata["role_name"] = res.RoleBase.Nick.GetString();
|
|
rdata["uid"] = res.RoleBase.Uid;
|
|
rdata["server_id"] = 0;
|
|
rdata["register_time"] = res.RoleBase.CreateTime;
|
|
rdata["last_login_time"] = res.RoleBase.LastLoginTime;
|
|
rdata["level"] = res.RoleBase.Level;
|
|
rdata["vip_level"] = res.RoleBase.VipLevel;
|
|
rdata["total_pay"] = res.RoleData.PayData.TotalPayMoney;
|
|
|
|
int ban_type = 0;
|
|
if (res.FreezeTime > 0)
|
|
{
|
|
ban_type = 1;
|
|
}
|
|
rdata["ban_type"] = ban_type;
|
|
rdata["ban_time"] = res.FreezeTime;
|
|
rdata["ban_reason"] = (int)res.FreezeReason;
|
|
|
|
jsondata["msg"] = "success";
|
|
jsondata["code"] = 0;
|
|
jsondata["data"] = rdata;
|
|
|
|
//jsondata["Arena"] = res.RoleData.Arena.ArenaBaseList.ToString();
|
|
|
|
//jsondata["Data"] = res.ToString();
|
|
|
|
rsp.IsWaitFor = false;
|
|
return;
|
|
}
|
|
|
|
public static int DoSelect(JsonData jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint id)
|
|
{
|
|
TraceLog.Trace("SelectRole.DoSelect Url{0},param count {1}", request.Url, query.Count);
|
|
|
|
SSGmQueryUserRoleInfoReq req = new SSGmQueryUserRoleInfoReq();
|
|
int uid = query.GetValue("uid").Toint32(0);
|
|
req.ReqType = 1;
|
|
if (0 != query.GetValue("identifier").Toint32(0) && uid == 0)
|
|
{
|
|
uid = query.GetValue("identifier").Toint32(0);
|
|
req.ReqType = 0;
|
|
}
|
|
|
|
req.Id = id;
|
|
req.Uid = (uint)uid;
|
|
req.AccountType = 0;
|
|
//发送消息
|
|
OperationServerUtils.SendToWorld((int)SSGameMsgID.GmQueryUserRoleReq, ref req, uid, 0, "");
|
|
rsp.IsWaitFor = true;
|
|
|
|
return 0;
|
|
}
|
|
|
|
[RequestMapping("角色信息查询", PermissionCode.SELECT_ROLE, true, ignored: true)]
|
|
public static int OnSelectRoleHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
try
|
|
{
|
|
DoSelect(jsonData, rsp, request, query, httpContextId);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TraceLog.Error("SelectRole.ProccessRequest Error Msg {0}", ex.Message);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static int OnSelectRoleApiHttpReq(string httpApiCmd, JsonData jsonData, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)
|
|
{
|
|
try
|
|
{
|
|
DoSelect(jsonData, rsp, request, query, httpContextId);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TraceLog.Error("SelectRole.ProccessRequest Error Msg {0}", ex.Message);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
public static int OnSelectRoleHeroHttpReq(string httpApiCmd, JsonData jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, uint httpContextId)//, HttpContext httpContext)
|
|
{
|
|
TraceLog.Trace("SelectRole.OnSelectRoleHeroHttpReq Url{0},param count {1}", request.Url, query.Count);
|
|
|
|
string sign = query.GetValue("sign");
|
|
string reqData = HttpUtility.UrlDecode(query.GetValue("data"));
|
|
var allParams = new Dictionary<string, string>();
|
|
|
|
foreach (var item in query.m_map)
|
|
{
|
|
if (item.Key != "sign")
|
|
{
|
|
allParams[item.Key] = HttpUtility.UrlDecode(item.Value);
|
|
}
|
|
}
|
|
|
|
// 校验签名
|
|
string appKey = OperationServerUtils.GetServerConfig().heroAppKey;
|
|
string calcSign = HeroUSDKSecurity.CalcSign(appKey, allParams);
|
|
if (calcSign != sign)
|
|
{
|
|
TraceLog.Error("SelectRole.OnSelectRoleHeroHttpReq sign not same, calc {0} req {1}", calcSign, sign);
|
|
jsondata["msg"] = "签名校验错误!";
|
|
jsondata["code"] = -1;
|
|
return -1;
|
|
}
|
|
|
|
byte[] tmp = Convert.FromBase64String(reqData);
|
|
var reqDataStr = Encoding.UTF8.GetString(tmp);
|
|
TraceLog.Trace("SelectRole.OnSelectRoleHeroHttpReq :{0}", reqDataStr);
|
|
JsonData reqDataJson = JsonMapper.ToObject(reqDataStr);
|
|
|
|
int uid = reqDataJson["role_id"].ToString().Toint32(0);
|
|
int realmId = reqDataJson["server_id"].ToString().Toint32(0);
|
|
|
|
//int uid = query.GetValue("role_id").ToString().Toint32(0);
|
|
//int realmId = query.GetValue("server_id").ToString().Toint32(0);
|
|
|
|
TraceLog.Trace("SelectRole.OnSelectRoleHeroHttpReq - uid: {0},realmId: {1}", uid, realmId);
|
|
if (uid <= 0 || realmId <= 0)
|
|
{
|
|
jsondata["msg"] = "请求参数错误!";
|
|
jsondata["code"] = 1;
|
|
return 1;
|
|
}
|
|
|
|
//TODO
|
|
//httpContext.callbackArgs = new UidRelm { uid = uid, realmId =realmId };
|
|
|
|
SSGmQueryUserAccountInfoReq reqAc = new SSGmQueryUserAccountInfoReq();
|
|
reqAc.Id = httpContextId;
|
|
reqAc.ReqType = 1;
|
|
reqAc.Account.SetString(uid.ToString());
|
|
OperationServerUtils.SendToDBServer((int)SSGameMsgID.GmQueryUserAccountinfoReq, ref reqAc, 0, 0);
|
|
|
|
rsp.IsWaitFor = true;
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static void OnResMsgHero(uint id, JsonData jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, ref SSGmQueryUserAccountInfoRes res, object callBackArgs)
|
|
{
|
|
if (string.IsNullOrEmpty( res.AccountId.GetString()))
|
|
{
|
|
TraceLog.Error("SelectRole.OnResMsgHero res.AccountId is null! ");
|
|
jsondata["msg"] = "未查询到角色!";
|
|
jsondata["code"] = -1;
|
|
rsp.IsWaitFor = false;
|
|
return;
|
|
}
|
|
|
|
jsondata["msg"] = "success";
|
|
|
|
List<myRoleData> RoleList = new List<myRoleData>();
|
|
if (res.RoleList.Count == 0)
|
|
{
|
|
jsondata["msg"] = "未查询到角色!";
|
|
jsondata["code"] = 1;
|
|
rsp.IsWaitFor = false;
|
|
return;
|
|
}
|
|
|
|
int myUid = 0;
|
|
int myRealm = 0;
|
|
|
|
try
|
|
{
|
|
UidRelm myuidRealm = callBackArgs as UidRelm;
|
|
myUid = myuidRealm.uid;
|
|
myRealm = myuidRealm.realmId;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
TraceLog.Error("SelectRole.OnResMsgHero callBackArgs as UidRelm error:{0}! ", ex.Message);
|
|
jsondata["msg"] = "查询角色失败!";
|
|
jsondata["code"] = -1;
|
|
rsp.IsWaitFor = false;
|
|
return;
|
|
}
|
|
|
|
bool isTrue = true;
|
|
for (int i = 0; i < res.RoleList.Count; i++)
|
|
{
|
|
var Role = res.RoleList.Get(i);
|
|
|
|
if(myUid != Role.Uid || myRealm != Role.Realm)
|
|
{
|
|
// 这里查询结果只会又一个,所以break没问题的
|
|
isTrue = false;
|
|
break;
|
|
}
|
|
|
|
var roleItem = new myRoleData();
|
|
roleItem.server_id = Role.Realm.ToString();
|
|
roleItem.cpUid = Role.Uid.ToString();
|
|
roleItem.role_name = Role.Nick.GetString();
|
|
roleItem.cpExt = GetcpExt((int)Role.Realm);
|
|
roleItem.cUid = res.AccountId.GetString();
|
|
if(res.ChannelId != 0)
|
|
{
|
|
roleItem.cid = res.ChannelId.ToString();
|
|
}
|
|
else
|
|
{
|
|
roleItem.cid = "";
|
|
}
|
|
RoleList.Add(roleItem);
|
|
}
|
|
|
|
if (!isTrue)
|
|
{
|
|
jsondata["msg"] = "角色Id与服务器Id不匹配!";
|
|
jsondata["code"] = 2;
|
|
rsp.IsWaitFor = false;
|
|
return;
|
|
}
|
|
|
|
jsondata["data"] = JsonConfig.stringify(RoleList);
|
|
|
|
TraceLog.Trace("SelectRole.OnResMsgHero param {1}", jsondata["data"]);
|
|
|
|
jsondata["code"] = 0;
|
|
|
|
rsp.IsWaitFor = false;
|
|
|
|
return;
|
|
}
|
|
|
|
public static string GetcpExt(int realmId)
|
|
{
|
|
var allRealm = OperationServerUtils.GetOperationServerData().m_allRealm.Values.ToList();
|
|
int wordId = 0;
|
|
|
|
foreach (var realm in allRealm)
|
|
{
|
|
if (realm.realmId == realmId)
|
|
{
|
|
wordId = realm.WorldId;
|
|
break;
|
|
}
|
|
}
|
|
|
|
var msg = new HeroPayCpCustomMsg();
|
|
msg.worldId = wordId;
|
|
string json = JsonSerializer.Serialize(msg);
|
|
string cpExt = Convert.ToBase64String(Encoding.ASCII.GetBytes(json));
|
|
|
|
return cpExt;
|
|
}
|
|
|
|
public static void OnResMsgParse(uint id, JsonData jsondata, HttpResponse rsp, HttpRequest request, HttpQueryParams query, ref SSGmQueryUserRoletInfoRes res)
|
|
{
|
|
if (res.RoleBase.Uid == 0)
|
|
{
|
|
TraceLog.Error("SelectRole.OnResMsgHero res.RoleBase.uid == 0! ");
|
|
jsondata["msg"] = "未查询到角色!";
|
|
jsondata["code"] = -1;
|
|
return;
|
|
}
|
|
|
|
jsondata["RoleBase"] = res.RoleBase.ToString();
|
|
|
|
JsonData currencyData = new JsonData();
|
|
|
|
currencyData["Chip"] = res.RoleBase.Chip;
|
|
currencyData["Diamond"] = res.RoleBase.Diamond;
|
|
currencyData["HeroExp"] = res.RoleBase.HeroExpPool;
|
|
currencyData["VipExp"] = res.RoleBase.VipExp;
|
|
|
|
jsondata["Currency"] = currencyData;
|
|
|
|
JsonData rdata = new JsonData();
|
|
rdata["role_name"] = res.RoleBase.Nick.GetString();
|
|
rdata["server_id"] = res.DbRealmId;
|
|
rdata["cpUid"] = res.RoleBase.Uid;
|
|
|
|
jsondata["msg"] = "success";
|
|
jsondata["code"] = 0;
|
|
jsondata["data"] = rdata;
|
|
|
|
rsp.IsWaitFor = false;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|