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.
 
 
 
 
 
 

572 lines
23 KiB

using ProtoCSStruct;
using Sog;
using Sog.Log;
namespace Game
{
public static class GameBDCLogUtils
{
private static readonly string Android = "ANDROID";
private static readonly string IOS = "IOS";
private static readonly string PC = "PC";
private static string GetBdcOs(PlatformType platform)
{
switch (platform)
{
case PlatformType.PlatformType_Android:
return Android;
case PlatformType.PlatformType_IOS:
return IOS;
case PlatformType.PlatformType_Windows:
return PC;
default:
return PC;
}
}
// 业务逻辑通用参数
public static void InitBusinessLogHead(BDCLogHelper bdc, PlayerOnGame player,
string transaction_id = "0", long buess_time = 0)
{
var nowSec = GameServerUtils.GetTimeSecond();
string userId = player.AccountInfo.AccountID.GetString();
bdc.Append("user_id", userId);
bdc.Append("open_id", userId);
bdc.Append("role_id", player.UserID);
bdc.Append("role_key", player.UserID);
string realmBdcName = null;
foreach (RealmBriefInfo info in GameServerUtils.GetGameServerData().m_configRealm)
{
if (info.realmId == player.RealmID)
{
realmBdcName = info.realmBdcName;
break;
}
}
// serverId填区服名称
bdc.Append("server_id", string.IsNullOrEmpty(realmBdcName) ? "0" : realmBdcName);
bdc.Append("client_os", GetBdcOs(player.Platform));
bdc.Append("device_id", string.IsNullOrEmpty(player.deviceIdBdc) ? player.deviceId : player.deviceIdBdc);
bdc.Append("user_ip", string.IsNullOrEmpty(player.loginIpAddr) ? "0" : player.loginIpAddr);
bdc.Append("channel_id", player.channelId);
bdc.Append("app_channel_id", player.appChannelIdBdc);
// 业务发生时间
bdc.Append("buess_time", buess_time == 0 ? nowSec : buess_time);
// 同一行为触发的多个日志使用同一个关联ID
bdc.Append("transaction_id", transaction_id);
//bdc参数
ref var playerBdc = ref player.clientInfo.bdcData;
bdc.Append("bdc_device_id", playerBdc.Bdc_device_id.ToString());
bdc.Append("deviceid_type", playerBdc.Deviceid_type.ToString());
bdc.Append("device_key", playerBdc.Device_key.ToString());
bdc.Append("device_model", playerBdc.Device_model.ToString());
bdc.Append("ime", playerBdc.Ime.ToString());
bdc.Append("gaid", playerBdc.Gaid.ToString());
bdc.Append("idfa", playerBdc.Idfa.ToString());
bdc.Append("idfv", playerBdc.Idfv.ToString());
bdc.Append("android_id", playerBdc.Android_id.ToString());
bdc.Append("oaid", playerBdc.Oaid.ToString());
bdc.Append("sdk_version", playerBdc.Sdk_version.ToString());
bdc.Append("bdc_client_os", playerBdc.Bdc_client_os.ToString());
bdc.Append("old_device_id", playerBdc.Old_device_id.ToString());
// 以下是接口通用参数, 由BillLogServer负责填写
//sb.Append("event_uuid="); // 日志记录唯一标志码,防止记录重复生成
//sb.Append("event_time="); // 事件上传时间, 1532595738
//sb.Append("event_time2="); // 事件上传时间, 2018-07-26
//sb.Append("appkey="); // appkey
//sb.Append("platform="); // SERVER|SERVER_TEST
}
public static void UserInfo(PlayerOnGame player, long buess_time = 0)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.UserInfo);
InitBusinessLogHead(bdc, player, "0", buess_time);
bdc.Append("role_name", player.GetNick());
bdc.Append("role_level", player.GetLevel());
bdc.Append("vip_level", player.GetVipLevel());
bdc.Append("sex", player.RoleBase.Gender);
bdc.Append("free_diamond_balance", player.RoleBase.Diamond);
bdc.Append("donate_diamond_balance", 0);
bdc.Append("charge_diamond_balance", 0);
bdc.Append("month_card_balance", 0);
bdc.Append("register_ip", player.accountCreateIpStr);
bdc.Append("accountregister_time", player.accountCreateTime);
bdc.Append("userregister_time", player.RoleBase.CreateTime);
bdc.Append("userlast_active_time", player.PingInfo.LastRecvPingTime);
bdc.Append("total_charge", 0);
bdc.Append("currency_info", PlayerUtils.GetCurrencyJson(player));
bdc.Append("status_info", "{}");
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.UserInfo);
}
/// <summary>
/// 金额转换
/// </summary>
/// <param name="money"></param>
/// <returns></returns>
private static string GetMoneyStr(uint money)
{
float fAmount = (float)money / 100;
return fAmount.ToString("f2");
}
/// <summary>
/// 金额转换
/// </summary>
/// <param name="money"></param>
/// <returns></returns>
private static string GetMoneyStr(long money)
{
double dAmount = (double)money / 100;
return dAmount.ToString("f2");
}
// 充值信息
public static void ChargeInfo(PlayerOnGame player, ref DBPaySuccWaitAddRole data, int bdc_product_type, bool firstPay)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.ChargeInfo);
InitBusinessLogHead(bdc, player);
bdc.Append("role_name", player.GetNick());
bdc.Append("role_level", player.GetLevel());
bdc.Append("vip_level", player.GetVipLevel());
// 聚合SDK订单号
bdc.Append("order_id", data.OrderId3rd.GetString());
// 游戏订单号
bdc.Append("game_order_id", data.OrderId.GetString());
// 商品id
bdc.Append("product_id", data.ItemID);
// 档位类型
bdc.Append("product_type", bdc_product_type);
// 玩家累计充值金额
bdc.Append("total_charge", GetMoneyStr(player.RoleData.PayData.TotalPayMoneyUSD));
// 金额
bdc.Append("amount", GetMoneyStr(data.Amount));
// 货币单位
bdc.Append("unit", data.Currency.GetString());
// 充值时间
bdc.Append("pay_time", data.PayTime3rd);
// 到账时间
bdc.Append("get_time", GameServerUtils.GetTimeSecond());
// 获得代币类型
bdc.Append("money_type", (int)CurrencyType.Diamond);
// 付款方式, 1是SDK支付 2是测试支付
bdc.Append("payment_method", data.IsTestPay == 0 ? 1 : 2);
uint payDiamond = 0;
long freeDiamond = 0;
var descPay = PayDiamondDescMgr.Instance.GetConfig(data.ItemID);
if (descPay != null)
{
payDiamond = descPay.payDiamond + descPay.diamond;
}
bdc.Append("extra_get1", data.DiamondExchange);
bdc.Append("extra_get2", freeDiamond);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.ChargeInfo);
}
// 账号登录
public static void UserLogin(PlayerOnGame player)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.UserLogin);
InitBusinessLogHead(bdc, player);
// 账号下各类代币持有数量json,如果为空,请填{}
bdc.Append("user_balance", "{}");
bdc.Append("ads_json", "0");
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.UserLogin);
}
// 创建角色
public static void CreateRole(PlayerOnGame player)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.CreateRole);
InitBusinessLogHead(bdc, player);
bdc.Append("character_id", player.RoleBase.Uid);
bdc.Append("role_name", player.RoleBase.Nick.GetString());
bdc.Append("role_extra", "0");
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.CreateRole);
}
public static void RoleLogin(PlayerOnGame player)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.RoleLogin);
InitBusinessLogHead(bdc, player);
bdc.Append("free_diamond_balance", player.RoleBase.Diamond);
bdc.Append("donate_diamond_balance", 0);
bdc.Append("charge_diamond_balance", 0);
bdc.Append("gold_balance", player.RoleBase.Chip);
bdc.Append("login_situation", 0);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("vip_level", player.RoleBase.VipLevel);
bdc.Append("ads_json", "0");
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.RoleLogin);
}
public static void RoleLogout(PlayerOnGame player)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.RoleLogout);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("vip_level", player.RoleBase.VipLevel);
bdc.Append("free_diamond_balance", player.RoleBase.Diamond);
bdc.Append("donate_diamond_balance", 0);
bdc.Append("charge_diamond_balance", 0);
bdc.Append("gold_balance", player.RoleBase.Chip);
bdc.Append("final_scene", 0);
bdc.Append("final_action", 0);
bdc.Append("online_time", player.CurrOnlineTime);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.RoleLogout);
}
public static void GetMoney(PlayerOnGame player, int moneyType, int beforBalance, int afterBanlance, int reasonID, string reasonInfo)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.GetMoney);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("vip_level", player.RoleBase.VipLevel);
bdc.Append("before_balance", beforBalance);
bdc.Append("after_balance", afterBanlance);
bdc.Append("money_type", moneyType);
bdc.Append("reason_id", reasonID);
bdc.Append("reason_info", reasonInfo);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.GetMoney);
}
public static void RemoveMoney(PlayerOnGame player, int moneyType, int beforBalance, int afterBanlance, int reasonID, string reasonInfo)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.RemoveMoney);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("vip_level", player.RoleBase.VipLevel);
bdc.Append("before_balance", beforBalance);
bdc.Append("after_balance", afterBanlance);
bdc.Append("money_type", moneyType);
bdc.Append("reason_id", reasonID);
bdc.Append("reason_info", reasonInfo);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.RemoveMoney);
}
public static void NewGuide(PlayerOnGame player, int guideId, int guideNum)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.NewGuide);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("guide_id", guideId);
bdc.Append("guide_num", guideNum);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.NewGuide);
}
public static void GetItem(PlayerOnGame player, int productType, int productId, int productNum,
int beforBalance, int afterBanlance, int subType, int reasonID, string reasonInfo,
int productGuid, int bindingState, string productInfo)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.GetItem);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("vip_level", player.RoleBase.VipLevel);
bdc.Append("product_type", productType);
bdc.Append("product_id", productId);
bdc.Append("product_num", productNum);
bdc.Append("before_balance", beforBalance);
bdc.Append("after_balance", afterBanlance);
bdc.Append("sub_type", subType);
bdc.Append("reason_id", reasonID);
bdc.Append("reason_info", reasonInfo);
bdc.Append("product_guid", productGuid);
bdc.Append("binding_state", bindingState);
bdc.Append("product_info", productInfo);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.GetItem);
}
public static void RemoveItem(PlayerOnGame player, int productType, int productId, int productNum,
int beforBalance, int afterBanlance, int subType, int reasonID, string reasonInfo,
int productGuid, int bindingState, string productInfo)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.RemoveItem);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("vip_level", player.RoleBase.VipLevel);
bdc.Append("product_type", productType);
bdc.Append("product_id", productId);
bdc.Append("product_num", productNum);
bdc.Append("before_balance", beforBalance);
bdc.Append("after_balance", afterBanlance);
bdc.Append("sub_type", subType);
bdc.Append("reason_id", reasonID);
bdc.Append("reason_info", reasonInfo);
bdc.Append("product_guid", productGuid);
bdc.Append("binding_state", bindingState);
bdc.Append("product_info", productInfo);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.RemoveItem);
}
public static void ShopBuy(PlayerOnGame player, int productType, string productId, int productNum, string costInfo, int shopType)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.ShopBuy);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("vip_level", player.RoleBase.VipLevel);
bdc.Append("product_type", productType);
bdc.Append("product_id", productId);
bdc.Append("product_num", productNum);
bdc.Append("money_type", 0);
bdc.Append("buy_cost", 0);
bdc.Append("shop_type", shopType);
bdc.Append("cost_info", costInfo);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.ShopBuy);
}
public static void PVEEnter(PlayerOnGame player, int mainlandType, int mainlandId, string mainlandName, string heros, int teamId)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.PVEEnter);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("pve_type", mainlandType);
bdc.Append("pve_id", mainlandId);
if (mainlandName == null || mainlandName == "")
{
bdc.Append("pve_name", "No Name Mainland");
}
else
{
bdc.Append("pve_name", mainlandName);
}
bdc.Append("team_id", teamId);
bdc.Append("lineup", heros);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.PVEEnter);
}
//public static void PVEComplete(PlayerOnGame player, MainlandDesc desc, string heros,
// int teamId, int isWin, int completeType, int fightTime, int grade, string teamInfo)
//{
// var bdc = new BDCLogHelper((int)BDCLogEventId.PVEComplete);
// InitBusinessLogHead(bdc, player);
// bdc.Append("role_level", player.RoleBase.Level);
// bdc.Append("pve_type", desc.mainlandType);
// //地牢单独上传
// //if(desc.mainlandType == (int)MainlandType.Dungeon)
// //{
// // bdc.Append("pve_subtype", player.RoleData.Dungeon.CurDungeonId);
// //}
// //else
// {
// bdc.Append("pve_subtype", desc.subtype);
// }
// bdc.Append("pve_id", desc.id);
// if (desc.name == "")
// {
// bdc.Append("pve_name", "No Name Mainland");
// }
// else
// {
// bdc.Append("pve_name", desc.name);
// }
// bdc.Append("team_id", teamId);
// bdc.Append("lineup", heros);
// bdc.Append("team_info", teamInfo);
// bdc.Append("iswin", isWin);
// bdc.Append("complete_type", completeType);
// bdc.Append("fight_time", fightTime);
// bdc.Append("grade", grade);
// BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.PVEComplete);
//}
public static void ExpChange(PlayerOnGame player, int point, int pointBefore, int pointAfter, int durationTime)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.ExpChange);
InitBusinessLogHead(bdc, player);
bdc.Append("point", point);
bdc.Append("point_before", pointBefore);
bdc.Append("point_after", pointAfter);
bdc.Append("duration_time", durationTime);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.ExpChange);
}
public static void ReceiveQuest(PlayerOnGame player, int taskType, int taskId)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.ReceiveQuest);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("task_type", taskType);
bdc.Append("task_id", taskId);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.ReceiveQuest);
}
public static void FinishQuest(PlayerOnGame player, int taskType, int taskId, string rewardsInfo)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.FinishQuest);
InitBusinessLogHead(bdc, player);
bdc.Append("role_level", player.RoleBase.Level);
bdc.Append("task_type", taskType);
bdc.Append("task_id", taskId);
bdc.Append("rewards_info", rewardsInfo);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.FinishQuest);
}
public static int GetActivityLogTypeByTaskType(int taskType)
{
//if (taskType == (int)TaskType.TimeLimit)
//{
// return (int)ActivityLogType.TimeLimit;
//}
//if (taskType == (int)TaskType.BaseActivity)
//{
// return (int)ActivityLogType.BaseActivity;
//}
return 0;
}
public static void ActivityTaskComplete(PlayerOnGame player, int taskType, int activityId, int taskId)
{
int actType = GetActivityLogTypeByTaskType(taskType);
if (actType > 0)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.ActivityTaskComplete);
InitBusinessLogHead(bdc, player);
bdc.Append("activity_type", actType);
bdc.Append("activity_id", activityId);
bdc.Append("task_id", taskId);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.ActivityTaskComplete);
}
}
public static void HerosSnapshot(PlayerOnGame player, long buess_time = 0)
{
var bdc = new BDCLogHelper((int)BDCLogEventId.HerosSnapshot);
InitBusinessLogHead(bdc, player,"0", buess_time);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString(), (int)BDCLogEventId.HerosSnapshot);
}
/*
public static void DungeonBattleBDCLog(PlayerOnGame player, int mainlandId, int result)
{
ref DBDungeon dungeon = ref player.RoleData.Dungeon;
int deathCount = 0;
for (int i = 0; i < dungeon.HeroInfo.Heros.Count; i++)
{
if (dungeon.HeroInfo.Heros[i].Hp <= 0)
{
deathCount++;
}
}
var bdc = new BDCLogHelper((int)BDCLogEventId.DungeonBattle);
InitBusinessLogHead(bdc, player);
bdc.Append("dungeon_id", dungeon.CurDungeonId);
bdc.Append("dungeon_diffculty", dungeon.Diffculty);
bdc.Append("dungeon_layerindex", dungeon.NowLayerIndex);
bdc.Append("main_mainlandid", player.RoleData.Mainland.MaxPassed.Mainline);
bdc.Append("dungeon_mainlandid", mainlandId);
bdc.Append("dungeon_deathcount", deathCount);
bdc.Append("dungeon_result", result);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString());
}
public static void DungeonExitBDCLog(PlayerOnGame player)
{
ref DBDungeon dungeon = ref player.RoleData.Dungeon;
int deathCount = 0;
for (int i = 0; i < dungeon.HeroInfo.Heros.Count; i++)
{
if (dungeon.HeroInfo.Heros[i].Hp <= 0)
{
deathCount++;
}
}
var bdc = new BDCLogHelper((int)BDCLogEventId.DungeonExit);
InitBusinessLogHead(bdc, player);
bdc.Append("dungeon_id", dungeon.CurDungeonId);
bdc.Append("dungeon_diffculty", dungeon.Diffculty);
bdc.Append("dungeon_layerindex", dungeon.NowLayerIndex);
bdc.Append("main_mainlandid", player.RoleData.Mainland.MaxPassed.Mainline);
bdc.Append("dungeon_deathcount", deathCount);
//bdc.Append("dungeon_enterOrExit", op);
BillLogWriter.Instance.SendBDCToBillLogSvr(player.UserID, bdc.ToString());
}
*/
}
}