public void OnChangeingWeaponMessage(MessageChangingWeapon message) { if (message.TargetID != MyID) { clients [message.TargetID].unit.GetComponent <InfantryBasement> ().ChangingWeapon(message.ChangedWeapon); } }
public void ChangingWeaponRequest(int WeaponSlot) { MessageChangingWeapon weapon = new MessageChangingWeapon(); weapon.ChangedWeapon = WeaponSlot; weapon.TargetID = MyID; SendMessage(weapon); }
public void FiringMessage(string s) { string[] message = s.Split('$'); foreach (string text in message) { try { if (text.Length < 4) { return; } MessageBase TempBase = JsonUtility.FromJson <MessageBase> (text); MessageBase MsgBase = (MessageBase)JsonUtility.FromJson(text, Type.GetType(TempBase.ProtoName)); //批发处理 if (typeof(MessageMove).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageMove move = (MessageMove)MsgBase; OnMoveMessage(move); } else if (typeof(MessageAttack).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageAttack attack = (MessageAttack)MsgBase; OnAttackMessage(attack); } else if (typeof(MessageBuildingAttack).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageBuildingAttack attack = (MessageBuildingAttack)MsgBase; OnBuildingAttackMessage(attack); } else if (typeof(MessageBuildingFocusing).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageBuildingFocusing focus = (MessageBuildingFocusing)MsgBase; OnBuildingFocusMessage(focus); } else if (typeof(MessageInteractiveStart).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageInteractiveStart interactive = (MessageInteractiveStart)MsgBase; OnInteractiveStartMessage(interactive); } else if (typeof(MessageInteractiveExit).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageInteractiveExit interactive = (MessageInteractiveExit)MsgBase; OnInteractiveExitMessage(interactive); } else if (typeof(MessageRespawnConstruction).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageRespawnConstruction respawn = (MessageRespawnConstruction)MsgBase; OnConstructionRespawn(respawn); } else if (typeof(MessageChangingWeapon).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageChangingWeapon Stats = (MessageChangingWeapon)MsgBase; OnChangeingWeaponMessage(Stats); } else if (typeof(MessageDamage).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageDamage Stats = (MessageDamage)MsgBase; OnDamageMessage(Stats); } else if (typeof(MessagePlayerDead).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessagePlayerDead dead = (MessagePlayerDead)MsgBase; OnPlayerDeadMessage(dead); } else if (typeof(MessageClientsStats).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageClientsStats Stats = (MessageClientsStats)MsgBase; OnNewClientMessage(Stats); } else if (typeof(MessageRespawnPlayer).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageRespawnPlayer respawn = (MessageRespawnPlayer)MsgBase; OnRespawnPlayer((MessageRespawnPlayer)MsgBase); } else if (typeof(MessageLeaveGame).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageLeaveGame leave = (MessageLeaveGame)MsgBase; OnPlayerLeaveGame(leave); } else if (typeof(MessageChat).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageChat chat = (MessageChat)MsgBase; OnPlayerChatting(chat); } else { Debug.Log("未知数据类型,该数据为:" + MsgBase.ToString() + ",记得处理!"); } }catch (ArgumentException ex) { }catch (Exception ex) { Debug.LogError("协议包无法解析!出错报告为:" + ex.ToString()); Debug.LogError("数据包为:" + text); } } }
public void OnChangingWeaponMessage(MessageChangingWeapon message) { string s = JsonUtility.ToJson(message); BroadcastingMessage(s); }
public void DecodeMessage(Socket sender, byte[] Message, int count) { string message = System.Text.Encoding.Default.GetString(Message); // string[] s = message.Split ('"'); // string type = s [3]; // //判断数据类型 // //TODO 你永远也更新不完 // if (type == "MessageMove") { // try { // MessageMove move = (MessageMove)JsonUtility.FromJson (message, Type.GetType (s [3])); // OnMoveMessage (move); // } catch { // Debug.Log (message); // } // } else if (type == "MessageAttack") { // MessageAttack Attack = (MessageAttack)JsonUtility.FromJson (message, Type.GetType (s [3])); // OnAttackMessage (Attack); // } else if (type == "MessageChangingWeapon") { // MessageChangingWeapon change = (MessageChangingWeapon)JsonUtility.FromJson (message, Type.GetType (s [3])); // OnChangingWeaponMessage (change); // } // else if (type == "MessageDamage") // { // MessageDamage Damage = (MessageDamage)JsonUtility.FromJson(message, Type.GetType(s[3])); // OnDamageMessage(Damage); // } // else if (type == "MessagePlayerDead") // { // MessagePlayerDead dead = (MessagePlayerDead)JsonUtility.FromJson(message, Type.GetType(s[3])); // OnPlayerDeadMessage(dead); // } // else if (type == "MessageClientsStats") // { // MessageClientsStats Stats = (MessageClientsStats)JsonUtility.FromJson(message, Type.GetType(s[3])); // OnNewClientMessage(Stats); // } // else if (type == "MessageRespawnPlayer") // { // MessageRespawnPlayer respawn = (MessageRespawnPlayer)JsonUtility.FromJson(message, Type.GetType(s[3])); // OnRespawnPlayer(respawn); // } string[] s = message.Split('$'); foreach (string text in s) { try { MessageBase TempBase = JsonUtility.FromJson <MessageBase> (text); MessageBase MsgBase = (MessageBase)JsonUtility.FromJson(text, Type.GetType(TempBase.ProtoName)); if (typeof(MessageMove).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageMove move = (MessageMove)MsgBase; OnMoveMessage(move); } else if (typeof(MessageAttack).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageAttack attack = (MessageAttack)MsgBase; OnAttackMessage(attack); } else if (typeof(MessageBuildingAttack).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageBuildingAttack attack = (MessageBuildingAttack)MsgBase; OnBuildingAttackMessage(attack); } else if (typeof(MessageBuildingFocusing).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageBuildingFocusing focus = (MessageBuildingFocusing)MsgBase; OnBuildingFocusingMessage(focus); } else if (typeof(MessageInteractiveStart).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageInteractiveStart interactive = (MessageInteractiveStart)MsgBase; OnInteractiveStartMessage(interactive); } else if (typeof(MessageInteractiveExit).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageInteractiveExit interactive = (MessageInteractiveExit)MsgBase; OnInteractiveExitMessage(interactive); } else if (typeof(MessageChangingWeapon).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageChangingWeapon Stats = (MessageChangingWeapon)MsgBase; OnChangingWeaponMessage(Stats); } else if (typeof(MessageDamage).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageDamage Stats = (MessageDamage)MsgBase; OnDamageMessage(Stats); } else if (typeof(MessagePlayerDead).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessagePlayerDead dead = (MessagePlayerDead)MsgBase; OnPlayerDeadMessage(dead); } else if (typeof(MessageClientsStats).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageClientsStats Stats = (MessageClientsStats)MsgBase; OnNewClientMessage(sender, Stats); } else if (typeof(MessageRespawnPlayer).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageRespawnPlayer respawn = (MessageRespawnPlayer)MsgBase; OnRespawnPlayer(respawn); } else if (typeof(MessageRespawnConstruction).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageRespawnConstruction respawn = (MessageRespawnConstruction)MsgBase; OnConstructionRespawn(respawn); } else if (typeof(MessageChat).IsAssignableFrom(Type.GetType(MsgBase.ProtoName))) { MessageChat chat = (MessageChat)MsgBase; OnChattingMessage(chat); } else { Debug.Log("未知数据类型,该数据为:" + text + ",服务器已做丢包处理.或者说,你忘记处理了?"); } }catch (ArgumentException ex) { }catch (Exception ex) { Debug.LogError("协议包无法解析!出错报告为:" + ex.ToString()); Debug.LogError("数据包为:" + text); } } }