using Sog; using ProtoCSStruct; using System.ComponentModel; namespace Battle { public class BattleMsgHandler : BaseReloadableService { private ServerApp m_app; public override int GetServiceType() { return BattleServiceType.BattleMsgHandler; } //销毁的时候置空,提高垃圾回收效率 public override void Dispose() { m_app = null; } public BattleMsgHandler(ServerApp app) { m_app = app; } public ServerApp GetApp() { return m_app; } public void HandlerMessage(uint remoteAppID, MessageData message) { StructPacket packet; bool bSuccess = BattleServerUtils.GetProtoPacker().UnpackMessage(message, out packet); if (bSuccess == false) { TraceLog.Error("BattleMsgHandler.HandlerMessage, unpack msg failed {0}, remoteAppID {1}" , message.Header.Type, remoteAppID); return; } //预先判断,提高效率 if (TraceLog.GetLogLevel() <= (int) Sog.Log.LogLevel.TraceDetail && TraceLog.IsSkipLogMsgID(packet.MsgID) == false) { TraceLog.TraceDetail("BattleMsgHandler.HandlerMessage recv message from server {0}, message type {1} length {2}: {3}->{4}" , ServerIDUtils.IDToString(remoteAppID) , message.Header.Type , message.Header.Length , packet.MessageName() , packet.ToString()); } switch (packet.MsgID) { case (int) SSGameMsgID.GmStopServerNotify: BattleServerUtils.GetApp().PrepareStop(); break; case (int) SSGameMsgID.ServerStopNotify: BattleServerUtils.GetBattleServerData().forceLeaveOnSvrStop = 1; break; case (int) SSGameMsgID.AddServerTimeSync: SysSvc.OnAddServerTimeSync(remoteAppID, packet); break; case (int)SSGameMsgID.BattleServerVersionReq: SysSvc.BattleServerVersionReq(remoteAppID, packet); break; case (int)SSGameMsgID.BattleBeginReq: OnBattleBeginReq(remoteAppID, packet); break; default: TraceLog.Error("BattleMsgHandler.HandlerMessage unknow MsgID {0}", packet.MsgID); break; } } public void OnBattleBeginReq(uint remoteAppID, StructPacket packet) { ref SSBattleBeginReq req = ref packet.GetMessage(); var battle = new BattleObj(ref req.BattleInfo); if (req.TestPropId == 0) { BattleInitSvc.InitBattle(battle); } else { //BattleInitSvc.InitTestBattle(battle, req.TestPropId); // 测试用 } //BattleControl.BattleBegin(battle); //试炼之塔胜利后通知服务器,随机战利品 // if(battle.battleInfo.MainlandType == (int)MainlandType.TowerOfTrials) // { // SSToweroftrialsWinSyn towerSyn = new SSToweroftrialsWinSyn(); // towerSyn.Uid = battle.battleInfo.RoleA.RoleBase.Uid; // towerSyn.Result = battle.Result == CSBattleResult.Succ ? 0 : 1; // towerSyn.BattleRound = battle.round; // BattleServerUtils.GetPacketSender().SendToServerByID(remoteAppID, // (int)SSGameMsgID.ToweroftrialsWinSyn, ref towerSyn, packet.ObjectID); // } var res = new SSBattleBeginRes {BattleInfo = battle.battleInfo, IsGM = req.IsGM}; BattleServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.BattleBeginRes, ref res, packet.ObjectID); } } }