using System;
using ProtoCSStruct;
using ThinkingData.Analytics;
namespace Sog.Log
{
///
/// 把运营日志写到BillLogServer
///
public class BillLogWriter : Singleton
{
//taSdk暂时放在这把
public ThinkingdataAnalytics m_taSdk = new ThinkingdataAnalytics(new SogConsumer(), true);
private uint m_billLogSvrID;
private StructPacketSender m_structPacketSender;
SSBillLogReq billLogReq = new SSBillLogReq();
SSBDCLogReq bdcLogReq = new SSBDCLogReq();
SSTALogReq taLogReq = new SSTALogReq();
public void Init(uint serverID, StructPacketSender packetSender)
{
// cluster层的accountbill有主备两套, 根据instId来连接
if (ServerIDUtils.GetWorldID(serverID) == 0)
{
int clusterInstId = (int)ServerIDUtils.GetInstanceID(serverID);
m_billLogSvrID = ServerIDUtils.GetLevel0ServerIDByType((int)ServerType.AccountBillLog, clusterInstId);
}
else
{
m_billLogSvrID = ServerIDUtils.GetLevel1ServerIDByType(serverID, (int)ServerType.BillLog, 1);
}
m_structPacketSender = packetSender;
}
public ThinkingdataAnalytics GetTASDK()
{
return m_taSdk;
}
public void SendCliToBillBDCLogSvr(StructPacket packet)
{
m_structPacketSender.SendToServerByID(m_billLogSvrID, packet);
}
///
/// 注意,这个不是线程安全的
///
///
///
public void SendToBillLogSvr(long uid, string logMessage)
{
TraceLog.UserTrace(uid, "BillLogWriter.SendToBillLogSvr {0}", logMessage);
billLogReq.Clear();
billLogReq.StrLogMessage.SetString(logMessage);
m_structPacketSender.SendToServerByID(m_billLogSvrID
, (int)SSGameMsgID.BillLogReq
, ref billLogReq
, uid
, 0);
}
public void SendBDCToBillLogSvr(long uid, string logMessage, int eventId)
{
//TraceLog.UserTraceDetail(uid, "BillLogWriter.SendBDCToBillLogSvr {0}", logMessage);
bdcLogReq.Clear();
bdcLogReq.LogMsg.SetString(logMessage);
bdcLogReq.EventId = eventId;
//m_structPacketSender.SendToServerByID(m_billLogSvrID, (int) CSGameMsgID.LogClientBdcReq, ref bdcLogReq, uid);
m_structPacketSender.SendToServerByID(m_billLogSvrID, (int) SSGameMsgID.BdcLogReq, ref bdcLogReq, uid);
}
public void SendCliToBillTALogSvr(StructPacket packet)
{
m_structPacketSender.SendToServerByID(m_billLogSvrID, packet);
}
public void SendTAToBillLogSvr(long uid, string logMessage, string event_name)
{
//TraceLog.UserTraceDetail(uid, "BillLogWriter.SendBDCToBillLogSvr {0}", logMessage);
taLogReq.Clear();
taLogReq.LogMsg.SetString(logMessage);
if(!string.IsNullOrEmpty(event_name))
{
taLogReq.EventName.SetString(event_name);
}
//m_structPacketSender.SendToServerByID(m_billLogSvrID, (int) CSGameMsgID.LogClientBdcReq, ref bdcLogReq, uid);
m_structPacketSender.SendToServerByID(m_billLogSvrID, (int)SSGameMsgID.TaLogReq, ref taLogReq, uid);
}
}
}