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.
343 lines
18 KiB
343 lines
18 KiB
1 month ago
|
using System.Linq;
|
||
|
using Sog;
|
||
|
using SimpleHttpServer;
|
||
|
using ProtoCSStruct;
|
||
|
|
||
|
namespace Operation
|
||
|
{
|
||
|
public class HttpApiRootHandler : Singleton<HttpApiRootHandler>
|
||
|
{
|
||
|
private Route m_RouteConfig;
|
||
|
|
||
|
public Route Init()
|
||
|
{
|
||
|
Route rootRoute = new Route()
|
||
|
{
|
||
|
Name = "Root Handler",
|
||
|
UrlRegex = @"^/api/.*",
|
||
|
Method = "*",
|
||
|
Callable = this.ProcessRequest,
|
||
|
};
|
||
|
|
||
|
m_RouteConfig = rootRoute;
|
||
|
|
||
|
RegisterAllHttpApiCmd();
|
||
|
Resolver.Flusher();
|
||
|
WebsiteSvc.LoadDataFromFile();
|
||
|
|
||
|
return m_RouteConfig;
|
||
|
}
|
||
|
|
||
|
private void RegisterAllHttpApiCmd()
|
||
|
{
|
||
|
#region 公告
|
||
|
|
||
|
HttpApiMgr.Instance.Register("update_notice_backgrounds", SysNoticeBackgroungs.OnUpdateNoticeBackGroundsHttpReq, SysNoticeBackgroungs.DoUpdateNoticeBackGrounds);
|
||
|
HttpApiMgr.Instance.Register("del_notice_backgrounds", SysNoticeBackgroungs.OnDeleteNoticeBackGroundsHttpReq, SysNoticeBackgroungs.DoDeleteNoticeBackGrounds);
|
||
|
HttpApiMgr.Instance.Register("select_notice_backgrounds", SysNoticeBackgroungs.OnSelectNoticeBackGroundsHttpReq, SysNoticeBackgroungs.DoSelectNoticeBackGrounds);
|
||
|
HttpApiMgr.Instance.Register("update_notice_backgrounds_state", SysNoticeBackgroungs.OnUpdateNoticeBackGroundsStateHttpReq, SysNoticeBackgroungs.DoUpdateNoticeBackGroundsState);
|
||
|
HttpApiMgr.Instance.Register("update_notice", UpdateNotice.OnUpdateNoticeHttpReq, UpdateNotice.DoUpdateNotice);
|
||
|
HttpApiMgr.Instance.Register("del_notice", DeleteNotice.OnDeleteNoticeHttpReq, DeleteNotice.DoDeleteNotice);
|
||
|
HttpApiMgr.Instance.Register("ban_notice", UpdateNotice.OnBanNoticeHttpReq, UpdateNotice.DoBanNotice);
|
||
|
HttpApiMgr.Instance.Register("Doshownoticeday_notice", SelectNotice.OnShowNoticeDayNoticeHttpReq, SelectNotice.DoShowNoticeDayNotice);
|
||
|
HttpApiMgr.Instance.Register("SysNoticeLamp_send", SysNoticeLamp.OnSendNoticeLampHttpReq, SysNoticeLamp.DoSendNoticeLamp);
|
||
|
HttpApiMgr.Instance.Register("SysNoticeLamp_Select", SysNoticeLamp.OnSelectNoticeLampHttpReq, SysNoticeLamp.DoSelectNoticeLamp);
|
||
|
HttpApiMgr.Instance.Register("select_notice", SelectNotice.OnSelectNoticeHttpReq, SelectNotice.DoSelectNotice);
|
||
|
HttpApiMgr.Instance.Register("get_notice_jumplist", GetInfo.GetDescInfo, null);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 封号禁言
|
||
|
|
||
|
HttpApiMgr.Instance.Register("lift_ban", BanUser.OnUnBanUserChatReq, null);
|
||
|
HttpApiMgr.Instance.Register("banuser", BanUser.OnBanUserChatReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_banUser", SelectBanUser.OnSelectBanUserHttpReq, SelectBanUser.DoSelectBanUser);
|
||
|
HttpApiMgr.Instance.Register("banPlayer", BanUser.OnBanPlayerReq, null);
|
||
|
HttpApiMgr.Instance.Register("unbanPlayer", BanUser.OnUnBanPlayerReq, null);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 兑换码
|
||
|
|
||
|
HttpApiMgr.Instance.Register("create_exchangecode", Exchange.OnCreateExchangeHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("export_exchangecode", Exchange.OnExportExchangeHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("update_exchangecode_group", Exchange.OnUpdateExchangeGroupHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_exchange", Exchange.OnSelectExchangeHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("add_exchange", Exchange.OnAddExchangeHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("DoDisable_exchange", Exchange.OnDisableExchangeHttpReq, null);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 邮件
|
||
|
|
||
|
HttpApiMgr.Instance.Register("recall_email", RecalledEmail.OnRecalledEmailHttpReq, RecalledEmail.DoRecalledEmail);
|
||
|
HttpApiMgr.Instance.Register("send_email_hero", SendEmail.SendEmailHero, null);
|
||
|
HttpApiMgr.Instance.Register("select_email", SelectEmail.OnSelectEmailHttpReq, SelectEmail.DoSelectEmail);
|
||
|
HttpApiMgr.Instance.Register("send_email", SendEmail.OnSendEmailHttpReq, SendEmail.DoSendEmail);
|
||
|
HttpApiMgr.Instance.Register("sendMail", SendEmail.OnSendMailHttpReq, SendEmail.DoSendMail);
|
||
|
HttpApiMgr.Instance.Register("review_mail", SendEmail.OnReviewMailHttpReq, SendEmail.DoReviewMail);
|
||
|
HttpApiMgr.Instance.Register("delete_refuse_mail", SendEmail.OnDeleteRefuseMailHttpReq, SendEmail.DoDeleteRefuseMail);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 配置
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_itemlist", GameData.OnGetItemListHttpReq, null);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_item_cost", GameData.OnGetItemCostHttpReq, GameData.DoOnGetItemCostHttpRes);
|
||
|
HttpApiMgr.Instance.Register("insert_item_cost", GameData.OnInsertItemCostHttpReq, GameData.DoOnInsertItemCost);
|
||
|
HttpApiMgr.Instance.Register("delete_item_cost", GameData.OnDeleteItemCostHttpReq, GameData.DoOnDeleteItemCost);
|
||
|
HttpApiMgr.Instance.Register("select_game_data", GameData.OnGetGameDataConfigHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_game_table", GameData.OnGetGameDataConfigNamesHttpReq, null);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_game_table_diff", DiffGameData.OnGetDiffDirListHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_context_diff", DiffGameData.OnGetDiffContextListHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("bak_game_cfg_data", DiffGameData.OnBakGameDataHttpReq, null);
|
||
|
|
||
|
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_paydiamond", GMPayment.OnGetPayDiamondListHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("add_payment", GMPayment.OnInsertPaymentHttpReq, GMPayment.OnInsertPaymentHttpRes);
|
||
|
HttpApiMgr.Instance.Register("select_payment_list", GMPayment.OnGetPaymentListHttpReq, GMPayment.OnGetPaymentListHttpRes);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("unlock_player_weekly_bp", PlayerMonitor.OnUnlockPlayerWeeklyBp, GMPayment.OnInsertPaymentHttpRes);
|
||
|
HttpApiMgr.Instance.Register("update_player_task", PlayerMonitor.OnDoneTaskReq, null);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 区服
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_realmInfos", Realm.OnSelectRealmInfosHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_allrealms", Realm.OnSelectAllRealmHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("add_realm", Realm.OnAddNewRealmHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_recentRealm", Realm.OnSelectRecentRealmHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_recentOperationRealm", Realm.OnSelectRecentOperationRealmHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("send_realmlist", Realm.SendRealmInfosHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("add_realmInfo", Realm.OnAddRealmInfoHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("commit_realmInfo", Realm.OnCommitRealmInfoHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_realmlist", Realm.OnSelectRealmListHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_realmlist_hero", Realm.OnSelectRealmlistHeroHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_realmlist_pay", Realm.OnSelectRealmlistWebPayHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("servers", Realm.OnSelectServerListHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("realmlist_operation", Realm.OnRealmOptionHttpReq, null);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("ip_device_limit", Limit.OnSelectLimitIpHttpReq, null);
|
||
|
#endregion
|
||
|
|
||
|
#region 玩家角色
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_role", SelectRole.OnSelectRoleHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("roleinfo", SelectRole.OnSelectRoleApiHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_role_hero", SelectRole.OnSelectRoleHeroHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_heros", SelectRole.OnSelectHerosHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_bag", SelectBag.OnSelectBagHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_cus", SelectCus.OnSelectCusHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("cost_bag_item", SelectBag.DoCostBagItem, null);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("player_monitor", PlayerMonitor.OnPlayerMonitorHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("player_role_field", PlayerMonitor.OnGetRoleDataProp, null);
|
||
|
HttpApiMgr.Instance.Register("delete_player_mail", PlayerMonitor.OnDeletePlayerMailHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("update_role_data", PlayerMonitor.UpdateRoleDataHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("import_role_data", PlayerMonitor.OnImportRoleDataHttpReq, null);
|
||
|
|
||
|
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_item", SelectBag.OnSelectItemHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("playerop", PlayerInfoOp.OnInsertPlayerOpHttpReq, PlayerInfoOp.DoInsertPlayerOp);
|
||
|
HttpApiMgr.Instance.Register("select_playerop", PlayerInfoOp.OnSelectPlayerOpHttpReq, PlayerInfoOp.DoSelectPlayerOp);
|
||
|
HttpApiMgr.Instance.Register("querypayrecord", QueryPayRecord.OnQueryPayRecordHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("install", InstallData.OnInstallDataHttpReq, null);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_hero_skin", SelectRole.OnSelectHeroSkinHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("changeName", ChangeName.OnChangeNameHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_accountinfo", SelectAccount.OnSelectAccountInfoHttpReq, null);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 预设
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_preset", PlayerPresetOp.OnSelectPresetHttpReq, PlayerPresetOp.DoSelectPreset);
|
||
|
HttpApiMgr.Instance.Register("update_preset", PlayerPresetOp.OnInsertPresetHttpReq, PlayerPresetOp.DoInsertPreset);
|
||
|
HttpApiMgr.Instance.Register("delete_preset", PlayerPresetOp.OnDeletePresetHttpReq, PlayerPresetOp.DoDeletePreset);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
#region 活动
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_activity", SelectActivity.OnSelectActivityHttpReq, null);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 聊天
|
||
|
|
||
|
HttpApiMgr.Instance.Register("reload_chat", ChatLog.OnReloadChatFile, null);
|
||
|
HttpApiMgr.Instance.Register("chat_list", ChatLog.OnGetChatListHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("download_chat", ChatLog.OnDownloadChatListCsvHttpReq, null);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 服务器数据
|
||
|
|
||
|
HttpApiMgr.Instance.Register("server_monitor", ServerMonitor.OnHttpServerMonitorReq, null);
|
||
|
HttpApiMgr.Instance.Register("gm_command", ServerMonitor.OnHttpGMCommandReq, null);
|
||
|
HttpApiMgr.Instance.Register("gate_monitor", ServerMonitor.OnHttpGateMonitorReq, null);
|
||
|
HttpApiMgr.Instance.Register("gate_push", ServerMonitor.OnHttpGateInfoPush, null);
|
||
|
|
||
|
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_server_cfg", ServerMonitor.OnHttpGetServerCfgReq, null);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_website", Website.OnSelectWebsiteHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("update_website", Website.OnUpdateWebsiteHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("select_feature_switch", Website.OnSelectFeatureHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("update_feature_switch", Website.OnUpdateFeatureHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("gm_reward", GMReward.OnReward, null);
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
#region 系统管理 (账号,权限、菜单、角色)
|
||
|
|
||
|
HttpApiMgr.Instance.Register("index", Admin.IndexHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("server_api_list", Admin.OnApiListHttpReq, null);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_language", SelectNotice.OnSelectLanguageAbbrCfgHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("login", Login.OnLoginHttpReq, Login.DoLogin);
|
||
|
HttpApiMgr.Instance.Register("logout", Login.OnLogoutHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("delete_account", DelAccount.OnDeleteAccountHttpReq, DelAccount.DoDelAccount);
|
||
|
HttpApiMgr.Instance.Register("check_token", null, null);
|
||
|
HttpApiMgr.Instance.Register("auth", null, null);
|
||
|
HttpApiMgr.Instance.Register("operation_log", OperationLog.OnSelectOperationLogHttpReq, OperationLog.DoSelectOperationLog);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("select_menus", Admin.OnSelectMenuHttpReq, null);
|
||
|
|
||
|
HttpApiMgr.Instance.Register("menus_manager", Admin.OnSelectAllMenuHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("all_role", Admin.OnSelectAllRoleHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("create_role", Admin.OnCreateRoleHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("update_role", Admin.OnUpdateRoleHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("delete_role", Admin.OnDeleteRoleHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("all_permission", Admin.OnSelectAllPermissionHttpReq, null);
|
||
|
HttpApiMgr.Instance.Register("all_account", Admin.OnSelectAllAccountHttpReq, Admin.DoSelectAllAccount);
|
||
|
HttpApiMgr.Instance.Register("create_account", Admin.OnCreateAccountHttpReq, Admin.DoCreateAccount);
|
||
|
HttpApiMgr.Instance.Register("register", Admin.OnRegisterAccountHttpReq, Admin.DoCreateAccount);
|
||
|
HttpApiMgr.Instance.Register("update_account_role", Admin.OnUpdateAccountRoleHttpReq, null);
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
public void Dispose()
|
||
|
{
|
||
|
TraceLog.Debug("HttpApiRootHandler be disposed");
|
||
|
HttpApiMgr.Instance.ClearAll();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
private void ProcessRequest(HttpContext httpContext)
|
||
|
{
|
||
|
TraceLog.Trace("HttpApiRootHandler.ProccessRequest Method {0} url {1}", httpContext.httpRequest.Method,
|
||
|
httpContext.httpRequest.Url);
|
||
|
|
||
|
string reUrl = httpContext.httpRequest.Url;
|
||
|
if (GetFunctionNameByUrl(reUrl) == null)
|
||
|
{
|
||
|
reUrl = reUrl + "?";
|
||
|
}
|
||
|
|
||
|
string funName = GetFunctionNameByUrl(reUrl);
|
||
|
if (funName == "uploadclienterror")
|
||
|
{
|
||
|
httpContext.httpResponse = new HttpErrorlogList().ProcessRequest(httpContext.httpRequest);
|
||
|
}
|
||
|
|
||
|
HttpQueryParams queryParams = new HttpQueryParams(httpContext.httpRequest.Url);
|
||
|
|
||
|
httpContext.httpResponse = new HttpResponse
|
||
|
{
|
||
|
ContentAsUTF8 = "no process",
|
||
|
ReasonPhrase = "OK",
|
||
|
StatusCode = "200"
|
||
|
};
|
||
|
|
||
|
LitJson.JsonData builder = new LitJson.JsonData();
|
||
|
string token = queryParams.GetValue("token");
|
||
|
var hasPermission = AdminSvc.HasPermission(token, funName);
|
||
|
if (!hasPermission)
|
||
|
{
|
||
|
//所有权限统一在这个地方
|
||
|
var account = OperationServerUtils.GetAccount(token);
|
||
|
builder["code"] = -1;
|
||
|
builder["ret"] = 1;
|
||
|
builder["msg"] = "暂无权限操作";
|
||
|
string contJson = builder.ToJson();
|
||
|
httpContext.httpResponse.ContentAsUTF8 = contJson;
|
||
|
TraceLog.Error("HttpApiRootHandler.ProccessRequest permission denied account={0},funName={1}",
|
||
|
account, funName);
|
||
|
return; //这里必须return掉
|
||
|
}
|
||
|
builder["code"] = 0;
|
||
|
builder["ret"] = 0;
|
||
|
builder["msg"] = "Succeed";
|
||
|
HttpApiMgr.Instance.HandlerHttpApiFunction(funName, builder, httpContext.httpResponse,
|
||
|
httpContext.httpRequest, queryParams, httpContext.id);
|
||
|
|
||
|
string contentJson = builder.ToJson();
|
||
|
httpContext.httpResponse.ContentAsUTF8 = contentJson;
|
||
|
|
||
|
TraceLog.Trace("HttpApiRootHandler.ProccessRequest http fun {0} return content {1}", funName, contentJson);
|
||
|
}
|
||
|
|
||
|
public static void OnHttpApiDbReq(uint serverID, StructPacket packet, DBOperator dbOperator)
|
||
|
{
|
||
|
ref var req = ref packet.GetMessage<SSHttpApiDbReq>();
|
||
|
|
||
|
string funName = req.HttpApiCmd.GetString();
|
||
|
|
||
|
TraceLog.Debug("HttpApiRootHandler.OnHttpApiDbReq httpApiCmd {0} dataLen {1}", funName, req.Data.Count);
|
||
|
|
||
|
HttpApiMgr.Instance.HandlerHttpApiDbReqFunction(funName, req, dbOperator);
|
||
|
}
|
||
|
|
||
|
public static void FillHttpApiDbReq2MessageTaskDistributor(string httpApiCmd, uint httpContextId,
|
||
|
ref RepeatedFixedStructString128_10 data)
|
||
|
{
|
||
|
StructPacket packet = new StructPacket();
|
||
|
packet.Header.Type = (int)SSGameMsgID.HttpApiDbReq;
|
||
|
|
||
|
StructMessageParser<SSHttpApiDbReq> parser = new StructMessageParser<SSHttpApiDbReq>();
|
||
|
packet.Parser = parser;
|
||
|
|
||
|
ref SSHttpApiDbReq req = ref parser.GetMessage();
|
||
|
req.HttpContextId = httpContextId;
|
||
|
req.HttpApiCmd.SetString(httpApiCmd);
|
||
|
req.Data.CopyFrom(ref data);
|
||
|
|
||
|
uint serverId = OperationServerUtils.GetPacketSender().GetPlayerOpServerIDServerID();
|
||
|
OperationMsgHandler.AddMessageTaskDistributor(req.HttpContextId, serverId, packet);
|
||
|
}
|
||
|
|
||
|
private string GetFunctionNameByUrl(string url)
|
||
|
{
|
||
|
// "/api/xxxxxxxxxx?param1=yyyy¶m2=zzzzz"
|
||
|
int indexend = url.IndexOf('?');
|
||
|
if (indexend == -1)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string newurl = url.Substring(5, indexend - 5);
|
||
|
|
||
|
if (newurl.IndexOf("/") == -1)
|
||
|
{
|
||
|
return newurl;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return newurl.Substring(0, newurl.IndexOf("/"));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|