private void ProcessJoinClient() { var per = State.Perception as BattlePerception; var view = per.View as GameViews.BattlePerceptionView; lock (syncRoot) { //send Init message. while (_addTemp.Count > 0) { var client = _addTemp.Dequeue(); Clients.Add((long)client.UserState, client); BattlePlayer battlePlayer; //package if (BattlePlayers.TryToGetValue((long)client.UserState, out battlePlayer)) { var package = battlePlayer.GetNotifyPackage(); package.TimeNow = (Now.Time); client.SendMessage(NetProtoTool.ToNetMessage(MessageClass.Notify, package)); } var createNotify = view.GetInitNotify(); var messages = ToMessages(createNotify); //Notify package foreach (var i in messages) { client.SendMessage(i); } } while (_kickUsers.Count > 0) { //kick var u = _kickUsers.Dequeue(); BattlePlayers.Remove(u); Clients.Remove(u); per.State.Each <BattleCharacter>((el) => { if (el.UserID == u) { GObject.Destory(el); } return(false); }); } } }
//处理掉落 private void DoDrop() { if (drop == null) { return; } var items = drop.DropItem.SplitToInt(); var pors = drop.Pro.SplitToInt(); foreach (var i in this.BattlePlayers) { var notify = new Notify_Drop(); notify.UserID = i.Value.User.UserID; var gold = GRandomer.RandomMinAndMax(drop.GoldMin, drop.GoldMax); notify.Gold = gold; i.Value.AddGold(gold); if (items.Count > 0) { for (var index = 0; index < items.Count; index++) { if (GRandomer.Probability10000(pors[index])) { i.Value.AddDrop(items[index], 1); notify.Items.Add(new PlayerItem { ItemID = items[index], Num = 1 }); } } } Client client; if (this.Clients.TryToGetValue(i.Value.User.UserID, out client)) { var message = NetProtoTool.ToNetMessage(MessageClass.Notify, notify); client.SendMessage(message); } } }
public override L2C_Login DoResponse(C2L_Login request, Client client) { if (!ProtoTool.CompareVersion(request.Version)) { return(new L2C_Login { Code = ErrorCode.VersionError }); } using (var db = Appliaction.Current.GetDBContext()) { var pwd = DBTools.GetPwd(request.Password, db); var query = db.TbaCCount .Where(t => t.UserName == request.UserName && t.Password == pwd) .SingleOrDefault(); if (query == null) { return(new L2C_Login { Code = ErrorCode.LoginFailure }); } else { var session = DateTime.UtcNow.Ticks.ToString(); Appliaction.Current.SetSession(query.ID, session); query.LastLoginDateTime = DateTime.UtcNow; query.LoginCount += 1; db.SubmitChanges(); var mapp = ServerManager.Singleton.GetGateServerMappingByServerID(query.ServerID); if (mapp == null) { return(new L2C_Login { Code = ErrorCode.NOFoundServerID }); } UserServerInfo info; if (BattleManager.Singleton.GetBattleServerByUserID(query.ID, out info)) { var task = new Task_L2B_ExitUser { UserID = query.ID }; var server = ServerManager.Singleton.GetBattleServerMappingByServerID(info.BattleServerID); if (server != null) { var connection = Appliaction.Current.GetServerConnectByClientID(server.ClientID); if (connection != null) { var message = NetProtoTool.ToNetMessage(MessageClass.Task, task); connection.SendMessage(message); } } } return(new L2C_Login { Code = ErrorCode.OK, Server = mapp.ServerInfo, Session = session, UserID = query.ID }); } } }
private List <Message> ToMessages(ISerializerable[] notify) { return(notify.Select(t => NetProtoTool.ToNetMessage(MessageClass.Notify, t)).ToList()); }