static void ExecuteDecodedMessage(object obj, int messageCount, Protocol.MessageType messageType) { switch (messageType) { case Protocol.MessageType.GRID_POSITIONS: Grid grid = obj as Grid; BattleController.instance.SetBoatsTheirs(grid.playerUniqueId, grid.boats); break; case Protocol.MessageType.AIM_AT: if (messageCount < lastAimMessageReceiveCount) { Debug.LogWarning("***Ignoring out of order uneliable message " + messageType + " #" + messageCount); return; } lastAimMessageReceiveCount = messageCount; Position aimPosition = obj as Position; BattleController.instance.AimAt(Whose.Ours, aimPosition); break; case Protocol.MessageType.ROCKET_LAUNCH: Position targetPosition = obj as Position; BattleController.instance.LaunchRocket(Whose.Ours, targetPosition); break; default: throw new NotImplementedException("Unknown message type " + messageType); } }
public static void DecodeAndExecute(ref byte[] bytes, bool reliable) { IBattleSerializable obj; int messageCount; Protocol.MessageType messageType = Protocol.Decode(ref bytes, reliable, out obj, out messageCount); ExecuteDecodedMessage(obj, messageCount, messageType); }
static void EncodeAndSend(Protocol.MessageType messageType, IBattleSerializable obj, bool reliable) { byte[] bytes = Protocol.Encode(messageType, obj, reliable); if (!Application.isEditor || messageType == Protocol.MessageType.GRID_POSITIONS) { Debug.Log("***EncodeAndSend(" + (reliable ? "RELIABLE " : "") + "'" + messageType + "':" + bytes.Length + "bytes)"); } Game.instance.SendMessageToAll(reliable, ref bytes); }
public static float GetMessageDelay(Protocol.MessageType messageType) { switch (messageType) { case Protocol.MessageType.AIM_AT: return(2f); case Protocol.MessageType.GRID_POSITIONS: return(.2f); case Protocol.MessageType.ROCKET_LAUNCH: return(2f * BattleController.instance.rocketFlightTime); default: throw new NotImplementedException(); } }