/// <summary> /// 对时消息处理,分为server请求的和client请求的 /// </summary> /// <param name="sm"></param> public override void OnMessageReceived(SocketModel sm) { switch (sm.command) { case TimeProtocol.CHECK_SRES: DelayCheckDTO delayCheckDTO = sm.GetMessage <DelayCheckDTO>(); if (delayCheckDTO.timeStamps.Count <= delayCheckDTO.checkNum * 2) { //对时次数不够,就继续对够 delayCheckDTO.timeStamps.Add(DateTime.Now.Ticks); Send(TimeProtocol.CHECK_CREQ, delayCheckDTO); } if (delayCheckDTO.timeStamps.Count == delayCheckDTO.checkNum * 2 + 1) //这里的最后一个timestamp是client的 { //对时次数够了,计算时差和延迟 GameRuntimeData.delayAndFloating = GetDelayAndFloatingOdd(delayCheckDTO.timeStamps); MgrCenter.Instance.SendMsg(Msgs.GetMsgDelayAndFloating((ushort)NetEventTime.DelayGot, GameRuntimeData.delayAndFloating)); } break; case TimeProtocol.CHECK_SREQ: DelayCheckDTO delayCheck = sm.GetMessage <DelayCheckDTO>(); if (delayCheck.timeStamps.Count < delayCheck.checkNum * 2) { delayCheck.timeStamps.Add(DateTime.Now.Ticks); Send(TimeProtocol.CHECK_CRES, delayCheck); } else { //对时次数够了,计算时差和延迟,这里注意最后一个时间戳是server发来的,因此需要再把现在的时间加上再计算 delayCheck.timeStamps.Add(DateTime.Now.Ticks); GameRuntimeData.delayAndFloating = GetDelayAndFloatingEven(delayCheck.timeStamps); MgrCenter.Instance.SendMsg(Msgs.GetMsgDelayAndFloating((ushort)NetEventTime.DelayGot, GameRuntimeData.delayAndFloating)); } break; } }
internal void Load(BinaryReader br) { int ver = br.ReadInt32(); int count = br.ReadInt32(); lock (this) { while (count-- > 0) { string name = br.ReadString(); SoftCmd cmd = new SoftCmd(); cmd.Load(br); Cmds.Add(name, cmd); } count = br.ReadInt32(); while (count-- > 0) { ulong user = br.ReadUInt64(); Inbox inb = new Inbox(); inb.Load(br); Msgs.Add(user, inb); } ShowChanges = br.ReadBoolean(); count = br.ReadInt32(); while (count-- > 0) { string name = br.ReadString(); string value = br.ReadString(); Vars.Add(name, value); } SetLanguage(br.ReadString()); MusicChannel = ver >= 1 ? br.ReadString() : ""; CommandPrefix = ver >= 2 ? br.ReadString() : ">"; } }
/// <summary> /// 注册按钮 /// </summary> void OnRegisterClicked() { string accountStr = registerAccountInputField.text; string pwdStr = registerPwdInputField.text; string pwdAgainStr = registerPwdAgainInputField.text; if (string.IsNullOrEmpty(accountStr)) { errorPanel.Show("账号不能为空!"); return; } else if (accountStr.Length < 6) { errorPanel.Show("账号字符不能少于6个!"); return; } if (string.IsNullOrEmpty(pwdStr)) { errorPanel.Show("密码不能为空!"); return; } else if (pwdStr.Length < 8 || pwdStr.Length > 20) { errorPanel.Show("密码长度必须在8-20之间"); return; } else if (pwdStr != pwdAgainStr) { errorPanel.Show("重复密码不一致!"); return; } SendMsg(Msgs.GetMsgAccount((ushort)NetEventRegister.RegisterRequest, accountStr, pwdStr)); }
/// <summary> /// 显示伤害 /// </summary> /// <param name="damageCount"></param> /// <param name="isAlive"></param> public void Damage(int damageCount, bool isAlive) { fightInstance.hp -= damageCount; float percent = fightInstance.hp / fightInstance.fightModel.maxHp; MgrCenter.Instance.SendMsg(Msgs.GetMsgIntFloat((ushort)HUDEvent.UpdateHUDHp, fightInstance.instanceId, percent)); }
/// <summary> /// 根据服务器传来的数值,显示伤害 /// </summary> /// <param name="damageDTO"></param> private void Damage(DamageDTO damageDTO) { foreach (int[] damage in damageDTO.targetDamages) { SendMsg(Msgs.GetMsgIntArr((ushort)FightEvent.Damage, damage)); } }
// gets msgs public IActionResult ReceiveMsg(Msgs model) { // transfer from model string receiverID = model.userID; bool purge = model.purge; // build url string url = $"http://localhost:50225/Service1.svc/retrieve?x={receiverID}&y={purge}"; using (WebClient client = new WebClient()) { // try to download. try { // download information from url var json = client.DownloadString(url); // deserialize json string[] result = JsonConvert.DeserializeObject <string[]>(json); model.messages = new List <Msg>(); for (int i = 0; i < result.Length; i++) { Msg tmp = new Msg(); tmp.sendID = result[i]; tmp.timeStamp = result[++i]; tmp.msg = result[++i]; model.messages.Add(tmp); } model.success = true; } catch { model.success = false; } } return(View(model)); }
/// <summary> /// 加载一个建筑 /// </summary> /// <param name="buildingInstance"></param> /// <param name="isHost"></param> private void LoadBuilding(BuildingInstance buildingInstance, bool isHost) { int bKey = buildingInstance.fightModel.category.GetHashCode() + buildingInstance.fightModel.specieId.GetHashCode(); if (prefabNames.ContainsKey(bKey)) { string abAssetName = prefabNames[bKey]; string[] nameCompose = abAssetName.Split(' '); if (!instanceDic.ContainsKey(abAssetName)) { instanceDic.Add(abAssetName, new HashSet <AbsFightInstance>()); } if (!instanceDic[abAssetName].Contains(buildingInstance)) { instanceDic[abAssetName].Add(buildingInstance); } if (isHost && buildingInstance.teamId == GameRuntimeData.teamId) { hasAIDic.Add(buildingInstance.instanceId); } SendMsg(Msgs.GetMsgAssetLoadRequest((ushort)AssetLoadEvent.LoadRequest, nameCompose[0], nameCompose[1])); } }
protected override void CreateDeleteSql(BaseEntity entity, OleDbCommand cmd) { Msgs msgs = entity as Msgs; cmd.CommandText = "DELETE FROM Msgs WHERE ID=@ID"; cmd.Parameters.Add(new OleDbParameter("@ID", msgs.ID)); }
private IEnumerator missatges() { WWWForm form = new WWWForm(); var headers = form.headers; string credencials = PlayerPrefs.GetString("usuario") + ":" + PlayerPrefs.GetString("password"); headers["Authorization"] = "Basic " + Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credencials)); WWW www = new WWW(url, null, headers); yield return(www); // Print the error to the console if (www.error != null) { Debug.Log("request error: " + www.error); } else { // Debug.Log("request ok:" + www.text); Msgs msgs = JsonUtility.FromJson <Msgs>(www.text); t.text = ""; foreach (Msg m in msgs.data) { t.text += "<b>" + m.autor + "</b>" + "\t" + "<i>" + "<size=25>" + m.tiempo + "</size>" + "</i>" + "\n" + m.texto + "\n" + "\n"; } } }
/// <summary> /// 加载一个entity /// </summary> /// <param name="fightInstance"></param> /// <param name="isHost"></param> private void LoadEntity(AbsFightInstance fightInstance, bool isHost) { int key = fightInstance.fightModel.category.GetHashCode() + fightInstance.fightModel.specieId.GetHashCode(); if (prefabNames.ContainsKey(key)) { string abAssetName = prefabNames[key]; string[] nameCompose = abAssetName.Split(' '); if (!instanceDic.ContainsKey(abAssetName)) { instanceDic.Add(abAssetName, new HashSet <AbsFightInstance>()); } if (!instanceDic[abAssetName].Contains(fightInstance)) { instanceDic[abAssetName].Add(fightInstance); } if (isHost && fightInstance.teamId == GameRuntimeData.teamId) {//当本客户端是主机且这个实例是自己队伍的,那么这个实例运行AI hasAIDic.Add(fightInstance.instanceId); } SendMsg(Msgs.GetMsgAssetLoadRequest((ushort)AssetLoadEvent.LoadRequest, nameCompose[0], nameCompose[1])); } }
private float tmpDistance; //当前位置和预测位置的距离 private void FixedUpdate() { if (curActionStatus == ActionStatus.Moving) { tmpDistance = DistanceBetweenCurPosAndPredict(transform.position, lastSendPos, lastSendDir, Time.time - lastPosSyncTimestamp, Speed); //↓当[当前移动位置]超出[服务器预测位置]时提前发送同步包, 或者是到了同步时间,按定时同步频率发送 if (tmpDistance > Speed * 1.0f || Time.time >= lastPosSyncTimestamp + GameRuntimeData.PosSyncSecond) { lastSendDir = transform.eulerAngles; lastSendPos = transform.position; lastPosSyncTimestamp = Time.time; MgrCenter.Instance.SendMsg(Msgs.GetMsgPosSync((ushort)MoveEvent.PosSyncClientRequest, Id, lastSendPos, lastSendDir, DateTime.Now.Ticks)); } //↓如果已经到达小目标点 if ((!smallMoveAnswered) && Vector3.Distance(targetSmall, transform.position) <= this.Speed * GameRuntimeData.GetDelaySecond * 2.5f) { //↓但没有到达最终目标点,继续发送请求位置包 if (Vector3.Distance(curTargetPos, transform.position) > this.Speed * GameRuntimeData.GetDelaySecond * 2.5f) { MgrCenter.Instance.SendMsg(Msgs.GetMsgMoveRequest((ushort)MoveEvent.MoveClientRequest, Id, transform.position, curTargetPos)); } smallMoveAnswered = true; } } }
public void Close() { // Before destruct the object, delete the event handler. _synth.StateChanged -= SynthStateChanged; // Clear the notification queue. Msgs.Clear(); }
public void Add(Msg msg) { if (msg != null) { Msgs.Add(msg); } }
void OnLoginClicked() { string account = loginAccountInputField.text; string password = loginPasswordInputField.text; SendMsg(Msgs.GetMsgAccount((ushort)NetEventLogin.LoginRequest, account, password)); }
public override void ProcessEvent(MsgBase msg) { switch (msg.MsgId) { case (ushort)NetEventUser.HasNoUser: //没有角色,显示创建面板 ShowCreateUserPanel(); break; case (ushort)NetEventUser.GetUserInfo: //请求角色信息,并更新 MsgUserDTO msgUserDTO = msg as MsgUserDTO; UpdateUserInfo(msgUserDTO.userDTO); break; case (ushort)NetEventMatch.StartMatchSuccess: //开始匹配成功 ActiveMatchBtn(); break; case (ushort)NetEventMatch.CancelMatchSuccess: //取消匹配成功 ActiveMatchBtn(); break; case (ushort)NetEventUser.CreateUserFailed: //创建角色失败 errorPanel.Show("创建角色失败,已存在此角色"); break; case (ushort)NetEventUser.CreateUserSuccess: //创建角色成功 HideCreateUserPanel(); MgrCenter.Instance.SendMsg(Msgs.GetMsgBase((ushort)NetEventUser.RequestOnline)); break; } }
public void AddMaterial(List <MaterialItemData> items) { for (int i = 0; i < items.Count; i++) { Msgs.Add(items[i]); } RefreshDisplay(Msgs, false, true); }
public ActionResult DeleteConfirmed(int id) { Msgs msgs = db.Msgs.Find(id); db.Msgs.Remove(msgs); db.SaveChanges(); return(RedirectToAction("Index")); }
private void _client_message(string msg) { if (msg != null) { Msgs.Add(msg); NewMessage?.Invoke(msg); } }
/// <summary> /// 准备按钮 /// </summary> private void OnReadyPressed() { if (selectedHeroId != -1) { readyButton.GetComponent <Button>().enabled = false; SendMsg(Msgs.GetMsgBase((ushort)NetEventSelect.ReadyRequest)); } }
/// <summary> /// 请求发呆 /// </summary> /// <returns></returns> public behaviac.EBTStatus Idle() { if (curActionStatus != ActionStatus.StopAndDoingNothing) { curActionStatus = ActionStatus.StopAndDoingNothing; MgrCenter.Instance.SendMsg(Msgs.GetMsgInt((ushort)SoilderFightEvent.SoilderIdleClientRequest, this.Id)); } return(behaviac.EBTStatus.BT_SUCCESS); }
private Sprite[] headSprites;//英雄头像对应的Sprite /// <summary> /// 请求获取英雄头像Sprites /// </summary> private void GetHeroHeadSprites() { headSprites = new Sprite[spriteNames.Length]; for (int i = 0; i < spriteNames.Length; i++) { string[] nameCompose = spriteNames[i].Split('|'); SendMsg(Msgs.GetMsgAssetLoadRequest((ushort)AssetLoadEvent.LoadRequest, nameCompose[0], nameCompose[1])); } }
public double GetValue(string msg) { int index = Msgs.FindIndex(el => el == msg); if (index >= 0) { CurrentIndex = index; } return(Values[CurrentIndex]); }
public string GetGroup(string msg) { int index = Msgs.FindIndex(el => el == msg); if (index >= 0) { CurrentIndex = index; } return(Groups[CurrentIndex]); }
public string GetAngle(string msg) { int index = Msgs.FindIndex(el => el == msg); if (index >= 0) { CurrentIndex = index; } return(Angles[CurrentIndex]); }
protected override void CreateUpdateSql(BaseEntity entity, OleDbCommand cmd) { Msgs msg = entity as Msgs; cmd.CommandText = "UPDATE Msgs SET Txt=@Txt,Sender=@Sender,TxtDate=@TxtDate,GroupID=@GroupID WHERE ID=@ID"; cmd.Parameters.Add(new OleDbParameter("@Txt", msg.Txt)); cmd.Parameters.Add(new OleDbParameter("@Sender", msg.Sender)); cmd.Parameters.Add(new OleDbParameter("@TxtDate", msg.TxtDate)); cmd.Parameters.Add(new OleDbParameter("@GroupID", msg.GroupID)); }
/// <summary> /// 请求向一个目标移动 /// </summary> /// <param name="target"></param> /// <returns></returns> public behaviac.EBTStatus MoveToTarget(FightAgent target) { if (curActionStatus != ActionStatus.Moving) { curActionStatus = ActionStatus.Moving; curTargetPos = target.transform.position; MgrCenter.Instance.SendMsg(Msgs.GetMsgMoveRequest((ushort)MoveEvent.MoveClientRequest, Id, transform.position, curTargetPos)); } return(behaviac.EBTStatus.BT_RUNNING); }
protected override void CreateInsertSql(BaseEntity entity, OleDbCommand cmd) { Msgs msg = entity as Msgs; cmd.CommandText = "INSERT INTO Msgs (Txt, Sender, TxtDate, GroupID) VALUES (@Txt,@Sender,@TxtDate,@GroupID)"; cmd.Parameters.Add(new OleDbParameter("@Txt", msg.Txt)); cmd.Parameters.Add(new OleDbParameter("@Sender", msg.Sender)); cmd.Parameters.Add(new OleDbParameter("@TxtDate", msg.TxtDate)); cmd.Parameters.Add(new OleDbParameter("@GroupID", msg.GroupID)); //cmd.Parameters.Add(new OleDbParameter("@SYears", person.SYears)); }
private FightRoomDTO fightRoomDTO = null;//缓存战斗房间信息 /// <summary> /// 处理网络消息 /// </summary> /// <param name="sm"></param> public override void OnMessageReceived(SocketModel sm) { switch (sm.command) { case FightProtocol.START_BRO: fightRoomDTO = sm.GetMessage <FightRoomDTO>(); CreateBattelField(fightRoomDTO); Debug.LogError("收到创建战场信息"); break; case FightProtocol.ATK_TO_POS_SCMD: PosDTO atkToPosDTO = sm.GetMessage <PosDTO>(); MgrCenter.Instance.SendMsg(Msgs.GetMsgPos((ushort)SoilderFightEvent.SoilderAtkToPosServerCmd, atkToPosDTO)); break; case FightProtocol.MOVE_TARGET_SRES: PosDTO moveToTargetDTO = sm.GetMessage <PosDTO>(); MgrCenter.Instance.SendMsg(Msgs.GetMsgPos((ushort)MoveEvent.MoveServerRes, moveToTargetDTO)); break; case FightProtocol.SKILL_UP_SRES: break; case FightProtocol.POS_SYNC_BRO: PosSyncDTO posSyncDTO = sm.GetMessage <PosSyncDTO>(); //得到的PosSync是服务器处理时认可的服务器时间 //这里将它转化成client认可的时间 //floating = client - server //client = server + floating long timeStampClient = GetTimeStampClient(posSyncDTO.timeStamp); MgrCenter.Instance.SendMsg(Msgs.GetMsgPosSync((ushort)MoveEvent.PosSync, posSyncDTO.instanceId, new Vector3(posSyncDTO.x, posSyncDTO.y, posSyncDTO.z), new Vector3(posSyncDTO.dirX, posSyncDTO.dirY, posSyncDTO.dirZ), timeStampClient)); break; case FightProtocol.SKILL_BRO: break; case FightProtocol.ATTACK_BRO: break; case FightProtocol.DAMAGE_BRO: Damage(sm.GetMessage <DamageDTO>()); break; case FightProtocol.IDLE_BRO: int idleEntityId = sm.GetMessage <int>(); MgrCenter.Instance.SendMsg(Msgs.GetMsgInt((ushort)SoilderFightEvent.SoilderIdleServerAllow, idleEntityId)); break; } }
/// <summary> /// 创建战场所需的entity和建筑entity /// </summary> /// <param name="fightRoomDTO"></param> private void CreateBattelField(FightRoomDTO fightRoomDTO) { foreach (BuildingInstance building in fightRoomDTO.buildingEntities) { SendMsg(Msgs.GetMsgBuildingCreate((ushort)EntityEnum.CreateBuilding, building, fightRoomDTO.isHost)); } foreach (AbsFightInstance creature in fightRoomDTO.entities) { SendMsg(Msgs.GetMsgNPCCreate((ushort)EntityEnum.CreateEntity, creature, fightRoomDTO.isHost)); } }
protected override BaseEntity CreateModel(BaseEntity entity) { Msgs msg = entity as Msgs; msg.ID = (int)reader["ID"]; PersonDB db = new PersonDB(); msg.Sender = db.SelectById((int)reader["Sender"]); msg.Txt = reader["Txt"].ToString(); msg.TxtDate = (DateTime)reader["TxtDate"]; msg.GroupID = (int)reader["GroupID"]; return(msg); }
//MsgBox_Yes_No_Cancel private static DialogResult CHRM_MsgBox_Yes_No_Cancel(string i_strMsg, string i_titleMsg, Msgs.MsgIconType i_IconType) { DialogResult v_Result = default(DialogResult); switch(i_IconType) { case Msgs.MsgIconType.ErrorIcon: v_Result = XtraMessageBox.Show(i_strMsg, i_titleMsg, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error); break; case Msgs.MsgIconType.InfomationIcon: v_Result = XtraMessageBox.Show(i_strMsg, i_titleMsg, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); break; case Msgs.MsgIconType.QuestionIcon: v_Result = XtraMessageBox.Show(i_strMsg, i_titleMsg, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); break; case Msgs.MsgIconType.WarningIcon: v_Result = XtraMessageBox.Show(i_strMsg, i_titleMsg, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); break; } return v_Result; }
// MsgBox_OK private static void CHRM_MsgBox_OK(string i_strMsg, string i_titleMsg, Msgs.MsgIconType i_IconType) { switch(i_IconType) { case Msgs.MsgIconType.ErrorIcon: XtraMessageBox.Show(i_strMsg, i_titleMsg, MessageBoxButtons.OK, MessageBoxIcon.Error); break; case Msgs.MsgIconType.InfomationIcon: XtraMessageBox.Show(i_strMsg, i_titleMsg, MessageBoxButtons.OK, MessageBoxIcon.Information); break; case Msgs.MsgIconType.QuestionIcon: XtraMessageBox.Show(i_strMsg, i_titleMsg, MessageBoxButtons.OK, MessageBoxIcon.Question); break; case Msgs.MsgIconType.WarningIcon: XtraMessageBox.Show(i_strMsg, i_titleMsg, MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } }