void handleMsg(KBEngine.Packet packet) { var receivePkg = packet.protoBody.GetType().FullName; Debug.Log("Server Receive " + receivePkg); var className = receivePkg.Split(char.Parse(".")) [1]; IBuilderLite retPb = null; uint flowId = packet.flowId; bool findHandler = false; if (className == "CGAutoRegisterAccount") { var au = GCAutoRegisterAccount.CreateBuilder(); au.Username = "******"; retPb = au; } else if (className == "CGRegisterAccount") { var au = GCRegisterAccount.CreateBuilder(); retPb = au; } else if (className == "CGLoginAccount") { var au = GCLoginAccount.CreateBuilder(); var playerInfo = ServerData.Instance.playerInfo; if (playerInfo.HasRoles) { var role = RolesInfo.CreateBuilder().MergeFrom(playerInfo.Roles); au.AddRolesInfos(role); } retPb = au; } else if (className == "CGSelectCharacter") { var inpb = packet.protoBody as CGSelectCharacter; if (inpb.PlayerId == 101) { selectPlayerJob = 4; } else if (inpb.PlayerId == 102) { selectPlayerJob = 2; } else { selectPlayerJob = 1; } var au = GCSelectCharacter.CreateBuilder(); au.TokenId = "12345"; retPb = au; } else if (className == "CGBindingSession") { var au = GCBindingSession.CreateBuilder(); au.X = 22; au.Y = 1; au.Z = 17; au.Direction = 10; au.MapId = 0; au.DungeonBaseId = 0; au.DungeonId = 0; retPb = au; } else if (className == "CGEnterScene") { var inpb = packet.protoBody as CGEnterScene; var au = GCEnterScene.CreateBuilder(); au.Id = inpb.Id; retPb = au; } else if (className == "CGListBranchinges") { var au = GCListBranchinges.CreateBuilder(); var bran = Branching.CreateBuilder(); bran.Line = 1; bran.PlayerCount = 2; au.AddBranching(bran); retPb = au; } else if (className == "CGHeartBeat") { } else if (className == "CGCopyInfo") { var pinfo = ServerData.Instance.playerInfo; if (pinfo.HasCopyInfos) { retPb = GCCopyInfo.CreateBuilder().MergeFrom(pinfo.CopyInfos); } else { //First Fetch Login Info var au = GCCopyInfo.CreateBuilder(); var cin = CopyInfo.CreateBuilder(); cin.Id = 101; cin.IsPass = false; au.AddCopyInfo(cin); var msg = au.Build(); pinfo.CopyInfos = msg; retPb = GCCopyInfo.CreateBuilder().MergeFrom(msg); } } else if (className == "CGUserDressEquip") { PlayerData.UserDressEquip(packet); findHandler = true; } else if (className == "CGAutoRegisterAccount") { var au = GCAutoRegisterAccount.CreateBuilder(); au.Username = "******" + random.Next(); retPb = au; } else if (className == "CGRegisterAccount") { var inpb = packet.protoBody as CGRegisterAccount; ServerData.Instance.playerInfo.Username = inpb.Username; var au = GCRegisterAccount.CreateBuilder(); retPb = au; } else if (className == "CGPlayerMove") { var au = GCPlayerMove.CreateBuilder(); retPb = au; } else { var fullName = packet.protoBody.GetType().FullName; var handlerName = fullName.Replace("MyLib", "ServerPacketHandler"); var tp = Type.GetType(handlerName); if (tp == null) { if (ServerPacketHandler.HoldCode.staticTypeMap.ContainsKey(handlerName)) { tp = ServerPacketHandler.HoldCode.staticTypeMap [handlerName]; } } if (tp == null) { Debug.LogError("PushMessage noHandler " + handlerName); } else { findHandler = true; var ph = (ServerPacketHandler.IPacketHandler)Activator.CreateInstance(tp); ph.HandlePacket(packet); } } if (retPb != null) { SendPacket(retPb, flowId); } else { if (className != "CGHeartBeat" && !findHandler) { Debug.LogError("DemoServer::not Handle Message " + className); } } }
void handleMsg(KBEngine.Packet packet) { var receivePkg = packet.protoBody.GetType().FullName; Debug.Log("Server Receive " + receivePkg); var className = receivePkg.Split(char.Parse(".")) [1]; IBuilderLite retPb = null; uint flowId = packet.flowId; bool findHandler = false; if (className == "CGAutoRegisterAccount") { var au = GCAutoRegisterAccount.CreateBuilder(); au.Username = "******"; retPb = au; } else if (className == "CGRegisterAccount") { var au = GCRegisterAccount.CreateBuilder(); retPb = au; } else if (className == "CGLoginAccount") { var au = GCLoginAccount.CreateBuilder(); var playerInfo = ServerData.Instance.playerInfo; if (playerInfo.HasRoles) { var role = RolesInfo.CreateBuilder().MergeFrom(playerInfo.Roles); au.AddRolesInfos(role); } retPb = au; } else if (className == "CGSelectCharacter") { var inpb = packet.protoBody as CGSelectCharacter; if (inpb.PlayerId == 101) { selectPlayerJob = 4; } else if (inpb.PlayerId == 102) { selectPlayerJob = 2; } else { selectPlayerJob = 1; } var au = GCSelectCharacter.CreateBuilder(); au.TokenId = "12345"; retPb = au; } else if (className == "CGBindingSession") { var au = GCBindingSession.CreateBuilder(); au.X = 22; au.Y = 1; au.Z = 17; au.Direction = 10; au.MapId = 0; au.DungeonBaseId = 0; au.DungeonId = 0; retPb = au; } else if (className == "CGEnterScene") { var inpb = packet.protoBody as CGEnterScene; var au = GCEnterScene.CreateBuilder(); au.Id = inpb.Id; retPb = au; } else if (className == "CGListBranchinges") { var au = GCListBranchinges.CreateBuilder(); var bran = Branching.CreateBuilder(); bran.Line = 1; bran.PlayerCount = 2; au.AddBranching(bran); retPb = au; } else if (className == "CGHeartBeat") { } else if (className == "CGLoadSaleItems") { var au = GCLoadSaleItems.CreateBuilder(); retPb = au; } else if (className == "CGListAllTeams") { var au = GCListAllTeams.CreateBuilder(); retPb = au; } else if (className == "CGCopyInfo") { var pinfo = ServerData.Instance.playerInfo; if (pinfo.HasCopyInfos) { retPb = GCCopyInfo.CreateBuilder().MergeFrom(pinfo.CopyInfos); } else { //First Fetch Login Info var au = GCCopyInfo.CreateBuilder(); var cin = CopyInfo.CreateBuilder(); cin.Id = 101; cin.IsPass = false; au.AddCopyInfo(cin); var msg = au.Build(); pinfo.CopyInfos = msg; retPb = GCCopyInfo.CreateBuilder().MergeFrom(msg); } } else if (className == "CGLoadVipLevelGiftReceiveInfo") { var au = GCLoadVipLevelGiftReceiveInfo.CreateBuilder(); var vip = ReceviedReward.CreateBuilder(); vip.RewardId = 1; au.AddReceviedLevelRewards(vip); vip = ReceviedReward.CreateBuilder(); vip.RewardId = 2; au.AddReceviedLevelRewards(vip); vip = ReceviedReward.CreateBuilder(); vip.RewardId = 3; au.AddReceviedLevelRewards(vip); retPb = au; } else if (className == "CGLoadVipInfo") { var au = GCLoadVipInfo.CreateBuilder(); au.VipType = VipType.NONE_VIP; au.VipRemainTime = 0; au.VipLevel = 4; au.VipExp = 0; retPb = au; } else if (className == "CGLoadTaskList") { var au = GCLoadTaskList.CreateBuilder(); var task = PlayerTask.CreateBuilder(); task.TaskId = 1; task.PlayerTaskId = 1; task.PlayerId = 2; task.TaskState = 5; task.Chain = 6; au.AddPlayerTask(task); task = PlayerTask.CreateBuilder(); task.TaskId = 2; task.PlayerTaskId = 1; task.PlayerId = 2; task.TaskState = 5; task.Chain = 6; au.AddPlayerTask(task); task = PlayerTask.CreateBuilder(); task.TaskId = 3; task.PlayerTaskId = 1; task.PlayerId = 2; task.TaskState = 5; task.Chain = 6; au.AddPlayerTask(task); retPb = au; } else if (className == "CGLoadAchievements") { var au = GCLoadAchievements.CreateBuilder(); var ac = Achievement.CreateBuilder(); ac.AchievementId = 1000; au.AddAchievements(ac); ac = Achievement.CreateBuilder(); ac.AchievementId = 1001; au.AddAchievements(ac); ac = Achievement.CreateBuilder(); ac.AchievementId = 1002; au.AddAchievements(ac); ac = Achievement.CreateBuilder(); ac.AchievementId = 1003; au.AddAchievements(ac); ac = Achievement.CreateBuilder(); ac.AchievementId = 1004; au.AddAchievements(ac); retPb = au; } else if (className == "CGAuctionInfo") { var au = GCAuctionInfo.CreateBuilder(); au.MaxSize = 1; au.PageSize = 6; var item = AuctionItem.CreateBuilder(); item.Id = 11; item.BaseId = 14; item.Type = 1; item.SellCount = 2; item.RemainTime = 60; item.TotalCost = 88; au.AddAuctionItems(item); item = AuctionItem.CreateBuilder(); item.Id = 119; item.BaseId = 15; item.Type = 1; item.SellCount = 2; item.RemainTime = 609; item.TotalCost = 889; au.AddAuctionItems(item); item = AuctionItem.CreateBuilder(); item.Id = 118; item.BaseId = 16; item.Type = 1; item.SellCount = 2; item.RemainTime = 608; item.TotalCost = 888; au.AddAuctionItems(item); item = AuctionItem.CreateBuilder(); item.Id = 117; item.BaseId = 23; item.Type = 1; item.SellCount = 2; item.RemainTime = 607; item.TotalCost = 887; au.AddAuctionItems(item); item = AuctionItem.CreateBuilder(); item.Id = 116; item.BaseId = 24; item.Type = 1; item.SellCount = 2; item.RemainTime = 605; item.TotalCost = 886; au.AddAuctionItems(item); item = AuctionItem.CreateBuilder(); item.Id = 115; item.BaseId = 25; item.Type = 1; item.SellCount = 2; item.RemainTime = 605; item.TotalCost = 88; au.AddAuctionItems(item); retPb = au; } else if (className == "CGUserDressEquip") { PlayerData.UserDressEquip(packet); findHandler = true; } else if (className == "CGAutoRegisterAccount") { var au = GCAutoRegisterAccount.CreateBuilder(); au.Username = "******" + random.Next(); retPb = au; } else if (className == "CGRegisterAccount") { var inpb = packet.protoBody as CGRegisterAccount; ServerData.Instance.playerInfo.Username = inpb.Username; var au = GCRegisterAccount.CreateBuilder(); retPb = au; } else if (className == "CGPlayerMove") { var au = GCPlayerMove.CreateBuilder(); retPb = au; } else { var fullName = packet.protoBody.GetType().FullName; var handlerName = fullName.Replace("ChuMeng", "ServerPacketHandler"); var tp = Type.GetType(handlerName); if (tp == null) { if (ServerPacketHandler.HoldCode.staticTypeMap.ContainsKey(handlerName)) { tp = ServerPacketHandler.HoldCode.staticTypeMap [handlerName]; } } if (tp == null) { Debug.LogError("PushMessage noHandler " + handlerName); } else { findHandler = true; var ph = (ServerPacketHandler.IPacketHandler)Activator.CreateInstance(tp); ph.HandlePacket(packet); } } if (retPb != null) { SendPacket(retPb, flowId); } else { if (className != "CGHeartBeat" && !findHandler) { Debug.LogError("DemoServer::not Handle Message " + className); } } }